Debian Codegraph @

examples/physics/physics_persistent_forces_components/code/gameviewmain.pas

raw
1 {
2 Copyright 2022-2023 Michalis Kamburelis, Andrzej Kilijański.
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 { Main view, where most of the application logic takes place. }
17 unit GameViewMain;
18
19 interface
20
21 uses Classes,
22 CastleVectors, CastleComponentSerialize,
23 CastleUIControls, CastleControls, CastleKeysMouse, AddForceAtPositionBehavior,
24 AddVelocityBehavior, ForceBehavior, GravityForceBehavior, ExplosionBehavior,
25 WindForceBehavior, AddForceBehavior, ApplyImpulseBehavior, AddTorqueBehavior;
26
27 type
28 { Main view, where most of the application logic takes place. }
29 TViewMain = class(TCastleView)
30 published
31 { Components designed using CGE editor.
32 These fields will be automatically initialized at Start. }
33 LabelFps: TCastleLabel;
34 public
35 constructor Create(AOwner: TComponent); override;
36 procedure Start; override;
37 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
38 function Press(const Event: TInputPressRelease): Boolean; override;
39 end;
40
41 var
42 ViewMain: TViewMain;
43
44 implementation
45
46 uses SysUtils;
47
48 { TViewMain ----------------------------------------------------------------- }
49
50 constructor TViewMain.Create(AOwner: TComponent);
51 begin
52 inherited;
53 DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
54 end;
55
56 procedure TViewMain.Start;
57 begin
58 inherited;
59 end;
60
61 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
62 begin
63 inherited;
64 { This virtual method is executed every frame (many times per second). }
65 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
66 end;
67
68 function TViewMain.Press(const Event: TInputPressRelease): Boolean;
69 begin
70 Result := inherited;
71 if Result then Exit; // allow the ancestor to handle keys
72
73 { This virtual method is executed when user presses
74 a key, a mouse button, or touches a touch-screen.
75
76 Note that each UI control has also events like OnPress and OnClick.
77 These events can be used to handle the "press", if it should do something
78 specific when used in that UI control.
79 The TViewMain.Press method should be used to handle keys
80 not handled in children controls.
81 }
82
83 // Use this to handle keys:
84 {
85 if Event.IsKey(keyXxx) then
86 begin
87 // DoSomething;
88 Exit(true); // key was handled
89 end;
90 }
91 end;
92
93 end.