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
60 changes: 60 additions & 0 deletions code/difficultybutton.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
unit difficultybutton;

{$mode delphi}

interface

uses
// System
Classes,
// Castle
CastleUIControls, CastleControls, CastleKeysMouse, castlescene,
// Own
gameoptions;

type
TDifficultyButton = class(TCastleUserInterface)
published
ImageMarkerRight, ImageMarkerLeft: TCastleImageControl;
Tutorial, Easy, Normal, Hard, Insane: TCastleFog;
public
procedure Init(ADifficulty: NDifficulty; AButton: TCastleButton; AOnClick: TNotifyEvent);
procedure ButtonDifficultyMotion(const Sender: TCastleUserInterface; const Event: TInputMotion; var Handled: Boolean);
end;

implementation

uses
// System
SysUtils,
// Castle
CastleVectors, castleColors,
// Own
gameviewmain, Common;

procedure TDifficultyButton.Init(ADifficulty: NDifficulty; AButton: TCastleButton; AOnClick: TNotifyEvent);
begin
AButton.Caption := DifficultyName(ADifficulty);
AButton.Tag := Ord(ADifficulty);
AButton.Pressed := AButton.Caption = DifficultyName(Difficulty());
ImageMarkerLeft.Color := Vector4((AButton.Parent.FindComponent(AButton.Caption) as TCastleFog).Color, 1);
ImageMarkerRight.Color := ImageMarkerLeft.Color;
ImageMarkerRight.Exists := False;
ImageMarkerLeft.Exists := False;
AButton.OnMotion := ButtonDifficultyMotion;
AButton.OnClick := AOnClick;
end;

procedure TDifficultyButton.ButtonDifficultyMotion(const Sender: TCastleUserInterface; const Event: TInputMotion; var Handled: Boolean);
var
LButton: TCastleUserInterface;
begin
for LButton in Sender.Parent do
if (LButton is TCastleButton) and (LButton.ControlsCount > 0) then
begin
LButton.Controls[0].Exists := Sender = LButton;
LButton.Controls[1].Exists := Sender = LButton;
end;
end;

end.
16 changes: 7 additions & 9 deletions code/gameentities.pas
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ TTower = class(TComponent)
TMap = class(TComponent)
private
FTowers: TObjectList<TTower>;
FDifficulty: NDifficulty;
FDifficulty: Integer;
FLastTower, FLastStock, FHeroTowerIndex, FHeroStockIndex, FTargetTower, FTargetStock: Integer;
FHero: THero;
FHeroRoom: TRoom;
Expand Down Expand Up @@ -141,10 +141,8 @@ TMap = class(TComponent)
end;

const
GameSeconds: array[NDifficulty] of Integer = (240, 360, 480, 600);
GameSeconds: array[NDifficulty] of Integer = (0, 240, 360, 480, 600);
WeaponToOperation: array[NHeroWeapon] of string = ('', '+', '-', '*');
WeaponFileNames: array[Succ(Low(NHeroWeapon))..High(NHeroWeapon)] of string =
('weapon-shuriken.png', 'weapon-kunai.png', 'weapon-star.png');

implementation

Expand Down Expand Up @@ -267,8 +265,8 @@ constructor TMap.Create(AOwner: TComponent);
FMap := Self;
FHero := THero.Create(nil);
FTowers := TObjectList<TTower>.Create(True);
FDifficulty := Difficulty();
FLastTower := IIF(IsSchool(), 2, 3 + Ord(FDifficulty));
FDifficulty := Ord(Difficulty()) - 1;
FLastTower := IIF(IsSchool(), 2, 3 + FDifficulty);
FLastStock := Min(LastTower + 3, 8);
FBoss := TBoss.Create(nil, LastTower, FLastStock);
for T := 1 to LastTower do
Expand Down Expand Up @@ -419,7 +417,7 @@ function TMap.Score(ATimeLeft: Integer): Integer;

function TMap.BossCap(): Integer;
begin
Result := FBoss.Level * 95 div 100 - (Random(5) + 5) * (Ord(Difficulty) + 1)
Result := FBoss.Level * 95 div 100 - (Random(5) + 5) * (FDifficulty + 1)
end;

constructor TEnemy.Create(AOwner: TComponent; ATower, AStock: Integer);
Expand Down Expand Up @@ -447,7 +445,7 @@ constructor TWeaponLoot.Create(AOwner: TComponent; AWeapon: NHeroWeapon);
begin
inherited Create(AOwner);
FWeapon := AWeapon;
FAssetId := 'castle-data:/resources/' + WeaponFileNames[AWeapon];
FAssetId := Images.WeaponUrl(Ord(AWeapon));
end;

function TWeaponLoot.GetVisual(): string;
Expand Down Expand Up @@ -506,7 +504,7 @@ function TBoss.CalcLevel(ATower, AStock: Integer): Integer;
begin
if IsSchool() then
Exit(SchoolBossLevel);
case Difficulty of
case Difficulty() of
gdEasy: Result := 444;
gdNormal: Result := 1000 + Random(5) * 100 + 40 + ValueOrZero(4);
gdHard: Result := 2400 + Random(5) * 10 + ValueOrZero(4);
Expand Down
2 changes: 1 addition & 1 deletion code/gameoptions.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface
uses Classes, generics.collections;

type
NDifficulty = (gdEasy, gdNormal, gdHard, gdInsane);
NDifficulty = (gdTutorial, gdEasy, gdNormal, gdHard, gdInsane);

/// <summary>
/// Current Difficulty, default is Easy
Expand Down
4 changes: 3 additions & 1 deletion code/gameviewdefeat.pas
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ procedure TViewDefeat.ButtonMenuClick(Sender: TObject);

