Skip to content

Commit 64917b1

Browse files
author
Sygmei
committed
[wip] still working on Bomberman v0.5 port
1 parent 3decd95 commit 64917b1

23 files changed

+302
-270
lines changed

Bomberman/GameObjects/Bomb/Bomb.lua

+68-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,59 @@
1-
Directions =
2-
{
3-
Left = { propagate = true, x = -1, y = 0, cmp = "_LESS", use = "x", part = "exp_hori", endpart = "exp_left_end" },
4-
Right = { propagate = true, x = 1, y = 0, cmp = "_MORE", use = "x", part = "exp_hori", endpart = "exp_right_end"},
5-
Up = { propagate = true, x = 0, y = -1, cmp = "_LESS", use = "y", part = "exp_vert", endpart = "exp_up_end"},
6-
Down = { propagate = true, x = 0, y = 1, cmp = "_MORE", use = "y", part = "exp_vert", endpart = "exp_down_end"},
1+
Directions = {
2+
Left = {
3+
propagate = true,
4+
x = -1,
5+
y = 0,
6+
cmp = "_LESS",
7+
use = "x",
8+
part = "exp_hori",
9+
endpart = "exp_left_end"
10+
},
11+
Right = {
12+
propagate = true,
13+
x = 1,
14+
y = 0,
15+
cmp = "_MORE",
16+
use = "x",
17+
part = "exp_hori",
18+
endpart = "exp_right_end"
19+
},
20+
Up = {
21+
propagate = true,
22+
x = 0,
23+
y = -1,
24+
cmp = "_LESS",
25+
use = "y",
26+
part = "exp_vert",
27+
endpart = "exp_up_end"
28+
},
29+
Down = {
30+
propagate = true,
31+
x = 0,
32+
y = 1,
33+
cmp = "_MORE",
34+
use = "y",
35+
part = "exp_vert",
36+
endpart = "exp_down_end"
37+
}
738
}
839

940
local CompOps = {
10-
_LESS = function(a, b) return a <= b; end,
11-
_MORE = function(a, b) return a >= b; end
41+
_LESS = function(a, b)
42+
return a <= b;
43+
end,
44+
_MORE = function(a, b)
45+
return a >= b;
46+
end
1247
}
1348

1449
ExpSprites = {};
1550

1651
function Local.Init(position, terrain, power)
17-
local pVec = obe.UnitVector(
18-
position.x * This:LevelSprite():getSize().x,
19-
position.y * This:LevelSprite():getSize().y
52+
local pVec = obe.Transform.UnitVector(
53+
position.x * This.Sprite:getSize().x, position.y * This.Sprite:getSize().y
2054
);
21-
This:LevelSprite():setPosition(pVec, obe.Referential.TopLeft)
22-
This:Animator():setKey("Bomb");
55+
This.Sprite:setPosition(pVec, obe.Transform.Referential.TopLeft)
56+
This.Animator:setKey("Bomb");
2357
Object.exploded = false;
2458
Object.terrain = terrain;
2559
Object.position = position;
@@ -43,13 +77,18 @@ function Object:canPropagate(x, y)
4377
end
4478

4579
function Object:propagate()
46-
for i = 1, Object.power do
80+
for i = 1, Object.power do
4781
for direction, info in pairs(Directions) do
4882
if info.propagate then
4983
local useImg;
50-
local propagationStatus = self:canPropagate(Object.position.x + info.x * i + 1, Object.position.y + info.y * i + 1);
84+
local propagationStatus = self:canPropagate(
85+
Object.position.x + info.x * i + 1, Object.position.y + info.y * i + 1
86+
);
5187
if i ~= Object.power and propagationStatus == CAN_PROPAGATE then
52-
local futurePropagation = self:canPropagate(Object.position.x + info.x * (i + 1) + 1, Object.position.y + info.y * (i + 1) + 1);
88+
local futurePropagation = self:canPropagate(
89+
Object.position.x + info.x * (i + 1) + 1,
90+
Object.position.y + info.y * (i + 1) + 1
91+
);
5392
if futurePropagation == CAN_PROPAGATE or futurePropagation == STOP_PROPAGATE then
5493
useImg = info.part;
5594
else
@@ -63,13 +102,18 @@ function Object:propagate()
63102
local newSprite = Scene:createLevelSprite(sprId);
64103
table.insert(ExpSprites, sprId);
65104
newSprite:loadTexture("Sprites/GameObjects/Bomb/" .. useImg .. ".png");
66-
local spriteSize = obe.UnitVector(This:LevelSprite():getSize().x,This:LevelSprite():getSize().y);
67-
newSprite:setSize(spriteSize, obe.Referential.TopLeft);
68-
local spritePos = obe.UnitVector(
69-
(Object.position.x + info.x * i) * newSprite:getSize().x, (Object.position.y + info.y * i) * newSprite:getSize().y
105+
local spriteSize = obe.Transform.UnitVector(
106+
This.Sprite:getSize().x, This.Sprite:getSize().y
107+
);
108+
newSprite:setSize(spriteSize, obe.Transform.Referential.TopLeft);
109+
local spritePos = obe.Transform.UnitVector(
110+
(Object.position.x + info.x * i) * newSprite:getSize().x,
111+
(Object.position.y + info.y * i) * newSprite:getSize().y
112+
);
113+
newSprite:setPosition(spritePos, obe.Transform.Referential.TopLeft);
114+
self.terrain:removeElementAtPos(
115+
Object.position.x + info.x * i + 1, Object.position.y + info.y * i + 1
70116
);
71-
newSprite:setPosition(spritePos, obe.Referential.TopLeft);
72-
self.terrain:removeElementAtPos(Object.position.x + info.x * i + 1, Object.position.y + info.y * i + 1);
73117

74118
checkForKills(Object.position.x + info.x * i, Object.position.y + info.y * i);
75119
end
@@ -83,7 +127,7 @@ function Object:propagate()
83127
end
84128

85129
function Global.Game.Update(dt)
86-
if This:Animator():getKey() == "Propagate" and not Object.exploded then
130+
if This.Animator:getKey() == "Propagate" and not Object.exploded then
87131
Object:propagate();
88132
Object.exploded = true;
89133
end
@@ -107,4 +151,4 @@ function checkForKills(x, y)
107151
if character2.pos.x == x and character2.pos.y == y then
108152
character2:kill();
109153
end
110-
end
154+
end
+13-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
Include (Obe);
1+
Animator:
2+
path: "Sprites/GameObjects/Bomb"
23

3-
Bomb:
4-
Animator:
5-
path:"Sprites/GameObjects/Bomb"
6-
LevelSprite:
7-
rect:Rect<SceneUnits>(0.0, 0.0, 0.181818, 0.181818)
8-
xTransform:"Camera"
9-
yTransform:"Camera"
10-
z-depth:2
11-
Script:
12-
priority:0.0
13-
source:"Data/GameObjects/Bomb/Bomb.lua"
4+
Sprite:
5+
rect:
6+
x: 0
7+
y: 0
8+
width: 0.181818
9+
height: 0.181818
10+
transform: CameraTransform
11+
zdepth: 2
1412

13+
Script:
14+
priority: 0
15+
source: "self://Bomb.lua"
+11-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
Include (Obe);
1+
Sprite:
2+
path: "Sprites/GameObjects/Box/box.png"
3+
rect:
4+
x: 0
5+
y: 0
6+
width: 0.181818
7+
height: 0.181818
8+
transform: CameraTransform
9+
zdepth: 2
210

3-
Box:
4-
LevelSprite:
5-
path:"Sprites/GameObjects/Box/box.png"
6-
rect:Rect<SceneUnits>(0.0, 0.0, 0.181818, 0.181818)
7-
xTransform:"Camera"
8-
yTransform:"Camera"
9-
z-depth:2
10-
Script:
11-
source:"Data/GameObjects/Box/Box.lua"
11+
Script:
12+
source: "self://Box.lua"
+11-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
Include (Obe);
1+
Sprite:
2+
path: "Sprites/GameObjects/Bush/bush.png"
3+
rect:
4+
x: 0
5+
y: 0
6+
width: 0.181818
7+
height: 0.181818
8+
transform: CameraTransform
9+
zdepth: 2
210

3-
Bush:
4-
LevelSprite:
5-
path:"Sprites/GameObjects/Bush/bush.png"
6-
rect:Rect<SceneUnits>(0.0, 0.0, 0.181818, 0.181818)
7-
xTransform:"Camera"
8-
yTransform:"Camera"
9-
z-depth:2
10-
Script:
11-
source:"Data/GameObjects/Bush/Bush.lua"
11+
Script:
12+
source: "self://Bush.lua"
+40-36
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
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"}
66
}
77
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
1014
}
1115

1216
StartWalking = 0;
@@ -15,25 +19,24 @@ EndWalking = 2;
1519
NotWalking = 3;
1620

1721
function Local.Init(characterId, terrainId, pos)
18-
Terrain = Scene:getGameObject(terrainId);
22+
Terrain = Engine.Scene:getGameObject(terrainId);
1923
Object.cid = characterId;
20-
Object.pos = { x = pos.x, y = pos.y};
24+
Object.pos = {x = pos.x, y = pos.y};
2125
Object.direction = "None";
2226
Object.walking = NotWalking;
23-
Object.sprSize = This:LevelSprite():getSize().x;
27+
Object.sprSize = This.Sprite:getSize().x;
2428
Object.speed = 0.5;
2529
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");
2932
InitializeBindings();
3033
Object.dead = false;
3134
end
3235

3336
function InitializeBindings()
3437
for k, v in pairs(Directions) do
3538
Global.Actions[Object.cid .. "_" .. k] = function()
36-
if Object.walking == NotWalking then
39+
if Object.walking == NotWalking then
3740
Object.direction = k;
3841
Object.walking = StartWalking;
3942
end
@@ -42,19 +45,19 @@ function InitializeBindings()
4245
Global.Actions[Object.cid .. "_Bomb"] = function()
4346
if not Object.dead then
4447
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});
4851
end
4952
end
5053
end
5154

