Exemple #1
0
    def update_timer(self, dt):
        stats.update_timer(dt)

        if stats.time == 100:
            Sound.stop("mario")
            Sound.play("out_of_time")
            self.do(Delay(2) + CallFunc(Sound.play, "mario"))

        if stats.time <= 0:
            self.game_over("timeout")
Exemple #2
0
    def collide_with_obstacle(self):
        if not self.mario.collide_cells:
            return

        cell = self.mario.collide_cells.popleft()
        label = cell.get("label")

        if label == "normal brick":
            if self.mario.state == Mario.SMALL:
                Sound.play("bump")
                self.popup_brick("normal", cell)
            else:
                Sound.play("brick_smash")
                self.smash_brick(cell)
        elif label == "unknown brick":
            self.popup_brick("unknown", cell)

            objs = self.objects_map.get_in_region(cell.left, cell.bottom,
                                                  cell.right, cell.top)
            if objs:
                Sound.play("powerup_appears")
                # normally, only 1 object collide with cell
                self.collide_unknown_brick_with_obj(objs[0])
            else:
                Sound.play("coin")
                self.collide_unknown_brick_without_obj(cell)
        elif label == "flagpole":
            self.world_complete()
Exemple #3
0
    def collide_enemy(self, obj):
        if self.mario.collide_bottom_obj(obj):
            Sound.play("stomp")
            stats.score += 100
            obj.die()
            self.mario.do(JumpBy((0, 0), 16, 1, 0.3))
        else:
            if self.mario.state == Mario.SMALL:
                self.game_over("enemy")
            elif self.mario.state == Mario.BIG:
                self.mario.state = Mario.SMALL
            elif self.mario.state == Mario.FIRE:
                self.mario.state = Mario.BIG

            self.enemies.remove(obj)
Exemple #4
0
    def update_position(self, dt):
        if dt > 0.1:
            return

        view_x = self.maplayer.view_x
        view_w = self.maplayer.view_w

        vx, vy = self.velocity

        vx = (self.keys[key.RIGHT] - self.keys[key.LEFT]) * self.MOVE_SPEED
        vy += self.GRAVITY * dt

        if not self.keys[key.A] and self.on_ground:
            self.may_jump = True

        if self.keys[key.A] and self.may_jump:
            vy = self.JUMP_SPEED
            self.may_jump = False

            if self.state == Mario.SMALL:
                Sound.play("small_jump")
            else:
                Sound.play("big_jump")

        dx = vx * dt
        dy = vy * dt

        old = self.get_rect()
        self.last_rect = old

        new = old.copy()
        new.x += dx
        new.y += dy

        # prevent scroll the map backwards
        if new.x < view_x:
            new.x = old.x

        self.velocity = self.collide_map(self.maplayer, old, new, vx, vy)

        if new.x > view_x + view_w / 2:
            self.scroller.set_focus(new.x, 0)

        self.on_ground = (new.bottom == old.bottom)

        super().update_position(new.center)
Exemple #5
0
    def collide_prop(self, obj):
        Sound.play("powerup")

        if isinstance(obj, NormalMushroom):
            stats.score += 1000
            if self.mario.state == Mario.SMALL:
                self.mario.state = Mario.BIG
        elif isinstance(obj, LifeMushroom):
            stats.life += 1
        elif isinstance(obj, FireFlower):
            stats.score += 1000
            if self.mario.state == Mario.BIG:
                self.mario.state = Mario.FIRE
            elif self.mario.state == Mario.FIRE:
                # do something else
                pass

        self.remove(obj)
Exemple #6
0
    def __init__(self, *args):
        super().__init__()

        self.hud = args[0]
        self.obstacle_map = args[1]
        self.objects_map = args[2]
        self.tileset = args[3]

        self.create_mario()
        self.create_cliff()
        self.create_flag()

        self.enemies = BatchNode()
        self.add(self.enemies)
        self.enemy_objs = self.objects_map.match(label="enemy")
        self.exist_enemy_index = []

        width, height = director.get_window_size()
        self.cm = CollisionManagerGrid(0, width, 0, height, 20, 20)

        stats.reset_current_game()

        Sound.play("mario")
Exemple #7
0
    def world_complete(self):
        stats.update_score_flagpole_height(self.mario.y)

        Sound.stop("mario")
        Sound.play("flagpole")

        self.unschedule(self.update)

        end_point_pos_x = 0
        castle_flag_pos = 0, 0

        for obj in self.objects_map.objects:
            if obj.name == "End point":
                end_point_pos_x = obj.x
            elif obj.name == "Castle flag":
                castle_flag_pos = obj.position

        self.flag.lower()
        self.mario.raise_flag(end_point_pos_x)

        self.do(
            Delay(5) +
            CallFunc(lambda: self.add(CastleFlag(castle_flag_pos))) +
            Delay(5) + CallFunc(self.enter_info_scene, True))
Exemple #8
0
    def game_over(self, reason):
        stats.life -= 1

        Sound.stop("mario")
        if stats.life > 0:
            Sound.play("death")
        else:
            Sound.play("game_over")

        # change current layer z-order, make it the top
        self.parent.remove(self)
        self.parent.add(self, z=3)

        self.unschedule(self.update)

        if reason == "enemy" or reason == "timeout":
            self.mario.die()
            self.do(Delay(1) + CallFunc(self.enter_info_scene))
        elif reason == "cliff":
            self.enter_info_scene()
        else:
            pass