Browse Source

music tracks, fix projectile bug

master
Nicholas Hayashi 4 years ago
parent
commit
9b4f6654b1
  1. BIN
      res/track1.ogg
  2. 48
      src/main.lua
  3. 29
      src/mob.lua
  4. 15
      src/projectile.lua
  5. 7
      src/sound.lua
  6. 2
      src/tower.lua

BIN
res/track1.ogg

48
src/main.lua

@ -25,16 +25,24 @@ OFF_SCREEN = vec2(WIN.width * 2) -- arbitrary pixel position that is garunteed t
WORLD = false -- root scene node of everything considered to be in the game world
TIME = 0 -- runtime of the current game in seconds
SCORE = 0 -- score of the player
MONEY = 0 -- available resources
MOUSE = false -- position of the mouse at the start of every frame, if an action is tracking it
RAND = 0 -- result of first call to math.random() this frame
local COORDINATE_DISPLAY_TYPES = {
-- global audio settings
MUSIC_VOLUME = 0.1
SFX_VOLUME = 0.1
local TRDTS = {
NOTHING = -1,
CENTERED_EVENQ = 0,
EVENQ = 1,
HEX = 2
HEX = 2,
PLATFORM = 3,
PERF = 4
}
local COORDINATE_DISPLAY_TYPE = COORDINATE_DISPLAY_TYPES.CENTERED_EVENQ
local TRDT = TRDTS.CENTERED_EVENQ
local function game_action(scene)
if SCORE < 0 then game_end() end
@ -47,7 +55,7 @@ local function game_action(scene)
local rounded_mouse = hex_to_pixel(hex) + WORLDSPACE_COORDINATE_OFFSET
local evenq = hex_to_evenq(hex)
local centered_evenq = evenq{ y = -evenq.y } - vec2(math.floor(HEX_GRID_WIDTH/2)
, math.floor(HEX_GRID_HEIGHT/2))
, math.floor(HEX_GRID_HEIGHT/2))
local tile = HEX_MAP.get(hex.x, hex.y)
local hot = is_interactable(tile, evenq{ y = -evenq.y })
@ -67,7 +75,7 @@ local function game_action(scene)
WIN.scene = game_scene()
elseif WIN:key_pressed"f3" then
COORDINATE_DISPLAY_TYPE = (COORDINATE_DISPLAY_TYPE + 1) % #table.keys(COORDINATE_DISPLAY_TYPES)
TRDT = (TRDT + 1) % #table.keys(TRDTS)
elseif WIN:key_pressed"f4" then
log(HEX_MAP.seed)
@ -81,19 +89,26 @@ local function game_action(scene)
end
WIN.scene"score".text = string.format("SCORE: %.2f", SCORE)
WIN.scene"money".text = string.format("MONEY: %d", MONEY)
do
local str, coords
if COORDINATE_DISPLAY_TYPE == COORDINATE_DISPLAY_TYPES.CENTERED_EVENQ then
str, coords = "evenqc", centered_evenq
local str = ""
if TRDT == TRDTS.CENTERED_EVENQ then
str = string.format("%d,%d (cevenq)", centered_evenq.x, centered_evenq.y)
elseif TRDT == TRDTS.EVENQ then
str = string.format("%d,%d (evenq)", evenq.x, evenq.y)
elseif COORDINATE_DISPLAY_TYPE == COORDINATE_DISPLAY_TYPES.EVENQ then
str, coords = "evenq", evenq
elseif TRDT == TRDTS.HEX then
str = string.format("%d,%d (hex)", hex.x, hex.y)
elseif COORDINATE_DISPLAY_TYPE == COORDINATE_DISPLAY_TYPES.HEX then
str, coords = "hex", hex
elseif TRDT == TRDTS.PLATFORM then
str = string.format("%s %s lang %s", am.platform, am.version, am.language())
elseif TRDT == TRDTS.PERF then
str = table.tostring(am.perf_stats())
end
WIN.scene"coords".text = string.format("%d,%d (%s)", coords.x, coords.y, str)
WIN.scene"coords".text = str
end
end
@ -138,7 +153,8 @@ end
-- @NOTE must be global to allow the game_action to reference it
function game_scene()
local score = am.translate(WIN.left + 10, WIN.top - 20) ^ am.text("", "left"):tag"score"
local coords = am.translate(WIN.right - 10, WIN.top - 20) ^ am.text("", "right"):tag"coords"
local money = am.translate(WIN.left + 10, WIN.top - 40) ^ am.text("", "left"):tag"money"
local coords = am.translate(WIN.right - 10, WIN.top - 20) ^ am.text("", "right", "top"):tag"coords"
local hex_cursor = am.circle(OFF_SCREEN, HEX_SIZE, COLORS.TRANSPARENT, 6):tag"hex_cursor"
local curtain = am.rect(WIN.left, WIN.bottom, WIN.right, WIN.top, COLORS.TRUE_BLACK)
@ -155,16 +171,18 @@ function game_scene()
hex_cursor,
toolbelt(),
score,
money,
coords,
}
scene:action(game_action)
scene:action(am.play(SOUNDS.TRACK1))
return scene
end
function get_debug_string()
return string.format("%s, %s lang %s\n%s", am.platform, am.version, am.language(), am.perf_stats())
end
require "texture"

