1
- local Directions = {
2
- Left = { x = - 1 , y = 0 , cmp = " _LESS" , use = " x" },
3
- Right = { x = 1 , y = 0 , cmp = " _MORE" , use = " x" },
4
- Down = { x = 0 , y = 1 , cmp = " _MORE" , use = " y" },
5
- Up = { x = 0 , y = - 1 , cmp = " _LESS" , use = " y" }
1
+ local Directions = {
2
+ Left = {x = - 1 , y = 0 , cmp = " _LESS" , use = " x" },
3
+ Right = {x = 1 , y = 0 , cmp = " _MORE" , use = " x" },
4
+ Down = {x = 0 , y = 1 , cmp = " _MORE" , use = " y" },
5
+ Up = {x = 0 , y = - 1 , cmp = " _LESS" , use = " y" }
6
6
}
7
7
local CompOps = {
8
- _LESS = function (a , b ) return a <= b ; end ,
9
- _MORE = function (a , b ) return a >= b ; end
8
+ _LESS = function (a , b )
9
+ return a <= b ;
10
+ end ,
11
+ _MORE = function (a , b )
12
+ return a >= b ;
13
+ end
10
14
}
11
15
12
16
StartWalking = 0 ;
@@ -15,25 +19,24 @@ EndWalking = 2;
15
19
NotWalking = 3 ;
16
20
17
21
function Local .Init (characterId , terrainId , pos )
18
- Terrain = Scene :getGameObject (terrainId );
22
+ Terrain = Engine . Scene :getGameObject (terrainId );
19
23
Object .cid = characterId ;
20
- Object .pos = { x = pos .x , y = pos .y };
24
+ Object .pos = {x = pos .x , y = pos .y };
21
25
Object .direction = " None" ;
22
26
Object .walking = NotWalking ;
23
- Object .sprSize = This : LevelSprite () :getSize ().x ;
27
+ Object .sprSize = This . Sprite :getSize ().x ;
24
28
Object .speed = 0.5 ;
25
29
Object .bombIndex = 0 ;
26
- This :Animator ():setPath (" Sprites/GameObjects/Character/" .. characterId );
27
- This :Animator ():loadAnimator ();
28
- This :Animator ():setKey (" Idle_Right" );
30
+ This .Animator :load (obe .System .Path (" root://Sprites/GameObjects/Character/" .. characterId ));
31
+ This .Animator :setKey (" Idle_Right" );
29
32
InitializeBindings ();
30
33
Object .dead = false ;
31
34
end
32
35
33
36
function InitializeBindings ()
34
37
for k , v in pairs (Directions ) do
35
38
Global .Actions [Object .cid .. " _" .. k ] = function ()
36
- if Object .walking == NotWalking then
39
+ if Object .walking == NotWalking then
37
40
Object .direction = k ;
38
41
Object .walking = StartWalking ;
39
42
end
@@ -42,19 +45,19 @@ function InitializeBindings()
42
45
Global .Actions [Object .cid .. " _Bomb" ] = function ()
43
46
if not Object .dead then
44
47
Object .bombIndex = Object .bombIndex + 1 ;
45
- Scene :createGameObject ( " Bomb " , Object . cid .. " _bomb_ " .. tostring ( Object . bombIndex )) (
46
- { position = Object .pos , terrain = Terrain , power = 6 }
47
- );
48
+ Engine . Scene :createGameObject (
49
+ " Bomb " , Object .cid .. " _bomb_ " .. tostring ( Object . bombIndex )
50
+ )({ position = Object . pos , terrain = Terrain , power = 6 }) ;
48
51
end
49
52
end
50
53
end
51
54
52
- function Global .Game .Update (dt )
55
+ function Event .Game .Update (evt )
53
56
if Object .walking == StartWalking then
54
57
if not Object .dead then
55
- This : Animator () :setKey (" Walk_" .. Object .direction );
58
+ This . Animator :setKey (" Walk_" .. Object .direction );
56
59
end
57
- Object .bound = {
60
+ Object .bound = {
58
61
x = Directions [Object .direction ].x ,
59
62
y = Directions [Object .direction ].y ,
60
63
cmp = Directions [Object .direction ].cmp ,
@@ -67,46 +70,47 @@ function Global.Game.Update(dt)
67
70
if tileOnFuturePosition ~= " Grass" then
68
71
Object .walking = NotWalking ;
69
72
if not Object .dead then
70
- This : Animator () :setKey (" Idle_" .. Object .direction );
73
+ This . Animator :setKey (" Idle_" .. Object .direction );
71
74
end
72
75
else
73
- Object .pos = {
76
+ Object .pos = {
74
77
x = Object .pos .x + Directions [Object .direction ].x ,
75
78
y = Object .pos .y + Directions [Object .direction ].y
76
79
};
77
80
end
78
81
elseif Object .walking == Walking then
79
82
local mx , my ;
80
83
if Object .bound .use == " x" then
81
- mx , my = Object .bound .x * dt * Object .speed , 0 ;
82
- else
83
- mx , my = 0 , Object .bound .y * dt * Object .speed ;
84
+ mx , my = Object .bound .x * evt . dt * Object .speed , 0 ;
85
+ else
86
+ mx , my = 0 , Object .bound .y * evt . dt * Object .speed ;
84
87
end
85
- local move = obe .UnitVector (mx , my );
86
- This :LevelSprite ():move (move );
87
- local newpos = This :LevelSprite ():getPosition (obe .Referential .TopLeft );
88
- if CompOps [Object .bound .cmp ](newpos [Object .bound .use ], Object .pos [Object .bound .use ] * Object .sprSize ) then
88
+ local move = obe .Transform .UnitVector (mx , my );
89
+ This .Sprite :move (move );
90
+ local newpos = This .Sprite :getPosition (obe .Transform .Referential .TopLeft );
91
+ if CompOps [Object .bound .cmp ](
92
+ newpos [Object .bound .use ], Object .pos [Object .bound .use ] * Object .sprSize
93
+ ) then
89
94
Object .walking = EndWalking ;
90
95
end
91
96
elseif Object .walking == EndWalking then
92
97
if not InputManager :getAction (Object .cid .. " _" .. Object .direction ):check () then
93
98
if not Object .dead then
94
- This : Animator () :setKey (" Idle_" .. Object .direction );
99
+ This . Animator :setKey (" Idle_" .. Object .direction );
95
100
end
96
101
Object .walking = NotWalking ;
97
102
else
98
103
Object .walking = StartWalking ;
99
104
end
100
105
else
101
- local spritePos = obe .UnitVector (
102
- Object .pos .x * This :LevelSprite ():getSize ().x ,
103
- Object .pos .y * This :LevelSprite ():getSize ().y
106
+ local spritePos = obe .Transform .UnitVector (
107
+ Object .pos .x * This .Sprite :getSize ().x , Object .pos .y * This .Sprite :getSize ().y
104
108
);
105
- This : LevelSprite (): setPosition (spritePos , obe .Referential .TopLeft );
109
+ This . Sprite : setPosition (spritePos , obe . Transform .Referential .TopLeft );
106
110
end
107
111
end
108
112
109
113
function Object :kill ()
110
114
Object .dead = true ;
111
- This : Animator () :setKey (" Dead" );
112
- end
115
+ This . Animator :setKey (" Dead" );
116
+ end
0 commit comments