-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.py
More file actions
178 lines (154 loc) · 6.93 KB
/
light.py
File metadata and controls
178 lines (154 loc) · 6.93 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
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
import pygame
from pygame.locals import*
from characters import*
from movements import*
from attacks import*
pygame.init()
clock = pygame.time.Clock()
running = True
knockout = False
screenWidth, screenHeight = 1200, 675
screen = pygame.display.set_mode((screenWidth, screenHeight))
background = pygame.image.load("background.jpg").convert()
stageWidth, stageHeight = screenWidth, 125
stage = pygame.Surface((stageWidth, stageHeight), pygame.SRCALPHA, 32)
stage = stage.convert_alpha()
themeSound = pygame.mixer.Sound("sounds/theme.mp3")
themeSound.play(loops=-1)
character1 = makeCharacter("ryu", 400, 100, forward=True)
character2 = makeCharacter("ken", 800, 100, forward=False)
characterMoves1 = {'up': K_w, 'down': K_s, 'left': K_a, 'right': K_d,
'block': K_e, 'punch': K_r, 'kick': K_t}
characterMoves2 = {'up': K_UP, 'down': K_DOWN, 'left': K_LEFT, 'right': K_RIGHT,
'block': K_m, 'punch': K_COMMA, 'kick': K_PERIOD}
def startGame():
titleFont = pygame.font.Font('font.ttf', 90)
startFont = pygame.font.Font('font.ttf', 60)
titleText = titleFont.render('FARNAMS FIGHT OFF', True, 'red')
startText = startFont.render('PRESS SPACE TO START', True, 'gold')
textRect1 = titleText.get_rect()
textRect2 = startText.get_rect()
textRect1.center = (600, 300)
textRect2.center = (600, 450)
screen.blit(titleText, textRect1)
screen.blit(startText, textRect2)
pygame.display.flip()
startScreen = True
while startScreen:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_SPACE:
startScreen = False
startSound = pygame.mixer.Sound("sounds/start.mp3")
startSound.play()
def victory(character):
victoryFont = pygame.font.Font('font.ttf', 80)
restartFont = pygame.font.Font('font.ttf', 30)
victoryText = victoryFont.render(f'{character} WINS', True, 'lightblue' if character == "PAT" else 'orange')
restartText = restartFont.render('PRESS SPACE TO RESTART', True, 'white')
victoryTextRect = victoryText.get_rect()
restartTextRect = restartText.get_rect()
victoryTextRect.center = (600, 200)
restartTextRect.center = (600, 300)
screen.blit(victoryText, victoryTextRect)
screen.blit(restartText, restartTextRect)
pygame.display.flip()
victoryScreen = True
while victoryScreen:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_SPACE:
restart(visionMode=False)
def restart(visionMode):
startSound = pygame.mixer.Sound("sounds/start.mp3")
startSound.play()
global character1
global character2
global knockout
character1 = makeCharacter("ryu", 400, 100, forward=True)
character2 = makeCharacter("ken", 800, 100, forward=False)
knockout = False
global themeSound
themeSound = pygame.mixer.Sound("sounds/theme.mp3")
themeSound.play(loops=-1)
startGame()
while running:
clock.tick(60)
yBound1 = screenHeight-stageHeight-character1.surf.get_height()
yBound2 = screenHeight-stageHeight-character2.surf.get_height()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
changeVelocity(character1, characterMoves1, event.key, yBound1)
changeVelocity(character2, characterMoves2, event.key, yBound2)
attack(character1, characterMoves1, character2, event.key, screenWidth)
attack(character2, characterMoves2, character1, event.key, screenWidth)
elif event.type == KEYUP:
stopVelocity(character1, characterMoves1, event.key)
stopVelocity(character2, characterMoves2, event.key)
if not knockout:
if character1.hp <= 0:
character1.posX -= 60
koSound = pygame.mixer.Sound("sounds/death.mp3")
koSound.play()
character1.changeSprite("ryu/ryu_ko.png", character2.posY, character2.sizeY, 225, 75)
character1.posY -= 100
knockout = True
themeSound.fadeout(1000)
victorySound = pygame.mixer.Sound("sounds/victory.mp3")
victorySound.set_volume(200)
victorySound.play()
if character2.hp <= 0:
character2.posX += 50
koSound = pygame.mixer.Sound("sounds/death.mp3")
koSound.play()
character2.posY -= 100
character2.changeSprite("ken/ken_ko.png", character2.posY, character2.sizeY, 225, 75)
knockout = True
themeSound.fadeout(1000)
victorySound = pygame.mixer.Sound("sounds/victory.mp3")
victorySound.set_volume(200)
victorySound.play()
changeCharacterPosition(character1, yBound1, character2, screenWidth, screenHeight)
changeCharacterPosition(character2, yBound2, character1, screenWidth, screenHeight)
hpBar1 = [50, 40, 500, 20]
hpBarOutline1 = Rect(hpBar1[0] - 4, hpBar1[1] - 4, hpBar1[2] + 8, hpBar1[3] + 8)
hpBarHealth1 = Rect(550 - character1.hp * 5, hpBar1[1], character1.hp * 5, hpBar1[3])
hpBar2 = [650, 40, 500, 20]
hpBarOutline2 = Rect(hpBar2[0] - 4, hpBar2[1] - 4, hpBar2[2] + 8, hpBar2[3] + 8)
hpBarHealth2 = Rect(hpBar2[0], hpBar2[1], character2.hp * 5, hpBar2[3])
middleBoxOutline = Rect(550, 24, 100, 52)
middleBoxFill = Rect(550, 28, 100, 44)
screen.blit(background, (0, 0))
pygame.draw.rect(screen, "white", hpBarOutline1, 4)
pygame.draw.rect(screen, "red", hpBarHealth1)
pygame.draw.rect(screen, "white", hpBarOutline2, 4)
pygame.draw.rect(screen, "red", hpBarHealth2)
pygame.draw.rect(screen, "black", middleBoxFill)
pygame.draw.rect(screen, "white", middleBoxOutline, 4)
font = pygame.font.Font('font.ttf', 60)
text = font.render('KO', False, 'red')
textRect = text.get_rect()
textRect.center = (600, 50)
font = pygame.font.Font('font.ttf', 30)
character1Text = font.render('PAT', False, 'white')
character1Rect = character1Text.get_rect()
character1Rect.center = (character1.posX, character1.posY-25)
character2Text = font.render('MIKE', False, 'white')
character2Rect = character2Text.get_rect()
character2Rect.center = (character2.posX + 140, character2.posY-25)
screen.blit(text, textRect)
screen.blit(character1Text, character1Rect)
screen.blit(character2Text, character2Rect)
screen.blit(stage, (0, screenHeight-stageHeight))
screen.blit(character1.surf, (character1.posX, character1.posY))
screen.blit(character2.surf, (character2.posX, character2.posY))
if character1.hp <= 0:
victory('MIKE')
elif character2.hp <= 0:
victory('PAT')
pygame.display.flip()
pygame.quit()