game.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:pyweek-game-poor-man-medal-of-honor-game 作者: ReekenX 项目源码 文件源码
def movement(self, obstacles, offset, i):
        self.rect[i] += offset
        collisions = pg.sprite.spritecollide(self, obstacles, False)
        callback = pg.sprite.collide_mask
        while pg.sprite.spritecollideany(self, collisions, callback):
            self.rect[i] += (1 if offset<0 else -1)
            self.remainder[i] = 0
            rand_move = random.choice([pg.K_s, pg.K_a, pg.K_w, pg.K_d])
            while rand_move == self.direction:
                rand_move = random.choice([pg.K_s, pg.K_a, pg.K_w, pg.K_d])
                pass
            self.direction = rand_move
            if self.direction == pg.K_a:
                self.direction = pg.K_a
                self.vector = [-1, 0]
            elif self.direction == pg.K_w:
                self.direction = pg.K_w
                self.vector = [0, -1]
            elif self.direction == pg.K_s:
                self.direction = pg.K_s
                self.vector = [0, 1]
            elif self.direction == pg.K_d:
                self.direction = pg.K_d
                self.vector = [1, 0]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号