-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_state.py
executable file
·52 lines (39 loc) · 1.11 KB
/
game_state.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
import pygame, Box2D
import math
import params
from common import *
from Box2D import b2Vec2
vec = b2Vec2
class GameState(object):
current = None
def __init__(self):
self.scroll = vec(0,0)
self.zoom = params.game.px_scale
def update(self):
pass
def draw(self):
pass
def toScreen(self, v):
p = v*self.zoom - self.scroll
return (int(p.x), int(p.y))
# just a shortcut to get the current state (in our case it's always PlayState, until we make a MenuState or something)
def state():
return GameState.current
class PlayState(GameState):
def __init__(self):
super(PlayState, self).__init__()
self.scroll = vec(-400,-400)
self.cannon_group = pygame.sprite.RenderClear()
self.clods = pygame.sprite.RenderClear()
self.snakes = pygame.sprite.RenderClear()
self.dragons = pygame.sprite.RenderClear()
def update(self):
self.clods.update()
self.snakes.update()
self.dragons.update()
self.cannon_group.update()
def draw(self, screen):
self.clods.draw(screen)
self.snakes.draw(screen)
# self.dragons.draw(screen)
self.cannon_group.draw(screen)