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