Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CastleEngineManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ See https://castle-engine.io/project_manifest for documentation of this file.
<service name="keyboard" />
</services>
</android>
<!--Exclusion for WEB until music is supported-->
<!--<package><exclude path="data/music/*" /></package>-->
</project>
56 changes: 50 additions & 6 deletions code/gameviewcredits.pas
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
unit GameViewCredits;

{$mode delphi}

interface

uses
Expand All @@ -11,15 +13,21 @@ interface
type
TViewCredits = class(TCastleView)
published
ButtonMenu, ButtonCastle, ButtonAuthor: TCastleButton;
ButtonMenu, ButtonCredits, ButtonRules, ButtonKeys, ButtonWeapon,
ButtonCastle, ButtonAuthor, ButtonItch, ButtonDiscord, ButtonWeb: TCastleButton;
GroupCredits, GroupRules, GroupKeys, GroupWeapon: TCastleUserInterface;
public
constructor Create(AOwner: TComponent); override;
procedure Start; override;
function Press(const Event: TInputPressRelease): Boolean; override;
private
procedure ButtonMenuClick(Sender: TObject);
procedure ButtonPanelClick(Sender: TObject);
procedure ButtonCastleClick(Sender: TObject);
procedure ButtonAuthorClick(Sender: TObject);
procedure ButtonItchClick(Sender: TObject);
procedure ButtonDiscordClick(Sender: TObject);
procedure ButtonWebClick(Sender: TObject);
end;

var
Expand All @@ -31,7 +39,7 @@ implementation
// System
SysUtils,
// Castle
castlewindow, CastleOpenDocument,
castlewindow, CastleOpenDocument, CastleApplicationProperties,
// Own
gameviewmain;

Expand All @@ -44,9 +52,18 @@ constructor TViewCredits.Create(AOwner: TComponent);
procedure TViewCredits.Start;
begin
inherited;
ButtonMenu.OnClick := @ButtonMenuClick;
ButtonCastle.OnClick := @ButtonCastleClick;
ButtonAuthor.OnClick := @ButtonAuthorClick;
ButtonMenu.OnClick := ButtonMenuClick;
ButtonCredits.OnClick := ButtonPanelClick;
ButtonRules.OnClick := ButtonPanelClick;
ButtonKeys.OnClick := ButtonPanelClick;
ButtonWeapon.OnClick := ButtonPanelClick;
ButtonCastle.OnClick := ButtonCastleClick;
ButtonAuthor.OnClick := ButtonAuthorClick;
ButtonItch.OnClick := ButtonItchClick;
ButtonDiscord.OnClick := ButtonDiscordClick;
ButtonWeb.OnClick := ButtonWebClick;

ButtonKeys.Exists := ApplicationProperties.ShowUserInterfaceToQuit {$IFDEF WASI} or True {$ENDIF};
end;

function TViewCredits.Press(const Event: TInputPressRelease): Boolean;
Expand Down Expand Up @@ -74,6 +91,33 @@ procedure TViewCredits.ButtonCastleClick(Sender: TObject);
procedure TViewCredits.ButtonAuthorClick(Sender: TObject);
begin
OpenURL('https://github.com/phomm/Towerfight');
end;
end;

procedure TViewCredits.ButtonItchClick(Sender: TObject);
begin
OpenURL('https://phomm.itch.io/tower-fight');
end;

procedure TViewCredits.ButtonDiscordClick(Sender: TObject);
begin
OpenURL('https://discord.gg/fz7bbM3dr3');
end;

procedure TViewCredits.ButtonWebClick(Sender: TObject);
begin
OpenURL('https://ephyre.ru');
end;

procedure TViewCredits.ButtonPanelClick(Sender: TObject);
begin
GroupCredits.Exists := Sender = ButtonCredits;
GroupRules.Exists := Sender = ButtonRules;
GroupKeys.Exists := Sender = ButtonKeys;
GroupWeapon.Exists := Sender = ButtonWeapon;
ButtonCredits.Pressed := Sender = ButtonCredits;
ButtonRules.Pressed := Sender = ButtonRules;
ButtonKeys.Pressed := Sender = ButtonKeys;
ButtonWeapon.Pressed := Sender = ButtonWeapon;
end;

