aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/game
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-12-09 16:32:22 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-12-09 16:32:22 +0000
commitd267ce95e1743fad0d383d1d7fe51e9b8bf5b66f (patch)
tree3bc133649ffb0bd32b9c461e3d67fe5d810dbc0b /Lua/game
parentc3a430e61e20c47ad2b0632e35f48c83af22a5b3 (diff)
downloadusdx-d267ce95e1743fad0d383d1d7fe51e9b8bf5b66f.tar.gz
usdx-d267ce95e1743fad0d383d1d7fe51e9b8bf5b66f.tar.xz
usdx-d267ce95e1743fad0d383d1d7fe51e9b8bf5b66f.zip
adds working teamduel lua plugin
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2010 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Lua/game')
-rw-r--r--Lua/game/plugins/LuaTest.usdx6
-rw-r--r--Lua/game/plugins/teamduel.usdx230
2 files changed, 234 insertions, 2 deletions
diff --git a/Lua/game/plugins/LuaTest.usdx b/Lua/game/plugins/LuaTest.usdx
index 4cfd718f..553fca13 100644
--- a/Lua/game/plugins/LuaTest.usdx
+++ b/Lua/game/plugins/LuaTest.usdx
@@ -1,8 +1,7 @@
function plugin_init()
register('lua interface test plugin', 'not Versioned', 'Hawkear');
- require('Usdx.Gl');
- require('Usdx.TextGl');
+ require('Usdx.Gl', 'Usdx.TextGl', 'Usdx.ScreenSing');
Usdx.Hook('Display.Draw', 'OnDraw');
@@ -34,6 +33,9 @@ function OnDraw()
Gl.Color(0.9, 0.9, 0.9, 0.7)
TextGl.Print('FPS: ' .. LastFPSCounted)
+ TextGl.Pos(650, 50)
+ TextGl.Print('Beat: ' .. ScreenSing.GetBeat())
+
-- Draw some rectanGles
Gl.Enable("Gl_BLEND")
Gl.Color(1, 1, 1, 0.5)
diff --git a/Lua/game/plugins/teamduel.usdx b/Lua/game/plugins/teamduel.usdx
new file mode 100644
index 00000000..844e53b0
--- /dev/null
+++ b/Lua/game/plugins/teamduel.usdx
@@ -0,0 +1,230 @@
+-- some values to adjust the creation of PlayerChanges
+local MinPercentage = 0.06; -- minimal amount of points between changes (in percent)
+local MaxPercentage = 0.12; -- maximal amount of points between changes (in percent)
+-- position of big progress bar in the center
+local BarPos = {};
+BarPos.Top = 30
+BarPos.Bottom = 50
+BarPos.Left = 300
+BarPos.Right = 500
+
+function plugin_init()
+ register('party mode: teamduel', '1.00', 'USDX Team', 'http://www.UltrastarDeluxe.org');
+
+ require('math', 'Usdx.Party', 'Usdx.ScreenSing', 'Usdx.Gl', 'Usdx.TextGl');
+ local Mode = {}
+
+ Mode.Name = 'teamduel';
+ Mode.CanParty = true;
+ Mode.PlayerCount = {2,3,4,5,6};
+
+ Mode.BeforeSing = 'BeforeSing'
+ Mode.OnSing = 'Sing';
+
+ Usdx.Party.Register(Mode)
+
+ ScreenSing.GetBeat();
+
+ return true;
+end
+
+-- called everytime a singing session w/ this party mode is startet
+-- we just hook ScreenSing.SongLoaded to prepare the mic changes here
+function BeforeSing()
+ hSongLoaded = Usdx.Hook('ScreenSing.SongLoaded', 'PrepareChanges');
+end;
+
+-- adds a new SentenceChange at Line to the PlayerChanges array
+function AddChange(Line)
+ PlayerChanges[#PlayerChanges + 1] = {};
+ PlayerChanges[#PlayerChanges].OnBeat = Lines[Line].Start;
+
+ PlayerChanges[#PlayerChanges].NextPlayer = {}
+ for i = 1, #Teams do
+ repeat
+ PlayerChanges[#PlayerChanges].NextPlayer[i] = math.random(#Teams[i].Players);
+ until (1 == #PlayerChanges) or (PlayerChanges[#PlayerChanges].NextPlayer[i] ~= PlayerChanges[#PlayerChanges-1].NextPlayer[i]) or (#Teams[i].Players == 1);
+ end;
+end;
+
+function PrepareChanges()
+ Lines = ScreenSing.GetSongLines();
+ Teams = Party.GetTeams();
+
+ -- get sum of hittable beats (per line and total)
+ local TotalBeats = 0;
+ local LineValue = {};
+ for i = 1, #Lines do
+ for j = 1, #Lines[i].Notes do
+ LineValue[i] = (LineValue[i] or 0) + Lines[i].Notes[j].Length * Lines[i].Notes[j].NoteType;
+ end;
+ TotalBeats = TotalBeats + LineValue[i];
+ end;
+
+ -- calculate changes
+ PlayerChanges = {};
+ -- fallback if there are only freestyle notes
+ -- random count of lines between changes
+ if (TotalBeats == 0) then
+ local i = 1;
+ repeat
+ if i > 1 then
+ AddChange(i);
+ end
+
+ local step = math.ceil((MinPercentage + (MaxPercentage - MinPercentage) * math.random()) * #Lines);
+ if step < 1 then
+ step = 1;
+ end;
+
+ i = i + step;
+ until i >= #Lines;
+ else -- calculate changes by amount of hittable beats
+ local i = 1;
+ local BeatsToChange = math.ceil((MinPercentage + (MaxPercentage - MinPercentage) * math.random()) * TotalBeats);
+ local Beats = 0;
+
+ repeat
+ Beats = Beats + LineValue[i];
+ if Beats >= BeatsToChange then
+ AddChange(i);
+ BeatsToChange = BeatsToChange + math.ceil((MinPercentage + (MaxPercentage - MinPercentage) * math.random()) * TotalBeats);
+ end
+ i = i + 1;
+ until i >= #Lines;
+ end;
+
+ -- free lines
+ Lines = nil;
+
+ -- init NextPlayerChange
+ NextPlayerChange = 1;
+
+ -- calculate OSD position for players
+ do
+ local RBRect = ScreenSing.GetRBRect();
+ OSD = {};
+
+ for i = 1, #RBRect do
+ OSD[i] = {};
+ OSD[i].Left = RBRect[i].x;
+ OSD[i].Right = RBRect[i].x + RBRect[i].w;
+ OSD[i].Top = RBRect[i].y + RBRect[i].h;
+ OSD[i].Bottom = RBRect[i].y + RBRect[i].h + math.max(RBRect[i].h, 13);
+ end;
+ end;
+
+ -- remove hook
+ hSongLoaded:Unhook();
+ hSongLoaded = nil;
+end
+
+function DrawPlayerText(i, Text)
+ Gl.Disable('GL_TEXTURE_2D');
+
+ -- background
+ Gl.Color (0, 0, 0, 1);
+ Gl.Begin('GL_QUADS');
+ Gl.Vertex(OSD[i].Left, OSD[i].Top);
+ Gl.Vertex(OSD[i].Left, OSD[i].Bottom);
+ Gl.Vertex(OSD[i].Right, OSD[i].Bottom);
+ Gl.Vertex(OSD[i].Right, OSD[i].Top);
+ Gl.End();
+
+ -- text
+ Gl.Color(1, 0, 0, 1);
+ TextGl.Size(6);
+ TextGl.Style(1);
+ TextGl.Italic(false);
+
+ local PosX = (OSD[i].Left + OSD[i].Right) / 2;
+ PosX = PosX - TextGl.Width(Text) / 2;
+
+ TextGl.Pos(PosX, OSD[i].Top - 3);
+
+ TextGl.Print(Text);
+end;
+
+-- draws the progress bar for player i
+function DrawPlayerProgress(i, Progress)
+ Gl.Disable('GL_TEXTURE_2D');
+
+ -- background
+ Gl.Color (0, 0, 0, 1);
+ Gl.Begin('GL_QUADS');
+ Gl.Vertex(OSD[i].Left, OSD[i].Top);
+ Gl.Vertex(OSD[i].Left, OSD[i].Bottom);
+ Gl.Vertex(OSD[i].Right, OSD[i].Bottom);
+ Gl.Vertex(OSD[i].Right, OSD[i].Top);
+ Gl.End();
+
+ -- bar
+ Gl.Color(1, 0, 0, 1);
+ Gl.Begin('GL_QUADS');
+ Gl.Vertex(OSD[i].Left + 2, OSD[i].Top + 2);
+ Gl.Vertex(OSD[i].Left + 2, OSD[i].Bottom - 2);
+ Gl.Vertex(OSD[i].Left + 2 + (OSD[i].Right - OSD[i].Left - 4) * Progress, OSD[i].Bottom - 2);
+ Gl.Vertex(OSD[i].Left + 2 + (OSD[i].Right - OSD[i].Left - 4) * Progress, OSD[i].Top + 2);
+ Gl.End();
+end;
+
+-- draws the big progress bar in the screen center
+function DrawCenterProgress(Progress)
+ Gl.Disable('GL_TEXTURE_2D');
+
+ -- background
+ Gl.Color (0, 0, 0, 1);
+ Gl.Begin('GL_QUADS');
+ Gl.Vertex(BarPos.Left, BarPos.Top);
+ Gl.Vertex(BarPos.Left, BarPos.Bottom);
+ Gl.Vertex(BarPos.Right, BarPos.Bottom);
+ Gl.Vertex(BarPos.Right, BarPos.Top);
+ Gl.End();
+
+ -- bar
+ Gl.Color(1, 0, 0, 1);
+ Gl.Begin('GL_QUADS');
+ Gl.Vertex(BarPos.Left + 2, BarPos.Top + 2);
+ Gl.Vertex(BarPos.Left + 2, BarPos.Bottom - 2);
+ Gl.Vertex(BarPos.Left + 2 + (BarPos.Right - BarPos.Left - 4) * Progress, BarPos.Bottom - 2);
+ Gl.Vertex(BarPos.Left + 2 + (BarPos.Right - BarPos.Left - 4) * Progress, BarPos.Top + 2);
+ Gl.End();
+end;
+
+function Sing()
+ if (NextPlayerChange <= #PlayerChanges) then
+ local BeatsToNextChange = PlayerChanges[NextPlayerChange].OnBeat - ScreenSing.GetBeat();
+ local TimeToNextChange = ScreenSing.BeatsToSeconds(BeatsToNextChange);
+
+ -- draw next player text or progress bar
+ if (TimeToNextChange <= 0) then
+ --there is a change
+ NextPlayerChange = NextPlayerChange + 1;
+
+ elseif (TimeToNextChange <= 5) then
+ for i = 1, #Teams do
+ DrawPlayerProgress(i, 1 - TimeToNextChange/5);
+ end;
+ elseif (TimeToNextChange <= 6.5) then
+ for i = 1, #Teams do
+ DrawPlayerText(i, Teams[i].Players[PlayerChanges[NextPlayerChange].NextPlayer[i]].Name);
+ end;
+ elseif (TimeToNextChange <= 8) then
+ for i = 1, #Teams do
+ DrawPlayerText(i, 'Next Player');
+ end;
+ elseif (TimeToNextChange <= 9.5) then
+ for i = 1, #Teams do
+ DrawPlayerText(i, Teams[i].Players[PlayerChanges[NextPlayerChange].NextPlayer[i]].Name);
+ end;
+ elseif (TimeToNextChange <= 11) then
+ for i = 1, #Teams do
+ DrawPlayerText(i, 'Next Player');
+ end;
+ end
+
+ if (TimeToNextChange <= 11) then
+ DrawCenterProgress(1 - TimeToNextChange/11);
+ end;
+ end;
+end \ No newline at end of file