| 1 |
{ |
| 2 |
Copyright 2023-2023 Michalis Kamburelis, Andrzej Kilijanski |
| 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 |
{ |
| 16 |
For this example, run the project in the editor and test |
| 17 |
different settings for the Items.PhysicsProperties.LayerCollisions. |
| 18 |
The sources don't contain any interesting code about physics layers. |
| 19 |
} |
| 20 |
unit GameViewMain; |
| 21 |
|
| 22 |
interface |
| 23 |
|
| 24 |
uses Classes, |
| 25 |
CastleVectors, CastleComponentSerialize, |
| 26 |
CastleUIControls, CastleControls, CastleKeysMouse; |
| 27 |
|
| 28 |
type |
| 29 |
{ Main view, where most of the application logic takes place. } |
| 30 |
TViewMain = class(TCastleView) |
| 31 |
published |
| 32 |
{ Components designed using CGE editor. |
| 33 |
These fields will be automatically initialized at Start. } |
| 34 |
LabelFps: TCastleLabel; |
| 35 |
public |
| 36 |
constructor Create(AOwner: TComponent); override; |
| 37 |
procedure Start; override; |
| 38 |
procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override; |
| 39 |
function Press(const Event: TInputPressRelease): 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 |
end; |
| 61 |
|
| 62 |
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean); |
| 63 |
begin |
| 64 |
inherited; |
| 65 |
{ This virtual method is executed every frame (many times per second). } |
| 66 |
Assert(LabelFps <> nil, 'If you remove LabelFps from the design, remember to remove also the assignment "LabelFps.Caption := ..." from code'); |
| 67 |
LabelFps.Caption := 'FPS: ' + Container.Fps.ToString; |
| 68 |
end; |
| 69 |
|
| 70 |
function TViewMain.Press(const Event: TInputPressRelease): Boolean; |
| 71 |
begin |
| 72 |
Result := inherited; |
| 73 |
if Result then Exit; // allow the ancestor to handle keys |
| 74 |
end; |
| 75 |
|
| 76 |
end. |