end.
6 changes: 5 additions & 1 deletion code/gameviewformula.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ TViewFormula = class(TCastleView)
These fields will be automatically initialized at Start. }
ButtonGo: TCastleButton;
GroupElements: TCastleHorizontalGroup;
ImageEnemy: TCastleImageControl;
LabelHeroLevel: TCastleLabel;
public
RoomComponent: TRoomComponent;
constructor Create(AOwner: TComponent); override;
Expand Down Expand Up @@ -83,7 +85,7 @@ procedure TViewFormula.Resume;
if AMarked then
begin
LButton.ImageScale := 0.2;
LButton.Image.Url := 'castle-data:/resources/' + WeaponFileNames[Weapon];
LButton.Image.Url := 'castle-data:/resources/' + WeaponFileNames[Weapon];
end
else
begin
Expand All @@ -102,6 +104,8 @@ procedure TViewFormula.Resume;
inherited;
Weapon := TMap.Map.Hero.Weapon;
LActor := TMap.Map.GetRoomByIndex(RoomComponent.Tag).Actors[0];
ImageEnemy.Url := LActor.AssetId;
LabelHeroLevel.Caption := TMap.Map.Hero.Visual;
Formula := LActor.Visual;
GroupElements.ClearControls();
SetLength(FPositions, Length(Formula) + 1);
Expand Down
49 changes: 22 additions & 27 deletions code/gameviewgame.pas
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TViewGame = class(TCastleView)
BloodSplash0, BloodSplash1, BloodSplash2: TCastleScene;
Viewport1: TCastleViewport;
ImageWeapon: TCastleImageControl;
TimerGame, TimerHint: TCastleTimer;
TimerBlood, TimerGame, TimerHint: TCastleTimer;
function GetMap(): TMap;
property Map: TMap read GetMap;
protected
Expand All @@ -46,15 +46,14 @@ TViewGame = class(TCastleView)
FPosFrom, FPosTo: TVector2;
FAnimateWeaponTicks, FGameTicks: Integer;
FRoomFight: TRoomComponent;
FBloodTime: Single;
procedure ButtonDefeatClick(Sender: TObject);
procedure ButtonRoomClick(Sender: TObject);
procedure ButtonWeaponClick(Sender: TObject);
procedure RunAnimation(AScene: TCastleScene; ARoom: TCastleUserInterface);
procedure AnimationStopped(const AScene: TCastleSceneCore; const ATimeSensorNode: TTimeSensorNode);
function RandomBloodSplash(): TCastleScene;
procedure DefeatQuestionYes(Sender: TObject);
procedure TimerBloodTrigger();
procedure TimerBloodTick(ASender: TObject);
procedure TimerGameTick(ASender: TObject);
procedure TimerHintTick(ASender: TObject);
procedure WeaponHint(ADoShow: Boolean; AWeapon: NHeroWeapon = hwNo);
Expand Down Expand Up @@ -148,7 +147,9 @@ procedure TViewGame.Start();
FWeapons[1] := WeaponPlus;
FWeapons[2] := WeaponMinus;
FWeapons[3] := WeaponMultiply;
WeaponNo.DoClick();
WeaponNo.DoClick();
TimerBlood.Exists := False;
TimerBlood.OnTimer := TimerBloodTick;
TimerHint.OnTimer := TimerHintTick;
TimerGame.OnTimer := TimerGameTick;
TimerGame.IntervalSeconds := 1;
Expand Down Expand Up @@ -208,7 +209,7 @@ procedure TViewGame.ButtonWeaponClick(Sender: TObject);
LWeaponButton := Sender as TCastleButton;
for i := 0 to High(FWeapons) do
begin
LIsWeapon := FWeapons[i] = LWeaponButton;
LIsWeapon := FWeapons[i] = LWeaponButton;
if LIsWeapon then
begin
if not FInternalWeaponSwitch then
Expand Down Expand Up @@ -237,7 +238,8 @@ procedure TViewGame.Stop();
begin
inherited;
TMap.Die();
FPreviousRoom := nil;
FPreviousRoom := nil;
FPause := True;
end;

procedure TViewGame.ButtonDefeatClick(Sender: TObject);
Expand Down Expand Up @@ -268,20 +270,11 @@ procedure TViewGame.Update(const SecondsPassed: Single; var HandleInput: boolean
begin
ImageWeapon.Url := '';
WeaponClick(hwNo);
end;
end;
end;
if not FPause and (Map.Hero.Weapon <> hwNo) then
with FPreviousRoom.ImageHeroWeapon do
Rotation := Rotation + 4 * SecondsPassed;
if not FPause and (FBloodTime > 0) then
begin
FBloodTime := FBloodTime - SecondsPassed;
if FBloodTime <= 0 then
begin
TimerBloodTrigger();
FBloodTime := 0;
end;
end;
end;

function TViewGame.Press(const Event: TInputPressRelease): Boolean;
Expand All @@ -306,7 +299,7 @@ function TViewGame.Press(const Event: TInputPressRelease): Boolean;
if Result then Exit; // allow the ancestor to handle keys
if FPause then Exit;

if Event.IsKey(keyEscape) or Event.IsKey(keyBackSpace) then
if Event.IsKey(keyEscape) or Event.IsKey(keyBackSpace) or Event.IsKey(keyEnter) then
begin
ButtonDefeat.DoClick();
Exit(True); // key was handled
Expand All @@ -317,20 +310,20 @@ function TViewGame.Press(const Event: TInputPressRelease): Boolean;
W := Ord(Map.Hero.Weapon);
repeat
W := (W + 1) mod Length(FWeapons);
until FWeapons[W].Enabled;
WeaponClick(NHeroWeapon(W), True);
until FWeapons[W].Enabled;
WeaponClick(NHeroWeapon(W), True);
Exit(True); // key was handled
end;

if Event.Key in [key1, key2, key3, key4] then
begin
WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(key1)), True);
WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(key1)), True);
Exit(True); // key was handled
end;

