Debian Codegraph @

examples/physics/physics_simple_3d_bullet/code/gameviewplay.pas

raw
1 {
2 Copyright 2022-2022 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 "playing game" view, where most of the game logic takes place. }
17 unit GameViewPlay;
18
19 interface
20
21 uses Classes,
22 CastleComponentSerialize, CastleUIControls, CastleControls,
23 CastleKeysMouse, CastleViewport, CastleScene, CastleVectors, CastleCameras,
24 CastleTransform;
25
26 type
27 { Main "playing game" view, where most of the game logic takes place. }
28 TViewPlay = class(TCastleView)
29 published
30 { Components designed using CGE editor, loaded from gameviewplay.castle-user-interface. }
31 LabelFps: TCastleLabel;
32 MainViewport: TCastleViewport;
33 Sphere: TCastleTransform;
34 BulletBody: TCastleRigidBody;
35 WalkNavigation: TCastleWalkNavigation;
36 public
37 constructor Create(AOwner: TComponent); override;
38 procedure Start; override;
39 procedure Stop; override;
40 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
41 function Press(const Event: TInputPressRelease): Boolean; override;
42 end;
43
44 var
45 ViewPlay: TViewPlay;
46
47 implementation
48
49 uses SysUtils, Math,
50 CastleSoundEngine, CastleLog, CastleStringUtils, CastleFilesUtils,
51 GameViewMenu;
52
53 { TViewPlay ----------------------------------------------------------------- }
54
55 constructor TViewPlay.Create(AOwner: TComponent);
56 begin
57 inherited;
58 DesignUrl := 'castle-data:/gameviewplay.castle-user-interface';
59 end;
60
61 procedure TViewPlay.Start;
62 begin
63 inherited;
64 end;
65
66 procedure TViewPlay.Stop;
67 begin
68 inherited;
69 end;
70
71 procedure TViewPlay.Update(const SecondsPassed: Single; var HandleInput: Boolean);
72 begin
73 inherited;
74 { This virtual method is executed every frame (many times per second). }
75 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
76 end;
77
78 function TViewPlay.Press(const Event: TInputPressRelease): Boolean;
79 begin
80 Result := inherited;
81 if Result then Exit; // allow the ancestor to handle keys
82
83 if Event.IsMouseButton(buttonRight) then
84 begin
85 WalkNavigation.MouseLook := not WalkNavigation.MouseLook;
86 Exit(true);
87 end;
88
89 if Event.IsKey(keyEnter) then
90 begin
91 Sphere.Translation := Vector3(0, 2.17, -5.51);
92 BulletBody.ApplyImpulse(Vector3(0,0,100), Vector3(0,0,0));
93 Exit(true);
94 end;
95
96 if Event.IsKey(keyEscape) then
97 begin
98 Container.View := ViewMenu;
99 Exit(true);
100 end;
101 end;
102
103 end.