29
src/mob.lua

@ -3,10 +3,6 @@
require "extra"
require "sound"
function mob_die(mob, entity_index)
WORLD:action(vplay_sound(SOUNDS.EXPLOSION1))
delete_entity(entity_index)
end
-- @NOTE returns i,v in the table
function mob_on_hex(hex)
@ -15,6 +11,12 @@ function mob_on_hex(hex)
end)
end
function mob_die(mob, entity_index)
WORLD:action(vplay_sound(SOUNDS.EXPLOSION1))
delete_entity(entity_index)
end
function do_hit_mob(mob, damage, index)
mob.health = mob.health - damage
@ -27,7 +29,10 @@ end
function check_for_broken_mob_pathing(hex)
for _,entity in pairs(ENTITIES) do
if entity.type == ENTITY_TYPE.MOB and entity.path[hex.x] and entity.path[hex.x][hex.y] then
entity.path = get_mob_path(entity, HEX_MAP, entity.hex, HEX_GRID_CENTER)
--local pathfinder = coroutine.create(function()
entity.path = get_mob_path(entity, HEX_MAP, entity.hex, HEX_GRID_CENTER)
--end)
--coroutine.resume(pathfinder)
end
end
end
@ -123,7 +128,7 @@ local function make_and_register_mob()
end
-- passive animation
if RAND < 0.01 then
if math.random() < 0.01 then
_mob.node"rotate":action(am.tween(0.3, { angle = _mob.node"rotate".angle + math.pi*3 }))
else
_mob.node"rotate".angle = math.wrapf(_mob.node"rotate".angle + am.delta_time, math.pi*2)
@ -131,14 +136,14 @@ local function make_and_register_mob()
end
)
mob.path = get_mob_path(mob, HEX_MAP, mob.hex, HEX_GRID_CENTER)
mob.health = 10
mob.speed = 5
mob.bounty = 5
mob.hurtbox_radius = 15
mob.path = get_mob_path(mob, HEX_MAP, mob.hex, HEX_GRID_CENTER)
mob.health = 10
mob.speed = 1
mob.bounty = 5
mob.hurtbox_radius = 15
end
local SPAWN_CHANCE = 50
local SPAWN_CHANCE = 100
function do_mob_spawning()
--if WIN:key_pressed"space" then
if math.random(SPAWN_CHANCE) == 1 then

15
src/projectile.lua

@ -16,7 +16,13 @@ function make_and_register_projectile(hex, vector, velocity)
_projectile.node.position2d = _projectile.position
_projectile.hex = pixel_to_hex(_projectile.position)
if not point_in_rect(_projectile.position + WORLDSPACE_COORDINATE_OFFSET, {
local mob_index,mob = mob_on_hex(_projectile.hex)
if mob and math.distance(mob.position, _projectile.position) > math.abs(_projectile.hitbox_radius - mob.hurtbox_radius) then
do_hit_mob(mob, _projectile.damage, mob_index)
delete_entity(_projectile_index)
WORLD:action(vplay_sound(SOUNDS.HIT1))
elseif not point_in_rect(_projectile.position + WORLDSPACE_COORDINATE_OFFSET, {
x1 = WIN.left,
y1 = WIN.bottom,
x2 = WIN.right,
@ -24,13 +30,6 @@ function make_and_register_projectile(hex, vector, velocity)
}) then
delete_entity(_projectile_index)
end
local mob_index,mob = mob_on_hex(_projectile.hex)
if mob and math.distance(mob.position, _projectile.position) > math.abs(_projectile.hitbox_radius - mob.hurtbox_radius) then
do_hit_mob(mob, _projectile.damage, mob_index)
delete_entity(_projectile_index)
WORLD:action(vplay_sound(SOUNDS.HIT1))
end
end
)

7
src/sound.lua

@ -1,17 +1,22 @@
SOUNDS = {
-- sfxr_synth seeds
EXPLOSION1 = 49179102, -- this slowed sounds metal as fuck
EXPLOSION2 = 19725402,
EXPLOSION3 = 69338002,
HIT1 = 25811004,
LASER1 = 79859301,
LASER2 = 86914201,
PUSH1 = 30455908,
BIRD1 = 50838307,
RANDOM1 = 85363309,
RANDOM2 = 15482409,
RANDOM3 = 58658009,
RANDOM4 = 89884209,
RANDOM5 = 36680709
RANDOM5 = 36680709,
-- audio buffers
TRACK1 = am.track(am.load_audio("../res/track1.ogg"), true, 1, 0.1)
}
-- play a sound with variable pitch

2
src/tower.lua

@ -42,7 +42,7 @@ function make_and_register_tower(hex)
)
_tower.last_shot_time = TIME
_tower.node:action(vplay_sound(SOUNDS.EXPLOSION3))
_tower.node:action(vplay_sound(SOUNDS.LASER2))
end
end
end

Loading…
Cancel
Save