if Event.Key in [keyNumpad1, keyNumpad2, keyNumpad3, keyNumpad4] then
begin
WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(keyNumpad1)), True);
WeaponClick(NHeroWeapon(Ord(Event.Key) - Ord(keyNumpad1)), True);
Exit(True); // key was handled
end;

Expand Down Expand Up @@ -366,11 +359,11 @@ procedure TViewGame.ButtonRoomClick(Sender: TObject);
begin
FPreviousRoom.LabelLeft.Caption := '';
FPreviousRoom.ImageLeft.Url := '';
FPreviousRoom.ImageHeroWeapon.Url := '';
FPreviousRoom.ImageHeroWeapon.Url := '';
end;

// Show image on currently clicked button
FPreviousRoom := LRoom;
FPreviousRoom := LRoom;
LRoom.ImageLeft.Url := Map.Hero.AssetId;
LRoom.LabelLeft.Caption := Map.Hero.Visual;
SwitchHeroWeaponImage();
Expand Down Expand Up @@ -411,7 +404,7 @@ procedure TViewGame.RoomFight(ARoom: TRoomComponent);

SwitchHeroWeaponImage(True);
FSkip := True;
FBloodTime := 1;
TimerBlood.Exists := True;
FRoomFight := ARoom;
end;

Expand All @@ -422,7 +415,7 @@ function TViewGame.RandomBloodSplash(): TCastleScene;
1: Result := BloodSplash1;
2: Result := BloodSplash2;
end;
end;
end;

procedure TViewGame.RunAnimation(AScene: TCastleScene; ARoom: TCastleUserInterface);
var
Expand All @@ -446,10 +439,12 @@ procedure TViewGame.AnimationStopped(const AScene: TCastleSceneCore; const ATime
AScene.Exists := False;
end;

procedure TViewGame.TimerBloodTrigger();
procedure TViewGame.TimerBloodTick(ASender: TObject);
var
LWeapon: NHeroWeapon;
begin
TimerBlood.Exists := False;

if Map.Hero.Dead then
Container.View := ViewDefeat
else
Expand Down Expand Up @@ -479,7 +474,7 @@ procedure TViewGame.TimerBloodTrigger();
Container.View := ViewWin;
end;
end;
FSkip := False;
FSkip := False;
end;

procedure TViewGame.TimerHintTick(ASender: TObject);
Expand Down
3 changes: 2 additions & 1 deletion code/gameviewmain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TViewMain = class(TCastleView)
GroupOptions: TCastleUserInterface;
SliderMusic, SliderFullscreen, SliderUseTimer: TCastleIntegerSlider;
FactoryButton: TCastleComponentFactory;
ImageRoomRoof3: TCastleImageControl;
ImageRoomRoof2, ImageRoomRoof3: TCastleImageControl;
public
constructor Create(AOwner: TComponent); override;
procedure Start(); override;
Expand Down Expand Up @@ -92,6 +92,7 @@ procedure TViewMain.Start();
ButtonExit.Exists := ApplicationProperties.ShowUserInterfaceToQuit;
ImageRoomRoof3.Exists := ApplicationProperties.ShowUserInterfaceToQuit;
SliderFullScreen.Exists := ApplicationProperties.ShowUserInterfaceToQuit;

for LButton in Buttons do
LButton.OnMotion := ButtonMotion;

Expand Down
1 change: 1 addition & 0 deletions code/gameviewwin.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TViewWin = class(TCastleView)
LabelScore: TCastleLabel;
EditName: TCastleEdit;
PanelNotifications: TCastleNotifications;
ImageControl1: TCastleImageControl;
public
Score: Integer;
constructor Create(AOwner: TComponent); override;
Expand Down
1 change: 1 addition & 0 deletions code/models.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ procedure TSubmitLeader.CalcHash();
begin
FHash := Format(HashTemplate, [Difficulty, IIF(Guid = '', '', ':Guid='+ Guid), Name, Salt, Score]);
//WriteLnLog('ForHash ' + FHash);
// TODO : remove this when WEB platform supports http requests
FHash := TSHA2_256.Create().ComputeString(FHash, TEncoding.UTF8).ToString();
end;

Expand Down
Loading