Browse Source

entities reload

master
Nicholas Hayashi 4 years ago
parent
commit
a381a6a9d7
  1. 4
      src/entity.lua
  2. 3
      src/game.lua
  3. 9
      src/tower.lua

4
src/entity.lua

@ -77,8 +77,8 @@ end
function entity_basic_json_parse(json_string)
local entity = am.parse_json(json_string)
entity.position = vec2(entity.position[0], entity.position[1])
entity.hex = vec2(entity.hex[0], entity.hex[1])
entity.position = vec2(entity.position[1], entity.position[2])
entity.hex = vec2(entity.hex[1], entity.hex[2])
return entity
end

3
src/game.lua

@ -142,7 +142,6 @@ local function game_deserialize(json_string)
new_state.map, new_state.world = random_map(new_state.seed)
new_state.seed = nil
new_state.towers = {}
for i,t in pairs(new_state.towers) do
if t then
new_state.towers[i] = tower_deserialize(t)
@ -152,7 +151,6 @@ local function game_deserialize(json_string)
end
end
new_state.mobs = {}
for i,m in pairs(new_state.mobs) do
if m then
new_state.mobs[i] = mob_deserialize(m)
@ -162,7 +160,6 @@ local function game_deserialize(json_string)
end
end
new_state.projectiles = {}
for i,p in pairs(new_state.projectiles) do
if p then
new_state.projectiles[i] = projectile_deserialize(p)

9
src/tower.lua

@ -232,11 +232,11 @@ function tower_deserialize(json_string)
tower.hexes = {}
for i,h in pairs(tower.hexes) do
tower.hexes[i] = vec2(tower.hexes[i][0], tower.hexes[i][1])
tower.hexes[i] = vec2(tower.hexes[i][1], tower.hexes[i][2])
end
tower.update = get_tower_update_function(tower.type)
tower.node = am.translate(tower.position) ^ make_tower_node(tower_type)
tower.node = am.translate(tower.position) ^ make_tower_node(tower.type)
return tower
end
@ -364,7 +364,7 @@ function update_tower_redeye(tower, tower_index)
end
end
else
if state.mobs[tower.target_index] == false then
if not state.mobs[tower.target_index] then
tower.target_index = false
elseif (state.time - tower.last_shot_time) > tower.fire_rate then
@ -397,7 +397,8 @@ function update_tower_howitzer(tower, tower_index)
tower.node("rotate").angle = math.wrapf(tower.node("rotate").angle + 0.1 * am.delta_time, math.pi*2)
else
-- we should have a target
if state.mobs[tower.target_index] == false then
-- @NOTE don't compare to false, empty indexes appear on game reload
if not state.mobs[tower.target_index] then
-- the target we have was invalidated
tower.target_index = false

Loading…
Cancel
Save