-
Notifications
You must be signed in to change notification settings - Fork 0
/
hunt.py
67 lines (54 loc) · 1.74 KB
/
hunt.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
import os, sys
import pygame
import pygame.transform
from game.registry import adjpos, adjrect, adjwidth, adjheight
# Game parameters
SCREEN_WIDTH, SCREEN_HEIGHT = adjpos (800, 500)
TITLE = "classic hunt shoot"
FRAMES_PER_SEC = 50
BG_COLOR = 255, 255, 255
# Initialize pygame before importing modules
pygame.mixer.pre_init(44100, -16, 2, 1024)
pygame.init()
pygame.display.set_caption(TITLE)
pygame.mouse.set_visible(False)
import game.driver
class Game(object):
def __init__(self):
self.running = True
self.surface = None
self.clock = pygame.time.Clock()
self.size = SCREEN_WIDTH, SCREEN_HEIGHT
background = os.path.join('media', 'background.jpg')
bg = pygame.image.load(background)
self.background = pygame.transform.smoothscale (bg, self.size)
self.driver = None
def init(self):
self.surface = pygame.display.set_mode(self.size)
self.driver = game.driver.Driver(self.surface)
def handleEvent(self, event):
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == 27):
self.running = False
else:
self.driver.handleEvent(event)
def loop(self):
self.clock.tick(FRAMES_PER_SEC)
self.driver.update()
def render(self):
self.surface.blit(self.background, (0,0))
self.driver.render()
pygame.display.flip()
def cleanup(self):
pygame.quit()
sys.exit(0)
def execute(self):
self.init()
while (self.running):
for event in pygame.event.get():
self.handleEvent(event)
self.loop()
self.render()
self.cleanup()
if __name__ == "__main__":
theGame = Game()
theGame.execute()