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 79da926 commit 1fad7c3
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions scripts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,49 @@ engine:prefetch({
"blobs/octopus.png",
"blobs/player.png",
"blobs/princess.png",
"blobs/ship.png",
"blobs/ship.png"
})

engine:set_scene("ship")

local postal = PostalService.new()

local soundmanager = engine:soundmanager()

local octopus = engine:spawn("octopus")
local player = engine:spawn("player")
local princess = engine:spawn("princess")
local candle1 = engine:spawn("candle")
local candle2 = engine:spawn("candle")

local life = 20

local shooting = false
local bullet_pool = {}
local explosion_pool = {}

local function create_bullet_pool(size)
for _ = 1, size do
local bullet = engine:spawn("bullet")
bullet:set_placement(-128, -128)

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

bullet:unset_action()
bullet:set_placement(-128, -128)
table.insert(bullet_pool, bullet)
end
end)

table.insert(bullet_pool, bullet)
end
for _ = 1, 3 do
local bullet = engine:spawn("bullet")
bullet:set_placement(-128, -128)
bullet:on_update(function(self)
if self.x > 1200 then
postal:post(Mail.new(0, "bullet", "hit"))
bullet:unset_action()
bullet:set_placement(-128, -128)
table.insert(bullet_pool, bullet)
end
end)
table.insert(bullet_pool, bullet)
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
for _ = 1, 9 do
local explosion = engine:spawn("explosion")
explosion:set_placement(-128, -128)
table.insert(explosion_pool, explosion)
end

create_explosion_pool(9)

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

Expand All @@ -88,9 +75,7 @@ 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")
Expand All @@ -113,7 +98,8 @@ candle2:set_placement(1800, 100)
local function fire()
if #bullet_pool > 0 then
local bullet = table.remove(bullet_pool)
local x, y = (player.x + player.size.width) - 30, player.y + 30
local x = (player.x + player.size.width) - 30
local y = player.y + 30
local offset_y = (math.random(-2, 2)) * 20

bullet:set_placement(x, y + offset_y)
Expand All @@ -125,8 +111,6 @@ local function fire()
end
end

local shooting = false

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

Expand Down

0 comments on commit 1fad7c3

Please sign in to comment.