code cleanup
This commit is contained in:
parent
2a22347592
commit
3cea434bc4
28
main.py
28
main.py
@ -18,15 +18,6 @@ def terminate():
|
|||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def redrawGameWindow():
|
|
||||||
window.fill((0,0,0))
|
|
||||||
|
|
||||||
for baddie in baddies:
|
|
||||||
baddie.draw(window)
|
|
||||||
man.draw(window)
|
|
||||||
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
def drawText(text, font, window, x,y):
|
def drawText(text, font, window, x,y):
|
||||||
textObj = font.render(text, 1, textColor)
|
textObj = font.render(text, 1, textColor)
|
||||||
textRect = textObj.get_rect()
|
textRect = textObj.get_rect()
|
||||||
@ -45,15 +36,12 @@ def waitForKeyPress():
|
|||||||
return
|
return
|
||||||
|
|
||||||
def resetGame(player, baddies, gameLogic):
|
def resetGame(player, baddies, gameLogic):
|
||||||
window.fill((0,0,0))
|
|
||||||
player.x = 100
|
player.x = 100
|
||||||
player.y = 700
|
player.y = 700
|
||||||
|
|
||||||
baddies.clear()
|
baddies.clear()
|
||||||
|
|
||||||
gameLogic.retry = False
|
|
||||||
gameLogic.timer = 0
|
gameLogic.timer = 0
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
def askForRetry(keys, gameLogic):
|
def askForRetry(keys, gameLogic):
|
||||||
window.fill((0,0,0))
|
window.fill((0,0,0))
|
||||||
@ -62,7 +50,6 @@ def askForRetry(keys, gameLogic):
|
|||||||
|
|
||||||
if keys[pygame.K_y]:
|
if keys[pygame.K_y]:
|
||||||
gameLogic.lost = False
|
gameLogic.lost = False
|
||||||
gameLogic.retry = True
|
|
||||||
if keys[pygame.K_n]:
|
if keys[pygame.K_n]:
|
||||||
gameLogic.run = False
|
gameLogic.run = False
|
||||||
|
|
||||||
@ -71,7 +58,6 @@ class game(object):
|
|||||||
self.timer = 0
|
self.timer = 0
|
||||||
self.run = True
|
self.run = True
|
||||||
self.lost = False
|
self.lost = False
|
||||||
self.retry = False
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def play(self, keys, baddies, baddiesSpawnRate, player):
|
def play(self, keys, baddies, baddiesSpawnRate, player):
|
||||||
@ -91,6 +77,14 @@ class game(object):
|
|||||||
|
|
||||||
self.timer += 1
|
self.timer += 1
|
||||||
|
|
||||||
|
self.draw(baddies, player)
|
||||||
|
def draw(self, baddies, player):
|
||||||
|
window.fill((0,0,0))
|
||||||
|
for baddie in baddies:
|
||||||
|
baddie.draw(window)
|
||||||
|
player.draw(window)
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
# enemy class
|
# enemy class
|
||||||
class enemy(object):
|
class enemy(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -158,13 +152,11 @@ while dodger.run:
|
|||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
|
||||||
if dodger.lost:
|
if dodger.lost:
|
||||||
|
if dodger.timer > 0:
|
||||||
|
resetGame(man, baddies, dodger)
|
||||||
askForRetry(keys, dodger)
|
askForRetry(keys, dodger)
|
||||||
else :
|
else :
|
||||||
if dodger.retry:
|
|
||||||
resetGame(man, baddies, dodger)
|
|
||||||
dodger.play(keys, baddies, baddieSpawnRate, man)
|
dodger.play(keys, baddies, baddieSpawnRate, man)
|
||||||
redrawGameWindow()
|
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
terminate()
|
terminate()
|
||||||
|
Loading…
Reference in New Issue
Block a user