movement update

This commit is contained in:
eugenep 2021-04-10 23:30:03 +02:00
parent 8123f1726e
commit 5d2603b65e

46
main.py
View File

@ -7,6 +7,8 @@ from grid import *
from settings import *
from sprites import *
class Game:
def __init__(self):
pg.init()
@ -15,6 +17,7 @@ class Game:
self.clock = pg.time.Clock()
pg.key.set_repeat(500, 100)
self.load_data()
self.wentyl_bezpieczenstwa = 0
def load_data(self):
game_folder = path.dirname(__file__)
@ -44,7 +47,6 @@ class Game:
# game loop - set self.playing = False to end the game
self.playing = True
while self.playing:
self.dt = self.clock.tick(FPS) / 1000
self.events()
self.update()
self.draw()
@ -71,6 +73,7 @@ class Game:
def events(self):
# catch all events here
for event in pg.event.get():
if event.type == pg.QUIT:
self.quit()
@ -85,42 +88,55 @@ class Game:
self.player.move(dy=-1, direction='Up')
if event.key == pg.K_DOWN:
self.player.move(dy=1, direction='Down')
if event.key == pg.K_F2:
if event.key == pg.K_F2 and self.wentyl_bezpieczenstwa == 0:
self.player.maze.run()
self.player.parse_maze_moves()
self.i_like_to_move_it()
self.wentyl_bezpieczenstwa = 1
def i_like_to_move_it(self):
for i in self.player.moves:
if i == 'Right':
self.player.move(dx=1, direction='Right')
#pg.time.delay(250)
self.update()
self.draw()
pg.time.delay(250)
if i == 'Turn Right':
self.player.move(0, 0, direction='Right')
self.update()
self.draw()
pg.time.delay(250)
if i == 'Left':
self.player.move(dx=-1, direction='Left')
#pg.time.delay(250)
self.update()
self.draw()
pg.time.delay(250)
if i == 'Turn Left':
self.player.move(0, 0, direction='Left')
self.update()
self.draw()
pg.time.delay(250)
if i == 'Down':
self.player.move(dy=1, direction='Down')
#pg.time.delay(250)
self.update()
self.draw()
pg.time.delay(250)
if i == 'Turn Down':
self.player.move(0, 0, direction='Down')
self.update()
self.draw()
pg.time.delay(250)
if i == 'Up':
self.player.move(dy=-1, direction='Up')
#pg.time.delay(250)
self.update()
self.draw()
pg.time.delay(250)
if i == 'Turn Up':
self.player.move(0, 0, direction='Up')
self.update()
self.draw()
pg.time.delay(250)
def show_start_screen(self):