diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/base/UGraphicClasses.pas | 392 |
1 files changed, 207 insertions, 185 deletions
diff --git a/src/base/UGraphicClasses.pas b/src/base/UGraphicClasses.pas index b7174991..0e620cac 100644 --- a/src/base/UGraphicClasses.pas +++ b/src/base/UGraphicClasses.pas @@ -1,4 +1,3 @@ -// notes: unit UGraphicClasses; interface @@ -9,106 +8,124 @@ interface {$I switches.inc} -uses UTexture,SDL; +uses + UTexture, + SDL; + +const + DelayBetweenFrames : cardinal = 60; -const DelayBetweenFrames : Cardinal = 60; type - TParticleType=(GoldenNote, PerfectNote, NoteHitTwinkle, PerfectLineTwinkle, ColoredStar, Flare); + TParticleType = (GoldenNote, PerfectNote, NoteHitTwinkle, PerfectLineTwinkle, ColoredStar, Flare); - TColour3f = Record - r, g, b: Real; - end; + TColour3f = record + r, g, b: real; + end; - TParticle = Class - X, Y : Real; //Position - Screen : Integer; - W, H : Cardinal; //dimensions of particle + TParticle = class + X, Y : real; //Position + Screen : integer; + W, H : cardinal; //dimensions of particle Col : array of TColour3f; // Colour(s) of particle - Scale : array of Real; // Scaling factors of particle layers - Frame : Byte; //act. Frame - Tex : Cardinal; //Tex num from Textur Manager - Live : Byte; //How many Cycles before Kill - RecIndex : Integer; //To which rectangle this particle belongs (only GoldenNote) + Scale : array of real; // Scaling factors of particle layers + Frame : byte; //act. Frame + Tex : cardinal; //Tex num from Textur Manager + Live : byte; //How many Cycles before Kill + RecIndex : integer; //To which rectangle this particle belongs (only GoldenNote) StarType : TParticleType; // GoldenNote | PerfectNote | NoteHitTwinkle | PerfectLineTwinkle - Alpha : Real; // used for fading... - mX, mY : Real; // movement-vector for PerfectLineTwinkle - SizeMod : Real; // experimental size modifier + Alpha : real; // used for fading... + mX, mY : real; // movement-vector for PerfectLineTwinkle + SizeMod : real; // experimental size modifier SurviveSentenceChange : Boolean; - Constructor Create(cX,cY: Real; cScreen: Integer; cLive: Byte; cFrame : integer; cRecArrayIndex : Integer; cStarType : TParticleType; Player: Cardinal); - Destructor Destroy(); override; + constructor Create(cX, cY : real; + cScreen : integer; + cLive : byte; + cFrame : integer; + cRecArrayIndex : integer; + cStarType : TParticleType; + Player : cardinal); + destructor Destroy(); override; procedure Draw; procedure LiveOn; end; - RectanglePositions = Record - xTop, yTop, xBottom, yBottom : Real; - TotalStarCount : Integer; - CurrentStarCount : Integer; - Screen : Integer; + RectanglePositions = record + xTop, yTop, xBottom, yBottom : real; + TotalStarCount : integer; + CurrentStarCount : integer; + Screen : integer; end; - PerfectNotePositions = Record - xPos, yPos : Real; - Screen : Integer; + PerfectNotePositions = record + xPos, yPos : real; + Screen : integer; end; - TEffectManager = Class + TEffectManager = class Particle : array of TParticle; - LastTime : Cardinal; - RecArray : Array of RectanglePositions; - TwinkleArray : Array[0..5] of Real; // store x-position of last twinkle for every player - PerfNoteArray : Array of PerfectNotePositions; + LastTime : cardinal; + RecArray : array of RectanglePositions; + TwinkleArray : array[0..5] of real; // store x-position of last twinkle for every player + PerfNoteArray : array of PerfectNotePositions; FlareTex: TTexture; constructor Create; destructor Destroy; override; procedure Draw; - function Spawn(X, Y: Real; - Screen: Integer; - Live: Byte; - StartFrame: Integer; - RecArrayIndex: Integer; // this is only used with GoldenNotes + function Spawn(X, Y: real; + Screen: integer; + Live: byte; + StartFrame: integer; + RecArrayIndex: integer; // this is only used with GoldenNotes StarType: TParticleType; - Player: Cardinal // for PerfectLineTwinkle - ): Cardinal; + Player: cardinal // for PerfectLineTwinkle + ): cardinal; procedure SpawnRec(); - procedure Kill(index: Cardinal); + procedure Kill(index: cardinal); procedure KillAll(); procedure SentenceChange(); - procedure SaveGoldenStarsRec(Xtop, Ytop, Xbottom, Ybottom: Real); - procedure SavePerfectNotePos(Xtop, Ytop: Real); - procedure GoldenNoteTwinkle(Top,Bottom,Right: Real; Player: Integer); + procedure SaveGoldenStarsRec(Xtop, Ytop, Xbottom, Ybottom: real); + procedure SavePerfectNotePos(Xtop, Ytop: real); + procedure GoldenNoteTwinkle(Top, Bottom, Right: real; Player: integer); procedure SpawnPerfectLineTwinkle(); end; -var GoldenRec : TEffectManager; +var + GoldenRec : TEffectManager; implementation -uses sysutils, - gl, - UIni, - UMain, - UThemes, - USkins, - UGraphic, - UDrawTexture, - UCommon, - math; +uses + sysutils, + gl, + UIni, + UMain, + UThemes, + USkins, + UGraphic, + UDrawTexture, + UCommon, + math; //TParticle -Constructor TParticle.Create(cX,cY: Real; cScreen: Integer; cLive: Byte; cFrame : integer; cRecArrayIndex : Integer; cStarType : TParticleType; Player: Cardinal); +constructor TParticle.Create(cX, cY : real; + cScreen : integer; + cLive : byte; + cFrame : integer; + cRecArrayIndex : integer; + cStarType : TParticleType; + Player : cardinal); begin inherited Create; // in this constructor we set all initial values for our particle X := cX; Y := cY; Screen := cScreen; - Live := cLive; - Frame:= cFrame; + Live := cLive; + Frame := cFrame; RecIndex := cRecArrayIndex; StarType := cStarType; Alpha := (-cos((Frame+1)*2*pi/16)+1); // neat fade-in-and-out @@ -123,9 +140,9 @@ begin W := 20; H := 20; SetLength(Scale,4); - Scale[1]:=0.8; - Scale[2]:=0.4; - Scale[3]:=0.3; + Scale[1] := 0.8; + Scale[2] := 0.4; + Scale[3] := 0.3; SetLength(Col,4); Col[0].r := 1; Col[0].g := 0.7; @@ -170,11 +187,11 @@ begin W := RandomRange(10,20); H := W; SizeMod := (-cos((Frame+1)*5*2*pi/16)*0.5+1.1); - SurviveSentenceChange:=True; + SurviveSentenceChange := True; // assign colours according to player given SetLength(Scale,3); - Scale[1]:=0.3; - Scale[2]:=0.2; + Scale[1] := 0.3; + Scale[2] := 0.2; SetLength(Col,3); case Player of 0: LoadColor(Col[0].r,Col[0].g,Col[0].b,'P1Light'); @@ -188,9 +205,9 @@ begin Col[1].r := 1; Col[1].g := 1; Col[1].b := 0.4; - Col[2].r:=Col[0].r+0.5; - Col[2].g:=Col[0].g+0.5; - Col[2].b:=Col[0].b+0.5; + Col[2].r := Col[0].r+0.5; + Col[2].g := Col[0].g+0.5; + Col[2].b := Col[0].b+0.5; mX := RandomRange(-5,5); mY := RandomRange(-5,5); end; @@ -200,7 +217,7 @@ begin W := RandomRange(10,20); H := W; SizeMod := (-cos((Frame+1)*5*2*pi/16)*0.5+1.1); - SurviveSentenceChange:=True; + SurviveSentenceChange := True; // assign colours according to player given SetLength(Scale,1); SetLength(Col,1); @@ -219,9 +236,9 @@ begin mX := RandomRange(-5,5); mY := RandomRange(-5,5); SetLength(Scale,4); - Scale[1]:=0.8; - Scale[2]:=0.4; - Scale[3]:=0.3; + Scale[1] := 0.8; + Scale[2] := 0.4; + Scale[3] := 0.3; SetLength(Col,4); Col[0].r := 1; Col[0].g := 0.7; @@ -254,7 +271,7 @@ begin end; end; -Destructor TParticle.Destroy(); +destructor TParticle.Destroy(); begin SetLength(Scale,0); SetLength(Col,0); @@ -304,18 +321,19 @@ begin // move around X := X + mX; Y := Y + mY; - mY:=mY+1.8; -// mX:=mX/2; + mY := mY+1.8; +// mX := mX/2; end; end; end; procedure TParticle.Draw; -var L: Cardinal; +var + L: cardinal; begin if ScreenAct = Screen then // this draws (multiple) texture(s) of our particle - for L:=0 to High(Col) do + for L := 0 to High(Col) do begin glColor4f(Col[L].r, Col[L].g, Col[L].b, Alpha); @@ -324,14 +342,12 @@ begin glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - begin - glBegin(GL_QUADS); - glTexCoord2f((1/16) * Frame, 0); glVertex2f(X-W*Scale[L]*SizeMod, Y-H*Scale[L]*SizeMod); - glTexCoord2f((1/16) * Frame + (1/16), 0); glVertex2f(X-W*Scale[L]*SizeMod, Y+H*Scale[L]*SizeMod); - glTexCoord2f((1/16) * Frame + (1/16), 1); glVertex2f(X+W*Scale[L]*SizeMod, Y+H*Scale[L]*SizeMod); - glTexCoord2f((1/16) * Frame, 1); glVertex2f(X+W*Scale[L]*SizeMod, Y-H*Scale[L]*SizeMod); - glEnd; - end; + glBegin(GL_QUADS); + glTexCoord2f((1/16) * Frame, 0); glVertex2f(X-W*Scale[L]*SizeMod, Y-H*Scale[L]*SizeMod); + glTexCoord2f((1/16) * Frame + (1/16), 0); glVertex2f(X-W*Scale[L]*SizeMod, Y+H*Scale[L]*SizeMod); + glTexCoord2f((1/16) * Frame + (1/16), 1); glVertex2f(X+W*Scale[L]*SizeMod, Y+H*Scale[L]*SizeMod); + glTexCoord2f((1/16) * Frame, 1); glVertex2f(X+W*Scale[L]*SizeMod, Y-H*Scale[L]*SizeMod); + glEnd; end; glcolor4f(1,1,1,1); end; @@ -340,11 +356,12 @@ end; // TEffectManager constructor TEffectManager.Create; -var c: Cardinal; +var + c: cardinal; begin inherited; LastTime := SDL_GetTicks(); - for c:=0 to 5 do + for c := 0 to 5 do begin TwinkleArray[c] := 0; end; @@ -359,44 +376,44 @@ end; procedure TEffectManager.Draw; var - I: Integer; - CurrentTime: Cardinal; + I: integer; + CurrentTime: cardinal; //const -// DelayBetweenFrames : Cardinal = 100; +// DelayBetweenFrames : cardinal = 100; begin CurrentTime := SDL_GetTicks(); //Manage particle life if (CurrentTime - LastTime) > DelayBetweenFrames then - begin - LastTime := CurrentTime; - for I := 0 to high(Particle) do - Particle[I].LiveOn; - end; + begin + LastTime := CurrentTime; + for I := 0 to high(Particle) do + Particle[I].LiveOn; + end; I := 0; //Kill dead particles while (I <= High(Particle)) do + begin + if (Particle[I].Live <= 0) then begin - if (Particle[I].Live <= 0) then - begin - kill(I); - end - else - begin - inc(I); - end; + kill(I); + end + else + begin + inc(I); end; + end; //Draw - for I := 0 to high(Particle) do - begin - Particle[I].Draw; - end; + for I := 0 to high(Particle) do + begin + Particle[I].Draw; + end; end; // this method creates just one particle -function TEffectManager.Spawn(X, Y: Real; Screen: Integer; Live: Byte; StartFrame : Integer; RecArrayIndex : Integer; StarType : TParticleType; Player: Cardinal): Cardinal; +function TEffectManager.Spawn(X, Y: real; Screen: integer; Live: byte; StartFrame : integer; RecArrayIndex : integer; StarType : TParticleType; Player: cardinal): cardinal; begin Result := Length(Particle); SetLength(Particle, (Result + 1)); @@ -405,32 +422,32 @@ end; // manage Sparkling of GoldenNote Bars procedure TEffectManager.SpawnRec(); -Var - Xkatze, Ykatze : Real; - RandomFrame : Integer; - P : Integer; // P as seen on TV as Positionman +var + Xkatze, Ykatze : real; + RandomFrame : integer; + P : integer; // P as seen on TV as Positionman begin //Spawn a random amount of stars within the given coordinates //RandomRange(0,14) <- this one starts at a random frame, 16 is our last frame - would be senseless to start a particle with 16, cause it would be dead at the next frame -for P:= 0 to high(RecArray) do + for P := 0 to high(RecArray) do begin while (RecArray[P].TotalStarCount > RecArray[P].CurrentStarCount) do - begin - Xkatze := RandomRange(Ceil(RecArray[P].xTop), Ceil(RecArray[P].xBottom)); - Ykatze := RandomRange(Ceil(RecArray[P].yTop), Ceil(RecArray[P].yBottom)); - RandomFrame := RandomRange(0,14); - // Spawn a GoldenNote Particle - Spawn(Xkatze, Ykatze, RecArray[P].Screen, 16 - RandomFrame, RandomFrame, P, GoldenNote, 0); - inc(RecArray[P].CurrentStarCount); - end; + begin + Xkatze := RandomRange(Ceil(RecArray[P].xTop), Ceil(RecArray[P].xBottom)); + Ykatze := RandomRange(Ceil(RecArray[P].yTop), Ceil(RecArray[P].yBottom)); + RandomFrame := RandomRange(0,14); + // Spawn a GoldenNote Particle + Spawn(Xkatze, Ykatze, RecArray[P].Screen, 16 - RandomFrame, RandomFrame, P, GoldenNote, 0); + inc(RecArray[P].CurrentStarCount); end; + end; draw; end; // kill one particle (with given index in our particle array) -procedure TEffectManager.Kill(Index: Cardinal); +procedure TEffectManager.Kill(Index: cardinal); var - LastParticleIndex : Integer; + LastParticleIndex : integer; begin // delete particle indexed by Index, // overwrite it's place in our particle-array with the particle stored at the last array index, @@ -449,23 +466,25 @@ end; // clean up all particles and management structures procedure TEffectManager.KillAll(); -var c: Cardinal; +var + c: cardinal; begin //It's the kill all kennies rotuine while Length(Particle) > 0 do // kill all existing particles Kill(0); SetLength(RecArray,0); // remove GoldenRec positions SetLength(PerfNoteArray,0); // remove PerfectNote positions - for c:=0 to 5 do + for c := 0 to 5 do begin TwinkleArray[c] := 0; // reset GoldenNoteHit memory end; end; procedure TEffectManager.SentenceChange(); -var c: Cardinal; +var + c: cardinal; begin - c:=0; + c := 0; while c <= High(Particle) do begin if Particle[c].SurviveSentenceChange then @@ -475,22 +494,22 @@ begin end; SetLength(RecArray,0); // remove GoldenRec positions SetLength(PerfNoteArray,0); // remove PerfectNote positions - for c:=0 to 5 do + for c := 0 to 5 do begin TwinkleArray[c] := 0; // reset GoldenNoteHit memory end; end; -procedure TeffectManager.GoldenNoteTwinkle(Top,Bottom,Right: Real; Player: Integer); +procedure TeffectManager.GoldenNoteTwinkle(Top, Bottom, Right: real; Player: integer); //Twinkle stars while golden note hit // this is called from UDraw.pas, SingDrawPlayerCzesc var - C, P, XKatze, YKatze, LKatze: Integer; - H: Real; + C, P, XKatze, YKatze, LKatze: integer; + H: real; begin // make sure we spawn only one time at one position if (TwinkleArray[Player] < Right) then - For P := 0 to high(RecArray) do // Are we inside a GoldenNoteRectangle? + for P := 0 to high(RecArray) do // Are we inside a GoldenNoteRectangle? begin H := (Top+Bottom)/2; // helper... with RecArray[P] do @@ -540,12 +559,12 @@ begin end; end; -procedure TEffectManager.SaveGoldenStarsRec(Xtop, Ytop, Xbottom, Ybottom: Real); +procedure TEffectManager.SaveGoldenStarsRec(Xtop, Ytop, Xbottom, Ybottom: real); var - P : Integer; // P like used in Positions - NewIndex : Integer; + P : integer; // P like used in Positions + NewIndex : integer; begin - For P := 0 to high(RecArray) do // Do we already have that "new" position? + for P := 0 to high(RecArray) do // Do we already have that "new" position? begin if (ceil(RecArray[P].xTop) = ceil(Xtop)) and (ceil(RecArray[P].yTop) = ceil(Ytop)) and @@ -565,105 +584,108 @@ begin RecArray[NewIndex].Screen := ScreenAct; end; -procedure TEffectManager.SavePerfectNotePos(Xtop, Ytop: Real); +procedure TEffectManager.SavePerfectNotePos(Xtop, Ytop: real); var - P : Integer; // P like used in Positions - NewIndex : Integer; - RandomFrame : Integer; - Xkatze, Ykatze : Integer; + P : integer; // P like used in Positions + NewIndex : integer; + RandomFrame : integer; + Xkatze, Ykatze : integer; begin - For P := 0 to high(PerfNoteArray) do // Do we already have that "new" position? - begin - with PerfNoteArray[P] do - if (ceil(xPos) = ceil(Xtop)) and (ceil(yPos) = ceil(Ytop)) and - (Screen = ScreenAct) then - exit; // it's already in the array, so we don't have to create a new one - end; //for + for P := 0 to high(PerfNoteArray) do // Do we already have that "new" position? + begin + with PerfNoteArray[P] do + if (ceil(xPos) = ceil(Xtop)) and (ceil(yPos) = ceil(Ytop)) and + (Screen = ScreenAct) then + exit; // it's already in the array, so we don't have to create a new one + end; //for // we got a new position, add the new positions to our array - NewIndex := Length(PerfNoteArray); - SetLength(PerfNoteArray, NewIndex + 1); - PerfNoteArray[NewIndex].xPos := Xtop; - PerfNoteArray[NewIndex].yPos := Ytop; - PerfNoteArray[NewIndex].Screen := ScreenAct; + NewIndex := Length(PerfNoteArray); + SetLength(PerfNoteArray, NewIndex + 1); + PerfNoteArray[NewIndex].xPos := Xtop; + PerfNoteArray[NewIndex].yPos := Ytop; + PerfNoteArray[NewIndex].Screen := ScreenAct; - for P:= 0 to 2 do - begin - Xkatze := RandomRange(ceil(Xtop) - 5 , ceil(Xtop) + 10); - Ykatze := RandomRange(ceil(Ytop) - 5 , ceil(Ytop) + 10); - RandomFrame := RandomRange(0,14); - Spawn(Xkatze, Ykatze, ScreenAct, 16 - RandomFrame, RandomFrame, -1, PerfectNote, 0); - end; //for + for P := 0 to 2 do + begin + Xkatze := RandomRange(ceil(Xtop) - 5 , ceil(Xtop) + 10); + Ykatze := RandomRange(ceil(Ytop) - 5 , ceil(Ytop) + 10); + RandomFrame := RandomRange(0,14); + Spawn(Xkatze, Ykatze, ScreenAct, 16 - RandomFrame, RandomFrame, -1, PerfectNote, 0); + end; //for end; procedure TEffectManager.SpawnPerfectLineTwinkle(); var - P,I,Life: Cardinal; - Left, Right, Top, Bottom: Cardinal; - cScreen: Integer; + P, I, Life: cardinal; + Left, Right, Top, Bottom: cardinal; + cScreen: integer; begin // calculation of coordinates done with hardcoded values like in UDraw.pas // might need to be adjusted if drawing of SingScreen is modified // coordinates may still be a bit weird and need adjustment - if Ini.SingWindow = 0 then begin + if Ini.SingWindow = 0 then + begin Left := 130; - end else begin + end + else + begin Left := 30; end; Right := 770; // spawn effect for every player with a perfect line - for P:=0 to PlayersPlay-1 do + for P := 0 to PlayersPlay-1 do if Player[P].LastSentencePerfect then begin // calculate area where notes of this player are drawn case PlayersPlay of 1: begin - Bottom:=Skin_P2_NotesB+10; - Top:=Bottom-105; - cScreen:=1; + Bottom := Skin_P2_NotesB+10; + Top := Bottom-105; + cScreen := 1; end; 2,4: begin case P of 0,2: begin - Bottom:=Skin_P1_NotesB+10; - Top:=Bottom-105; + Bottom := Skin_P1_NotesB+10; + Top := Bottom-105; end; else begin - Bottom:=Skin_P2_NotesB+10; - Top:=Bottom-105; + Bottom := Skin_P2_NotesB+10; + Top := Bottom-105; end; end; case P of - 0,1: cScreen:=1; - else cScreen:=2; + 0,1: cScreen := 1; + else cScreen := 2; end; end; 3,6: begin case P of 0,3: begin - Top:=130; - Bottom:=Top+85; + Top := 130; + Bottom := Top+85; end; 1,4: begin - Top:=255; - Bottom:=Top+85; + Top := 255; + Bottom := Top+85; end; 2,5: begin - Top:=380; - Bottom:=Top+85; + Top := 380; + Bottom := Top+85; end; end; case P of - 0,1,2: cScreen:=1; - else cScreen:=2; + 0,1,2: cScreen := 1; + else cScreen := 2; end; end; end; // spawn Sparkling Stars inside calculated coordinates - for I:= 0 to 80 do + for I := 0 to 80 do begin - Life:=RandomRange(8,16); + Life := RandomRange(8,16); Spawn(RandomRange(Left,Right), RandomRange(Top,Bottom), cScreen, Life, 16-Life, -1, PerfectLineTwinkle, P); end; end; |