forked from llortus/Run-
/
game.py
executable file
·77 lines (67 loc) · 2.3 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
70
71
72
73
74
75
76
77
import sys
import time
import pygame
from pygame.locals import *
import state
import level
import player
import title
import hud
import highscores
import surface_manager
class Game(state.State):
score = 0
streak_counter = 0
combo_timer = time.clock()
player
def __init__(self):
self.timer = pygame.time.Clock()
self.display = pygame.display.get_surface()
self.level_manager = state.StateMachine(self, level.Level())
self.player = player.Player()
Game.player = self.player
self.hud_manager = state.StateMachine(self, hud.Hud(self, self.player, self.timer))
self.background = pygame.image.load("data/images/city.png").convert_alpha()
surface_manager.add(self.player)
self.music = pygame.mixer.Sound("data/sound/game.wav")
self.music.play(loops=-1)
def exit(self):
self.music.stop()
Game.score = 0
Game.streak_counter = 0
def reason(self):
keys = pygame.key.get_pressed()
if keys[K_ESCAPE]:
self.level_manager.current_state.exit()
return title.Title()
if self.player.pos_y > self.display.get_height():
if Game.streak_counter > 1:
Game.score += 5 * (Game.streak_counter*2)
self.level_manager.current_state.exit()
return highscores.HighScores(Game.score)
def act(self):
self.timer.tick(60)
surface_manager.clear(self.display, self.background)
keys = pygame.key.get_pressed()
if keys[K_SPACE]:
self.player.jump()
else:
self.player.stop_jumping()
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_1:
self.player.throw_shuriken()
check_for_combo()
self.level_manager.update()
surface_manager.update()
dirty_rects = surface_manager.draw(self.display)
pygame.display.update(dirty_rects)
def update_score():
Game.score += 5
Game.combo_timer = time.clock()
Game.streak_counter += 1
def check_for_combo():
if Game.streak_counter > 1 and time.clock() > Game.combo_timer + 1:
Game.score += 5 * (Game.streak_counter*2)
hud.show_combo(5 * (Game.streak_counter*2))
Game.streak_counter = 0