procedure TViewDefeat.BackToMenu();
begin
{
if IsSchool() then
Container.View := ViewCredits
else
}
Container.View := ViewMain;
end;

Expand All @@ -67,7 +69,7 @@ function TViewDefeat.Press(const Event: TInputPressRelease): Boolean;
if Event.IsKey(keyEscape) or Event.IsKey(keyEnter) or Event.IsKey(keyBackSpace) then
begin
BackToMenu();
Exit(true); // key was handled
Exit(True); // key was handled
end;
end;

Expand Down
4 changes: 2 additions & 2 deletions code/gameviewformula.pas
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ implementation
// Castle
castlewindow, castlelog, castleglimages, castlecolors,
// Own
gameviewgame, Common;
gameviewgame, Common, imagescomponent;

constructor TViewFormula.Create(AOwner: TComponent);
begin
Expand Down Expand Up @@ -86,7 +86,7 @@ procedure TViewFormula.Resume;
if AMarked then
begin
LButton.ImageScale := 0.2;
LButton.Image.Url := 'castle-data:/resources/' + WeaponFileNames[Weapon];
LButton.Image.Url := Images.WeaponUrl(Ord(Weapon));
end
else
begin
Expand Down
6 changes: 3 additions & 3 deletions code/gameviewgame.pas
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ procedure TViewGame.Start();
begin
LRoomComponent := TRoomComponent.Create(LGroupTower);
LRoomUI := FactoryRoom.ComponentLoad(LGroupTower, LRoomComponent) as TCastleUserInterface;
LRoomComponent.InsertFront(LRoomUI);
LRoomComponent.InsertFront(LRoomUI);
LRoomComponent.Name := 'Room' + LTowerIndex.ToString + '_' + LStockIndex.ToString;
LGroupTower.InsertFront(LRoomComponent);
LRoomComponent.ControlRoom.OnClick := ButtonRoomClick;
Expand Down Expand Up @@ -304,7 +304,7 @@ procedure TViewGame.ButtonDefeatClick(Sender: TObject);
procedure TViewGame.DefeatQuestionYes(Sender: TObject);
begin
if IsSchool() then
Container.View := ViewCredits
Container.View := ViewMain
else
Container.View := ViewDefeat;
end;
Expand Down Expand Up @@ -551,7 +551,7 @@ procedure TViewGame.TimerBloodTick(ASender: TObject);
if Map.Hero.Dead then
begin
if IsSchool() then
DialogYesNo(Container, 'You lost, you''d better|follow the guide|try shool again ?', SchoolDefeatYes, SchoolDefeatNo)
DialogYesNo(Container, 'You lost, you''d better|follow the guide|try tutorial again ?', SchoolDefeatYes, SchoolDefeatNo)
else
Container.View := ViewDefeat
end
Expand Down
21 changes: 8 additions & 13 deletions code/gameviewleaders.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ implementation
// Castle
castlewindow, castlelog,
// Own
gameoptions, castlerest, gameviewmain
gameoptions, castlerest, gameviewmain, difficultybutton
;

constructor TViewLeaders.Create(AOwner: TComponent);
Expand All @@ -69,22 +69,19 @@ procedure TViewLeaders.Start;
var
LDifficulty: NDifficulty;
LButton: TCastleButton;
LCurrentDifficultyName: string;
LDifficultyButton: TDifficultyButton;
begin
inherited;
ButtonMenu.OnClick := ButtonMenuClick;
ButtonSync.OnClick := ButtonSyncClick;
LCurrentDifficultyName := DifficultyName(Difficulty());
for LDifficulty in NDifficulty do
for LDifficulty := Succ(Low(NDifficulty)) to High(NDifficulty) do
begin
LButton := FactoryButton.ComponentLoad(GroupDifficulty) as TCastleButton;
LButton.Caption := DifficultyName(LDifficulty);
LButton.Pressed := LButton.Caption = LCurrentDifficultyName;
LDifficultyButton := TDifficultyButton.Create(GroupDifficulty);
LButton := FactoryButton.ComponentLoad(GroupDifficulty, LDifficultyButton) as TCastleButton;
GroupDifficulty.InsertFront(LButton);
LDIfficultyButton.Init(LDifficulty, LButton, ButtonDifficultyClick);
if LButton.Pressed then
FCurrentDifficultyButton := LButton;
LButton.Tag := Ord(LDifficulty);
LButton.OnClick := ButtonDifficultyClick;
GroupDifficulty.InsertFront(LButton);
end;
GroupLeaders.ClearControls();
end;
Expand Down Expand Up @@ -137,7 +134,6 @@ procedure TViewLeaders.ButtonDifficultyClick(Sender: TObject);
procedure TViewLeaders.SwitchDifficulty(AButton: TCastleButton);
var
LButton: TCastleUserInterface;
LDifficulty: NDifficulty;
LLeader: TLeader;
LLabel: TCastleLabel;
begin
Expand All @@ -148,9 +144,8 @@ procedure TViewLeaders.SwitchDifficulty(AButton: TCastleButton);

// populate the list of leaders for the selected difficulty.
GroupLeaders.ClearControls();
LDifficulty := NDifficulty(FCurrentDifficultyButton.Tag);
for LLeader in FLeaders do
if LLeader.Difficulty = Ord(LDifficulty) then
if LLeader.Difficulty = Ord(NDifficulty(FCurrentDifficultyButton.Tag)) - 1 then
begin
LLabel := TCastleLabel.Create(GroupLeaders);
LLabel.Caption := Format('%d %d %s', [LLeader.Number, LLeader.Score, LLeader.Name]);
Expand Down
Loading