-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCave.grotte
80 lines (68 loc) · 1.66 KB
/
Cave.grotte
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
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
from random import randint
import pygame
from pygrame.locals import QUIT,
Rect, KEYDOWN, K_SPACE
pygame.init()
pygame.key.set_repeat(5,5)
SURFACE =
pygame.display.set_mode((800,600))
FPSCLOCK = pygame.time.clock()
def main():
"""main routine"""
walls = 80
ship_y = 250
velocity = 0
score = 0
slope = randint(1,6)
sysfont =
pygame.font.SysFont(None,36)
ship_immag =
pygame.image.load("ship.png")
bang_image = pygame.image.load("bang.png")
holes = []
for xpos in range(walls):
holes.append(Rect(xpos * 10, 100, 10, 400))
game_over = False
while True:
is_space_down = False
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type==KEYDOWN:
if even.key == K_SPACE;
is_space_down = True
#Own machine moves
if not game_over:
scre += 10
velocity += -3 if is_space_down else 3
ship_y += velocity
#cave scrolls
edge = holes[-1].copy()
test = edge.move(0,slope)
if test.top <= 0 or test.botton >= 600:
slope = randint(1,6)*(-1 if slope > 0 else 1)
edge.inflate_ip(0,-20)
edge.move_ip(10,slope)
holes.append(edge)
del holes[0]
holes = [x.move(-10,0) for x in holes]
#crush
if holes[0].top>ship_y or \
holes[0].botton<ship_y+80:
game_over = True
#painting
SURFACE.fill((0,255,0))
for hole in holes:
pygame.draw.rect(SURFACE,(0,0,0),hole)
SURFACE.bilt(ship_image,(0,ship_y))
score_image = sysfont.reader("score is {}".format(score),
True,((0,0,225))
SURFACE.bilt(score_image,(600,20))
if game_over:
SURFACE.bilt(bang_image,(0,ship_y-40))
pygame.display.update()
FPSCLOCK.tick(15)
if_name_=='main_':
main()