-
Notifications
You must be signed in to change notification settings - Fork 0
/
arcadoid.py
68 lines (55 loc) · 2.05 KB
/
arcadoid.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
import pygame
import time
import os
from etc.setup import Setup
from game.arena import Arena
from game.sounds import Effects
class Arcadoid:
def __init__(self, fps, screen_dim=(800, 600)):
self.pause_mode = False
self.fps = fps
Effects.init(os.path.split(os.path.abspath(__file__))[0])
pygame.init()
if pygame.mixer and not pygame.mixer.get_init():
print('Warning, no sound')
pygame.mixer = None
pygame.display.set_caption('Arcadoid')
pygame.display.set_icon(pygame.image.load(Setup.images + 'icon.png' ))
self.screen = pygame.display.set_mode(screen_dim, pygame.SRCALPHA)
self.clock = pygame.time.Clock()
self.scene = Arena(self.screen)
def events(self, pressed_keys):
filtered_events = []
for event in pygame.event.get():
quit_attempt = False
if event.type == pygame.QUIT:
quit_attempt = True
elif event.type == pygame.KEYDOWN:
alt_pressed = pressed_keys[pygame.K_LALT] or \
pressed_keys[pygame.K_RALT]
if event.key == pygame.K_ESCAPE:
quit_attempt = True
elif event.key == pygame.K_F4 and alt_pressed:
quit_attempt = True
elif event.key == pygame.K_p:
self.pause_mode = not self.pause_mode
if quit_attempt:
exit(0)
else:
filtered_events.append(event)
return filtered_events
def run(self):
while True:
pressed_keys = pygame.key.get_pressed()
filtered_events = self.events(pressed_keys)
if self.pause_mode:
time.sleep(1)
continue
self.scene.ProcessInput(filtered_events, pressed_keys)
self.scene.Update()
self.scene.Render(self.screen)
pygame.display.flip()
self.clock.tick(self.fps)
if __name__ == "__main__":
app = Arcadoid(48)
app.run()