From 3989afb04fdfdce0f99596894f6b97f7331bd637 Mon Sep 17 00:00:00 2001 From: UndeadMaelys Date: Fri, 19 Mar 2021 19:58:05 +0100 Subject: [PATCH] units, display, enums --- default_font.png => assets/default_font.png | Bin .../{ariel => imp_ariel}/attack.png | Bin .../characters/{ariel => imp_ariel}/death.png | Bin .../characters/{ariel => imp_ariel}/hit.png | Bin .../characters/{ariel => imp_ariel}/idle.png | Bin .../characters/{ariel => imp_ariel}/idle1.png | Bin .../characters/{ariel => imp_ariel}/idle2.png | Bin .../characters/{ariel => imp_ariel}/idle3.png | Bin .../characters/{ariel => imp_ariel}/idle4.png | Bin .../{ariel => imp_ariel}/portrait.png | Bin .../characters/{ariel => imp_ariel}/walk.png | Bin .../textures/characters/impling/portrait.png | Bin 288 -> 289 bytes assets/textures/hud/units.png | Bin 0 -> 759 bytes creatures.lua | 0 g3d/camera.lua | 2 +- main.lua | 152 ++++++++++----- enums.lua => scripts/enums.lua | 175 ++++++++++-------- levels.lua => scripts/levels.lua | 40 +++- objects.lua => scripts/objects.lua | 0 scripts/units.lua | 28 +++ 20 files changed, 265 insertions(+), 132 deletions(-) rename default_font.png => assets/default_font.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/attack.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/death.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/hit.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/idle.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/idle1.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/idle2.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/idle3.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/idle4.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/portrait.png (100%) rename assets/textures/characters/{ariel => imp_ariel}/walk.png (100%) create mode 100644 assets/textures/hud/units.png delete mode 100644 creatures.lua rename enums.lua => scripts/enums.lua (57%) rename levels.lua => scripts/levels.lua (58%) rename objects.lua => scripts/objects.lua (100%) create mode 100644 scripts/units.lua diff --git a/default_font.png b/assets/default_font.png similarity index 100% rename from default_font.png rename to assets/default_font.png diff --git a/assets/textures/characters/ariel/attack.png b/assets/textures/characters/imp_ariel/attack.png similarity index 100% rename from assets/textures/characters/ariel/attack.png rename to assets/textures/characters/imp_ariel/attack.png diff --git a/assets/textures/characters/ariel/death.png b/assets/textures/characters/imp_ariel/death.png similarity index 100% rename from assets/textures/characters/ariel/death.png rename to assets/textures/characters/imp_ariel/death.png diff --git a/assets/textures/characters/ariel/hit.png b/assets/textures/characters/imp_ariel/hit.png similarity index 100% rename from assets/textures/characters/ariel/hit.png rename to assets/textures/characters/imp_ariel/hit.png diff --git a/assets/textures/characters/ariel/idle.png b/assets/textures/characters/imp_ariel/idle.png similarity index 100% rename from assets/textures/characters/ariel/idle.png rename to assets/textures/characters/imp_ariel/idle.png diff --git a/assets/textures/characters/ariel/idle1.png b/assets/textures/characters/imp_ariel/idle1.png similarity index 100% rename from assets/textures/characters/ariel/idle1.png rename to assets/textures/characters/imp_ariel/idle1.png diff --git a/assets/textures/characters/ariel/idle2.png b/assets/textures/characters/imp_ariel/idle2.png similarity index 100% rename from assets/textures/characters/ariel/idle2.png rename to assets/textures/characters/imp_ariel/idle2.png diff --git a/assets/textures/characters/ariel/idle3.png b/assets/textures/characters/imp_ariel/idle3.png similarity index 100% rename from assets/textures/characters/ariel/idle3.png rename to assets/textures/characters/imp_ariel/idle3.png diff --git a/assets/textures/characters/ariel/idle4.png b/assets/textures/characters/imp_ariel/idle4.png similarity index 100% rename from assets/textures/characters/ariel/idle4.png rename to assets/textures/characters/imp_ariel/idle4.png diff --git a/assets/textures/characters/ariel/portrait.png b/assets/textures/characters/imp_ariel/portrait.png similarity index 100% rename from assets/textures/characters/ariel/portrait.png rename to assets/textures/characters/imp_ariel/portrait.png diff --git a/assets/textures/characters/ariel/walk.png b/assets/textures/characters/imp_ariel/walk.png similarity index 100% rename from assets/textures/characters/ariel/walk.png rename to assets/textures/characters/imp_ariel/walk.png diff --git a/assets/textures/characters/impling/portrait.png b/assets/textures/characters/impling/portrait.png index b1c97f5edc366e00dc85722074cc92faca130d3a..0038abd02e04b91c2d082f2a15361bb7b9fbb7b7 100644 GIT binary patch delta 248 zcmZ3$w2*0nVf}4S7sn8b-ei%KgrDaf7!#DjAMgIZU(>iDN&ElK-)}RAxSpsx wmdUWMCFOj>ZBd^Sv%c4-AIs$M;k&EEu%*&xN?;6A1_Kayy85}Sb4q9e0Qys8P5=M^ delta 247 zcmZ3;w18=XVf`&n7sn8b-sA)cjSv5UfCmVCrbxMLWYjq^N0%$=|3}Sll?A$v#x6AEmTCIATJBur+$6(eQgNzg1NeLjZGk^J?`HhW@4__&_q+HlsUGU9HQ&nVR zQsG^&ndcXN^66@SXB1a^bP0l+XkKuP$-s diff --git a/assets/textures/hud/units.png b/assets/textures/hud/units.png new file mode 100644 index 0000000000000000000000000000000000000000..a380ee8e7227b86118a1ca2e7f60f97f65ceea38 GIT binary patch literal 759 zcmV1m<~00001b5ch_0Itp) z=>Px%u}MThRCt{2oWE|HP!z^L5Uo|o>?od+ya7|&(dt7~d4W#2>d>X0-K9e%{0>!? zZW$YoO((wvk$2mwtSF*`xnS@;hRDDr_4k|je-587aKEGLYsI%g48<@6W~2P_Fx;-s zM!g?a8MEu7tr>uX^C z{&(xitgl-SS&D5sfv%EkF^@OE+CUPIHwJ>1z!oFm6gPD7*E50Rx!Ife!@^)D=MM&h z=keU6#dt06AJ_6h(S>ee%#<3nW_DG?4qyU2D*~Yl+Qf(_}8K)9dw0kD*r*pfCayMu5Ty*r}N! zDW03O7>bjjv~b`DNA-NW`YEsSNfx2I){wYsJ6DV%X@QRJx(MC10Nu3=-L(d#1$({% zmC6psuv)Dexo*GTZ{)fPwip2lBS2vUD2xEh4jNc?(4e%i;Rj|j=^`vUXkghvfMo{( zmK_9Gc93D&K?BPUB~Tav3L`*a1SpIE-L(d~YYlYQhoHOG@RT9*hlYAQ$6+9c_HoF( z1l_d&-L(wewFbKD5-5zo(W4!X8XehT*kS}Ii~!xW2D)nvbk~QVyVk%zr0b!(mY};9 zpu3i#yVj6%*X+k+r2QC*vQIh{6Z`;C6y~NPs^js>iLN@5yHh)rO!rh*9+h%T`Y$Sn pv>#KqD0_ib@G3Nr$02m$`~!KjD8fjeJ^TOw002ovPDHLkV1kggWCs8M literal 0 HcmV?d00001 diff --git a/creatures.lua b/creatures.lua deleted file mode 100644 index e69de29..0000000 diff --git a/g3d/camera.lua b/g3d/camera.lua index e70683c..50bb337 100644 --- a/g3d/camera.lua +++ b/g3d/camera.lua @@ -209,7 +209,7 @@ function camera.strategyViewMovement(dt,speed,is_scrolling) camera.position[1] = camera.pivot[1] + math.cos(camera.pitch)*camera.zoom - camera.position[2] = camera.pivot[2] - math.sin(-30)*camera.zoom + camera.position[2] = camera.pivot[2] - math.sin(45)*camera.zoom camera.position[3] = camera.pivot[3] + math.sin(camera.pitch)*camera.zoom -- update the camera's in the shader diff --git a/main.lua b/main.lua index b4cac1c..4b9b555 100644 --- a/main.lua +++ b/main.lua @@ -7,7 +7,7 @@ function love.load() -- GOOD PIXEL love.graphics.setDefaultFilter("nearest") -- FONTS - DefaultFont = love.graphics.newImageFont("default_font.png", + DefaultFont = love.graphics.newImageFont("assets/default_font.png", " abcdefghijklmnopqrstuvwxyz" .. "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" .. "123456789.,!?-+/():;%&`'*#=[]\"") @@ -27,14 +27,19 @@ function love.load() g3d.camera.zoom = 10 speed = 0 + -- player + player = { + id = 1 + } -- enums - require "enums" + require "scripts/enums" --objects - require "objects" + require "scripts/objects" + require "scripts/units" -- levels - require "levels" + require "scripts/levels" current_level = levels.main_menu end @@ -53,14 +58,9 @@ function love.update(dt) fps_count = fps_count + 1 -- camera: slow, fast, medium? - if love.keyboard.isDown("lshift") then - speed = 2 - elseif love.keyboard.isDown("lctrl") then - speed = 6 - else - speed = 4 - end + speed = g3d.camera.zoom/2 + -- do camera if not game_pause then g3d.camera.strategyViewMovement(dt,speed,is_scrolling) -- movement: w,a,s,d, @@ -81,13 +81,14 @@ function love.update(dt) end end -function love.wheelmoved(_, y) +function love.wheelmoved(_, y) + -- get scroll to do zoom, and call camera update g3d.camera.zoom = math.min(math.max(3,g3d.camera.zoom-y/1.5),30) is_scrolling = true end function love.keypressed(key) - -- pause the game and free the mouse + -- pause the game if key == "escape" then if game_pause then game_pause = false @@ -96,6 +97,14 @@ function love.keypressed(key) end end + -- select all units button + if key == "f1" then + for _, unit in pairs(current_level.units) do + if unit.faction == player.id then + unit.is_selected = true + end + end + end end function love.draw() @@ -103,46 +112,15 @@ function love.draw() game_width = love.graphics.getWidth() game_height = love.graphics.getHeight() - -- draw every model + -- draw every model in entities local ent_count = 0 for _, entity in pairs(current_level.entities) do - ent_count = ent_count + 1 - if entity.model ~= nil then - - -- do animated models - if entity.is_animated == true and entity.anim_path ~= nil and game_pause ~= true then - -- try to animate - entity.anim_subframe = entity.anim_subframe + 1 - if entity.anim_subframe >= entity.anim_speed then - entity.anim_frame = entity.anim_frame + 1 - entity.anim_subframe = entity.anim_subframe - entity.anim_speed - end - -- cycle - if entity.anim_frame >= entity.anim_frames+1 then entity.anim_frame = entity.anim_frame - entity.anim_frames end - -- change - entity.model.mesh:setTexture(entity.anim_imgs[entity.anim_frame]) - end - - -- do rotating models - if entity.rotate_mode ~= nil and entity.rotate_mode ~= "none" and game_pause ~= true then - local rm = entity.rotate_mode - - if rm == "cam_xz" then - - local sin = g3d.camera.position[1]-entity.model.translation[1] - local cos = g3d.camera.position[3]-entity.model.translation[3] - - local angle = math.atan2(sin,cos)-math.rad(180) - - entity.model:setRotation(0,angle,0) - end - end - - entity.model:draw() - else - entity:draw() - end + draw_entity(entity) end + -- draw every unit's troops + for _, unit in pairs(current_level.units) do for _, entity in pairs(unit.troops) do + draw_entity(entity) + end end -- draw selection if selecting_troops == true then @@ -154,7 +132,8 @@ function love.draw() if game_pause then draw_pause_menu(30,30) else - love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..fps_dt..", x: "..math.floor(g3d.camera.position[1])..", y: "..math.floor(g3d.camera.position[2])..", z: "..math.floor(g3d.camera.position[3]), x, y) + draw_debug() + draw_combat_ui() end for _, entity in pairs(current_level.entities) do @@ -167,9 +146,80 @@ function love.draw() end end +function draw_debug() + love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..fps_dt..", x: "..math.floor(g3d.camera.position[1])..", y: "..math.floor(g3d.camera.position[2])..", z: "..math.floor(g3d.camera.position[3]), x, y) +end + + function draw_pause_menu(x,y) love.graphics.setColor(1,1,1,0.3) love.graphics.rectangle("fill", x, y, game_width-2*x, game_height-2*y) love.graphics.setColor(1,1,1,1) end +function draw_entity(entity) + if entity.model ~= nil then + -- do animated models if animated, if anim_path and if game playing + if entity.is_animated == true and entity.anim_path ~= nil and game_pause ~= true then + -- try to animate + entity.anim_subframe = entity.anim_subframe + 1 + if entity.anim_subframe >= entity.anim_speed then + entity.anim_frame = entity.anim_frame + 1 + entity.anim_subframe = entity.anim_subframe - entity.anim_speed + end + -- cycle + if entity.anim_frame >= entity.anim_frames+1 then entity.anim_frame = entity.anim_frame - entity.anim_frames end + -- change + entity.model.mesh:setTexture(entity.anim_imgs[entity.anim_frame]) + end + + -- do rotating models if animated, if has to rotate and if game playing + if entity.rotate_mode ~= nil and entity.rotate_mode ~= "none" and game_pause ~= true then + local rm = entity.rotate_mode + + if rm == "cam_xz" then + + local sin = g3d.camera.position[1]-entity.model.translation[1] + local cos = g3d.camera.position[3]-entity.model.translation[3] + + local angle = math.atan2(sin,cos)-math.rad(180) + + entity.model:setRotation(0,angle,0) + end + end + + entity.model:draw() + else -- simple loaded entities dont require so much fuss + entity:draw() + end +end + +function draw_combat_ui() + local unit_count = 0 + -- count how much units + for _, unit in pairs(current_level.units) do + if unit.faction == player.id then + unit_count = unit_count + 1 + end + end + local unit_total = unit_count + -- position units accordingly + unit_count = 0 + for _, unit in pairs(current_level.units) do + unit_count = unit_count + 1 + if unit.faction == player.id then + draw_portrait(unit,unit_count,unit_total) + end + end +end + +function draw_portrait(u,unit_count,unit_total) + --$-- temporal + --love.graphics.line(game_width/2,0,game_width/2,game_height) + --$-- + local pos_x = game_width/2-(74*unit_total)+74*unit_count+74/2 + local pos_y = game_height-83 + + love.graphics.draw(img.hud.unit_show, pos_x-2, pos_y, 0, 1) + love.graphics.draw(u.portrait, pos_x, pos_y+14, 0, 4) +end \ No newline at end of file diff --git a/enums.lua b/scripts/enums.lua similarity index 57% rename from enums.lua rename to scripts/enums.lua index be8bdc4..b393b1b 100644 --- a/enums.lua +++ b/scripts/enums.lua @@ -37,74 +37,82 @@ icon = { } portrait = { - elementalAir = nil, - elementalArcane = nil, - elementalEarth = nil, - elementalFire = nil, - elementalIce = nil, - elementalMagma = nil, - elementalPsychic = nil, - elementalStorm = nil, - elementalWater = nil, - militia = nil, - pikeman = nil, - crossbow = nil, - eliteCrossbow = nil, - gryphon = nil, - ancientGryphon = nil, - swordman = nil, - humanCaptain = nil, - monk = nil, - priest = nil, - horseman = nil, - cavailer = nil, - knight = nil, - paladin = nil, - impling = nil, - imp = nil, - gog = nil, - magog = nil, - hellhound = nil, - hellbeast = nil, - demon = nil, - archdemon = nil, - pitfiend = nil, - elitePitfiend = nil, - efreet = nil, - eliteEfreet = nil, - devil = nil, - theDevil = nil, - skeleton = nil, - skeletonRisen = nil, - zombie = nil, - zombieRisen = nil, - spider = nil, - spiderMatriarch = nil, - spirit = nil, - ghost = nil, - vampire = nil, - bloodlinePatriarch = nil, - necromancer = nil, - lich = nil, - bloodknight = nil, - deathknight = nil, - dwarf1 = nil, - dwarf2 = nil, - pixie = nil, - fairie = nil, - satyrArcher = nil, - satyrWarrior = nil, - elvenHunter = nil, - elvenCaptain = nil, - deerWhite = nil, - deerBrown = nil, - spellweaver = nil, - druid = nil, - treant = nil, - ent = nil + _ariel = "assets/textures/characters/imp_ariel/portrait.png", + elementalAir = "assets/textures/characters/elemental_air/portrait.png", + elementalArcane = "assets/textures/characters/elemental_arcane/portrait.png", + elementalEarth = "assets/textures/characters/elemental_earth/portrait.png", + elementalFire = "assets/textures/characters/elemental_fire/portrait.png", + elementalIce = "assets/textures/characters/elemental_ice/portrait.png", + elementalMagma = "assets/textures/characters/elemental_magma/portrait.png", + elementalPsychic = "assets/textures/characters/elemental_psychic/portrait.png", + elementalStorm = "assets/textures/characters/elemental_storm/portrait.png", + elementalWater = "assets/textures/characters/elemental_water/portrait.png", + militia = "assets/textures/characters/militia/portrait.png", + pikeman = "assets/textures/characters/pikeman/portrait.png", + crossbow = "assets/textures/characters/crossbow/portrait.png", + eliteCrossbow = "assets/textures/characters/elite_crossbow/portrait.png", + gryphon = "assets/textures/characters/gryphon/portrait.png", + ancientGryphon = "assets/textures/characters/ancient_gryphon/portrait.png", + swordman = "assets/textures/characters/swordman/portrait.png", + humanCaptain = "assets/textures/characters/human_captain/portrait.png", + monk = "assets/textures/characters/monk/portrait.png", + priest = "assets/textures/characters/priest/portrait.png", + horseman = "assets/textures/characters/horseman/portrait.png", + cavailer = "assets/textures/characters/cavailer/portrait.png", + knight = "assets/textures/characters/knight/portrait.png", + paladin = "assets/textures/characters/paladin/portrait.png", + impling = "assets/textures/characters/impling/portrait.png", + imp = "assets/textures/characters/imp/portrait.png", + gog = "assets/textures/characters/gog/portrait.png", + magog = "assets/textures/characters/magog/portrait.png", + hellhound = "assets/textures/characters/hellhound/portrait.png", + hellbeast = "assets/textures/characters/hellbeast/portrait.png", + demon = "assets/textures/characters/demon/portrait.png", + archdemon = "assets/textures/characters/archdemon/portrait.png", + pitfiend = "assets/textures/characters/pitfiend/portrait.png", + elitePitfiend = "assets/textures/characters/elite_pitfiend/portrait.png", + efreet = "assets/textures/characters/efreet/portrait.png", + eliteEfreet = "assets/textures/characters/elite_efreet/portrait.png", + devil = "assets/textures/characters/devil/portrait.png", + theDevil = "assets/textures/characters/the_devil/portrait.png", + skeleton = "assets/textures/characters/skeleton/portrait.png", + skeletonRisen = "assets/textures/characters/risen_skeleton/portrait.png", + zombie = "assets/textures/characters/zombie/portrait.png", + zombieRisen = "assets/textures/characters/risen_zombie/portrait.png", + spider = "assets/textures/characters/spider/portrait.png", + spiderMatriarch = "assets/textures/characters/spider_matriarch/portrait.png", + spirit = "assets/textures/characters/spirit/portrait.png", + ghost = "assets/textures/characters/ghost/portrait.png", + vampire = "assets/textures/characters/vampire/portrait.png", + bloodlinePatriarch = "assets/textures/characters/bloodline_patriarch/portrait.png", + necromancer = "assets/textures/characters/necromancer/portrait.png", + lich = "assets/textures/characters/lich/portrait.png", + bloodknight = "assets/textures/characters/bloodknight/portrait.png", + deathknight = "assets/textures/characters/deathknight/portrait.png", + dwarf1 = "assets/textures/characters/dwarf1/portrait.png", + dwarf2 = "assets/textures/characters/dwarf2/portrait.png", + pixie = "assets/textures/characters/pixie/portrait.png", + faerie = "assets/textures/characters/faerie/portrait.png", + satyrArcher = "assets/textures/characters/satyr_archer/portrait.png", + satyrWarrior = "assets/textures/characters/satyr_warrior/portrait.png", + elvenHunter = "assets/textures/characters/elven_hunter/portrait.png", + elvenCaptain = "assets/textures/characters/elven_captain/portrait.png", + deerWhite = "assets/textures/characters/deer_white/portrait.png", + deerBrown = "assets/textures/characters/deer_brown/portrait.png", + spellweaver = "assets/textures/characters/spellweaver/portrait.png", + druid = "assets/textures/characters/druid/portrait.png", + treant = "assets/textures/characters/treant/portrait.png", + ent = "assets/textures/characters/ent/portrait.png" } animation = { + _ariel = { + idle = "assets/textures/characters/imp_ariel/idle", + walk = "assets/textures/characters/imp_ariel/walk", + attack = "assets/textures/characters/imp_ariel/attack", + hit = "assets/textures/characters/imp_ariel/hit", + death = "assets/textures/characters/imp_ariel/death" + }, elementalAir = { idle = nil, walk = nil, @@ -268,10 +276,10 @@ animation = { }, impling = { idle = "assets/textures/characters/impling/idle", - walk = nil, - attack = nil, - hit = nil, - death = nil + walk = "assets/textures/characters/impling/walk", + attack = "assets/textures/characters/impling/attack", + hit = "assets/textures/characters/impling/hit", + death = "assets/textures/characters/impling/death" }, imp = { idle = nil, @@ -303,10 +311,10 @@ animation = { }, hellbeast = { idle = "assets/textures/characters/hellbeast/idle", - walk = nil, - attack = nil, - hit = nil, - death = nil + walk = "assets/textures/characters/hellbeast/walk", + attack = "assets/textures/characters/hellbeast/attack", + hit = "assets/textures/characters/hellbeast/hit", + death = "assets/textures/characters/hellbeast/death" }, demon = { idle = nil, @@ -317,10 +325,10 @@ animation = { }, archdemon = { idle = "assets/textures/characters/archdemon/idle", - walk = nil, - attack = nil, - hit = nil, - death = nil + walk = "assets/textures/characters/archdemon/walk", + attack = "assets/textures/characters/archdemon/attack", + hit = "assets/textures/characters/archdemon/hit", + death = "assets/textures/characters/archdemon/death" }, pitfiend = { idle = nil, @@ -562,3 +570,16 @@ animation = { } } +statTable = { + implings = { + health = 10, + speed = 2 + } +} + + +img = { + hud = { + unit_show = love.graphics.newImage("assets/textures/hud/units.png") + } +} diff --git a/levels.lua b/scripts/levels.lua similarity index 58% rename from levels.lua rename to scripts/levels.lua index 96b6b07..b229ed2 100644 --- a/levels.lua +++ b/scripts/levels.lua @@ -1,10 +1,12 @@ levels = {} levels.main_menu = { - entities = {} + entities = {}, + units = {} } local entities = levels.main_menu.entities +local units = levels.main_menu.units -- campfire entities.campfire = { @@ -28,23 +30,55 @@ end end math.randomseed(3) -- bunch of implings (40) + +local nu = Unit:newUnit("Ariel Army",player.id,portrait._ariel,statTable.implings) + +local xx, yy, zz = 3, 0, 0 +for i = 1, 8, 1 do for j = 1, 5, 1 do + local imp = Object:new2DAnimated("implings",portrait._ariel,xx+0.5*(i+1),yy+0,zz+0.5*(j+1),16,16) + load_animation(imp,animation._ariel.idle,4,8) + table.insert(nu.troops,imp) +end end +table.insert(units,nu) + +local nu = Unit:newUnit("Implings",player.id,portrait.impling,statTable.implings) + local xx, yy, zz = 3, 0, 3 for i = 1, 8, 1 do for j = 1, 5, 1 do - local imp = Object:new2DAnimated("imp",portrait.impling,xx+0.5*(i+1),yy+0,zz+0.5*(j+1),16,16) + local imp = Object:new2DAnimated("implings",portrait.impling,xx+0.5*(i+1),yy+0,zz+0.5*(j+1),16,16) load_animation(imp,animation.impling.idle,4,8) - table.insert(entities,imp) + table.insert(nu.troops,imp) end end +table.insert(units,nu) +local nu = Unit:newUnit("Implings",player.id,portrait.impling,statTable.implings) + +local xx, yy, zz = 3, 0, -3 +for i = 1, 8, 1 do for j = 1, 5, 1 do + local imp = Object:new2DAnimated("implings",portrait.impling,xx+0.5*(i+1),yy+0,zz+0.5*(j+1),16,16) + load_animation(imp,animation.impling.idle,4,8) + table.insert(nu.troops,imp) +end end +table.insert(units,nu) + + +--[[ -- bunch of hellbeast pack (6) local xx, yy, zz = -3, 0, 3 + for i = 1, 3, 1 do for j = 1, 2, 1 do local hellbeast = Object:new2DAnimated("hellbeast",portrait.hellbeast,xx+1*(i+1),yy+0,zz+1*(j+1),16,16) load_animation(hellbeast,animation.hellbeast.idle,4,8) table.insert(entities,hellbeast) end end +creat_unit +table.insert(units,"hellbeast") -- hero archdemon (1) local xx, yy, zz = 0, 0, 3 local archdemon = Object:new2DAnimated("archdemon",portrait.archdemon,xx,yy,zz,16,16) load_animation(archdemon,animation.archdemon.idle,4,8) table.insert(entities,archdemon) +table.insert(units,archdemon) +table.insert(units,"archdemon") +]]-- \ No newline at end of file diff --git a/objects.lua b/scripts/objects.lua similarity index 100% rename from objects.lua rename to scripts/objects.lua diff --git a/scripts/units.lua b/scripts/units.lua new file mode 100644 index 0000000..e0377b8 --- /dev/null +++ b/scripts/units.lua @@ -0,0 +1,28 @@ +Unit = { + class = "Unit", + faction = 0, + troops = {}, + is_selected = false, + portrait = nil, + stat = { + health = nil, + speed = nil + } +} +function Unit:newUnit(name,faction,portrait,stat_table) + o = { + -- ids + name = name, + faction = faction, + portrait = love.graphics.newImage(portrait), + -- stats + stat = { + health = stat_table.health, + speed = stat_table.speed + } + } + + setmetatable(o, self) + self.__index = self + return o +end \ No newline at end of file