Browse Source

fix healthbar bug

master
Nicholas Hayashi 4 years ago
parent
commit
5ddba662b5
  1. 2
      color.lua
  2. 4
      src/game.lua
  3. 25
      src/mob.lua
  4. 73
      src/tower.lua

2
color.lua

@ -10,7 +10,7 @@ COLORS = {
VERY_DARK_GRAY = vec4(35/255, 35/255, 25/255, 1),
TRUE_BLACK = vec4(0, 0, 0, 1),
-- non-standard hues
-- non-standard ??? hues
WATER = vec4(0.12, 0.25, 0.3, 1),
GRASS = vec4(0.05, 0.22, 0.11, 1),
DIRT = vec4(0.22, 0.20, 0.10, 1),

4
src/game.lua

@ -96,11 +96,11 @@ function select_toolbelt_button(i)
end
local function get_wave_time(current_wave)
return 90
return 15
end
local function get_break_time(current_wave)
return 15
return 90
end
function do_day_night_cycle()

25
src/mob.lua

@ -32,6 +32,16 @@ function get_mob_spec(mob_type)
return MOB_SPECS[mob_type]
end
local function grow_mob_health(mob_type, spec_health, time)
return spec_health * math.log(time)
end
local function grow_mob_speed(mob_type, spec_speed, time)
return spec_speed
end
local function grow_mob_bounty(mob_type, spec_speed, time)
return spec_speed * math.log(time)
end
function mobs_on_hex(hex)
local t = {}
for mob_index,mob in pairs(MOBS) do
@ -70,7 +80,8 @@ function do_hit_mob(mob, damage, mob_index)
mob_die(mob, mob_index)
else
mob.healthbar:action(coroutine.create(function(self)
self:child(1).x2 = -HEALTHBAR_WIDTH/2 + mob.health/get_mob_health(mob.type) * HEALTHBAR_WIDTH/2
local x2 = -HEALTHBAR_WIDTH/2 + mob.health/grow_mob_health(mob.type, get_mob_health(mob.type), state.time) * HEALTHBAR_WIDTH/2
self:child(2).x2 = x2
self.hidden = false
am.wait(am.delay(0.8))
self.hidden = true
@ -80,7 +91,7 @@ end
function make_mob_node(mob_type, mob)
local healthbar = am.group{
--am.rect(-HEALTHBAR_WIDTH/2, -HEALTHBAR_HEIGHT/2, HEALTHBAR_WIDTH/2, HEALTHBAR_HEIGHT/2, COLORS.VERY_DARK_GRAY),
am.rect(-HEALTHBAR_WIDTH/2, -HEALTHBAR_HEIGHT/2, HEALTHBAR_WIDTH/2, HEALTHBAR_HEIGHT/2, COLORS.VERY_DARK_GRAY),
am.rect(-HEALTHBAR_WIDTH/2, -HEALTHBAR_HEIGHT/2, HEALTHBAR_WIDTH/2, HEALTHBAR_HEIGHT/2, COLORS.GREEN_YELLOW)
}
healthbar.hidden = true
@ -264,16 +275,6 @@ local function get_mob_update_function(mob_type)
end
end
local function grow_mob_health(mob_type, spec_health, time)
return spec_health * math.log(time)
end
local function grow_mob_speed(mob_type, spec_speed, time)
return spec_speed
end
local function grow_mob_bounty(mob_type, spec_speed, time)
return spec_speed * math.log(time)
end
local function make_and_register_mob(mob_type)
local mob = make_basic_entity(
get_spawn_hex(),

73
src/tower.lua

@ -25,6 +25,7 @@ TOWER_SPECS = {
cost = 10,
range = 0,
fire_rate = 2,
size = 0,
},
[TOWER_TYPE.HOWITZER] = {
name = "Howitzer",
@ -35,6 +36,7 @@ TOWER_SPECS = {
cost = 20,
range = 10,
fire_rate = 4,
size = 1,
},
[TOWER_TYPE.REDEYE] = {
name = "Redeye",
@ -45,6 +47,7 @@ TOWER_SPECS = {
cost = 20,
range = 12,
fire_rate = 1,
size = 1,
},
[TOWER_TYPE.MOAT] = {
name = "Moat",
@ -55,6 +58,7 @@ TOWER_SPECS = {
cost = 10,
range = 0,
fire_rate = 2,
size = 0,
},
[TOWER_TYPE.RADAR] = {
name = "Radar",
@ -65,6 +69,7 @@ TOWER_SPECS = {
cost = 20,
range = 0,
fire_rate = 1,
size = 1,
},
[TOWER_TYPE.LIGHTHOUSE] = {
name = "Lighthouse",
@ -75,6 +80,7 @@ TOWER_SPECS = {
cost = 20,
range = 8,
fire_rate = 1,
size = 1,
},
}
@ -105,43 +111,14 @@ end
function get_tower_fire_rate(tower_type)
return TOWER_SPECS[tower_type].fire_rate
end
function get_tower_size(tower_type)
return TOWER_SPECS[tower_type.size]
end
local function make_tower_sprite(tower_type)
return pack_texture_into_sprite(get_tower_texture(tower_type), HEX_PIXEL_WIDTH, HEX_PIXEL_HEIGHT)
end
do
local tower_cursors = {}
for _,i in pairs(TOWER_TYPE) do
local tower_sprite = make_tower_sprite(i)
tower_sprite.color = COLORS.TRANSPARENT
local coroutine_ = coroutine.create(function(node)
local flash_on = {}
local flash_off = {}
while true do
for _,n in node:child_pairs() do
table.insert(flash_on, am.tween(n, 1, { color = vec4(0.4) }))
table.insert(flash_off, am.tween(n, 1, { color = vec4(0) }))
end
am.wait(am.parallel(flash_on))
am.wait(am.parallel(flash_off))
flash_on = {}
flash_off = {}
end
end)
tower_cursors[i] = am.group{
make_hex_cursor(get_tower_range(i), vec4(0), coroutine_),
tower_sprite
}
end
function get_tower_cursor(tower_type)
return tower_cursors[tower_type]
end
end
local function make_tower_node(tower_type)
if tower_type == TOWER_TYPE.REDEYE then
return make_tower_sprite(tower_type)
@ -188,6 +165,38 @@ local function make_tower_node(tower_type)
end
end
do
local tower_cursors = {}
for _,i in pairs(TOWER_TYPE) do
local tower_sprite = make_tower_sprite(i)
tower_sprite.color = COLORS.TRANSPARENT
local coroutine_ = coroutine.create(function(node)
local flash_on = {}
local flash_off = {}
while true do
for _,n in node:child_pairs() do
table.insert(flash_on, am.tween(n, 1, { color = vec4(0.4) }))
table.insert(flash_off, am.tween(n, 1, { color = vec4(0) }))
end
am.wait(am.parallel(flash_on))
am.wait(am.parallel(flash_off))
flash_on = {}
flash_off = {}
end
end)
tower_cursors[i] = am.group{
make_hex_cursor(get_tower_range(i), vec4(0), coroutine_),
tower_sprite
}
end
function get_tower_cursor(tower_type)
return tower_cursors[tower_type]
end
end
local function get_tower_update_function(tower_type)
if tower_type == TOWER_TYPE.REDEYE then
return update_tower_redeye

Loading…
Cancel
Save