-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
104 lines (73 loc) · 2.79 KB
/
process.py
File metadata and controls
104 lines (73 loc) · 2.79 KB
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
import pygame, sys, classes, random
def process(bug,FPS,total_frames):
# processing
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_e:
classes.BugAttack.fire = not classes.BugAttack.fire
keys = pygame.key.get_pressed()
if keys[pygame.K_d]:
classes.Bug.going_right = True
bug.image = pygame.image.load("images/bug2right.png")
bug.velx = 5
elif keys[pygame.K_a]:
classes.Bug.going_right = False
bug.image = pygame.image.load("images/bug2left.png")
bug.velx = -5
else:
bug.velx = 0
if keys[pygame.K_w]:
bug.jumping = True
if keys[pygame.K_SPACE]:
if classes.Game.end == True:
classes.Game.end = False
if classes.Game.start == False:
classes.Game.start = True
for fly in classes.Fly.List:
fly.destroy(classes.Fly)
for attack in classes.BugAttack.List:
attack.destroy()
classes.Fly.count = 0
else:
def direction():
if classes.Bug.going_right:
p.velx = 6
else:
p.image = pygame.transform.flip(p.image, True, False)
p.velx = -6
if (classes.BugAttack.fire):
p = classes.BugAttack(bug.rect.x,bug.rect.y, "images/fire2.gif")
direction()
p.velx = p.velx/3.0
else:
p = classes.BugAttack(bug.rect.x,bug.rect.y, "images/bolt.gif")
direction()
if classes.Game.start == True:
spawn(FPS,total_frames)
collisions(bug)
def spawn(FPS,total_frames):
seconds = FPS * 3
if total_frames % seconds==0:
r = random.randint(1,2)
x = 1
if r == 2:
x = 640 - 40
classes.Fly(x,130,"images/fly.png")
def collisions(bug):
for fly in classes.Fly.List:
if pygame.sprite.spritecollide(fly, classes.BugAttack.List, False):
if classes.BugAttack.fire:
fly.health -= fly.half_health
else:
fly.velx = 0
fly.go_down = True
if pygame.sprite.spritecollide(fly, classes.Bug.List, False):
classes.Game.end = True
classes.Game.start = False
for attack in classes.BugAttack.List:
if pygame.sprite.spritecollide(attack, classes.Fly.List, False):
attack.rect.x = 2 * -attack.rect.width
attack.destroy()