Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
skhaz committed Oct 7, 2024
1 parent ce5641e commit 2d25dd6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 70 deletions.
2 changes: 1 addition & 1 deletion entities/bullet.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"width": 40,
"height": 40,
"animations": {
"shoot": {
"default": {
"frames": [
{
"x": 0,
Expand Down
2 changes: 1 addition & 1 deletion entities/candle.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"width": 14,
"height": 31,
"animations": {
"light": {
"default": {
"frames": [
{
"x": 1,
Expand Down
5 changes: 3 additions & 2 deletions entities/explosion.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"width": 52,
"height": 72,
"animations": {
"explosion": {
"default": {
"frames": [
{
"x": 1,
Expand Down Expand Up @@ -47,7 +47,8 @@
"y": 371,
"width": 52,
"height": 72,
"duration": 120
"duration": 120,
"singleshoot": true
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion entities/princess.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"width": 18,
"height": 29,
"animations": {
"idle": {
"default": {
"frames": [
{
"x": 1,
Expand Down
136 changes: 71 additions & 65 deletions scripts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,16 @@ local postal = PostalService.new()

local soundmanager = engine:soundmanager()

local bullets = {}

local state = {
space = false
}

local octopus = engine:spawn("octopus")
local life = 13

octopus:set_action("idle")
octopus:set_placement(1200, 620)
octopus:on_mail(function(self, message)
if message == 'hit' then
octopus:set_action("attack")
life = life - 1
if life <= 0 then
self:set_action("dead")
else
-- local explosion = engine:spawn("explosion")
-- explosion:set_action("explosion")
-- explosion:set_placement(1300, 700)
end
end
end)

local player = engine:spawn("player")
player:set_action("idle")
player:set_placement(30, 794)

local princess = engine:spawn("princess")
princess:set_action("idle")
princess:set_placement(1600, 806)

local candle1 = engine:spawn("candle")
candle1:set_action("light")
candle1:set_placement(60, 100)

local candle2 = engine:spawn("candle")
candle2:set_action("light")
candle2:set_placement(1800, 100)

-- local explosion = engine:spawn("explosion")
-- explosion:set_action("explosion")
-- explosion:set_placement(1300, 700)

-- local bullet = engine:spawn("bullet")
-- bullet:set_action("shoot")
-- bullet:set_placement(300, 580)
-- bullet:set_velocity(Vector2D.new(0.4, 0))
-- bullet:on_update(function(self)
-- if self.x > 860 then
-- local message = Mail.new(0, "hit")
-- postal:post(message)
-- engine:destroy(bullet)
-- end
-- end)
local life = 20

local bullet_pool = {}
local explosion_pool = {}

local function create_bullet_pool(size)
for _ = 1, size do
Expand All @@ -88,7 +41,6 @@ local function create_bullet_pool(size)

bullet:on_update(function(self)
if self.x > 1200 then
print("self x " .. self.x)
local message = Mail.new(0, "bullet", "hit")
postal:post(message)

Expand All @@ -102,6 +54,63 @@ local function create_bullet_pool(size)
end
end

create_bullet_pool(3)

local function create_explosion_pool(size)
for _ = 1, size do
local explosion = engine:spawn("explosion")
explosion:set_placement(-128, -128)
table.insert(explosion_pool, explosion)
end
end

create_explosion_pool(32)

local function bomb()
print("pool size " .. #explosion_pool)
if #explosion_pool > 0 then
local explosion = table.remove(explosion_pool)
local x, y = octopus.x, player.y
local offset_x = (math.random(-2, 2)) * 30
local offset_y = (math.random(-2, 2)) * 30

explosion:set_placement(x + offset_x, y + offset_y)
explosion:set_action("default")
explosion:on_update(function(self)
if not self.visible then
self:set_placement(-128, -128)
end
end)
end
end

octopus:set_action("idle")
octopus:set_placement(1200, 620)
octopus:on_mail(function(self, message)
if message == 'hit' then
bomb()

octopus:set_action("attack")

life = life - 1
if life <= 0 then
self:set_action("dead")
end
end
end)

player:set_action("idle")
player:set_placement(30, 794)

princess:set_action("default")
princess:set_placement(1600, 806)

candle1:set_action("default")
candle1:set_placement(60, 100)

candle2:set_action("default")
candle2:set_placement(1800, 100)

local function fire()
if #bullet_pool > 0 then
local bullet = table.remove(bullet_pool)
Expand All @@ -110,34 +119,31 @@ local function fire()

bullet:set_placement(x, y + offset_y)
bullet:set_velocity(Vector2D.new(0.6, 0))
bullet:set_action("shoot")
bullet:set_action("default")

local sound = "bomb" .. math.random(1, 2)
soundmanager:play(sound)
end
end

create_bullet_pool(3)

local shooting = false

player:on_update(function(self)
local velocity = Vector2D.new(0, 0)

if engine:is_keydown(KeyEvent.a) then
velocity.x = -.4
-- octopus:set_action("attack")
elseif engine:is_keydown(KeyEvent.d) then
velocity.x = .4
-- octopus:set_action("dead")
end

if engine:is_keydown(KeyEvent.space) then
if not state.space then
if not shooting then
fire()
state.space = true
shooting = true
end
else
state.space = false
shooting = false
end

if engine:is_keydown(KeyEvent.a) then
velocity.x = -.4
elseif engine:is_keydown(KeyEvent.d) then
velocity.x = .4
end

if velocity:moving() then
Expand Down

0 comments on commit 2d25dd6

Please sign in to comment.