Python实现超级玛丽游戏系列教程03玛丽跳跃

2020-12-20  本文已影响0人  __豆约翰__

配套视频教程

配套视频教程

项目代码

项目代码

跳跃

mario.py

init


handle_state

standing

walking

新增

玛丽不掉落,但上去就下不来

jumping


玛丽跳跃正常

jumping



新增falling

    def falling(self, keys, current_time):
        self.y_vel += self.gravity

        if (self.rect.bottom > (600 - self.rect.height)):
            self.y_vel = 0
            self.gravity = c.GRAVITY
            self.state = c.WALK

        if keys[pg.K_LEFT]:
            self.facing_right = False
            if self.x_vel > (self.max_x_vel * - 1):
                self.x_vel -= self.x_accel

        elif keys[pg.K_RIGHT]:
            self.facing_right = True
            if self.x_vel < self.max_x_vel:
                self.x_vel += self.x_accel

玛丽跳跃短按小跳,长按大跳

jumping


上一篇 下一篇

猜你喜欢

热点阅读