tappytux: Implements the hammer throwing
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2155 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
d5be64af68
commit
e295603a2f
@ -67,7 +67,10 @@ begin
|
||||
labelWordlist.Caption := lModule.ConfigCaption;
|
||||
listWordlist.Items.Text := lModule.ConfigItems;
|
||||
if listWordlist.Items.Count >= comboLanguage.ItemIndex then
|
||||
listWordlist.ItemIndex := comboLanguage.ItemIndex;
|
||||
begin
|
||||
if comboLanguage.ItemIndex < listWordlist.Items.Count then
|
||||
listWordlist.ItemIndex := comboLanguage.ItemIndex;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TformConfig.comboLanguageChange(Sender: TObject);
|
||||
|
@ -42,6 +42,7 @@ type
|
||||
procedure GameWon(); override;
|
||||
procedure GameLost(); override;
|
||||
procedure ProcessFallingTextEnd(); override;
|
||||
procedure ProcessSpriteEnd(AUserData: TObject; APosition: TPoint); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -260,8 +261,8 @@ procedure TTappyMath.Answered(AText: string);
|
||||
var
|
||||
i: Integer;
|
||||
j: Integer;
|
||||
snowmanRight: TFallingText;
|
||||
lAnimation: TTappyTuxAnimation;
|
||||
hammer: TTappySpriteAnimation;
|
||||
begin
|
||||
i:= 0;
|
||||
j:= vTappyTuxDrawer.GetAnimationCount - 1;
|
||||
@ -276,18 +277,23 @@ begin
|
||||
gameLevel := (gameScore div 20) + gameSLevel;
|
||||
UpdateScore(gameScore);
|
||||
UpdateLevel(gameLevel);
|
||||
snowmanRight := TFallingText.Create;
|
||||
snowmanRight.IsInfinite := False;
|
||||
snowmanRight.StartPoint := vTappyTuxDrawer.GetAnimation(i).Position;
|
||||
snowmanRight.EndPoint := vTappyTuxDrawer.GetAnimation(i).Position;
|
||||
snowmanRight.Position := vTappyTuxDrawer.GetAnimation(i).Position;
|
||||
snowmanRight.StepCount := 2000;
|
||||
snowmanRight.LoadImageFromPng(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'snowmanright.png');
|
||||
snowmanRight.caption:= 'OK!';
|
||||
snowmanRight.ProcessOnEnd := False;
|
||||
vTappyTuxDrawer.AddAnimation(snowmanRight);
|
||||
vTappyTuxDrawer.RemoveAnimation(i);
|
||||
i := i - 1;
|
||||
|
||||
lAnimation.Stopped := True;
|
||||
|
||||
hammer := TTappySpriteAnimation.Create;
|
||||
hammer.IsInfinite := False;
|
||||
hammer.StartPoint := Point(250, 328);
|
||||
hammer.EndPoint := lAnimation.Position;
|
||||
hammer.StepCount := 1000;
|
||||
hammer.SpriteChangeInterval := 200;
|
||||
SetLength(hammer.Images, 4);
|
||||
hammer.LoadImageFromPng(0, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_1.png');
|
||||
hammer.LoadImageFromPng(1, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_2.png');
|
||||
hammer.LoadImageFromPng(2, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_3.png');
|
||||
hammer.LoadImageFromPng(3, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_4.png');
|
||||
hammer.UserData := lAnimation;
|
||||
hammer.UserPosition := lAnimation.Position;
|
||||
vTappyTuxDrawer.AddAnimation(hammer);
|
||||
end;
|
||||
end;
|
||||
i := i + 1;
|
||||
@ -349,6 +355,25 @@ begin
|
||||
if gameLives <= 0 then GameLost();
|
||||
end;
|
||||
|
||||
procedure TTappyMath.ProcessSpriteEnd(AUserData: TObject; APosition: TPoint);
|
||||
var
|
||||
snowmanRight: TFallingText;
|
||||
lIndex: Integer;
|
||||
begin
|
||||
snowmanRight := TFallingText.Create;
|
||||
snowmanRight.IsInfinite := False;
|
||||
snowmanRight.StartPoint := APosition;
|
||||
snowmanRight.EndPoint := APosition;
|
||||
snowmanRight.Position := APosition;
|
||||
snowmanRight.StepCount := 2000;
|
||||
snowmanRight.LoadImageFromPng(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'snowmanright.png');
|
||||
snowmanRight.caption:= 'OK!';
|
||||
snowmanRight.ProcessOnEnd := False;
|
||||
vTappyTuxDrawer.AddAnimation(snowmanRight);
|
||||
lIndex := vTappyTuxDrawer.GetAnimationIndex(TTappyTuxAnimation(AUserData));
|
||||
if lIndex >= 0 then vTappyTuxDrawer.RemoveAnimation(lIndex);
|
||||
end;
|
||||
|
||||
initialization
|
||||
AddModule(TTappyMath.Create);
|
||||
end.
|
||||
|
@ -46,6 +46,7 @@ type
|
||||
procedure GameWon(); override;
|
||||
procedure GameLost(); override;
|
||||
procedure ProcessFallingTextEnd(); override;
|
||||
procedure ProcessSpriteEnd(AUserData: TObject; APosition: TPoint); override;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -237,7 +238,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
snowmanAnimation.StartPoint := Point(xAux, 5);
|
||||
snowmanAnimation.StartPoint := Point(xAux, -100);
|
||||
snowmanAnimation.EndPoint := Point(xAux, 270);
|
||||
snowmanAnimation.IsInfinite := false;
|
||||
snowmanAnimation.StepCount := GetFallingDurationFromLevel();
|
||||
@ -275,8 +276,8 @@ procedure TTappyWords.Answered(AText: string);
|
||||
var
|
||||
i: Integer;
|
||||
j: Integer;
|
||||
snowmanRight: TFallingText;
|
||||
lAnimation: TTappyTuxAnimation;
|
||||
hammer: TTappySpriteAnimation;
|
||||
begin
|
||||
i:= 0;
|
||||
j:= vTappyTuxDrawer.GetAnimationCount - 1;
|
||||
@ -285,25 +286,30 @@ begin
|
||||
lAnimation := vTappyTuxDrawer.GetAnimation(i);
|
||||
if lAnimation is TFallingText then
|
||||
begin
|
||||
if TFallingText(lAnimation).Caption = AText then
|
||||
begin
|
||||
gameScore := gameScore +1;
|
||||
gameLevel := (gameScore div 20) + gameSLevel;
|
||||
UpdateScore(gameScore);
|
||||
UpdateLevel(gameLevel);
|
||||
snowmanRight := TFallingText.Create;
|
||||
snowmanRight.IsInfinite := False;
|
||||
snowmanRight.StartPoint := vTappyTuxDrawer.GetAnimation(i).Position;
|
||||
snowmanRight.EndPoint := vTappyTuxDrawer.GetAnimation(i).Position;
|
||||
snowmanRight.Position := vTappyTuxDrawer.GetAnimation(i).Position;
|
||||
snowmanRight.StepCount := 2000;
|
||||
snowmanRight.LoadImageFromPng(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'snowmanright.png');
|
||||
snowmanRight.caption:= 'OK!';
|
||||
snowmanRight.ProcessOnEnd := False;
|
||||
vTappyTuxDrawer.AddAnimation(snowmanRight);
|
||||
vTappyTuxDrawer.RemoveAnimation(i);
|
||||
i := i - 1;
|
||||
end;
|
||||
if TFallingText(lAnimation).Caption = AText then
|
||||
begin
|
||||
gameScore := gameScore +1;
|
||||
gameLevel := (gameScore div 20) + gameSLevel;
|
||||
UpdateScore(gameScore);
|
||||
UpdateLevel(gameLevel);
|
||||
|
||||
lAnimation.Stopped := True;
|
||||
|
||||
hammer := TTappySpriteAnimation.Create;
|
||||
hammer.IsInfinite := False;
|
||||
hammer.StartPoint := Point(250, 328);
|
||||
hammer.EndPoint := lAnimation.Position;
|
||||
hammer.StepCount := 1000;
|
||||
hammer.SpriteChangeInterval := 200;
|
||||
SetLength(hammer.Images, 4);
|
||||
hammer.LoadImageFromPng(0, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_1.png');
|
||||
hammer.LoadImageFromPng(1, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_2.png');
|
||||
hammer.LoadImageFromPng(2, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_3.png');
|
||||
hammer.LoadImageFromPng(3, vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'hammer_4.png');
|
||||
hammer.UserData := lAnimation;
|
||||
hammer.UserPosition := lAnimation.Position;
|
||||
vTappyTuxDrawer.AddAnimation(hammer);
|
||||
end;
|
||||
end;
|
||||
i := i + 1;
|
||||
j := vTappyTuxDrawer.GetAnimationCount - 1;
|
||||
@ -365,6 +371,25 @@ begin
|
||||
if gameLives <= 0 then GameLost();
|
||||
end;
|
||||
|
||||
procedure TTappyWords.ProcessSpriteEnd(AUserData: TObject; APosition: TPoint);
|
||||
var
|
||||
snowmanRight: TFallingText;
|
||||
lIndex: Integer;
|
||||
begin
|
||||
snowmanRight := TFallingText.Create;
|
||||
snowmanRight.IsInfinite := False;
|
||||
snowmanRight.StartPoint := APosition;
|
||||
snowmanRight.EndPoint := APosition;
|
||||
snowmanRight.Position := APosition;
|
||||
snowmanRight.StepCount := 2000;
|
||||
snowmanRight.LoadImageFromPng(vTappyTuxConfig.GetResourcesDir() + 'images' + PathDelim + 'sprites' + PathDelim + 'snowmanright.png');
|
||||
snowmanRight.caption:= 'OK!';
|
||||
snowmanRight.ProcessOnEnd := False;
|
||||
vTappyTuxDrawer.AddAnimation(snowmanRight);
|
||||
lIndex := vTappyTuxDrawer.GetAnimationIndex(TTappyTuxAnimation(AUserData));
|
||||
if lIndex >= 0 then vTappyTuxDrawer.RemoveAnimation(lIndex);
|
||||
end;
|
||||
|
||||
initialization
|
||||
AddModule(TTappyWords.Create);
|
||||
end.
|
||||
|
@ -20,6 +20,10 @@ type
|
||||
CurrentStep: Integer;
|
||||
StepCount: Integer; // In miliseconds
|
||||
IsInfinite: Boolean; // if True the animation will never end
|
||||
Stopped: Boolean;
|
||||
// User data
|
||||
UserData: TObject;
|
||||
UserPosition: TPoint;
|
||||
constructor Create; virtual;
|
||||
procedure DrawToIntfImg(AIntfImage: TLazIntfImage); virtual;
|
||||
procedure DrawToCanvas(ACanvas: TCanvas); virtual;
|
||||
@ -80,6 +84,7 @@ type
|
||||
procedure HandleOnTimer(Sender: TObject);
|
||||
function AddAnimation(AAnimation: TTappyTuxAnimation): Integer;
|
||||
function GetAnimation(AIndex: Integer): TTappyTuxAnimation;
|
||||
function GetAnimationIndex(AAnimation: TTappyTuxAnimation): Integer;
|
||||
function GetAnimationCount: Integer;
|
||||
procedure RemoveAnimation(AIndex: Integer);
|
||||
procedure HandleAnimationOnTimer(AInterval: Integer);
|
||||
@ -102,8 +107,8 @@ destructor TTappySpriteAnimation.Destroy;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
{ for i := 0 to Length(Images)-1 do
|
||||
if Assigned(Images[i]) then Images[i].Free;}
|
||||
for i := 0 to Length(Images)-1 do
|
||||
if Assigned(Images[i]) then Images[i].Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -122,7 +127,7 @@ end;
|
||||
|
||||
procedure TTappySpriteAnimation.ExecuteFinal;
|
||||
begin
|
||||
|
||||
GetCurrentModule().ProcessSpriteEnd(UserData, UserPosition);
|
||||
end;
|
||||
|
||||
procedure TTappySpriteAnimation.LoadImageFromPng(AIndex: Integer; APath: string);
|
||||
@ -428,6 +433,12 @@ begin
|
||||
Result := TTappyTuxAnimation(FAnimationList.Items[AIndex]);
|
||||
end;
|
||||
|
||||
function TTappyTuxDrawer.GetAnimationIndex(AAnimation: TTappyTuxAnimation
|
||||
): Integer;
|
||||
begin
|
||||
Result := FAnimationList.IndexOf(AAnimation);
|
||||
end;
|
||||
|
||||
function TTappyTuxDrawer.GetAnimationCount: Integer;
|
||||
begin
|
||||
Result := FAnimationList.Count;
|
||||
@ -447,8 +458,9 @@ begin
|
||||
while i < FAnimationList.Count do
|
||||
begin
|
||||
lAnimation := GetAnimation(i);
|
||||
Inc(lAnimation.CurrentStep, AInterval);
|
||||
if (not lAnimation.IsInfinite) and (lAnimation.CurrentStep >= lAnimation.StepCount) then
|
||||
if (not lAnimation.Stopped) then Inc(lAnimation.CurrentStep, AInterval);
|
||||
if (not lAnimation.IsInfinite) and (lAnimation.CurrentStep >= lAnimation.StepCount)
|
||||
and (not lAnimation.Stopped) then
|
||||
begin
|
||||
lAnimation.ExecuteFinal();
|
||||
RemoveAnimation(i);
|
||||
|
@ -39,6 +39,7 @@ type
|
||||
procedure GameWon(); virtual; abstract;
|
||||
procedure GameLost(); virtual; abstract;
|
||||
procedure ProcessFallingTextEnd(); virtual; abstract;
|
||||
procedure ProcessSpriteEnd(AUserData: TObject; APosition: TPoint); virtual; abstract;
|
||||
end;
|
||||
|
||||
procedure AddModule(AModule: TTappyModule);
|
||||
|
@ -63,6 +63,7 @@
|
||||
<RequiredPackages Count="4">
|
||||
<Item1>
|
||||
<PackageName Value="fpsound_pkg"/>
|
||||
<DefaultFilename Value="..\..\components\fpsound\fpsound_pkg.lpk" Prefer="True"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LazUtils"/>
|
||||
|
Loading…
Reference in New Issue
Block a user