| 1 |
{ |
| 2 |
Copyright 2022-2022 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
{ Main view, where most of the application logic takes place. } |
| 16 |
unit GameViewMain; |
| 17 |
|
| 18 |
interface |
| 19 |
|
| 20 |
uses Classes, |
| 21 |
CastleVectors, CastleComponentSerialize, |
| 22 |
CastleUIControls, CastleControls, CastleKeysMouse, CastleTransform; |
| 23 |
|
| 24 |
type |
| 25 |
{ Main view, where most of the application logic takes place. } |
| 26 |
TViewMain = class(TCastleView) |
| 27 |
published |
| 28 |
{ Components designed using CGE editor. |
| 29 |
These fields will be automatically initialized at Start. } |
| 30 |
LabelFps: TCastleLabel; |
| 31 |
ButtonRotateCameraHorizontally: TCastleButton; |
| 32 |
CameraHorizontalRotation: TCastleTransform; |
| 33 |
private |
| 34 |
CameraRot: Integer; |
| 35 |
procedure ClickRotateCameraHorizontally(Sender: TObject); |
| 36 |
public |
| 37 |
constructor Create(AOwner: TComponent); override; |
| 38 |
procedure Start; override; |
| 39 |
procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override; |
| 40 |
end; |
| 41 |
|
| 42 |
var |
| 43 |
ViewMain: TViewMain; |
| 44 |
|
| 45 |
implementation |
| 46 |
|
| 47 |
uses SysUtils; |
| 48 |
|
| 49 |
{ TViewMain ----------------------------------------------------------------- } |
| 50 |
|
| 51 |
constructor TViewMain.Create(AOwner: TComponent); |
| 52 |
begin |
| 53 |
inherited; |
| 54 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 55 |
end; |
| 56 |
|
| 57 |
procedure TViewMain.Start; |
| 58 |
begin |
| 59 |
inherited; |
| 60 |
CameraRot := 0; |
| 61 |
ButtonRotateCameraHorizontally.OnClick := {$ifdef FPC}@{$endif} ClickRotateCameraHorizontally; |
| 62 |
end; |
| 63 |
|
| 64 |
procedure TViewMain.ClickRotateCameraHorizontally(Sender: TObject); |
| 65 |
begin |
| 66 |
CameraRot := (CameraRot + 1) mod 4; |
| 67 |
CameraHorizontalRotation.Rotation := Vector4(0, 1, 0, Pi / 4 + Pi / 2 * CameraRot); |
| 68 |
end; |
| 69 |
|
| 70 |
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean); |
| 71 |
begin |
| 72 |
inherited; |
| 73 |
{ This virtual method is executed every frame (many times per second). } |
| 74 |
Assert(LabelFps <> nil, 'If you remove LabelFps from the design, remember to remove also the assignment "LabelFps.Caption := ..." from code'); |
| 75 |
LabelFps.Caption := 'FPS: ' + Container.Fps.ToString; |
| 76 |
end; |
| 77 |
|
| 78 |
end. |