52-
function Global.Game.Update(dt)
55+
function Event.Game.Update(evt)
5356
if Object.walking == StartWalking then
5457
if not Object.dead then
55-
This:Animator():setKey("Walk_" .. Object.direction);
58+
This.Animator:setKey("Walk_" .. Object.direction);
5659
end
57-
Object.bound = {
60+
Object.bound = {
5861
x = Directions[Object.direction].x,
5962
y = Directions[Object.direction].y,
6063
cmp = Directions[Object.direction].cmp,
@@ -67,46 +70,47 @@ function Global.Game.Update(dt)
6770
if tileOnFuturePosition ~= "Grass" then
6871
Object.walking = NotWalking;
6972
if not Object.dead then
70-
This:Animator():setKey("Idle_" .. Object.direction);
73+
This.Animator:setKey("Idle_" .. Object.direction);
7174
end
7275
else
73-
Object.pos = {
76+
Object.pos = {
7477
x = Object.pos.x + Directions[Object.direction].x,
7578
y = Object.pos.y + Directions[Object.direction].y
7679
};
7780
end
7881
elseif Object.walking == Walking then
7982
local mx, my;
8083
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;
8487
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
8994
Object.walking = EndWalking;
9095
end
9196
elseif Object.walking == EndWalking then
9297
if not InputManager:getAction(Object.cid .. "_" .. Object.direction):check() then
9398
if not Object.dead then
94-
This:Animator():setKey("Idle_" .. Object.direction);
99+
This.Animator:setKey("Idle_" .. Object.direction);
95100
end
96101
Object.walking = NotWalking;
97102
else
98103
Object.walking = StartWalking;
99104
end
100105
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
104108
);
105-
This:LevelSprite():setPosition(spritePos, obe.Referential.TopLeft);
109+
This.Sprite:setPosition(spritePos, obe.Transform.Referential.TopLeft);
106110
end
107111
end
108112

109113
function Object:kill()
110114
Object.dead = true;
111-
This:Animator():setKey("Dead");
112-
end
115+
This.Animator:setKey("Dead");
116+
end

0 commit comments

Comments
 (0)