forked from NJWasTaken/PokemonMelee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
537 lines (448 loc) · 18.3 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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
#Imports
import pygame
import random
import pandas as pd
from pygame.locals import *
import os
import tkinter as tk
from tkinter import *
from tkinter import simpledialog, ttk, messagebox
import functools
import pokedex
from pyvidplayer2 import Video
#Importing the pokedex list from pokedex.py
typelist = pokedex.typelist()
#Making sure the program reads the file paths correctly
os.chdir(os.path.dirname(os.path.abspath(__file__)))
#Obtaining Pokemon names from the csv
df = pd.read_csv("PokemonData.csv")
df["Path"]=df["Name"]+".png"
#Selecting a random Player Pokemon
r = random.randint(0,150)
pk = df.Path[r]
player_pk = df.Name[r]
ptype = typelist[r]
p_stats = pokedex.pokedata.iloc[r]
if p_stats['HP']<=70:
p_stats['HP']+=30
#Selecting a random Opponent Pokemon
r2 = random.randint(1,151)
oppath=str(r2)+'.png'
opponent_pk = df.Name[r2-1]
optype = typelist[r2-1]
op_stats = pokedex.pokedata.iloc[r2-1]
if op_stats['HP']<=70:
op_stats['HP']+=30
#Logic
if ptype.name in optype.strength:
op_stats['Attack']*=2
if ptype.name in optype.weakness:
op_stats['Attack']//=2
if ptype.name in optype.null:
op_stats['Attack']=0
if optype.name in ptype.strength:
p_stats['Attack']*=2
if optype.name in ptype.weakness:
p_stats['Attack']//=2
if optype.name in ptype.null:
p_stats['Attack']=0
#Defining chance for the opponent Pokemon to be shiny (rare)
schance = random.randint(1,100)
#Initializing canvas and mixer
pygame.init()
pygame.mixer.init()
#Setting canvas size
width=1050
height=700
screen = pygame.display.set_mode( (width, height) )
#Loading Player Pokemon images
pkmg = pygame.image.load(os.path.join('assets','player','img_back',pk)).convert()
pkmg = pygame.transform.scale(pkmg,(200,200))
#Loading Opponent Pokemon images
if schance == 42:
pkmg2 = pygame.image.load(os.path.join('assets','opp','shiny',oppath)).convert_alpha()
else:
pkmg2 = pygame.image.load(os.path.join('assets','opp','img_front',oppath)).convert_alpha()
pkmg2 = pygame.transform.scale(pkmg2,(200,200))
#Loading battle start animation images and game title
red = pygame.image.load(os.path.join('assets','art','red.jpeg')).convert()
red = pygame.transform.scale(red,(width,height//2))
blue = pygame.image.load(os.path.join('assets','art','blue.jpeg')).convert()
blue = pygame.transform.scale(blue,(width,height//2))
vs_img = pygame.image.load(os.path.join('assets','art','vs.png')).convert_alpha()
vs_img = pygame.transform.scale(vs_img,(256,256))
title = pygame.image.load(os.path.join('assets','art','title.png')).convert_alpha()
title = pygame.transform.scale(title,(550,290))
#Set game speed
fpsClock = pygame.time.Clock()
#Setting up tkinter
root = tk.Tk()
root.iconbitmap(os.path.join('assets','art','icon.ico'))
root.withdraw()
#Setting variables for the positions of the two Pokemon
pimageX= 190
pimageY= 360
cimageX=580
cimageY=220
#Setting variables for game states
op = False
pname = 'Red'
opname = 'Blue'
font = pygame.font.Font(os.path.join('assets','pokemon_fire_red.ttf'), 32)
running = True
hasatt=1
hasstag=1
st=False
pattack=False
path = 'mainmenu'
audio = 'home'
mainscreen = 'startup'
l=[]
lvol=[]
e = False
r_emoji = str(random.randint(0,9))
r_x =random.randint(0,950)
r_y =random.randint(0,413)
vs_x1 = -425
vs_x2 = 425
vs_centre = False
anim_start = False
singleplayer = True
video = 0
p_maxhealth = p_stats['HP']
o_maxhealth = op_stats['HP']
#Volume
sppath = 'speaker'
vol = 0.5
#Options
optionmenu = pygame.image.load(os.path.join('assets','gui','optionmenu.png')).convert_alpha()
optionmenu = pygame.transform.scale(optionmenu,(664,313))
#Sounds
sel_sound = pygame.mixer.Sound(os.path.join('assets','audio','select.mp3'))
vid = Video(os.path.join('assets','art','easter_egg.mp4'))
#Buttons
start_b = pygame.image.load(os.path.join('assets','gui','begin.png')).convert_alpha()
start_b = pygame.transform.scale(start_b,(275,100))
options_b = pygame.image.load(os.path.join('assets','gui','options.png')).convert_alpha()
options_b = pygame.transform.scale(options_b,(275,100))
exit_b = pygame.image.load(os.path.join('assets','gui','exit.png')).convert_alpha()
exit_b = pygame.transform.scale(exit_b,(275,100))
#VS Animation
def vs(x1,x2,k):
if k == False:
x1+=5
x2-=5
if x1 == x2:
k = True
if k == True:
x1+=10
x2-=10
return x1,x2,k
#Player Pokemon attack animation
def attan(x,y,c,s):
if x >= 240:
op_stats['HP']-=p_stats['Attack']+r_a
c=0
if x<240 and c!=0:
x += 1
y -= 0.2
if c==0 and x>190:
x-=1
y+=0.2
if c==0 and x<=190:
s = True
return (x,y,c,s)
#Opponent Pokemon stagger animation
def stagger(x,y,c,p):
if x >= 610:
c=0
if x<610 and c!=0:
x += 1
y -= 0.5
if c==0 and x>580:
x-=1
y+=0.5
if c==0 and x<=580:
p = False
p_stats['HP']-=op_stats['Attack']+r_a1
return (x,y,c,p)
#Main Loop
while (running):
bg_img = pygame.image.load(os.path.join('assets','art',mainscreen+'.jpg')).convert()
bg_img = pygame.transform.scale(bg_img,(width,height))
gui = pygame.image.load(os.path.join('assets','gui',path+'.png')).convert()
gui = pygame.transform.scale(gui,(1050, 187))
speaker = pygame.image.load(os.path.join('assets','audio',sppath+'.png')).convert_alpha()
speaker = pygame.transform.scale(speaker,(100,100))
emoji = pygame.image.load(os.path.join('assets','art',r_emoji+'.png')).convert_alpha()
emoji = pygame.transform.scale(emoji,(100,100))
player_pokemon_name = font.render(player_pk.capitalize(), True, (208,255,255))
opponent_pokemon_name = font.render(opponent_pk.capitalize(),True,(208,255,255))
if p_stats['HP']>=1:
p_hb = (p_stats['HP']/p_maxhealth)*180
else:
p_hb = 1
if op_stats['HP']>=1:
o_hb = (op_stats['HP']/o_maxhealth)*117
else:
o_hb = 1
player_healthbar = pygame.image.load(os.path.join('assets','gui','hp'+'.png')).convert_alpha()
player_healthbar = pygame.transform.scale(player_healthbar,(p_hb,18))
opponent_healthbar = pygame.image.load(os.path.join('assets','gui','hp'+'.png')).convert_alpha()
opponent_healthbar = pygame.transform.scale(opponent_healthbar,(o_hb,18))
#Setting up game music
if audio not in l:
l.clear()
pygame.mixer.music.load(os.path.join('assets','audio',audio+'.mp3'))
pygame.mixer.music.play(-1)
l.append(audio)
pygame.mixer.music.set_volume(vol)
screen.fill((0,0,0)) #Base Layer
if video != 1:
screen.blit(bg_img,[0,0]) #Background Image
if mainscreen not in ['black','win','lose','tie'] and video != 1:
screen.blit(speaker,[900,50]) #Volume
#Homescreen
if mainscreen == 'startup' and video != 1:
screen.blit(exit_b,[400,600])
screen.blit(start_b,[400,350])
screen.blit(options_b,[400,450])
screen.blit(title,[240,30])
if mainscreen == 'black':
screen.blit(red,[vs_x1, 0])
screen.blit(blue,[vs_x2,350])
if op == True and video != 1:
screen.blit(optionmenu,[200,200])
if video == 1:
vid.draw(screen, (0,0),force_draw=False)
vol = 0
#VS Animation
if mainscreen == 'black':
vs_x1,vs_x2,vs_centre = vs(vs_x1,vs_x2,vs_centre)
if vs_centre == True:
screen.blit(vs_img,[400,250])
if vs_x1 >= 1050:
mainscreen = 'bgimg'
path = 'mainmenu'
vs_centre = False
if mainscreen in ['win','lose','tie']:
screen.blit(exit_b,[400,550])
#Player attack event
if pattack == True:
if p_stats['HP'] >= 0 and op_stats['HP']<=0:
mainscreen = 'win'
audio = 'win'
elif p_stats['HP'] <= 0 and op_stats['HP']<=0:
mainscreen = 'tie'
audio = 'tie'
elif p_stats['HP'] <= 0 and op_stats['HP']>=0:
mainscreen = 'lose'
audio = 'lose'
if st == False:
pimageX,pimageY,hasatt,st=attan(pimageX,pimageY,hasatt,st)
else:
cimageX,cimageY,hasstag,pattack=stagger(cimageX,cimageY,hasstag,pattack)
#Pokemon sprites
if mainscreen == 'bgimg':
screen.blit(pkmg2 , [cimageX,cimageY])
screen.blit(pkmg , [pimageX, pimageY])
screen.blit(player_healthbar, [90,317])
screen.blit(opponent_healthbar, [905,207])
screen.blit(player_pokemon_name,[45,284])
screen.blit(opponent_pokemon_name,[859,173])
#User events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = event.pos
#print('x:',x,',y:',y)
#Homepage
if mainscreen == 'startup':
if x in range(405, 645) and y in range(610, 695):
if op == False:
pygame.mixer.Sound.play(sel_sound)
running = False
if x in range(405, 645) and y in range(360,440):
if op == False:
pygame.mixer.Sound.play(sel_sound)
mainscreen = 'black'
audio = 'theme'
anim_start = True
if x in range(405, 645) and y in range(461, 535):
pygame.mixer.Sound.play(sel_sound)
op = True
if op == True:
if x in range(720,845) and y in range(450,495):
pygame.mixer.Sound.play(sel_sound)
op = False
if x in range(235,835) and y in range(245,325):
pygame.mixer.Sound.play(sel_sound)
pname = simpledialog.askstring(title="Player Name",prompt="What's your name?")
if pname == None or pname == ''or functools.reduce(lambda x,y: x+y,list(set(list(pname)))) == ' ':
pname = 'Red'
if x in range(235,835) and y in range(345,425):
pygame.mixer.Sound.play(sel_sound)
opname = simpledialog.askstring(title="Opponent Name",prompt="What's the opponent's name?")
if opname == None or opname == '' or functools.reduce(lambda x,y: x+y,list(set(list(opname)))) == ' ':
opname = 'Blue'
if x in range(200,230) and y in range(200,230):
pygame.mixer.Sound.play(sel_sound)
video +=1
if x in range(235,400) and y in range(430,500): #Reset button (Needs to reset health)
pygame.mixer.Sound.play(sel_sound)
r = random.randint(0,150)
pk = df.Path[r]
player_pk = df.Name[r]
ptype = typelist[r]
p_stats = pokedex.pokedata.iloc[r]
if p_stats['HP']<=70:
p_stats['HP']+=30
r2 = random.randint(1,151)
oppath=str(r2)+'.png'
opponent_pk = df.Name[r2-1]
optype = typelist[r2-1]
op_stats = pokedex.pokedata.iloc[r2-1]
if op_stats['HP']<=70:
op_stats['HP']+=30
if ptype.name in optype.strength:
op_stats['Attack']*=2
if ptype.name in optype.weakness:
op_stats['Attack']/=2
if ptype.name in optype.null:
op_stats['Attack']=0
if optype.name in ptype.strength:
p_stats['Attack']*=2
if optype.name in ptype.weakness:
p_stats['Attack']/=2
if optype.name in ptype.null:
p_stats['Attack']=0
schance = random.randint(1,100)
pkmg = pygame.image.load(os.path.join('assets','player','img_back',pk)).convert()
pkmg = pygame.transform.scale(pkmg,(200,200))
if schance == 42:
pkmg2 = pygame.image.load(os.path.join('assets','opp','shiny',oppath)).convert_alpha()
else:
pkmg2 = pygame.image.load(os.path.join('assets','opp','img_front',oppath)).convert_alpha()
pkmg2 = pygame.transform.scale(pkmg2,(200,200))
p_maxhealth = p_stats['HP']
o_maxhealth = op_stats['HP']
#Volume
if x in range(900,960) and y in range(70,130) and mainscreen not in ['black','lose','tie','win']:
if e == False:
if vol == 0:
sppath = 'speaker'
vol = 0.5
elif vol == 0.5:
pygame.mixer.Sound.play(sel_sound)
sppath = 'speakernt'
vol = 0
#Fight
if path == 'mainmenu' and (x in range(516,778) and y in range(525,610)):
if e == False:
path = 'fight/fight'+typelist[r].name
if path == f'fight/fight'+typelist[r].name and ((x in range(55,400) and y in range(555,606)) or (x in range(415,690) and y in range(555,606)) or (x in range(55,400) and y in range(615,665)) or (x in range(415,690) and y in range(615,665))):
pygame.mixer.Sound.play(sel_sound)
pattack = True
st = False
hasatt = 1
hasstag = 1
r_a = random.randint(-5,5)
r_a1 = random.randint(-5,5)
op_stats['HP']-=0
p_stats['HP']-=0
#Run
if path == 'mainmenu' and (x in range(780,1040) and y in range(590,693)):
if e == False:
path = 'run'
vs_x1 = -1050
vs_x2 = 1050
if path == 'run':
if (x in range(518,778) and y in range(565,650)):
pygame.mixer.Sound.play(sel_sound)
mainscreen = 'startup'
audio = 'home'
if (x in range(780,1040) and y in range(565,650)):
pygame.mixer.Sound.play(sel_sound)
path = 'mainmenu'
#Emote
if path == 'mainmenu' and (x in range(785,1035) and y in range(525,610)):
e = True
r_emoji = str(random.randint(0,9))
path = 'emojis'
pygame.mixer.Sound.play(sel_sound)
if e == True:
if x in range(r_x,r_x+100) and y in range(r_y,r_y+100):
e = False
r_emoji = str(random.randint(0,9))
path = 'mainmenu'
r_x =random.randint(0,950)
r_y =random.randint(0,600)
pygame.mixer.Sound.play(sel_sound)
#Scan
if path == 'mainmenu' and (x in range(516,778) and y in range(590,693)):
pygame.mixer.Sound.play(sel_sound)
messagebox.showinfo("Battle Stats",f"Player: {pname} \nPlayer Pokemon: {player_pk.capitalize()} \nPokemon Health: {p_stats['HP']} \nPokemon Attack: {p_stats['Attack']} \nPokemon Type: {ptype.name} \n\nOpponent: {opname} \nOpponent Pokemon: {opponent_pk.capitalize()} \nOpponent Health: {op_stats['HP']} \nOpponent Attack: {op_stats['Attack']} \nOpponent Type: {optype.name} ")
if mainscreen in ['win','lose','tie']:
if x in range(400, 670) and y in range(600, 695):
pygame.mixer.Sound.play(sel_sound)
mainscreen = 'startup'
audio = 'home'
r = random.randint(0,150)
pk = df.Path[r]
player_pk = df.Name[r]
ptype = typelist[r]
p_stats = pokedex.pokedata.iloc[r]
r2 = random.randint(1,151)
oppath=str(r2)+'.png'
opponent_pk = df.Name[r2-1]
optype = typelist[r2-1]
op_stats = pokedex.pokedata.iloc[r2-1]
if ptype.name in optype.strength:
op_stats['Attack']*=2
if ptype.name in optype.weakness:
op_stats['Attack']/=2
if ptype.name in optype.null:
op_stats['Attack']=0
if optype.name in ptype.strength:
p_stats['Attack']*=2
if optype.name in ptype.weakness:
p_stats['Attack']/=2
if optype.name in ptype.null:
p_stats['Attack']=0
schance = random.randint(1,100)
pkmg = pygame.image.load(os.path.join('assets','player','img_back',pk)).convert()
pkmg = pygame.transform.scale(pkmg,(200,200))
if schance == 42:
pkmg2 = pygame.image.load(os.path.join('assets','opp','shiny',oppath)).convert_alpha()
else:
pkmg2 = pygame.image.load(os.path.join('assets','opp','img_front',oppath)).convert_alpha()
pkmg2 = pygame.transform.scale(pkmg2,(200,200))
p_maxhealth = p_stats['HP']
o_maxhealth = op_stats['HP']
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
if path == 'fight/fight'+typelist[r].name:
path = 'mainmenu'
if path == 'emojis':
e = False
r_emoji = str(random.randint(0,9))
path = 'mainmenu'
r_x =random.randint(0,950)
r_y =random.randint(0,600)
pygame.mixer.Sound.play(sel_sound)
if mainscreen == 'black':
vs_x1 += 2000
vs_x2 -= 2000
if video == 1:
video += 1
vol = 0.5
#Battle Bg
if mainscreen == 'bgimg':
screen.blit(gui,[0,513])
#Emotes
if e == True:
screen.blit(emoji , [r_x,r_y])
pygame.display.update()
fpsClock.tick(200)
pygame.quit()