-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
69 lines (50 loc) · 1.92 KB
/
Game.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
#!/usr/bin/env python
import pygame
from pygame.sprite import Group
from Player import *
from Block import *
from Camera import *
from Level import *
NORTH =(0, -1)
EAST = (1, 0)
SOUTH =(0, 1)
WEST = (-1, 0)
class Game(object):
def __init__(self, screen):
self.deaths = 0
self.screen = screen
self.level = Level('reallevel')
self.spawn()
self.game_area = screen.subsurface((0, 40, screen.get_width(), screen.get_height() - 40))
self.cam = Camera(self.player, self.level.bounds, self.game_area.get_size())
self.hud = screen.subsurface((0, 0, screen.get_width(), 40))
self.deathtext = pygame.font.Font(None, 20)
def spawn(self):
self.player = Player((self.level.spawnPoint), self.level, self)
def quit(self):
self.done = True
def loop(self):
self.done = False
self.clock = pygame.time.Clock()
while not self.done:
dt = self.clock.tick(30)
#input
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
self.quit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
self.player.jump()
#update
self.player.update(dt)
self.cam.update(self.player.rect)
#draw
self.hud.fill((80, 80, 80))
text = self.deathtext.render("deaths: " + str(self.deaths), True, (0, 255, 0))
self.hud.blit(text, (0, 0))
self.game_area.fill((0,0,0))
self.cam.draw_background(self.game_area, self.level.background)
self.cam.draw_sprite(self.game_area, self.player)
#refresh
pygame.display.flip()