churchianity
6 years ago
2 changed files with 194 additions and 102 deletions
@ -1,32 +1,68 @@ |
|||||
--[[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] |
|
||||
--[[ |
|
||||
|
----- [[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] ------- |
||||
|
--[[ author@churchianity.ca |
||||
|
|
||||
]] |
]] |
||||
|
|
||||
require "hex" |
require "hex" |
||||
|
|
||||
-- ENTRY POINT ----------------------------------------------------------------- |
|
||||
win = am.window { |
|
||||
|
----- [[ DUMMY FUNCTIONS ]] ------------------------------------------------------ |
||||
|
|
||||
|
function draw_axes() |
||||
|
xaxis = am.line(vec2(-win.width / 2, 0) , vec2(win.width / 2, 0)) |
||||
|
yaxis = am.line(vec2(0, -win.height / 2), vec2(0, win.height / 2)) |
||||
|
|
||||
|
title_scene:append(xaxis) |
||||
|
title_scene:append(yaxis) |
||||
|
end |
||||
|
|
||||
|
function rcolor() |
||||
|
return vec4(math.random(20, 80) / 100) |
||||
|
end |
||||
|
|
||||
|
function show_hex_coords() |
||||
|
win.scene:action(function() |
||||
|
x, y = unpack(pixel_to_hex(win:mouse_position().x, win:mouse_position().y, layout)) |
||||
|
test_scene = ( |
||||
|
am.translate(vec2(unpack(hex_to_pixel(x, y, layout)))) |
||||
|
^ am.text(string.format("%d, %d", x, y))) |
||||
|
end) |
||||
|
end |
||||
|
|
||||
|
local win = am.window { |
||||
title = "Warzone 2: Electric Boogaloo", |
title = "Warzone 2: Electric Boogaloo", |
||||
|
|
||||
-- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 Aspect Ratio |
-- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 Aspect Ratio |
||||
width = 1280 * 3 / 4, |
|
||||
height = 800 * 3 / 4, |
|
||||
|
width = 1280 * 3 / 4, -- 960 |
||||
|
height = 800 * 3 / 4} -- 600 |
||||
|
|
||||
|
local layout = layout({11, 11}, |
||||
|
FLAT_ORIENTATION, |
||||
|
vec2(win.left, win.bottom), |
||||
|
45, 31) |
||||
|
|
||||
clear_color = vec4(0, 0, 0, 0) |
|
||||
} |
|
||||
|
----- [[ MAP RENDERING ]] ------------------------------------------------ |
||||
|
|
||||
-- GROUPS |
|
||||
local grid = am.group() |
|
||||
|
function render_map(layout) |
||||
|
coords = rect_map_store(layout) |
||||
|
map = am.group() |
||||
|
|
||||
--[[ |
|
||||
xaxis = am.line(vec2(-win.width / 2, 0) , vec2(win.width / 2, 0)) |
|
||||
yaxis = am.line(vec2(0, -win.height / 2), vec2(0, win.height / 2)) |
|
||||
|
for _,v in pairs(coords) do |
||||
|
map:append(am.circle(vec2(unpack(v)), layout.size[1], rcolor(), 6)) |
||||
|
end |
||||
|
return map |
||||
|
end |
||||
|
|
||||
grid:append(xaxis) |
|
||||
grid:append(yaxis) |
|
||||
--]] |
|
||||
|
----- [[ MAIN ]] ----------------------------------------------------------- |
||||
|
|
||||
win.scene = grid |
|
||||
|
local game_scene = render_map(layout) |
||||
|
local test_scene = am.group() |
||||
|
|
||||
|
win.scene = am.group{test_scene, game_scene} |
||||
|
|
||||
|
test_scene:action(function() |
||||
|
x, y = unpack(pixel_to_hex(win:mouse_position().x, win:mouse_position().y, layout)) |
||||
|
test_scene:replace("text", |
||||
|
am.translate(vec2(unpack(hex_to_pixel(x, y, layout)))) |
||||
|
^ am.text(string.format("%d, %d", x, y))) |
||||
|
am.delay(1) |
||||
|
end) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue