-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevels.py
77 lines (59 loc) · 1.88 KB
/
levels.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
import pygame
import datetime as dt
import sprite
import data
class LevelBase(object):
def __init__(self):
self.cell_size = (20,20)
self.next_wave = None
self.update = 0
self.wave = 0
self.next_wave = None
self.last_update = None
data.extents = ((20,20),(640-80,460))
def Draw(self, surf):
surf.blit(self.image, (0,0), None, 0)
if data.selected:
t = data.selected
pygame.draw.circle(surf, (255,0,0),
(t.pos[0]+10,t.pos[1]+10), t.range, 3)
def Update(self):
self.update += 1
now = dt.datetime.now()
if self.wave is None:
return
if self.next_wave is None:
self.next_wave = now + \
dt.timedelta(seconds=self.times[self.wave])
if self.last_update is None:
self.last_update = now
delta = now - self.last_update
if delta.seconds >= 1:
next_time = self.next_wave - now
print "seconds until next wave: %d" % next_time.seconds
self.last_update = now
if now > self.next_wave:
self.NextWave()
def IsFinished(self):
return self.wave >= len(self.times)
def NextWave(self):
pass
class Level1(LevelBase):
def __init__(self):
super(Level1,self).__init__()
self.image = pygame.image.load("level_snow.png")
data.start_pt = (540,40)
data.end_pt = (80,340)
self.times = [ 10,10 ]
the_base = sprite.Sprite("base.png", range(7), 15, (80,340))
data.sprites.append( the_base )
def NextWave(self):
if self.wave is None:
return
self.wave += 1
self.next_wave = None
if self.wave == 1:
print "wave1"
elif self.wave == 2:
print "wave2"
self.wave = None