Add cars to the docks area

- Allow enemies to spawn on wall tiles
This commit is contained in:
Hugues Ross 2021-01-29 07:08:04 -05:00
parent f1b317c748
commit da5794b507
10 changed files with 106 additions and 12 deletions

View File

@ -15,7 +15,7 @@ function jellyfish.new(x, y)
}
end
function jellyfish.update(self, player, level, dt)
function jellyfish.update(self, player, level, systems, dt)
if physics.boxCollide(self, player) then
player:hurt(1)
end

View File

@ -16,7 +16,7 @@ function urchin.new(x, y)
}
end
function urchin.update(self, player, level, dt)
function urchin.update(self, player, level, systems, dt)
if physics.boxCollide(self, player) then
player:hurt(1)
end

View File

@ -10,12 +10,12 @@ function enemies.add(self, enemy)
self.enemy_count = self.enemy_count + 1
end
function enemies.update(self, player, level, dt)
function enemies.update(self, player, level, systems, dt)
local i = 1
while self.enemies[i] do
local e = self.enemies[i]
if not e.dead and e.update then
e:update(player, level, dt)
e:update(player, level, systems, dt)
end
if e.dead then
@ -43,7 +43,9 @@ end
function enemies.draw(self)
for i,e in ipairs(self.enemies) do
e:draw()
if e.draw then
e:draw()
end
end
end

View File

@ -89,7 +89,11 @@ function level.init(self, filename, enemies)
enemies:add(enemy)
self.tiles[tileIndex] = (self.levelData.enemies[index].tile or 1) + 14
if self.levelData.enemies[index].wall then
self.tiles[tileIndex] = self.levelData.enemies[index].wall + 9
else
self.tiles[tileIndex] = (self.levelData.enemies[index].floor or 1) + 14
end
else
self.tiles[tileIndex] = 15
end

View File

@ -16,11 +16,11 @@ return {
doors = {
},
enemies = {
{ data = require("npcs.idler"), props = { id = "docks_fisherman_1" }, tile = 2 },
{ data = require("npcs.idler"), props = { id = "docks_fisherman_2" }, tile = 2 },
{ data = require("npcs.vendor"), props = { id = "docks_shopkeep" }, tile = 3 },
-- { data = require("npcs.car_spawner"), props = { path = 1 } },
-- { data = require("npcs.car_spawner"), props = { path = 2 } },
{ data = require("npcs.idler"), props = { id = "docks_fisherman_1" }, floor = 2 },
{ data = require("npcs.idler"), props = { id = "docks_fisherman_2" }, floor = 2 },
{ data = require("npcs.vendor"), props = { id = "docks_shopkeep" }, floor = 3 },
{ data = require("npcs.car_spawner"), props = { path = 1 }, wall = 3 },
{ data = require("npcs.car_spawner"), props = { path = 2 }, wall = 3 },
},
transitions = {
{ map = "reefs_1", x = 29, y = 0, tile = 2 },

View File

@ -42,7 +42,7 @@ end
function love.update(dt)
if not systems.dialogue.visible then
player:update(level, dt)
systems.enemies:update(player, level, dt)
systems.enemies:update(player, level, systems, dt)
end
systems.camera:update(level, player, dt)
end

55
npcs/car.lua Normal file
View File

@ -0,0 +1,55 @@
local car = {
sprites = {
love.graphics.newImage("sprites/car1.png"),
love.graphics.newImage("sprites/car2.png"),
}
}
function car.new(x, y)
return {
x = x,
y = y,
width = 12,
height = 12,
direction = 1,
update = car.update,
draw = car.draw,
path_index = 1,
}
end
function car.update(self, player, level, systems, dt)
local adj_x = self.x / level.tile_width
local adj_y = self.y / level.tile_width
if adj_x == self.path[self.path_index][1] and adj_y == self.path[self.path_index][2] then
self.path_index = self.path_index + 1
if self.path_index > #self.path then
self.dead = true
return
end
end
if adj_x < self.path[self.path_index][1] then
self.x = self.x + 2
self.direction = 1
elseif adj_x > self.path[self.path_index][1] then
self.x = self.x - 2
self.direction = 1
end
if adj_y < self.path[self.path_index][2] then
self.y = self.y + 2
self.direction = 2
elseif adj_y > self.path[self.path_index][2] then
self.y = self.y - 2
self.direction = 2
end
end
function car.draw(self)
love.graphics.setColor(1, 1, 1)
love.graphics.draw(car.sprites[self.direction], self.x, self.y);
end
return car

33
npcs/car_spawner.lua Normal file
View File

@ -0,0 +1,33 @@
local car_paths = {
{{25, 0}, {25, 12}, {0, 12}},
{{0, 15}, {28, 15}, {28, 0}},
}
local car = require("npcs.car")
local car_spawner = {
}
function car_spawner.new(x, y)
return {
x = x,
y = y,
width = 12,
height = 12,
update = car_spawner.update,
cooldown = love.math.random(1, 10)
}
end
function car_spawner.update(self, player, level, systems, dt)
self.cooldown = self.cooldown - dt
if self.cooldown <= 0 then
self.cooldown = love.math.random(1, 10)
local c = car.new(self.x, self.y)
c.path = car_paths[self.path]
systems.enemies:add(c)
end
end
return car_spawner

BIN
sprites/car1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B

BIN
sprites/car2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B