aboutsummaryrefslogtreecommitdiff
path: root/gamemode/hud
diff options
context:
space:
mode:
authorAlexander Pickering <Alexander.Pickering@anondomain.site90.net>2016-01-23 00:21:58 -0500
committerAlexander Pickering <Alexander.Pickering@anondomain.site90.net>2016-01-23 00:21:58 -0500
commit9b1057243fe1db65f351e213f00e41ceca67a8da (patch)
treed0d0982175639baaad0a28fee64c5dcbc41c11b9 /gamemode/hud
parente8439ad503f530724f1eae2de1a8ac2c19df52c0 (diff)
downloadwintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.tar.gz
wintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.tar.bz2
wintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.zip
Completed basic framework for setting up spells, and minigames for casting
Diffstat (limited to 'gamemode/hud')
-rw-r--r--gamemode/hud/draw_spell.lua105
-rw-r--r--gamemode/hud/games/base.lua9
-rw-r--r--gamemode/hud/games/connectthedots.lua25
3 files changed, 95 insertions, 44 deletions
diff --git a/gamemode/hud/draw_spell.lua b/gamemode/hud/draw_spell.lua
index 032c25f..96440e4 100644
--- a/gamemode/hud/draw_spell.lua
+++ b/gamemode/hud/draw_spell.lua
@@ -2,48 +2,67 @@ CASTING_SPELL = nil
--AddLUACSFolder("spellminigames")
-local Folder = GM.Folder:gsub("gamemodes/","").."/gamemode/hud/"
+local Folder = GM.Folder:gsub("gamemodes/","").."/gamemode/hud/games"
--A table of spells to functions?
-Spells = {}
---[[
- ["fireball"] = {
- ["minigame"] = connectthedots,
- ["interupt"] = connectextradots,
- ["difficulty"] = 1
- }
-}]]--
+Spells = {
+ ["Fireball"] = {
+ ["file"] = "connectthedots.lua",
+ ["minigame"] = "Cast",
+ ["interupt"] = "AddDots",
+ ["draw"] = "Draw",
+ ["difficulty"] = 1,
+ },
+}
+
+Games = {}
function loadgames()
- GAMEMODE.minigames = {}
- print("WS2A:Looking for minigames in:" .. Folder)
- AddCSLuaFile(Folder .. "/games/base.lua")
- include(Folder .. "/games/base.lua")
- local games, fold = file.Find(Folder.."*","LUA")
- local game = {}
- print("WS2A:Loading " .. #(games) .. " minigames")
- print("WS2A:Found " .. #(fold) .. " folders")
- for k,v in pairs(games) do
- print(v)
- --[[
- if (v != "base.lua") then
- AddCSLuaFile(Folder.."/"..v)
- include(Folder.."/"..v)
- if((not game.Name) or (not game.minigame) or (not game.interupt)) then
- print("WS2A:Error loading " .. Folder .. "/" .. v .. "One or more of the are missing: Name, minigame, interupt")
- continue
- else
- print("WS2A:Loaded " .. Folder .. "/" .. v)
+ includedfiles = {}
+ print("Looking for what minigames we need...")
+ for k,v in pairs(Spells) do
+ local filename = v["file"]
+ if (includedfiles[filename] == nil) then
+ print("Spell " .. k .. " depends on " .. filename)
+ includedfiles[filename] = true
+ end
+ end
+ Game = {}
+ print("Loading in minigames")
+ for k,v in pairs(includedfiles) do
+ AddCSLuaFile(Folder .. "/" .. k)
+ Game = {}
+ include(Folder .. "/" .. k)
+ Games[k] = Game
+ end
+ print("Resolveing minigame names")
+ for k,v in pairs(Spells) do
+ local mgname = v["minigame"]
+ local mginame = v["interupt"]
+ local mgdname = v["draw"]
+ for i,j in pairs(Games) do
+ if i == v["file"] then
+ print("Resolved " .. k)
+ local castfunc = j[mgname]
+ local drawfunc = j[mgdname]
+ local interuptfunc = j[mginame]
+ if(castfunc) then
+ v["minigame"] = castfunc
+ else
+ print("Spell " .. k .. " does not have a cast func! This may be an error!")
+ end
+ if(drawfunc) then
+ v["draw"] = drawfunc
+ else
+ print("Spell " .. k .. " does not have a draw func! This may be an error!")
+ end
+ if(interuptfunc) then
+ v["interupt"] = interuptfunc
+ else
+ print("Spell " .. k .. " does not have an interupt func! This may be an error!")
+ end
end
-
- table.insert(GAMEMODE.Spells,{
- Spell.Name
- })
-
- NPC = table.Copy(BaseItem)
-
end
- ]]--
end
end
@@ -60,13 +79,13 @@ function StartMinigame(spell)
if not spell then return end
--If we're already casting, and are told to cast again do someting.
if CASTING_SPELL != nil then
- CASTING_SPELL["interupt"]()
+ CASTING_SPELL["interupt"](CASTING_SPELL)
return
end
- if spells[spell] then
- CASTING_SPELL = spells[spell]
- spells[spell]["minigame"](spells[spell]["difficulty"])
+ if Spells[spell] then
+ CASTING_SPELL = Spells[spell]
+ Spells[spell]["minigame"](CASTING_SPELL, Spells[spell]["difficulty"])
else
print("Could not find spell " .. spell)
end
@@ -74,7 +93,11 @@ end
function DrawSpellOverlay()
if(CASTING_SPELL) then
- CASTING_SPELL["minigame"]()
+ CASTING_SPELL["draw"](CASTING_SPELL)
+ if(CASTING_SPELL.Score != nil) then
+ finishedcasting(CASTING_SPELL.Score)
+ CASTING_SPELL = nil
+ end
end
end
diff --git a/gamemode/hud/games/base.lua b/gamemode/hud/games/base.lua
index a6c68c1..a3d0938 100644
--- a/gamemode/hud/games/base.lua
+++ b/gamemode/hud/games/base.lua
@@ -1,2 +1,11 @@
--A file to show what functions are used for minigames
print("Base included!")
+
+--Required functions
+--Called once when the plyer starts casting
+Game.Cast = function(difficulty)
+end
+
+--Called continuously while the player is casting
+Game.Draw = function()
+end
diff --git a/gamemode/hud/games/connectthedots.lua b/gamemode/hud/games/connectthedots.lua
index c24ff14..9b89d70 100644
--- a/gamemode/hud/games/connectthedots.lua
+++ b/gamemode/hud/games/connectthedots.lua
@@ -1,7 +1,26 @@
--The connet the dots spell game
print("Hi from connectthedots.lua")
-function connectthedots()
- print("Blah!")
- return 100
+Game.Cast = function(self,difficulty)
+ print("Cast with dificulty: " .. difficulty)
+ self.Score = nil
+end
+
+Game.Draw = function(self)
+ if not input.IsKeyTrapping() then
+ input.StartKeyTrapping()
+ end
+ draw.DrawText( "You're casting a spell!", "TargetID", ScrW() * 0.5, ScrH() * 0.25, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
+ print("X:" .. gui.MouseX() .. " Y:" .. gui.MouseY())
+ if(input.IsMouseDown(MOUSE_RIGHT)) then
+ self.Score = 100
+ end
+end
+
+Game.AddDots = function(self)
+ print("Add dots function called!")
+end
+
+Game.InstantFail = function(self)
+ self.Score = 0
end