-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger.py
More file actions
71 lines (55 loc) · 1.77 KB
/
Copy pathtrigger.py
File metadata and controls
71 lines (55 loc) · 1.77 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import io
import itertools
from entity import Entity
class Trigger(object):
__script = None
__entered = []
def __init__(self,o):
self.__receipe = o
props = o.get("properties",{})
self.__receipe["x"] /= 64.
self.__receipe["y"] /= 64.
self.__receipe["width"] /= 64.
self.__receipe["height"] /= 64.
self.__entered = []
if "script" in props:
self.__script = compile(io.open(props["script"]).read(),"<string>","exec")
def trigger(self, entity):
x = self.__receipe["x"]
y = self.__receipe["y"]
w = self.__receipe["width"]
h = self.__receipe["height"]
x2 = entity.getPosition().x
y2 = entity.getPosition().y
if x2 >= x and y2 >= y and x2 <= x+w and y2 <= y+h:
if not (entity in self.__entered):
self.call("onEnter",entity)
self.__entered.append(entity)
else:
self.call("onStay",entity)
else:
if (entity in self.__entered):
self.call("onLeave",entity)
self.__entered.remove(entity)
def call(self, method, *args):
if method in self.__script.co_names:
#game = self.__game
# gamestate = self.__game.getGameStateManager().getCurrentGameState()
# entitymanager = gamestate.getEntityManager()
# keys = gamestate.keys
# specialkeys = gamestate.specialkeys
# mouseL = gamestate.mouseL
# mouseR = gamestate.mouseR
# mouseM = gamestate.mouseM
# cursorX = gamestate.cursorX
# cursorY = gamestate.cursorY
# cursorZ = gamestate.cursorZ
# current_animation = self.__animation
# position = self.__position
# velocity = self.__velocity
# alpha = self.__alpha
exec(self.__script,locals(),globals())
call_method = method+"("+(",".join(itertools.chain(["self"],["args["+str(x)+"]" for x in range(len(args))])))+")"
exec(call_method,locals(),globals())