Skip to content

Commit f1e36d1

Browse files
committed
Added Bombergine
1 parent f2e2601 commit f1e36d1

File tree

125 files changed

+1328
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1328
-1
lines changed

Diff for: Bomberman/Data/GameObjects/Bomb/Bomb.lua

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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"},
7+
}
8+
9+
local CompOps = {
10+
_LESS = function(a, b) return a <= b; end,
11+
_MORE = function(a, b) return a >= b; end
12+
}
13+
14+
ExpSprites = {};
15+
16+
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
20+
);
21+
This:LevelSprite():setPosition(pVec, obe.Referential.TopLeft)
22+
This:Animator():setKey("Bomb");
23+
Object.exploded = false;
24+
Object.terrain = terrain;
25+
Object.position = position;
26+
Object.power = power;
27+
Object.chrono = obe.Chronometer();
28+
Object.chrono:setLimit(1000);
29+
end
30+
31+
CAN_PROPAGATE = 0;
32+
STOP_PROPAGATE = 1;
33+
CANT_PROPAGATE = 2;
34+
function Object:canPropagate(x, y)
35+
local bType = self.terrain:get(x, y);
36+
if bType == "Grass" or bType == "Bush" then
37+
return CAN_PROPAGATE;
38+
elseif bType == "Box" then
39+
return STOP_PROPAGATE;
40+
else
41+
return CANT_PROPAGATE;
42+
end
43+
end
44+
45+
function Object:propagate()
46+
for i = 1, Object.power do
47+
for direction, info in pairs(Directions) do
48+
if info.propagate then
49+
local useImg;
50+
local propagationStatus = self:canPropagate(Object.position.x + info.x * i + 1, Object.position.y + info.y * i + 1);
51+
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);
53+
if futurePropagation == CAN_PROPAGATE or futurePropagation == STOP_PROPAGATE then
54+
useImg = info.part;
55+
else
56+
useImg = info.endpart;
57+
end
58+
else
59+
useImg = info.endpart;
60+
end
61+
if propagationStatus == CAN_PROPAGATE or propagationStatus == STOP_PROPAGATE then
62+
local sprId = This:getId() .. "_bpart_" .. direction .. "_" .. i;
63+
local newSprite = Scene:createLevelSprite(sprId);
64+
table.insert(ExpSprites, sprId);
65+
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
70+
);
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);
73+
74+
checkForKills(Object.position.x + info.x * i, Object.position.y + info.y * i);
75+
end
76+
if propagationStatus == STOP_PROPAGATE or propagationStatus == CANT_PROPAGATE then
77+
info.propagate = false;
78+
end
79+
end
80+
end
81+
end
82+
self.chrono:start();
83+
end
84+
85+
function Global.Game.Update(dt)
86+
if This:Animator():getKey() == "Propagate" and not Object.exploded then
87+
Object:propagate();
88+
Object.exploded = true;
89+
end
90+
if Object.chrono:limitExceeded() then
91+
This:delete();
92+
end
93+
end
94+
95+
function Local.Delete()
96+
for k, v in pairs(ExpSprites) do
97+
Scene:removeLevelSprite(v);
98+
end
99+
end
100+
101+
function checkForKills(x, y)
102+
local character1 = Scene:getGameObject("character1");
103+
local character2 = Scene:getGameObject("character2");
104+
if character1.pos.x == x and character1.pos.y == y then
105+
character1:kill();
106+
end
107+
if character2.pos.x == x and character2.pos.y == y then
108+
character2:kill();
109+
end
110+
end

Diff for: Bomberman/Data/GameObjects/Bomb/Bomb.obj.vili

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Include (Obe);
2+
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"
14+

Diff for: Bomberman/Data/GameObjects/Box/Box.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function Local.Init()
2+
end
3+
4+
function Object:delete()
5+
This:delete();
6+
end

Diff for: Bomberman/Data/GameObjects/Box/Box.obj.vili

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Include (Obe);
2+
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"

Diff for: Bomberman/Data/GameObjects/Bush/Bush.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function Local.Init()
2+
end
3+
4+
function Object:delete()
5+
This:delete();
6+
end

Diff for: Bomberman/Data/GameObjects/Bush/Bush.obj.vili

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Include (Obe);
2+
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"

