Exemplo n.º 1
0
    def __init__(self, x, y, level, screen, dashboard, sound, gravity=0.75):
        super(Mario, self).__init__(x, y, gravity)
        self.spriteCollection = Sprites().spriteCollection
        self.camera = Camera(self.rect, self)
        self.sound = sound
        self.input = Input(self)
        self.inAir = False
        self.inJump = False
        self.animation = Animation(
            [
                self.spriteCollection["mario_run1"].image,
                self.spriteCollection["mario_run2"].image,
                self.spriteCollection["mario_run3"].image,
            ],
            self.spriteCollection["mario_idle"].image,
            self.spriteCollection["mario_jump"].image,
        )

        self.traits = {
            "jumpTrait": jumpTrait(self),
            "goTrait": goTrait(self.animation, screen, self.camera, self),
            "bounceTrait": bounceTrait(self),
        }

        self.levelObj = level
        self.collision = Collider(self, level)
        self.screen = screen
        self.EntityCollider = EntityCollider(self)
        self.dashboard = dashboard
        self.restart = False
        self.pause = False
        self.pauseObj = Pause(screen, self, dashboard)
Exemplo n.º 2
0
    def __init__(self, screen, x, y, color):
        # Super initializer
        super(Object, self).__init__(x, y)

        # Input class instance
        self.input = Input(self)

        self.screen = screen
        self.color = color
        self.speed = 0

        # Traits
        self.traits = {"goTrait": goTrait(self.screen, self, self.speed)}
Exemplo n.º 3
0
    def __init__(self, speed, screen, x, y):
        # Super initializer
        super(Player, self).__init__(x, y)

        # Properties
        # Input class instance
        self.input = Input(self)

        self.screen = screen
        self.speed = speed

        # Traits
        self.traits = {"goTrait": goTrait(self.screen, self, self.speed)}
Exemplo n.º 4
0
    def __init__(self, x, y, level, gravity=1.25):
        super(MarioHeadless, self).__init__(x, y, gravity)
        self.input = Input(self)

        self.traits = {
            "jumpTrait": jumpTrait(self),
            "goTrait": goTraitHeadless(self),
            "bounceTrait": bounceTrait(self)
        }

        self.levelObj = level
        self.collision = Collider(self, level)
        self.EntityCollider = EntityCollider(self)
        self.restart = False
Exemplo n.º 5
0
    def __init__(self, screen, x, y):
        # Super initializer
        super(Background, self).__init__(x, y)

        # Input class instance
        self.input = Input(self)

        # Properties
        self.img = pygame.transform.rotozoom(
            pygame.image.load("imgs\grass2.png"), 0, 10)
        self.screen = screen
        self.speed = 0

        # Traits
        self.traits = {"goTrait": goTrait(self.screen, self, self.speed)}
Exemplo n.º 6
0
    def __init__(self, x, y, level, screen, dashboard, sound, gravity=0.75):
        super(Mario, self).__init__(x, y, gravity)
        self.x = x
        self.spriteCollection = Sprites().spriteCollection
        self.CT = CollisionTester()
        self.camera = Camera(self.rect, self)
        self.sound = sound
        self.level = level
        self.OI = Input(self)
        self.closest_mob = None
        self.closest_object = None
        self.output =0
        self.inAir = False
        self.brain = Model().share_memory()
        self.fitness = 0

        self.animation = Animation(
            [
                self.spriteCollection["mario_run1"].image,
                self.spriteCollection["mario_run2"].image,
                self.spriteCollection["mario_run3"].image,
            ],
            self.spriteCollection["mario_idle"].image,
            self.spriteCollection["mario_jump"].image,
        )

        self.traits = {
            "jumpTrait": jumpTrait(self),
            "goTrait": goTrait(self.animation, screen, self.camera, self),
            "bounceTrait": bounceTrait(self),
        }

        self.levelObj = level
        self.collision = Collider(self, level)
        self.screen = screen
        self.EntityCollider = EntityCollider(self)
        self.dashboard = dashboard
        self.restart = False
        self.pause = False
        self.pauseObj = Pause(screen, self, dashboard)
Exemplo n.º 7
0
def main():
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.init()
    screen = pygame.display.set_mode((640, 480))
    max_frame_rate = 60

    level = Level(screen)
    dashboard = Dashboard("./img/font.png", 8, screen)
    mario = Mario(0, 0, level, screen, dashboard)
    input = Input(mario)
    clock = pygame.time.Clock()

    while (not mario.restart):
        pygame.display.set_caption("{:.2f} FPS".format(clock.get_fps()))
        level.drawLevel(mario.camera)
        dashboard.update()
        input.checkForInput()
        mario.update()
        pygame.display.update()
        clock.tick(max_frame_rate)
    mario.sound.shutdown()
    main()
Exemplo n.º 8
0
    def __init__(self, x, y, level, screen, dashboard, sound, gravity=0.75):
        super(Mario, self).__init__(x, y, gravity)
        self.camera = Camera(self.rect, self)
        self.sound = sound
        self.input = Input(self)
        self.inAir = False
        self.inJump = False
        self.powerUpState = 0
        self.invincibilityFrames = 0
        self.traits = {
            "jumpTrait": JumpTrait(self),
            "goTrait": GoTrait(smallAnimation, screen, self.camera, self),
            "bounceTrait": bounceTrait(self),
        }

        self.levelObj = level
        self.collision = Collider(self, level)
        self.screen = screen
        self.EntityCollider = EntityCollider(self)
        self.dashboard = dashboard
        self.restart = False
        self.pause = False
        self.pauseObj = Pause(screen, self, dashboard)