-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
151 lines (117 loc) · 3.91 KB
/
game.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import pygame
import sys
import random
import time
from customSprite import Player
from customSprite import obs
pygame.init()
screen = pygame.display.set_mode((900,900))
clock = pygame.time.Clock()
bg = pygame.image.load('bg.jpeg')
bg_2 =pygame.image.load('bg.jpeg')
box = Player()
mov_sprite = pygame.sprite.Group()
mov_sprite.add(box)
obs_sprite = pygame.sprite.Group()
spawn_obst = pygame.USEREVENT
pygame.time.set_timer(spawn_obst,800)
x = 0
y1 = 0
y2 = -900
grav = 0.2
box_mov = 0
right_mov = 0
direction = 'right'
bg_mov = 5
obs_mov = 5
Active = False
while True:
if Active:
if pygame.sprite.spritecollide(box, obs_sprite, True):
Active = False
obs_sprite.empty()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == spawn_obst:
met = obs()
obs_sprite.add(met)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LCTRL:
if box.rect.centerx < 330 or box.rect.centerx > 570:
if box.rect.centerx < 330 :
box.rect.centerx = 300
y1 -= 2*bg_mov
y2 -= 2*bg_mov
box_mov = 5
right_mov = 0
if box.rect.centerx > 570:
box.rect.centerx = 600
y1 -= 2*bg_mov
y2 -= 2*bg_mov
box_mov = 5
right_mov = 0
if event.key == pygame.K_SPACE:
box_mov = -3
if direction == 'left':
right_mov += -3
elif direction == 'right':
right_mov += 3
elif direction == 'up':
box_mov += 3
mov_sprite.update(box_mov,right_mov,direction,'space')
if event.key == pygame.K_d:
if direction == 'left':
direction = 'up'
else:
direction = 'right'
mov_sprite.update(box_mov,right_mov,direction,'right')
if event.key == pygame.K_a:
if direction =='right':
direction = 'up'
else:
direction = 'left'
mov_sprite.update(box_mov,right_mov,direction,'left')
if box.rect.centery >900:
Active = False
box_mov = -box_mov*0.5
if box.rect.centerx >= 600 :
direction = 'left'
box.rect.centerx-=1
right_mov = -right_mov*0.8
box_mov = box_mov*0.8
elif box.rect.centerx <= 300:
direction ='right'
box.rect.centerx+=1
right_mov = -right_mov*0.8
box_mov = box_mov*0.8
mov_sprite.draw(screen)
obs_sprite.draw(screen)
for sprite in obs_sprite:
if sprite.rect.centery > 900:
obs_sprite.remove(sprite)
mov_sprite.update(box_mov,right_mov,direction)
obs_sprite.update(obs_mov)
elif not Active:
pass
#show_menu()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_TAB:
obs_sprite.empty()
box.rect.center = (450,450)
Active = True
box_mov +=grav
y1 +=bg_mov
y2 += bg_mov
if y1 >900 :
y1 = 0
y2 = -900
pygame.display.update()
screen.blit(bg,(x,y1))
screen.blit(bg_2,(x,y2))
clock.tick(200)