Debian Codegraph @

examples/deprecated_to_upgrade/fps_game_old_ai/code/gameviewmain.pas

raw
1 {
2 Copyright 2022-2023 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
16 { Main view handles playing the game. }
17 unit GameViewMain;
18
19 interface
20
21 uses Classes, CastleCameras,
22 CastleVectors, CastleUIControls, CastleControls, CastleKeysMouse;
23
24 type
25 TViewMain = class(TCastleView)
26 published
27 { Components designed using CGE editor.
28 These fields will be automatically initialized at Start. }
29 WalkNavigation: TCastleWalkNavigation;
30 LabelFps: TCastleLabel;
31 public
32 constructor Create(AOwner: TComponent); override;
33 procedure Start; override;
34 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
35 function Press(const Event: TInputPressRelease): Boolean; override;
36 end;
37
38 var
39 ViewMain: TViewMain;
40
41 implementation
42
43 constructor TViewMain.Create(AOwner: TComponent);
44 begin
45 inherited;
46 DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
47 end;
48
49 procedure TViewMain.Start;
50 begin
51 inherited;
52 end;
53
54 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
55 begin
56 inherited;
57 LabelFps.Caption := Container.Fps.ToString;
58 end;
59
60 function TViewMain.Press(const Event: TInputPressRelease): Boolean;
61 begin
62 Result := inherited;
63 if Result then Exit; // allow the ancestor to handle keys
64
65 if Event.IsKey(keyF4) then
66 begin
67 WalkNavigation.MouseLook := not WalkNavigation.MouseLook;
68 Exit(true);
69 end;
70 end;
71
72 end.