Skip to content

Commit 34b0af2

Browse files
committed
Code and Files
1 parent 24954b6 commit 34b0af2

8 files changed

+250
-0
lines changed

Piano_Desire.wav

4.61 MB
Binary file not shown.

Pygame II.py

+250
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
__author__ = 'Rutvik'
2+
import pygame
3+
import time
4+
import random
5+
import os
6+
7+
screen_x = 200
8+
screen_y = 100
9+
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (screen_x,screen_y)
10+
pygame.init()
11+
display_size = (1080,720)
12+
game_display = pygame.display.set_mode(display_size)
13+
pygame.display.set_caption("Copter Chase")
14+
clock = pygame.time.Clock()
15+
controls_image = pygame.image.load("wasd.png")
16+
missile_image = pygame.image.load("missile-war-weapon_318-48046.png")
17+
crash_sound = pygame.mixer.Sound("Smashing-Yuri_Santana-1233262689.wav")
18+
pygame.mixer.music.load("Piano_Desire.wav")
19+
20+
#Copter Values
21+
copter_image = pygame.image.load("copter2.png")
22+
copter_width = 100
23+
copter_height = 75
24+
25+
#Sound Files
26+
red = (255,0,0)
27+
white = (255,255,255)
28+
black = (0,0,0)
29+
green = (0,255,0)
30+
blue = (0,0,255)
31+
wood = (139,35,35)
32+
bg = (61,89,171)
33+
34+
35+
def missile_display(x,y):
36+
game_display.blit(missile_image,(x,y))
37+
38+
39+
def controls_display():
40+
game_display.blit(controls_image,(400,20))
41+
42+
43+
def copter_display(image1, x ,y):
44+
game_display.blit(image1, (x, y))
45+
46+
47+
def title_text_function(text, font, color):
48+
title_text_surface = font.render(text, True, color)
49+
return title_text_surface, title_text_surface.get_rect()
50+
51+
52+
def button_text(text, font, color):
53+
buttontext_surf = font.render(text,True, color)
54+
return buttontext_surf, buttontext_surf.get_rect()
55+
56+
57+
def title_screen(text, color):
58+
title_s_font = pygame.font.SysFont("comicsansms", 120)
59+
title_s_surf, title_s_rect = title_text_function(text, title_s_font, color)
60+
title_s_rect.center = ((display_size[0]/2), display_size[1]/2)
61+
game_display.blit(title_s_surf, title_s_rect)
62+
63+
def credits_object(text,font):
64+
cre_surf = font.render(text, True, white)
65+
return cre_surf, cre_surf.get_rect()
66+
67+
def game_credits(text):
68+
credits_font = pygame.font.SysFont("comicsansms", 15)
69+
credits_surf, credits_rect = credits_object(text, credits_font)
70+
credits_rect.center = (80, 10)
71+
game_display.blit(credits_surf, credits_rect)
72+
73+
def buttons(color_rect,x,y,w,h,button_font_size,text,color_font):
74+
pygame.draw.rect(game_display,color_rect,(x,y,w,h))
75+
button_font = pygame.font.Font("freesansbold.ttf", button_font_size)
76+
button_surf, button_rect = button_text(text,button_font,color_font)
77+
button_rect.center = (x+(w/2), y+(h/2))
78+
game_display.blit(button_surf, button_rect)
79+
80+
81+
def score_text_function(text_sc, font, color):
82+
score_text_f = font.render("Score: " + text_sc, True,color )
83+
return score_text_f,score_text_f.get_rect()
84+
85+
86+
def display_score(text_sc,font_sc,color):
87+
score_text = pygame.font.SysFont("comicsansms",20)
88+
score_text_surf, score_text_rect = score_text_function(text_sc,score_text, color)
89+
score_text_rect.center = (50,20)
90+
game_display.blit(score_text_surf,score_text_rect)
91+
92+
def crash_message():
93+
pygame.mixer.music.stop()
94+
pygame.mixer.Sound.play(crash_sound)
95+
game_display.fill(black)
96+
crash_text1 = pygame.font.SysFont("comnicsansms", 30)
97+
crash_text1_surf, crash_text1_rect = title_text_function("You Crashed :(", crash_text1, white)
98+
crash_text1_rect.center = (540, 620)
99+
game_display.blit(crash_text1_surf, crash_text1_rect)
100+
101+
102+
103+
def game_loop():
104+
pygame.mixer.music.play(-1)
105+
game_value = True
106+
copter_x = 100
107+
copter_y = 250
108+
altitude_change = 0
109+
horizontal_change =0
110+
score = 0
111+
top_obs_x = random.randrange(1100, 1400)
112+
top_obs_y = 110
113+
top_obs_height = random.randrange(110,260)
114+
bot_obs_x = random.randrange(1100, 1400)
115+
bot_obs_y = random.randrange(450,600)
116+
bot_obs_height = 600 - bot_obs_y
117+
obs_width = random.randrange(50,90)
118+
obs_speed = 4
119+
missile_x = 1200
120+
missile_y = random.randrange(220,580)
121+
missile_speed = 6
122+
missile_height = 100
123+
missile_width = 100
124+
copter_mis_x = copter_x+copter_width
125+
copter_mis_y = copter_y+copter_height
126+
missile_launch = False
127+
crash = False
128+
while game_value:
129+
copter_mouse_pos = pygame.mouse.get_pos()
130+
copter_mouse_click= pygame.mouse.get_pressed()
131+
for event in pygame.event.get():
132+
if event.type == pygame.QUIT:
133+
pygame.quit()
134+
quit()
135+
if event.type == pygame.KEYDOWN:
136+
if event.key == pygame.K_w:
137+
altitude_change -= 4
138+
if event.type == pygame.KEYDOWN:
139+
if event.key == pygame.K_s:
140+
altitude_change += 4
141+
if event.type == pygame.KEYDOWN:
142+
if event.key == pygame.K_d:
143+
horizontal_change += 5
144+
if event.type == pygame.KEYDOWN:
145+
if event.key == pygame.K_a:
146+
horizontal_change -= 5
147+
if event.type == pygame.KEYDOWN:
148+
if event.key == pygame.K_v:
149+
missile_launch = True
150+
if event.type == pygame.KEYUP:
151+
if event.key == pygame.K_w:
152+
altitude_change = 0
153+
if event.key == pygame.K_s:
154+
altitude_change = 0
155+
if event.key == pygame.K_d:
156+
horizontal_change = 0
157+
if event.key == pygame.K_a:
158+
horizontal_change = 0
159+
if event.key == pygame.K_v:
160+
missile_launch = True
161+
copter_y += altitude_change
162+
copter_x += horizontal_change
163+
game_display.fill(bg)
164+
#TOP OBSTACLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165+
pygame.draw.rect(game_display, black, (0,0,1080, 110))
166+
pygame.draw.rect(game_display,wood, (top_obs_x,top_obs_y,obs_width, top_obs_height))
167+
top_obs_x -= obs_speed
168+
#BOTTOM OBSTACLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169+
pygame.draw.rect(game_display, black, (0, 600, 1080, 150))
170+
pygame.draw.rect(game_display,wood, (bot_obs_x,bot_obs_y,obs_width, bot_obs_height))
171+
bot_obs_x -= obs_speed
172+
#GENERATING N OBSTACLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173+
if top_obs_x+obs_width < 0 :
174+
top_obs_x = random.randrange(1100, 1400)
175+
top_obs_height = random.randrange(110,240)
176+
score += 1
177+
if bot_obs_x + obs_width <0:
178+
bot_obs_x = random.randrange(1100, 1400)
179+
bot_obs_y = random.randrange(450,600)
180+
bot_obs_height = 600 - bot_obs_y
181+
score += 1
182+
score_str = str(score)
183+
#GENERATING RECT BLOCKS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184+
missile_x = missile_x - missile_speed
185+
missile_display(missile_x, missile_y)
186+
#GENERATING N RECT BLOCKS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187+
if missile_x < 0:
188+
missile_x = 1200
189+
missile_y = random.randrange(220,580)
190+
#GENERATE COPTER MISSILE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191+
if missile_launch == True:
192+
pygame.draw.circle(game_display,black,(copter_mis_x,copter_mis_y),8,0)
193+
copter_mis_x +=6
194+
if copter_mis_x > 1080:
195+
missile_launch = False
196+
copter_mis_x = copter_x + copter_width
197+
copter_mis_y = copter_y + copter_height
198+
#DETECTING COLLISIONS WITH WALL AND TOP/BOTTOM OBSTACLES~~~~~~~~~~~~~~~~~~~~~~~~
199+
if copter_x < 0:
200+
crash_message()
201+
game_value = False
202+
if copter_y + 50 < 110:
203+
crash_message()
204+
game_value = False
205+
if copter_y + 50 + copter_height > 600:
206+
crash_message()
207+
game_value = False
208+
if copter_y - 20 <= top_obs_height + 50 and top_obs_x-60 < copter_x + copter_width < top_obs_x + obs_width:
209+
crash_message()
210+
game_value = False
211+
if copter_y + copter_height + 30 >= bot_obs_y and bot_obs_x < copter_x + copter_width + 90 < bot_obs_x + obs_width:
212+
crash_message()
213+
game_value = False
214+
#DETECTING COLLISION WITH THE MISSILE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215+
if copter_x < missile_x < copter_x + copter_width and copter_y < missile_y < copter_y + copter_height:
216+
crash_message()
217+
game_value = False
218+
219+
220+
221+
display_score(score_str,20, blue)
222+
copter_display(copter_image, copter_x, copter_y)
223+
controls_display()
224+
pygame.display.update()
225+
clock.tick(70)
226+
227+
228+
def game_intro():
229+
intro_value = True
230+
while intro_value:
231+
for event in pygame.event.get():
232+
if event.type == pygame.QUIT:
233+
pygame.quit()
234+
quit()
235+
title_screen("Copter Chase", red)
236+
game_credits("Created by: Rutvik")
237+
buttons(white,200,550,100,50,25,"Play!",red)
238+
buttons(white,800,550,100,50,25,"Quit",red)
239+
mouse_location = pygame.mouse.get_pos()
240+
mouse_clicks = pygame.mouse.get_pressed()
241+
for event in pygame.event.get():
242+
if 800 < mouse_location[0] < 900 and 550 < mouse_location[1] < 600:
243+
if mouse_clicks[0] == 1:
244+
pygame.quit()
245+
quit()
246+
if 200 < mouse_location[0] < 300 and 550 < mouse_location[1] < 600:
247+
if mouse_clicks[0] == 1:
248+
game_loop()
249+
pygame.display.update()
250+
game_intro()

Screenshot.png

97.1 KB
Loading

Smashing-Yuri_Santana-1233262689.wav

363 KB
Binary file not shown.

copter1.png

59.1 KB
Loading

copter2.png

7.29 KB
Loading

missile-war-weapon_318-48046.png

1.19 KB
Loading

wasd.png

5.81 KB
Loading

0 commit comments

Comments
 (0)