|
@ -10,12 +10,11 @@ mob(entity) structure: |
|
|
} |
|
|
} |
|
|
--]] |
|
|
--]] |
|
|
|
|
|
|
|
|
-- distance from hex centerpoint to nearest edge |
|
|
|
|
|
MOB_SIZE = hex_height(HEX_SIZE, ORIENTATION.FLAT) / 2 |
|
|
|
|
|
|
|
|
MAX_MOB_SIZE = hex_height(HEX_SIZE, ORIENTATION.FLAT) / 2 |
|
|
|
|
|
MOB_SIZE = MAX_MOB_SIZE/2 |
|
|
|
|
|
|
|
|
function mobs_on_hex(hex) |
|
|
function mobs_on_hex(hex) |
|
|
local t = {} |
|
|
local t = {} |
|
|
|
|
|
|
|
|
for mob_index,mob in pairs(MOBS) do |
|
|
for mob_index,mob in pairs(MOBS) do |
|
|
if mob and mob.hex == hex then |
|
|
if mob and mob.hex == hex then |
|
|
table.insert(t, mob_index, mob) |
|
|
table.insert(t, mob_index, mob) |
|
@ -33,39 +32,11 @@ end |
|
|
|
|
|
|
|
|
function mob_die(mob, mob_index) |
|
|
function mob_die(mob, mob_index) |
|
|
WORLD:action(vplay_sound(SOUNDS.EXPLOSION1)) |
|
|
WORLD:action(vplay_sound(SOUNDS.EXPLOSION1)) |
|
|
--WORLD:append(mob_death_explosion(mob)) |
|
|
|
|
|
delete_entity(MOBS, mob_index) |
|
|
delete_entity(MOBS, mob_index) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
function mob_death_explosion(mob) |
|
|
|
|
|
local t = 0.5 |
|
|
|
|
|
return am.particles2d{ |
|
|
|
|
|
source_pos = mob.position, |
|
|
|
|
|
source_pos_var = vec2(mob.hurtbox_radius), |
|
|
|
|
|
max_particles = 25, |
|
|
|
|
|
start_size = mob.hurtbox_radius/10, |
|
|
|
|
|
start_size_var = mob.hurtbox_radius/15, |
|
|
|
|
|
end_size = 0, |
|
|
|
|
|
angle = 0, |
|
|
|
|
|
angle_var = math.pi, |
|
|
|
|
|
speed = 105, |
|
|
|
|
|
speed_var = 55, |
|
|
|
|
|
life = t * 0.8, |
|
|
|
|
|
life_var = t * 0.2, |
|
|
|
|
|
start_color = COLORS.CLARET, |
|
|
|
|
|
start_color_var = COLORS.DIRT, |
|
|
|
|
|
end_color = COLORS.DIRT, |
|
|
|
|
|
end_color_var = COLORS.CLARET, |
|
|
|
|
|
damping = 0.3 |
|
|
|
|
|
}:action(coroutine.create(function(self) |
|
|
|
|
|
am.wait(am.delay(t)) |
|
|
|
|
|
WORLD:remove(self) |
|
|
|
|
|
end)) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function do_hit_mob(mob, damage, mob_index) |
|
|
function do_hit_mob(mob, damage, mob_index) |
|
|
mob.health = mob.health - damage |
|
|
mob.health = mob.health - damage |
|
|
|
|
|
|
|
|
if mob.health <= 0 then |
|
|
if mob.health <= 0 then |
|
|
update_score(mob.bounty) |
|
|
update_score(mob.bounty) |
|
|
mob_die(mob, mob_index) |
|
|
mob_die(mob, mob_index) |
|
@ -74,9 +45,9 @@ end |
|
|
|
|
|
|
|
|
function check_for_broken_mob_pathing(hex) |
|
|
function check_for_broken_mob_pathing(hex) |
|
|
for _,mob in pairs(MOBS) do |
|
|
for _,mob in pairs(MOBS) do |
|
|
if mob and mob.path[hex.x] and mob.path[hex.x][hex.y] then |
|
|
|
|
|
mob.path = get_mob_path(mob, HEX_MAP, mob.hex, HEX_GRID_CENTER) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
--if mob and mob.path[hex.x] and mob.path[hex.x][hex.y] then |
|
|
|
|
|
--mob.path = get_mob_path(mob, HEX_MAP, mob.hex, HEX_GRID_CENTER) |
|
|
|
|
|
--end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
@ -90,7 +61,7 @@ end |
|
|
-- try reducing map size by identifying key nodes (inflection points) |
|
|
-- try reducing map size by identifying key nodes (inflection points) |
|
|
-- there are performance hits everytime we spawn a mob and it's Astar's fault |
|
|
-- there are performance hits everytime we spawn a mob and it's Astar's fault |
|
|
function get_mob_path(mob, map, start, goal) |
|
|
function get_mob_path(mob, map, start, goal) |
|
|
return Astar(map, goal, start, grid_heuristic, grid_cost) |
|
|
|
|
|
|
|
|
--return Astar(map, goal, start, grid_heuristic, grid_cost) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- @FIXME there's a bug here where the position of the spawn hex is sometimes 1 closer to the center than we want |
|
|
-- @FIXME there's a bug here where the position of the spawn hex is sometimes 1 closer to the center than we want |
|
@ -124,20 +95,43 @@ local function get_spawn_hex() |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function mob_update(mob, mob_index) |
|
|
local function mob_update(mob, mob_index) |
|
|
|
|
|
local last_frame_hex = mob.hex |
|
|
mob.hex = pixel_to_hex(mob.position) |
|
|
mob.hex = pixel_to_hex(mob.position) |
|
|
|
|
|
|
|
|
local frame_target = mob.path[mob.hex.x] and mob.path[mob.hex.x][mob.hex.y] |
|
|
|
|
|
|
|
|
|
|
|
if frame_target then |
|
|
|
|
|
mob.position = mob.position + math.normalize(hex_to_pixel(frame_target.hex) - mob.position) * mob.speed |
|
|
|
|
|
mob.node.position2d = mob.position |
|
|
|
|
|
else |
|
|
|
|
|
if mob.hex == HEX_GRID_CENTER then |
|
|
if mob.hex == HEX_GRID_CENTER then |
|
|
update_score(-mob.health) |
|
|
update_score(-mob.health) |
|
|
mob_die(mob, mob_index) |
|
|
mob_die(mob, mob_index) |
|
|
else |
|
|
|
|
|
log("stuck") |
|
|
|
|
|
|
|
|
return true |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
--local frame_target = mob.path[mob.hex.x] and mob.path[mob.hex.x][mob.hex.y] |
|
|
|
|
|
local frame_target = nil |
|
|
|
|
|
local neighbours = HEX_MAP.neighbours(mob.hex) |
|
|
|
|
|
if #neighbours ~= 0 then |
|
|
|
|
|
local first_entry = HEX_MAP.get(neighbours[1].x, neighbours[1].y) |
|
|
|
|
|
|
|
|
|
|
|
local best_hex = neighbours[1] |
|
|
|
|
|
local best_cost = first_entry and first_entry.priority or HEX_MAP.get(last_frame_hex.x, last_frame_hex.y).priority |
|
|
|
|
|
|
|
|
|
|
|
for _,h in pairs(neighbours) do |
|
|
|
|
|
--if h ~= last_frame_hex then |
|
|
|
|
|
local map_entry = HEX_MAP.get(h.x, h.y) |
|
|
|
|
|
local cost = map_entry.priority |
|
|
|
|
|
|
|
|
|
|
|
if cost and cost < best_cost then |
|
|
|
|
|
best_cost = cost |
|
|
|
|
|
best_hex = h |
|
|
|
|
|
end |
|
|
|
|
|
--end |
|
|
|
|
|
end |
|
|
|
|
|
frame_target = best_hex |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if frame_target then |
|
|
|
|
|
mob.position = mob.position + math.normalize(hex_to_pixel(frame_target) - mob.position) * mob.speed |
|
|
|
|
|
mob.node.position2d = mob.position |
|
|
|
|
|
else |
|
|
|
|
|
log("no frame target") |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
--[[ passive animation |
|
|
--[[ passive animation |
|
@ -165,7 +159,7 @@ local function make_and_register_mob() |
|
|
register_entity(MOBS, mob) |
|
|
register_entity(MOBS, mob) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local SPAWN_CHANCE = 100 |
|
|
|
|
|
|
|
|
local SPAWN_CHANCE = 25 |
|
|
function do_mob_spawning() |
|
|
function do_mob_spawning() |
|
|
--if WIN:key_pressed"space" then |
|
|
--if WIN:key_pressed"space" then |
|
|
if math.random(SPAWN_CHANCE) == 1 then |
|
|
if math.random(SPAWN_CHANCE) == 1 then |
|
|