-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.py
97 lines (97 loc) · 2.82 KB
/
Object.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Img
from random import randint, shuffle
import Entities
class Object(object):
is3d=True
img=None
destructible=True
def __init__(self,x,y):
self.x=x
self.y=y
def get_img(self):
return self.img
def update(self,world):
pass
def explode(self,world):
pass
class Block(Object):
img=Img.img2("Block")
class Indest(Object):
img=Img.img2("Grass2")
destructible = False
class SokoLock(Object):
img=Img.img2("SokoLok")
img2=Img.img2("SokoLokOpen")
destructible = False
lockopen = False
updtick=0
def get_img(self):
return self.img2 if self.lockopen else self.img
def update(self,world):
if not self.lockopen:
if self.updtick!=60:
self.updtick+=1
else:
self.updtick=0
breaking=False
for row in world.t:
for t in row:
if t==4 or t==6 or t==10:
breaking=True
break
if breaking:
break
else:
self.lockopen=True
self.destructible=True
class ExplosiveBlock(Object):
img=Img.img2("ExpBlock")
destructible = False
timer=None
eimgs=[Img.img2("ExpBlockAct"+str(n+1)) for n in range(2)]
def update(self,world):
if self.timer is not None:
self.timer-=1
if self.timer==0:
world.o[self.x][self.y]=None
world.create_exp(self.x,self.y,2)
def explode(self,world):
self.timer=30
def get_img(self):
if self.timer is None:
return self.img
return self.eimgs[self.timer//3%2]
class GhostSpawner(Object):
img=Img.imgsz("GhostSpawn",(32,40))
time=60
def update(self,world):
if not self.time:
dirs=[[1,0],[0,1],[-1,0],[0,-1]]
shuffle(dirs)
for dx,dy in dirs:
if world.is_clear(self.x+dx,self.y+dy):
world.e.append(Entities.Ghost(self.x+dx,self.y+dy))
break
self.time=randint(120,360)
else:
self.time-=1
shot=Img.sndget("Gun")
class CannonBlock(Object):
destructible = False
img=Img.img2("CannonBlock")
def __init__(self,x,y):
self.x=x
self.y=y
self.time=randint(60,120)
def update(self,world):
if not self.time:
p=world.get_p(self.x,self.y)
if p.x<self.x:
world.e.append(Entities.CannonBall(self.x,self.y,-1))
shot.play()
elif p.x>self.x:
world.e.append(Entities.CannonBall(self.x,self.y,1))
shot.play()
self.time=randint(120,360)
else:
self.time-=1