|
@ -13,13 +13,20 @@ require "projectile" |
|
|
require "tower" |
|
|
require "tower" |
|
|
|
|
|
|
|
|
-- Globals |
|
|
-- Globals |
|
|
WIN = am.window{ width = 1920, height = 1080, title = "hexyz" } |
|
|
|
|
|
|
|
|
WIN = am.window{ |
|
|
|
|
|
width = 1920, |
|
|
|
|
|
height = 1080, |
|
|
|
|
|
title = "hexyz", |
|
|
|
|
|
resizable = false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
OFF_SCREEN = vec2(WIN.width * 2) -- arbitrary pixel position that is garunteed to be off screen |
|
|
OFF_SCREEN = vec2(WIN.width * 2) -- arbitrary pixel position that is garunteed to be off screen |
|
|
|
|
|
|
|
|
TIME = 0 |
|
|
|
|
|
SCORE = 0 |
|
|
|
|
|
MOUSE = vec2(0) |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
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 = { |
|
|
local COORDINATE_DISPLAY_TYPES = { |
|
|
CENTERED_EVENQ = 0, |
|
|
CENTERED_EVENQ = 0, |
|
@ -29,8 +36,11 @@ local COORDINATE_DISPLAY_TYPES = { |
|
|
|
|
|
|
|
|
local COORDINATE_DISPLAY_TYPE = COORDINATE_DISPLAY_TYPES.CENTERED_EVENQ |
|
|
local COORDINATE_DISPLAY_TYPE = COORDINATE_DISPLAY_TYPES.CENTERED_EVENQ |
|
|
local function game_action(scene) |
|
|
local function game_action(scene) |
|
|
|
|
|
if SCORE < 0 then game_end() end |
|
|
|
|
|
|
|
|
TIME = am.current_time() |
|
|
TIME = am.current_time() |
|
|
SCORE = TIME |
|
|
|
|
|
|
|
|
SCORE = SCORE + am.delta_time |
|
|
|
|
|
RAND = math.random() |
|
|
MOUSE = WIN:mouse_position() |
|
|
MOUSE = WIN:mouse_position() |
|
|
|
|
|
|
|
|
local hex = pixel_to_hex(MOUSE - WORLDSPACE_COORDINATE_OFFSET) |
|
|
local hex = pixel_to_hex(MOUSE - WORLDSPACE_COORDINATE_OFFSET) |
|
@ -41,8 +51,8 @@ local function game_action(scene) |
|
|
local tile = HEX_MAP.get(hex.x, hex.y) |
|
|
local tile = HEX_MAP.get(hex.x, hex.y) |
|
|
local hot = is_interactable(tile, evenq{ y = -evenq.y }) |
|
|
local hot = is_interactable(tile, evenq{ y = -evenq.y }) |
|
|
|
|
|
|
|
|
do_mob_spawning() |
|
|
|
|
|
do_entity_updates() |
|
|
do_entity_updates() |
|
|
|
|
|
do_mob_spawning() |
|
|
|
|
|
|
|
|
if WIN:mouse_pressed"left" then |
|
|
if WIN:mouse_pressed"left" then |
|
|
if hot and is_buildable(hex, tile, nil) then |
|
|
if hot and is_buildable(hex, tile, nil) then |
|
@ -51,6 +61,9 @@ local function game_action(scene) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
if WIN:key_pressed"escape" then |
|
|
if WIN:key_pressed"escape" then |
|
|
|
|
|
pause() |
|
|
|
|
|
|
|
|
|
|
|
elseif WIN:key_pressed"f2" then |
|
|
WIN.scene = game_scene() |
|
|
WIN.scene = game_scene() |
|
|
|
|
|
|
|
|
elseif WIN:key_pressed"f3" then |
|
|
elseif WIN:key_pressed"f3" then |
|
@ -84,6 +97,24 @@ local function game_action(scene) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function pause() |
|
|
|
|
|
WORLD"group".paused = true |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function game_end() |
|
|
|
|
|
WIN.scene.paused = true |
|
|
|
|
|
|
|
|
|
|
|
-- de-initialize stuff |
|
|
|
|
|
delete_all_entities() |
|
|
|
|
|
SCORE = 0 |
|
|
|
|
|
|
|
|
|
|
|
WIN.scene = game_scene() |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function update_score(diff) |
|
|
|
|
|
SCORE = SCORE + diff |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
local function toolbelt() |
|
|
local function toolbelt() |
|
|
local toolbelt_height = hex_height(HEX_SIZE) * 2 |
|
|
local toolbelt_height = hex_height(HEX_SIZE) * 2 |
|
|
local toolbelt = am.group{ |
|
|
local toolbelt = am.group{ |
|
@ -116,11 +147,10 @@ function game_scene() |
|
|
WIN.scene:remove(curtain) |
|
|
WIN.scene:remove(curtain) |
|
|
end)) |
|
|
end)) |
|
|
|
|
|
|
|
|
local world |
|
|
|
|
|
HEX_MAP, world = random_map() |
|
|
|
|
|
|
|
|
HEX_MAP, WORLD = random_map() |
|
|
|
|
|
|
|
|
local scene = am.group{ |
|
|
local scene = am.group{ |
|
|
world, |
|
|
|
|
|
|
|
|
WORLD, |
|
|
curtain, |
|
|
curtain, |
|
|
hex_cursor, |
|
|
hex_cursor, |
|
|
toolbelt(), |
|
|
toolbelt(), |
|
@ -133,6 +163,10 @@ function game_scene() |
|
|
return scene |
|
|
return scene |
|
|
end |
|
|
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" |
|
|
require "texture" |
|
|
load_textures() |
|
|
load_textures() |
|
|
WIN.scene = am.scale(1) ^ game_scene() |
|
|
WIN.scene = am.scale(1) ^ game_scene() |
|
|