New animation class created.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2134 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
denniscuflat 2011-11-15 00:03:21 +00:00
parent 51c54f54ac
commit 63775e2439
6 changed files with 153 additions and 23 deletions

View File

@ -1,7 +1,7 @@
object formTappyTuxGame: TformTappyTuxGame object formTappyTuxGame: TformTappyTuxGame
Left = 626 Left = 76
Height = 425 Height = 425
Top = 277 Top = 292
Width = 621 Width = 621
Caption = 'Tappy Tux' Caption = 'Tappy Tux'
ClientHeight = 425 ClientHeight = 425
@ -9,7 +9,6 @@ object formTappyTuxGame: TformTappyTuxGame
OnCreate = FormCreate OnCreate = FormCreate
OnShow = FormShow OnShow = FormShow
LCLVersion = '0.9.31' LCLVersion = '0.9.31'
Visible = True
object btnExit: TButton object btnExit: TButton
Left = 8 Left = 8
Height = 31 Height = 31
@ -248,7 +247,7 @@ object formTappyTuxGame: TformTappyTuxGame
object Yes: TButton object Yes: TButton
Left = 240 Left = 240
Height = 30 Height = 30
Top = 219 Top = 216
Width = 80 Width = 80
Caption = 'Yes' Caption = 'Yes'
Color = clRed Color = clRed

View File

@ -9,7 +9,7 @@ uses
// LCL // LCL
ExtCtrls, ExtCtrls,
// TappyTux // TappyTux
tappymodules; tappyconfig, tappydrawer, tappymodules;
type type
@ -35,6 +35,7 @@ type
procedure TranslateTextsToEnglish; override; procedure TranslateTextsToEnglish; override;
procedure TranslateTextsToPortuguese; override; procedure TranslateTextsToPortuguese; override;
procedure StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer); override; procedure StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer); override;
procedure CreateQuestion(); override;
procedure Answered(); override; procedure Answered(); override;
procedure EndGame(); override; procedure EndGame(); override;
procedure QuestionGenerator(qNumber : Integer); procedure QuestionGenerator(qNumber : Integer);
@ -42,7 +43,7 @@ type
implementation implementation
uses tappydrawer, gameplayform; uses gameplayform;
{ TTappyMath } { TTappyMath }
@ -126,6 +127,11 @@ begin
end; end;
procedure TTappyMath.CreateQuestion;
begin
end;
procedure TTappyMath.Answered; procedure TTappyMath.Answered;
var var
i: Integer; i: Integer;

View File

