diff options
| -rw-r--r-- | gamemode/hud/draw_spell.lua | 76 | ||||
| -rw-r--r-- | gamemode/hud/games/connectthedots.lua | 143 |
2 files changed, 189 insertions, 30 deletions
diff --git a/gamemode/hud/draw_spell.lua b/gamemode/hud/draw_spell.lua index 96440e4..b68e988 100644 --- a/gamemode/hud/draw_spell.lua +++ b/gamemode/hud/draw_spell.lua @@ -19,6 +19,7 @@ Games = {} function loadgames() includedfiles = {} + Games = {} print("Looking for what minigames we need...") for k,v in pairs(Spells) do local filename = v["file"] @@ -34,36 +35,73 @@ function loadgames() Game = {} include(Folder .. "/" .. k) Games[k] = Game + print("Loaded game:") + PrintTable(Game,1) end print("Resolveing minigame names") + print("All games:") + PrintTable(Games,1) + print("All spells:") + PrintTable(Spells) + local needefunctions = {"minigame","draw","interupt"} for k,v in pairs(Spells) do + local spell = v + print("Resolveing spell:") + PrintTable(Spells) + local gametab = Games[v["file"]] + if not gametab then + print("Coudln't find " .. v["file"] .. " in games") + end + for i,j in pairs(gametab) do + local issimple = false + for l,m in pairs(spell) do + print("Checking if ",m,"is",i) + if(m == i) then + print("Overloading " .. m) + spell[l] = j + issimple = true + break + end + end + if not issimple then + spell[i] = j + end + end + --[[ 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!") + for l,m in pairs(j) do + Spells[k][l] = m + print("Resolved " .. k) + local castfunc = j[mgname] + local drawfunc = j[mgdname] + local interuptfunc = j[mginame] + if(castfunc) then + Spells[k]["minigame"] = castfunc + else + print("Spell " .. k .. " does not have a cast func! This may be an error!") + end + if(drawfunc) then + Spells[k]["draw"] = drawfunc + else + print("Spell " .. k .. " does not have a draw func! This may be an error!") + end + if(interuptfunc) then + Spells[k]["interupt"] = interuptfunc + else + print("Spell " .. k .. " does not have an interupt func! This may be an error!") + end end end + Spells[k] = j end + ]]-- end + print("After resolveing:") + PrintTable(Spells) end hook.Add("Initialize","Loadspells",function() @@ -85,7 +123,7 @@ function StartMinigame(spell) if Spells[spell] then CASTING_SPELL = Spells[spell] - Spells[spell]["minigame"](CASTING_SPELL, Spells[spell]["difficulty"]) + CASTING_SPELL["minigame"](CASTING_SPELL, CASTING_SPELL["difficulty"]) else print("Could not find spell " .. spell) end diff --git a/gamemode/hud/games/connectthedots.lua b/gamemode/hud/games/connectthedots.lua index d0e00b8..c5aea2a 100644 --- a/gamemode/hud/games/connectthedots.lua +++ b/gamemode/hud/games/connectthedots.lua @@ -2,21 +2,54 @@ print("Hi from connectthedots.lua") --Minigame is held in self.dots, each dot is a table, ---dot[num] = {dot x, dot y, {{armor_start_angle,armor_end_angle},{armor_start_angle,armor_end_angle}}} +--dot[num] = {dot x, dot y, { +-- {armor_start_angle, armor_end_angle}, +-- {armor_start_angle, armor_end_angle}, +-- ... +--}, activated} +--And in self.lines, each line is held as +--line[num] = {{start x, start y},{end x, end y}} -Game.Cast = function(self,difficulty) +Game.AddRegDot = nil +Game.dots = nil +Game.lines = nil + + +Game.Cast = function(spelltab,difficulty) print("Cast with dificulty: " .. difficulty) - self.Score = nil + spelltab.Score = nil --Create a dummy panel so that the mouse is trapped, untrap it when it right clicks - scoreboard = vgui.Create("MBFrame") + local scoreboard = vgui.Create("MBFrame") if(!scoreboard) then return end scoreboard:SetPos(0,0) scoreboard:SetSize(0,0) scoreboard:MakePopup() - self.scoreboard = scoreboard + spelltab.scoreboard = scoreboard --Create the minigame + spelltab.dots = {} + spelltab.lines = {} + + --Create the first dot in the middle of the screen + spelltab.dots[0] = {} + spelltab.dots[0][0] = ScrW()/2 + spelltab.dots[0][1] = ScrH()/2 + spelltab.dots[0][2] = {} + + --Create the first line from the first dot + local fline = {} + fline[0] = {} + fline[1] = {} + fline[0][0] = ScrW()/2 + fline[0][1] = ScrH()/2 + fline[1][0] = ScrW()/2 + fline[1][1] = ScrH()/2 + spelltab.lines[0] = fline + --Add some dots! + spelltab:AddRegDot(spelltab) + spelltab:AddRegDot(spelltab) + spelltab:AddRegDot(spelltab) end Game.Draw = function(self) @@ -25,7 +58,59 @@ Game.Draw = function(self) 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()) + for k,v in pairs(self.dots) do + local tcolor = Color(255,0,0,255) + if(v[3]) then + tcolor = Color(0,255,0,255) + end + surface.DrawCircle(v[0],v[1],10,tcolor) + + --If our mouse is touching dot, add a line that connects that dot, and set the dot to "activated" + if(math.Distance(gui.MouseX(),gui.MouseY(),v[0],v[1]) < 10 and not v[3]) then + v[3] = true + local finishedline = self.lines[#self.lines] + finishedline[1][0] = v[0] + finishedline[1][1] = v[1] + + --Create a new line + local newline = {} + newline[0] = {} + newline[1] = {} + newline[0][0] = v[0] + newline[0][1] = v[1] + newline[1][0] = v[0] + newline[1][1] = v[1] + self.lines[#self.lines+1]=newline + --Check the number of dots remaining, if there are none, we're done! + local done = true + for i,j in pairs(self.dots) do + if(not j[3]) then + done = false + break + end + end + if(done) then + self.Score = 100 + self.scoreboard:Remove() + end + end + end + + --Find the last line in the table + local lastl = self.lines[#self.lines] + --and set it's end to our mouse's position + lastl[1][0] = gui.MouseX() + lastl[1][1] = gui.MouseY() + for k,v in pairs(self.lines) do + if(v == lastl) then + surface.SetDrawColor(Color(255,0,0,255)) + else + surface.SetDrawColor(Color(0,255,0,255)) + end + surface.DrawLine(v[0][0],v[0][1],v[1][0],v[1][1]) + end + + --print("X:" .. gui.MouseX() .. " Y:" .. gui.MouseY()) if(input.IsMouseDown(MOUSE_RIGHT)) then self.Score = 100 self.scoreboard:Remove() @@ -33,10 +118,16 @@ Game.Draw = function(self) end --A basic dot, can be accessed from anywhere. -Game.AddRegDot = function(self) +Game.AddRegDot = function(spelltab) + if(spelltab.dots == nil) then + print("After calling, self is") + PrintTable(spelltab) + print("We have no starting dots! help!") + return + end --Find the most recently added dot - local fd = table.GetFirstValue(self.dots) + local fd = spelltab.dots[#spelltab.dots] local armors = {} for k,v in pairs(fd[2]) do armors[k] = v @@ -59,14 +150,44 @@ Game.AddRegDot = function(self) end print("Adding new dot at an angle of " .. position) - --Pick a random distance from this dot to the screen edge, and put a dot there + print("Adding a new dot after " .. fd[0] .. "," .. fd[1]) + + --Pick a random distance from this dot to the screen edge, and put a dot there, but at least 20 pixels local rand = 0 + local totop = fd[1]+20 + local toleft = fd[0]+20 + local tobot = ScrH() - totop - 40 + local toright = ScrW() - toleft - 40 --If we're in the first quadrent - if(math.cos(position) > 0) then - rand = math.random(fd[0],ScrW()) + if(position > 0 and position <= 90) then + --pick a distnce between us and the closer edge + local closer = math.min(totop,toright) + rand = math.random(20,closer) + elseif(position > 90 and position <= 180) then + local closer = math.min(totop,toleft) + rand = math.random(20,closer) + elseif(position > 180 and position <= 270) then + local closer = math.min(toleft,tobot) + rand = math.random(20,closer) + else + local closer = math.min(tobot,toright) + rand = math.random(20,closer) end + print("And at a distance of " .. rand) + + local xpos = (math.cos(position)*rand) + local ypos = (math.sin(position)*rand) + print("I think I should add a dot at " .. xpos .. "," .. ypos) + + local newdot = {} + newdot[0] = xpos + newdot[1] = ypos + newdot[2] = {} + + spelltab.dots[#spelltab.dots + 1] = newdot + end Game.AddDots = function(self) |