Diff for: Bomberman/Data/GameObjects/Character/Character.lua

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
}
7+
local CompOps = {
8+
_LESS = function(a, b) return a <= b; end,
9+
_MORE = function(a, b) return a >= b; end
10+
}
11+
12+
StartWalking = 0;
13+
Walking = 1;
14+
EndWalking = 2;
15+
NotWalking = 3;
16+
17+
function Local.Init(characterId, terrainId, pos)
18+
Terrain = Scene:getGameObject(terrainId);
19+
Object.cid = characterId;
20+
Object.pos = { x = pos.x, y = pos.y};
21+
Object.direction = "None";
22+
Object.walking = NotWalking;
23+
Object.sprSize = This:LevelSprite():getSize().x;
24+
Object.speed = 0.5;
25+
Object.bombIndex = 0;
26+
This:Animator():setPath("Sprites/GameObjects/Character/" .. characterId);
27+
This:Animator():loadAnimator();
28+
This:Animator():setKey("Idle_Right");
29+
InitializeBindings();
30+
Object.dead = false;
31+
end
32+
33+
function InitializeBindings()
34+
for k, v in pairs(Directions) do
35+
Global.Actions[Object.cid .. "_" .. k] = function()
36+
if Object.walking == NotWalking then
37+
Object.direction = k;
38+
Object.walking = StartWalking;
39+
end
40+
end
41+
end
42+
Global.Actions[Object.cid .. "_Bomb"] = function()
43+
if not Object.dead then
44+
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+
end
49+
end
50+
end
51+
52+
function Global.Game.Update(dt)
53+
if Object.walking == StartWalking then
54+
if not Object.dead then
55+
This:Animator():setKey("Walk_" .. Object.direction);
56+
end
57+
Object.bound = {
58+
x = Directions[Object.direction].x,
59+
y = Directions[Object.direction].y,
60+
cmp = Directions[Object.direction].cmp,
61+
use = Directions[Object.direction].use
62+
}
63+
Object.walking = Walking;
64+
local xProj = Object.pos.x + Directions[Object.direction].x;
65+
local yProj = Object.pos.y + Directions[Object.direction].y;
66+
local tileOnFuturePosition = Terrain:get(xProj + 1, yProj + 1);
67+
if tileOnFuturePosition ~= "Grass" then
68+
Object.walking = NotWalking;
69+
if not Object.dead then
70+
This:Animator():setKey("Idle_" .. Object.direction);
71+
end
72+
else
73+
Object.pos = {
74+
x = Object.pos.x + Directions[Object.direction].x,
75+
y = Object.pos.y + Directions[Object.direction].y
76+
};
77+
end
78+
elseif Object.walking == Walking then
79+
local mx, my;
80+
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+
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
89+
Object.walking = EndWalking;
90+
end
91+
elseif Object.walking == EndWalking then
92+
if not InputManager:getAction(Object.cid .. "_" .. Object.direction):check() then
93+
if not Object.dead then
94+
This:Animator():setKey("Idle_" .. Object.direction);
95+
end
96+
Object.walking = NotWalking;
97+
else
98+
Object.walking = StartWalking;
99+
end
100+
else
101+
local spritePos = obe.UnitVector(
102+
Object.pos.x * This:LevelSprite():getSize().x,
103+
Object.pos.y * This:LevelSprite():getSize().y
104+
);
105+
This:LevelSprite():setPosition(spritePos, obe.Referential.TopLeft);
106+
end
107+
end
108+
109+
function Object:kill()
110+
Object.dead = true;
111+
This:Animator():setKey("Dead");
112+
end
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Include (Obe);
2+
3+
Character:
4+
Collider:
5+
unit:
6+
unit:"SceneUnits"
7+
points:[0, 0
8+
0.181818, 0
9+
0.181818, 0.181818
10+
0, 0.181818]
11+
Animator:
12+
path:""
13+
LevelSprite:
14+
rect:Rect<SceneUnits>(0.0, 0.0, 0.181818, 0.181818)
15+
xTransform:"Camera"
16+
yTransform:"Camera"
17+
z-depth:1
18+
Script:
19+
priority:0.0
20+
source:"Data/GameObjects/Character/Character.lua"
21+
22+
Requires:
23+
Input:
24+
terrainId:
25+
type:"String"
26+
Output:
27+
terrainId:&(terrainId/value)

Diff for: Bomberman/Data/GameObjects/Game/Game.lua

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function makeTexture(name, path)
2+
local texture = Scene:createLevelSprite(name);
3+
texture:setPosition(obe.UnitVector(2.4, 1));
4+
texture:setSize(obe.UnitVector(1, 0.5));
5+
texture:loadTexture(path);
6+
texture:setVisible(false);
7+
return texture;
8+
end
9+
10+
function Local.Init()
11+
Object.character1 = Scene:getGameObject("character1");
12+
Object.character2 = Scene:getGameObject("character2");
13+
14+
Object.nobody_win = makeTexture("nobody_win", "Sprites/GameObjects/Game/nobody_win.png");
15+
Object.p1_win = makeTexture("p1_win", "Sprites/GameObjects/Game/p1_win.png");
16+
Object.p2_win = makeTexture("p2_win", "Sprites/GameObjects/Game/p2_win.png");
17+
Object.run_again = false;
18+
Object.run_again_count = 0;
19+
end
20+
21+
function Global.Game.Update(dt)
22+
if not Object.run_again then
23+
if Object.character1.dead and Object.character2.dead then
24+
Object.nobody_win:setVisible(true);
25+
Object.run_again = true;
26+
elseif Object.character1.dead then
27+
Object.p2_win:setVisible(true);
28+
Object.run_again = true;
29+
elseif Object.character2.dead then
30+
Object.p1_win:setVisible(true);
31+
Object.run_again = true;
32+
end
33+
end
34+
if Object.run_again then
35+
Object.run_again_count = Object.run_again_count + dt;
36+
end
37+
if Object.run_again_count > 5 then
38+
Scene:loadFromFile("Main.map.vili");
39+
end
40+
end

Diff for: Bomberman/Data/GameObjects/Game/Game.obj.vili

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Include (Obe);
2+
3+
Game:
4+
Script:
5+
source:"Data/GameObjects/Game/Game.lua"
6+
7+

0 commit comments

Comments
 (0)