@ -5,11 +5,11 @@ unit mod_tappywords;
interface interface
uses uses
Classes, SysUtils, FileUtil, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
// LCL // LCL
ExtCtrls, Graphics, ExtCtrls,
// TappyTux // TappyTux
tappyconfig, tappymodules; tappyconfig, tappydrawer, tappymodules;
type type
@ -33,14 +33,14 @@ type
procedure TranslateTextsToEnglish; override; procedure TranslateTextsToEnglish; override;
procedure TranslateTextsToPortuguese; override; procedure TranslateTextsToPortuguese; override;
procedure StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer); override; procedure StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer); override;
procedure createQuestion(); override;
procedure Answered(); override; procedure Answered(); override;
procedure EndGame(); override; procedure EndGame(); override;
end; end;
implementation implementation
uses tappydrawer, gameplayform; uses gameplayform;
{ TTappyWords } { TTappyWords }
@ -48,6 +48,15 @@ procedure TTappyWords.HandleOnTimer(Sender: TObject);
var var
i: Integer; i: Integer;
begin begin
{for i:= 1 to vTappyTuxDrawer.GetAnimationCount do
begin
if vTappyTuxDrawer.GetAnimation(i).InheritsFrom(TFallingText) then
begin
vTappyTuxDrawer.GetAnimation(i).;
end;
end;}
for i:= 1 to 5 do for i:= 1 to 5 do
begin begin
Questions[i].Top := Questions[i].Top + (5*gameLevel); Questions[i].Top := Questions[i].Top + (5*gameLevel);
@ -110,7 +119,8 @@ begin
gameSLevel := gameLevel; gameSLevel := gameLevel;
gameQuestionList := TStringList.Create; gameQuestionList := TStringList.Create;
gameQuestionList.LoadFromFile(vTappyTuxConfig.GetResourcesDir()+ 'images'+PathDelim+'modules'+PathDelim+'tappywords'+PathDelim+'0.txt'); //gameQuestionList.LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images'+PathDelim+'modules'+PathDelim+'tappywords'+PathDelim+'0.txt');
//gameQuestionList.LoadFromFile('C:/Users/User/Lazarus/Arquivos/Repositorio/applications/tappytux/images/modules/tappywords/0.txt');
//gameQuestionList.LoadFromFile('C:/0.txt'); //gameQuestionList.LoadFromFile('C:/0.txt');
formTappyTuxGame.Answer.ReadOnly := false; formTappyTuxGame.Answer.ReadOnly := false;
@ -123,11 +133,11 @@ begin
for i:= 1 to 5 do for i:= 1 to 5 do
begin begin
//Questions[i].Text := formTappyTuxGame.Test.Lines.Strings[random(71)]; Questions[i].Text := formTappyTuxGame.Test.Lines.Strings[random(71)];
Questions[i].Text := gameQuestionList[random(gameQuestionList.Count - 1)]; //Questions[i].Text := gameQuestionList[random(gameQuestionList.Count - 1)];
end; end;
// Adds the Tux animation // Animations Creation
lTuxAnimation := TTappySpriteAnimation.Create; lTuxAnimation := TTappySpriteAnimation.Create;
lTuxAnimation.IsInfinite := True; lTuxAnimation.IsInfinite := True;
lTuxAnimation.StartPoint := Point(250, 300); lTuxAnimation.StartPoint := Point(250, 300);
@ -144,6 +154,74 @@ begin
lTuxAnimation.Bitmaps[4] := lTuxAnimation.Bitmaps[2]; lTuxAnimation.Bitmaps[4] := lTuxAnimation.Bitmaps[2];
lTuxAnimation.Bitmaps[5] := lTuxAnimation.Bitmaps[1]; lTuxAnimation.Bitmaps[5] := lTuxAnimation.Bitmaps[1];
vTappyTuxDrawer.AddAnimation(lTuxAnimation); vTappyTuxDrawer.AddAnimation(lTuxAnimation);
for i:= 1 to 5 do
begin
CreateQuestion();
end;
end;
procedure TTappyWords.CreateQuestion();
var
i: Integer;
xAux: Integer;
yAux: Integer;
snowmanAnimation: TFallingText;
existenceAux1, existenceAux2, existenceAux3, existenceAux4, existenceAux5: boolean;
begin
existenceAux1:= false;
existenceAux2:= false;
existenceAux3:= false;
existenceAux4:= false;
existenceAux5:= false;
xAux:=5;
yAux:=5;
snowmanAnimation := TFallingText.Create;
snowmanAnimation.IsInfinite := True;
for i:= 0 to vTappyTuxDrawer.GetAnimationCount - 1 do
begin
if vTappyTuxDrawer.GetAnimation(i).InheritsFrom(TFallingText) then
begin
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 5 then existenceAux1 := True;
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 108 then existenceAux2 := True;
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 211 then existenceAux3 := True;
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 314 then existenceAux4 := True;
if vTappyTuxDrawer.GetAnimation(i).StartPoint.x = 427 then existenceAux5 := True;
if vTappyTuxDrawer.GetAnimation(i).StartPoint.y > yAux then
begin
xAux := vTappyTuxDrawer.GetAnimation(i).StartPoint.x;
yAux := vTappyTuxDrawer.GetAnimation(i).StartPoint.y;
end;
end;
end;
if existenceAux1 = false then xAux := 5
else
begin
if existenceAux2 = false then xAux := 108
else
begin
if existenceAux3 = false then xAux := 211
else
begin
if existenceAux4 = false then xAux := 314
else
begin
if existenceAux5 = false then xAux := 427
end;
end;
end;
end;
snowmanAnimation.StartPoint := Point(xAux, 5);
snowmanAnimation.EndPoint := snowmanAnimation.StartPoint;
snowmanAnimation.Bitmap := TPortableNetworkGraphic.Create;
snowmanAnimation.Bitmap.LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'snowman.png');
vTappyTuxDrawer.AddAnimation(snowmanAnimation);
end; end;
procedure TTappyWords.Answered; procedure TTappyWords.Answered;
@ -166,9 +244,23 @@ begin
end; end;
procedure TTappyWords.EndGame; procedure TTappyWords.EndGame;
var
gameOverScreen: TTappySpriteAnimation;
continueBtn: TButton;
exitBtn: TButton;
begin begin
timerWords.Enabled := False; timerWords.Enabled := False;
formTappyTuxGame.Answer.ReadOnly := true; formTappyTuxGame.Answer.ReadOnly := true;
//gameOverScreen := TTappySpriteAnimation.Create;
//gameOverScreen.IsInfinite := True;
//gameOverScreen.StartPoint := Point(90, 150);
//gameOverScreen.EndPoint := gameOverScreen.StartPoint;
//SetLength(gameOverScreen.Bitmaps, 1);
//gameOverScreen.Bitmaps[0] := TPortableNetworkGraphic.Create;
//gameOverScreen.Bitmaps[0].LoadFromFile(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'gameover.png');
//vTappyTuxDrawer.AddAnimation(gameOverScreen);
formTappyTuxGame.GameOver.Visible := true; formTappyTuxGame.GameOver.Visible := true;
formTappyTuxGame.Yes.Visible := true; formTappyTuxGame.Yes.Visible := true;
formTappyTuxGame.No.Visible := true; formTappyTuxGame.No.Visible := true;

