movement update

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

48
main.py
View File

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