-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
95 lines (79 loc) · 2.82 KB
/
test.py
File metadata and controls
95 lines (79 loc) · 2.82 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
import pygame as pg
import random
from settings import *
from sprites import *
from os import path
class Game:
def __init__(self):
pg.init()
pg.font.init()
pg.mixer.init()
self.screen = pg.display.set_mode((WIDTH, HEIGHT))
pg.display.set_caption(TITLE)
self.clock = pg.time.Clock()
self.running = True
self.font_name = pg.font.match_font(FONT)
self.load_data()
def load_data(self):
self.dir = path.dirname(__file__)
# load sounds
self.sound_dir = path.join(self.dir, 'sounds')
# sound effects will be added below
def run(self):
pg.mixer.music.play(loops = -1)
self.playing = True
while self.playing:
self.clock.tick(FPS)
self.events()
self.draw()
generateCannon(100,100)
pg.mixer.music.fadeout(500)
def reset(self):
pg.mixer.music.load(path.join(self.sound_dir, 'loop1.wav'))
self.run()
def events(self):
for event in pg.event.get():
if event.type == pg.QUIT:
if self.playing:
self.playing = False
self.running = False
def draw(self):
self.screen.fill(WHITE)
pg.display.flip()
def start_screen(self):
self.screen.fill(BLUE)
self.draw_text(TITLE, 48, WHITE, WIDTH / 2, HEIGHT / 4)
self.draw_text("- Orbs will be launched out of a cannon", 24, WHITE, WIDTH / 2, HEIGHT / 2)
self.draw_text("- You must make sure that they arrive at their destination", 24, WHITE, WIDTH / 2, HEIGHT / 2 - 24)
self.draw_text("- Watch out, theres a time limit!", 24, WHITE, WIDTH / 2, HEIGHT / 2 - 48)
self.draw_text("Press any key to play, you gopnik", 24, WHITE, WIDTH / 2, HEIGHT / 2 - 72)
pg.display.flip()
self.wait_for_key()
def end_screen(self):
if not self.running:
return
self.screen.fill(BLUE)
self.draw_text("GAME OVER", 48, WHITE, WIDTH / 2, HEIGHT / 4)
self.draw_text("wOmP wOmP", 48, WHITE, WIDTH / 2, HEIGHT / 4 - 48)
def draw_text(self, text, size, color, x, y):
font = pg.font.Font(self.font_name, size)
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
text_rect.midtop = (x, y)
self.screen.blit(text_surface, text_rect)
def wait_for_key(self):
waiting = True
while waiting:
self.clock.tick(FPS)
for event in pg.event.get():
if event.type == pg.QUIT:
waiting = False
self.running = False
if event.type == pg.KEYUP:
waiting = False
game = Game()
game.start_screen()
while game.running:
game.reset()
game.end_screen()
pg.quit()