-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBen10.py
286 lines (205 loc) · 6.73 KB
/
Ben10.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import pygame
import random
import math
from pygame import mixer
# Calling Pygame init
pygame.init()
# Screen Creation
screen = pygame.display.set_mode((800, 600))
# Background
background = pygame.image.load('other_assets/background.png')
# Background Music
mixer.music.load('sounds/background.mp3')
mixer.music.play(-1)
play = 1
# fire blast
# hold - holding the fire
# blast - fireball is currently moving
fireball_img = pygame.image.load('assets/fireball.png')
fireball_y = 270
fireball_x = 10
fireball_y_change = 0
fireball_x_change = -10
fireball_state = 'hold'
# Game Over
over = pygame.font.Font('freesansbold.ttf', 40)
# score and life
score_value = 0
font = pygame.font.Font('freesansbold.ttf', 19)
text_x = 7
text_y = 7
# Title and icon
pygame.display.set_caption('Heat-Blast @ankush_singh_gandhi')
icon = pygame.image.load('assets/icon.png')
pygame.display.set_icon(icon)
# Player
player_img = pygame.image.load('assets/player.png')
player_y = 270
player_x = 10
player_y_change = 0
# Vilgax Drone
vilgax_drone_img = []
vilgax_drone_y = []
vilgax_drone_x = []
vilgax_drone_y_change = []
vilgax_drone_x_change = []
nums_of_drone = 6
for i in range(nums_of_drone):
vilgax_drone_img.append(pygame.image.load('assets/drone.png'))
vilgax_drone_y.append(random.randint(0, 599))
vilgax_drone_x.append(random.randint(500, 730))
vilgax_drone_y_change.append(3.3)
vilgax_drone_x_change.append(-19)
# Gigantic Drone
gigantic_drone_img = pygame.image.load('assets/giganticdrone.png')
gigantic_drone_y = 270
gigantic_drone_x = 740
gigantic_drone_y_change = 3
gigantic_drone_x_change = 0
gigantic_drone_life = 10
def player(x, y):
screen.blit(player_img, (x, y))
def drone(x, y, i):
screen.blit(vilgax_drone_img[i], (x, y))
def giganticdrone(x, y):
screen.blit(gigantic_drone_img, (x, y))
def fireblast(x, y):
global fireball_state
fireball_state = 'blast'
screen.blit(fireball_img, (x + 10, y + 16))
def destruction(
vilgax_drone_x,
vilgax_drone_y,
fireball_x,
fireball_y,
):
distance = math.sqrt(math.pow(vilgax_drone_x - fireball_x, 2)
+ math.pow(vilgax_drone_y - fireball_y, 2))
if distance < 39:
return True
else:
return False
def gigantic_destruction(
gigantic_drone_x,
gigantic_drone_y,
fireball_x,
fireball_y,
):
distance = math.sqrt(math.pow(gigantic_drone_x - fireball_x, 2)
+ math.pow(gigantic_drone_y - fireball_y, 2))
global gigantic_drone_life
if gigantic_drone_life > 0:
if distance < 39:
gigantic_drone_life -= 1
return True
else:
False
def show_score(x, y):
score = font.render('Score : ' + str(score_value)
+ ' MegaDrone life : '
+ str(gigantic_drone_life), True, (255, 255,
255))
screen.blit(score, (x, y))
def game_over(result):
gover = over.render('Game Over' + result, True, (255, 255, 255))
screen.blit(gover, (200, 250))
# Game Loop
running = True
while running:
# RGB Value for screen
screen.fill((0, 0, 0))
# Background Image
screen.blit(background, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# if keystroke is pressed check wether is up or down
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
player_y_change += -7
if event.key == pygame.K_DOWN:
player_y_change += 7
if event.key == pygame.K_SPACE:
if fireball_state == 'hold':
fire_y = player_y
fireblast(player_x, player_y)
fire_sound = mixer.Sound('sounds/fire.wav')
fire_sound.play()
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
player_y_change = 0
# Checking for boundries of Ben 10 aka our Player
player_y += player_y_change
if player_y <= 0:
player_y = 0
if player_y >= 530:
player_y = 530
# Checking for boundries of Drones
# Vilgax Drone Movement
for i in range(nums_of_drone):
# Game Over
if vilgax_drone_x[i] < 100:
for j in range(nums_of_drone):
gigantic_drone_x = 900
gigantic_drone_y = 900
vilgax_drone_y[j] = 900
game_over(' You Lose')
break
vilgax_drone_y[i] += vilgax_drone_y_change[i]
if vilgax_drone_y[i] <= 0:
vilgax_drone_y_change[i] = 3.3
vilgax_drone_x[i] += vilgax_drone_x_change[i]
if vilgax_drone_y[i] >= 530:
vilgax_drone_y_change[i] = -3.3
vilgax_drone_x[i] += vilgax_drone_x_change[i]
# Destruction
drone_destruction = destruction(vilgax_drone_x[i],
vilgax_drone_y[i], fireball_x, fireball_y)
if drone_destruction:
fireball_x = 10
fireball_state = 'hold'
score_value += 1
vilgax_drone_y[i] = random.randint(0, 529)
vilgax_drone_x[i] = random.randint(500, 730)
explosion_sound = mixer.Sound('sounds/explosion.wav')
explosion_sound.play()
gigantic_drone_distruction = \
gigantic_destruction(gigantic_drone_x, gigantic_drone_y,
fireball_x, fireball_y)
if gigantic_drone_distruction:
fireball_x = 10
fireball_state = 'hold'
score_value += 5
drone(vilgax_drone_x[i], vilgax_drone_y[i], i)
if gigantic_drone_life == 0:
gigantic_drone_x = 900
gigantic_drone_y = 900
vilgax_drone_y[i] = 900
vilgax_drone_x[i] = 900
game_over(' You Won')
break
if play <= 2:
play += 1
explosion_sound = mixer.Sound('sounds/Explosion.wav')
explosion_sound.play()
# Calling Drones
# Checking for boundries of Gigantic Drones
# Gigantic Drone Movement
gigantic_drone_y += gigantic_drone_y_change
if gigantic_drone_y <= 0:
gigantic_drone_y_change = 3
if gigantic_drone_y >= 530:
gigantic_drone_y_change = -3
# fireball Movement
if fireball_x >= 800:
fireball_state = 'hold'
fireball_x = 10
if fireball_state is 'blast':
fireblast(fireball_x, fire_y)
fireball_x -= fireball_x_change
# Calling Gigantic drones
giganticdrone(gigantic_drone_x, gigantic_drone_y)
# Calling player
player(player_x, player_y)
show_score(text_x, text_y)
pygame.display.update()