-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersion_0.6.py
286 lines (243 loc) · 12.4 KB
/
Version_0.6.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 settings
from settings import *
from player import Player
from wasd_player import wasd_player
from arrow_key_player import arrow_key_player
from Scoreboard import Scoreboard
class Display:
def __init__(self, size):
self.size = size
self.width,self.height = size
self.screen = pygame.display.set_mode((self.width, self.height))
self.play_again_hitbox_left = pygame.Rect(5, 250, 300, 300)
self.play_again_hitbox_right = pygame.Rect(1065, 250, 300, 300) #values: moving leftright, up/down, width, heigh
if self.size == (800,600):
self.is_large = False # False mean small
elif self.size == (1366, 768):
self.is_large = True #True means large
self.x_y_center = (self.width/2,self.height/2)
def display(self):
pygame.display.set_mode((self.width, self.height))
def blit(self,background,location):
self.screen.blit(background,(location))
def draw_large(self): #updates
if scoreboard.counter >= 0:
player1.draw_player_large(self.screen)
player2.draw_player_large(self.screen)
pygame.display.update()
elif scoreboard.counter < 0:
if player1.won:
player1.draw_player_large(self.screen)
self.blit(background=scoreboard.draw_text("Player 1 Wins",(255,255,255),scoreboard.clock_font),
location=scoreboard.draw_text_location("Player 1 Wins",(settings.white),scoreboard.clock_font,self,0,-300))
if player2.won:
player2.draw_player_large(self.screen)
self.blit(background=scoreboard.draw_text("Player 2 Wins", (255, 255, 255), scoreboard.clock_font),
location=scoreboard.draw_text_location("Player 2 Wins", (settings.white), scoreboard.clock_font, self,
0, -300))
pygame.draw.rect(self.screen, (255, 0, 0), self.play_again_hitbox_right,2)
pygame.draw.rect(self.screen, (10, 10, 255), self.play_again_hitbox_left,3)
self.blit(background=scoreboard.draw_text("Play Again?",(255,255,255),scoreboard.font),
location=scoreboard.draw_text_location("Play Again?",(255,255,255),scoreboard.font,self,0,280))
self.blit(scoreboard.draw_text("Yes",(0,0,255),scoreboard.font),(110,360))
self.blit(scoreboard.draw_text("No",(255,0,0),scoreboard.font),(1180,360))
pygame.display.update()
def draw_small(self):
player1.draw_player_small(self.screen)
player2.draw_player_small(self.screen)
pygame.display.update()
def fill(self,color):
self.screen.fill(color)
def blit_random_collide_phrase(self,screen):
screen.fill(black)
temp_random_collide_phrase = settings.random_collide_phrase()
print(temp_random_collide_phrase)
Surface_text = Scoreboard.draw_text(self=scoreboard,text=temp_random_collide_phrase, color=settings.white,
font=settings.collide_font)
x_vary,y_vary = random.randint(1,25),random.randint(1,25)
self.blit(background=Surface_text,location=(214+x_vary, 132+y_vary))
pygame.display.update()
def main_loop_actions(self): # a function just to clean up the main loop things that happen each loop
if scoreboard.counter >= 0:
self.blit(background=scoreboard.draw_text(str(scoreboard.text_counter),(255,255,255),scoreboard.clock_font,), #drawing the counter
location=scoreboard.draw_text_location(str(scoreboard.text_counter),(255,255,255),scoreboard.clock_font,self,0,0))
self.blit(background=scoreboard.draw_text("Score: " + str(player1.tag_score),(255,255,255),scoreboard.font),location= (player1.x - 20, player1.y - 80))
self.blit(scoreboard.draw_text("Score: " + str(player2.tag_score),(255,255,255),scoreboard.font), (player2.x - 20, player2.y - 80))
keys_pressed = pygame.key.get_pressed()
player1.wasd_handlemovement(keys_pressed)
player2.arrow_key_handlemovement(keys_pressed)
player1.y += player1.playerychange
player1.x += player1.playerxchange
player2.x += player2.playerxchange
player2.y += player2.playerychange
if self.is_large: #if the screen is large
player1.border_large()
player2.border_large()
Player.collide_large_screen(player1,player2,self.play_again_hitbox_left,self.play_again_hitbox_right,scoreboard,self)
self.draw_large()
elif not self.is_large: #if the screen is small
player1.border_small()
player2.border_small()
Player.collide_small_screen(player1,player2)
self.draw_small()
def win_loop_actions(self):# a function just to clean up the main loop things that happen each loop
if player1.won:
keys_pressed = pygame.key.get_pressed()
player1.wasd_handlemovement(keys_pressed)
player1.y += player1.playerychange
player1.x += player1.playerxchange
elif player2.won:
keys_pressed = pygame.key.get_pressed()
player2.arrow_key_handlemovement(keys_pressed)
player2.x += player2.playerxchange
player2.y += player2.playerychange
if self.is_large: #if the screen is large
if player1.won:
player1.border_large()
elif player2.won:
player2.border_large()
if Player.collide_large_screen(player1,player2,self.play_again_hitbox_left,self.play_again_hitbox_right,scoreboard,Display): #if they select yes
self.draw_large()
return True
elif Player.collide_large_screen(player1,player2,self.play_again_hitbox_left,self.play_again_hitbox_right,scoreboard,Display): #if they select no
self.draw_large()
return False
elif Player.collide_large_screen(player1,player2,self.play_again_hitbox_left,self.play_again_hitbox_right,scoreboard,Display) == None:
pass
else:
self.draw_large()
return None
self.draw_large()
elif not self.is_large: #if the screen is small, broken don't select small option.
if player1.won:
player1.border_small()
elif player2.won:
player2.border_small()
self.draw_small()
# FUNCTIONS
def start(self):
clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT, 1000) # this is a timer that will tick once per second and is the main time engine
player1.set_initial_player_it_image()
player2.set_initial_player_it_image()
pygame.display.update()
def menu(): #ToDo: implement this as a gui in pygame menu. This is a temp placeholder.
screen_boolean = "large" #input(" Large or small screen ") #Small is false, true is large
if screen_boolean == "small":
# Screen
pygame.display.set_caption("TAG MINIGAME")
size = 800, 600 # 1366x768 is native laptop height
return size
elif screen_boolean == "large":
# Screen
pygame.display.set_caption("TAG MINIGAME")
size = 1366, 768 # 1366x768 is native laptop height
return size
count = 0
def win_screen(screen):
global player1, player2, size, scoreboard, play_again, count
running = True
clock = pygame.time.Clock()
player2.set_winner_image()
player1.set_winner_image()
player1.Velocity_End_Screen, player2.Velocity_End_Screen = 4, 4 #slow the player down so that they don't accidentally move to either option while the game runs out
screen.fill(black)
while running:
clock.tick(FPS)
for event in pygame.event.get():
# while play_again:
if event.type == pygame.QUIT: # if you press on the exit in the top right then it will stop the program
running = False
Display_win_loop_actions_bool = Display.win_loop_actions(screen)
if Display_win_loop_actions_bool: #if they select yes
running = False
return True
elif Display_win_loop_actions_bool == False:# if they select no #make sure you do ==, becase "elif not bool" means none too
running = False
pygame.quit()
elif Display_win_loop_actions_bool != True or Display_win_loop_actions_bool != False: #if they haven't selected
running = True
if not settings.play_again:
return False
if settings.play_again and Display_win_loop_actions_bool == True: #YESS FINALLY DEBUGGING IS GREAT I OVERLOOKED THAT PLAY AGAIN IS DEFAPULTE TO YES.
return True
def main():
global player1, player2, scoreboard, play_again
screen = Display(menu())
screen.display()
running = True
clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT,1000) # this is a timer that will tick once per second and is the main time engine
player1.set_initial_player_it_image()
player2.set_initial_player_it_image()
pygame.display.update()
while running:
clock.tick(FPS)
screen.fill(black)
for event in pygame.event.get():
if event.type == pygame.QUIT: # if you press on the exit in the top right then it will stop the program
pygame.quit()
if event.type == pygame.USEREVENT:
scoreboard.counter -= 1
scoreboard.text_counter = str(scoreboard.counter)
if player1.is_it:
player2.tag_score += 1
elif player2.is_it:
player1.tag_score += 1
if scoreboard.counter < 0: # if the game timer runs out
if player1.tag_score > player2.tag_score: # if player 1 wins
player1.won = True
player2.won = False
player2.move(10000, 1000)
player1.move(614,332)
#player1.move(player1.body_hitbox_large.centerx,player1.body_hitbox_large.centery) was an attempt but its bugged
if player2.tag_score > player1.tag_score: # if player 2 wins
player2.won = True
player1.won = False
player1.move(10000, 10000)
player2.move(614, 332)
elif player2.tag_score == player1.tag_score: # this is if I'm debugging just the win loop
player1.won = True
player2.won = False
player1.move(614, 332)
player2.move(1000000, 10000000)
win_screen_bool = win_screen(screen)
if win_screen_bool == True:
return True
elif win_screen_bool == False:
# pygame.quit()
return False
else:
pass
# running = False
Display.main_loop_actions(screen)
if not settings.play_again:
return False
elif settings.play_again:
return True
while settings.play_again: #while the player wants to keep playing
# Initialize
pygame.init()
num_of_games = 0
scoreboard = Scoreboard()
scoreboard.dice_roll()
player1 = wasd_player(936,200,0,0,pygame.K_w,pygame.K_s,pygame.K_a,pygame.K_d, player1ship,spaceship_it,scoreboard.player1_bool())
player2 = arrow_key_player(200,300,0,0,pygame.K_UP,pygame.K_DOWN,pygame.K_LEFT,pygame.K_RIGHT, player1ship,spaceship_it,scoreboard.player2_bool())
if main(): #if main returns true, and therefore the game should repeat:
pass
if not main(): #if main returns false, and therefore game is over:
pygame.quit()
print("clean break")
break
if num_of_games <= 1:
print("You've played 1 game!")
elif num_of_games > 1:
print(f"You've played {num_of_games} games!")
num_of_games += 1
pygame.quit()
#while true:
#start the game
#if the player chooses to play again, restart the game
#if the player chooses to stop the game, quit the game.