3 changed files with 89 additions and 209 deletions
			
			
		| @ -1,107 +1,57 @@ | |||
| ----- [[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] ------- | |||
| ----- [[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] -------- | |||
| --[[                                                    author@churchianity.ca | |||
| 
 | |||
|   ]] | |||
| 
 | |||
| require "hex" | |||
| require "util" | |||
| 
 | |||
| ----- [[ DUMMY FUNCTIONS ]] ---------------------------------------------------- | |||
| local world  | |||
| 
 | |||
| function show_hex_coords() | |||
|     grid:action(function() | |||
|         grid:remove("text") | |||
|          | |||
|         mouse_position = vec2(win:mouse_position().x, win:mouse_position().y) | |||
| 
 | |||
|         if mouse_position.x < 268 then | |||
|             hex = map.retrieve(mouse_position) | |||
|             grid:append(am.translate(win.left + 30, win.top - 10)  | |||
|                            ^ am.text(string.format("%d,%d", hex.s, hex.t))) | |||
|         end | |||
|     end) | |||
| end | |||
| 
 | |||
| function rcolor() | |||
|     return vec4(math.random(20, 80) / 100, | |||
|                 math.random(20, 80) / 100, | |||
|                 math.random(20, 80) / 100, | |||
|                 1) | |||
| end | |||
| local guibgcolor = vec4(0.5, 0.5, 0.2, 0) | |||
| 
 | |||
| SPRITES = {"BoulderHills1.png", "BoulderHills2.png", "BoulderHills2.png", | |||
|            "Brambles1.png", "Brambles2.png", "Brambles3.png", "Brambles4.png", | |||
|            "BrownHills1.png", "BrownHills2.png", "BrownHills3.png",  | |||
|            "Grass1.png", "Grass2.png", "Grass3.png", "Grass4.png", "Grass5.png",           "Hills1.png", "Hills2.png", "Hills3.png", "Hills4.png", "Hills5.png", | |||
|            "HillsGreen1.png", "HillsGreen2.png", "HillsGreen3.png",  | |||
|            "LightGrass1.png", "LightGrass2.png", "LightGrass3.png", | |||
|            "LowHills1.png", "LowHills2.png", "LowHills3.png", "LowHills4.png", | |||
|            "Mountains1.png", "Mountains2.png", "Mountains3.png",  | |||
|            "Mud1.png", "Mud2.png", "Mud3.png", "Mud4.png", "Mud5.png", | |||
|            "Orchards1.png", "Orchards2.png", "Orchards3.png", "Orchards4.png", | |||
|            "PineForest1.png", "PineForest2.png", "PineForest3.png",  | |||
|            "Woods1.png", "Woods2.png", "Woods3.png", "Woods4.png"} | |||
| local win = am.window{ | |||
|     -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 | |||
|     width = 1280 * 3 / 4, -- 960px | |||
|     height = 800 * 3 / 4, -- 600px | |||
|     | |||
|     title = "Warzone 2: Electric Boogaloo"} | |||
| 
 | |||
| function rsprite() | |||
|     return string.format("res/%s", SPRITES[math.random(#SPRITES)]) | |||
| function show_axes() | |||
|     xaxis = am.line(vec2(win.left, 0), vec2(win.right, 0)) | |||
|     yaxis = am.line(vec2(0, win.top), vec2(0, win.bottom))  | |||
|     world:append(am.group{xaxis, yaxis}:tag("axes")) | |||
| end | |||
| 
 | |||
| ----- [[ BLAH BLAH LBAH ]] ----------------------------------------------- | |||
| 
 | |||
| win = am.window { | |||
|         title = "Warzone 2: Electric Boogaloo", | |||
|      | |||
|         -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 Aspect Ratio | |||
|         width = 1280 * 3 / 4, -- 960 | |||
|         height = 800 * 3 / 4} -- 600 | |||
| 
 | |||
| ----- [[ MAP RENDERING ]] ------------------------------------------------ | |||
| 
 | |||
| function grid_init() | |||
|     grid = am.group() | |||
|      | |||
|     map = rectmap_init(layout_init(vec2(win.left, win.bottom)), 45, 31) | |||
|      | |||
|     grid:action(function()  | |||
|         for hex,pix in pairs(map) do | |||
|             grid:append(am.circle(pix, map.layout.size.x, rcolor(), 6)) | |||
| function world_init() | |||
|     world = am.group() | |||
|     local layout = layout_init(vec2(-402, win.bottom)) | |||
|     local map = rectmap_init(45, 31) | |||
|     local lgui = am.group( | |||
|                  am.rect(win.left, win.top, -402, win.bottom, guibgcolor)) | |||
|     local rgui = am.group( | |||
|                  am.rect(win.right, win.top, 402, win.bottom, guibgcolor)) | |||
| 
 | |||
|     world:append(lgui) | |||
|     world:append(rgui) | |||
| 
 | |||
|     world:action(coroutine.create(function() | |||
|         for hex,_ in pairs(map) do | |||
|             world:append(am.circle(hex_to_pixel(hex, layout), 11, rrgb(1), 6)) | |||
|             am.wait(am.delay(0.01)) | |||
|         end | |||
|         return true | |||
|     end)     | |||
|     end)) | |||
| 
 | |||
|     grid:append(am.translate(350, 200)  | |||
|              ^ am.scale(2)  | |||
|              ^ am.sprite("2.png")) | |||
| 
 | |||
|     show_hex_coords() | |||
| 
 | |||
|     return grid | |||
| end | |||
| 
 | |||
| function toolbar_init() | |||
|     local toolbar = am.group()  | |||
|     local toolbar_bg = vec4(0.4, 0.6, 0.8, 1) | |||
| 
 | |||
|     toolbar:append(am.rect(268, win.top, win.right, win.bottom, toolbar_bg)) | |||
|      | |||
|     toolbar:append(am.particles2d({source_pos=vec2(win.width/2-268, win.top), | |||
|                                    source_pos_var=vec2(0, 600), | |||
|                                    angle=math.pi/4, | |||
|                                    start_color=vec4(0.9), | |||
|                                    gravity=vec2(100), | |||
|                                    start_color_var=rcolor(), | |||
|                                    start_size=3})) | |||
|     return toolbar  | |||
| function init() | |||
|     world_init() | |||
|     show_axes() | |||
|     win.scene = world | |||
| end | |||
| 
 | |||
| function game_init() | |||
|     return am.group{grid_init(), toolbar_init()} | |||
| end | |||
| 
 | |||
| ----- [[ MAIN ]] ----------------------------------------------------------- | |||
| 
 | |||
| local map = {} | |||
| 
 | |||
| win.scene = game_init() | |||
| ----- [[ MAIN ]] --------------------------------------------------------------- | |||
| 
 | |||
| show_hex_coords() | |||
| init() | |||
| 
 | |||
| @ -0,0 +1,9 @@ | |||
| 
 | |||
| function rrgb(a) | |||
|     local R = math.random(20, 80) / 100 | |||
|     local G = math.random(20, 80) / 100 | |||
|     local B = math.random(20, 80) / 100 | |||
|     local A = a or math.random() | |||
| 
 | |||
|     return vec4(R, G, B, A) | |||
| end | |||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue