-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (53 loc) · 1.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pgzrun
from random import randint
import time
WIDTH = 600
HEIGHT = 600
playerXDefault = 275
playerYDefault = 475
playerSpeed = 4.4
pressed = {}
fond = Actor('fond')
player = Actor('player')
def initGame():
global zombies, score
score = 0
player.x = playerXDefault
player.y = playerYDefault
zombies = []
initGame()
def update():
global score
screen.fill((0, 0, 0))
fond.draw()
player.draw()
if player.x <= 0 or player.x >= WIDTH or player.y <= 0 or player.y >= HEIGHT:
gameOver()
if pressed.get(keys.LEFT):
player.x -= playerSpeed
if pressed.get(keys.RIGHT):
player.x += playerSpeed
if pressed.get(keys.UP):
player.y -= playerSpeed
if pressed.get(keys.DOWN):
player.y += playerSpeed
if randint(1, 12) == 1:
zombies.append(
Actor('mechant', (randint(1, WIDTH), 0))
)
for z in zombies:
z.draw()
if player.colliderect(z):
gameOver()
if z.y >= HEIGHT:
zombies.remove(z)
z.y += 4.4
screen.draw.text('Score: ' + str(score), (0, 0))
score += 1
def gameOver():
initGame()
def on_key_down(key):
pressed[key] = True
def on_key_up(key):
pressed[key] = False
pgzrun.go()