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]
game.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录