Browse Source

adsf

master
Nicholas Hayashi 3 years ago
parent
commit
f25e64bf08
  1. 2
      lib/random.lua
  2. 7
      src/mob.lua

2
lib/random.lua

@ -41,12 +41,12 @@ end
local R = math.random
local RS = math.randomseed
local function random(n, m)
RANDOM_CALLS_COUNT = RANDOM_CALLS_COUNT + 1
local r
if n then
log('calling random with "n" %g', n)
if m then
r = math.floor(R() * (m - n) + n)
else

7
src/mob.lua

@ -131,7 +131,7 @@ end
local function get_spawn_hex()
-- ensure we spawn on an random tile along the map's edges
local roll = math.random(HEX_GRID_WIDTH * 2 + HEX_GRID_HEIGHT * 2) - 1
local roll = math.floor(math.random() * (HEX_GRID_WIDTH * 2 + HEX_GRID_HEIGHT * 2) - 1)
local x, y
if roll < HEX_GRID_HEIGHT then
@ -298,6 +298,11 @@ local function update_mob_beeper(mob, mob_index)
if mob_can_pass_through(mob, mob.frame_target) then
local from = hex_map_get(game_state.map, mob.hex)
local to = hex_map_get(game_state.map, mob.frame_target)
if not from or not to then
-- @TODO this happens rarely, why? when?
return
end
local rate = (4 * mob.speed - math.abs(to.elevation - from.elevation)) * am.delta_time
mob.position = mob.position + math.normalize(hex_to_pixel(mob.frame_target, vec2(HEX_SIZE)) - mob.position) * rate

Loading…
Cancel
Save