View File

@ -14,6 +14,7 @@ type
{ TTappyTuxAnimation } { TTappyTuxAnimation }
TTappyTuxAnimation = class TTappyTuxAnimation = class
StartPoint, EndPoint: TPoint;
CurrentStep: Integer; CurrentStep: Integer;
StepCount: Integer; StepCount: Integer;
IsInfinite: Boolean; // if True the animation will never end IsInfinite: Boolean; // if True the animation will never end
@ -27,19 +28,29 @@ type
TTappySpriteAnimation = class(TTappyTuxAnimation) TTappySpriteAnimation = class(TTappyTuxAnimation)
public public
StartPoint, EndPoint: TPoint; //StartPoint, EndPoint: TPoint; override;
Bitmaps: array of TFPImageBitmap; Bitmaps: array of TFPImageBitmap;
procedure DrawToIntfImg(AIntfImage: TLazIntfImage); override; procedure DrawToIntfImg(AIntfImage: TLazIntfImage); override;
procedure ExecuteFinal; override; procedure ExecuteFinal; override;
end; end;
{ TBallonAnimation } { TBallonAnimation
TBallonAnimation = class(TTappyTuxAnimation) TBallonAnimation = class(TTappyTuxAnimation)
public public
constructor Create; override; constructor Create; override;
procedure DrawToCanvas(ACanvas: TCanvas); override; procedure DrawToCanvas(ACanvas: TCanvas); override;
procedure ExecuteFinal; override; procedure ExecuteFinal; override;
end;}
{ TFallingText }
TFallingText = class(TTappyTuxAnimation)
public
//StartPoint, EndPoint: TPoint; override;
Bitmap: TFPImageBitmap;
Question: TCanvas;
procedure DrawToIntfImg(AIntfImage: TLazIntfImage); override;
procedure ExecuteFinal; override;
end; end;
{ TTappyTuxDrawer } { TTappyTuxDrawer }
@ -75,7 +86,7 @@ var
implementation implementation
{ TBallonAnimation } { TBallonAnimation
constructor TBallonAnimation.Create; constructor TBallonAnimation.Create;
begin begin
@ -93,7 +104,7 @@ end;
procedure TBallonAnimation.ExecuteFinal; procedure TBallonAnimation.ExecuteFinal;
begin begin
// Lost the game if the ballon reached its end // Lost the game if the ballon reached its end
end; end}
{ TTappySpriteAnimation } { TTappySpriteAnimation }
@ -121,6 +132,28 @@ begin
inherited ExecuteFinal; inherited ExecuteFinal;
end; end;
{TFallingText}
procedure TFallingText.DrawToIntfImg(AIntfImage: TLazIntfImage);
var
t: Double;
lPos: TPoint;
begin
t := CurrentStep / StepCount;
lPos.X := Round(StartPoint.X + t * (EndPoint.X - StartPoint.X));
lPos.Y := Round(StartPoint.Y + t * (EndPoint.Y - StartPoint.Y));
TTappyTuxDrawer.DrawImageWithTransparentColor(AIntfImage,
lPos.X, lPos.Y, colFuchsia, Bitmap);
end;
procedure TFallingText.ExecuteFinal;
begin
inherited ExecuteFinal;
end;
{ TTappyTuxAnimation } { TTappyTuxAnimation }
constructor TTappyTuxAnimation.Create; constructor TTappyTuxAnimation.Create;
@ -332,6 +365,8 @@ begin
begin begin
lAnimation := TTappyTuxAnimation(FAnimationList.Items[i]); lAnimation := TTappyTuxAnimation(FAnimationList.Items[i]);
Inc(lAnimation.CurrentStep); Inc(lAnimation.CurrentStep);
if lAnimation.InheritsFrom(TFallingText) then lAnimation.StartPoint.y := lAnimation.StartPoint.y + 10;
end; end;
Self.Invalidate; Self.Invalidate;

View File

@ -27,6 +27,7 @@ type
procedure TranslateTextsToPortuguese; virtual; procedure TranslateTextsToPortuguese; virtual;
procedure InitModule(); virtual; procedure InitModule(); virtual;
procedure StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer); virtual; abstract; procedure StartNewGame(SndFX: Integer; Music: Integer; Level: Integer; QuestionList: Integer); virtual; abstract;
procedure CreateQuestion(); virtual; abstract;
procedure Answered(); virtual; abstract; procedure Answered(); virtual; abstract;
procedure EndGame(); virtual; abstract; procedure EndGame(); virtual; abstract;
end; end;

View File

@ -91,7 +91,7 @@
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
<Version Value="11"/> <Version Value="10"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Target> <Target>
<Filename Value="tappytux"/> <Filename Value="tappytux"/>
@ -101,9 +101,6 @@
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<Linking> <Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
</Debugging>
<Options> <Options>
<Win32> <Win32>
<GraphicApplication Value="True"/> <GraphicApplication Value="True"/>