Debian Codegraph @

examples/audio/doppler_demo/code/gameviewmain.pas

raw
1 {
2 Copyright 2021-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, where most of the application logic takes place. }
17 unit GameViewMain;
18
19 interface
20
21 uses Classes,
22 CastleComponentSerialize, CastleUIControls, CastleControls,
23 CastleKeysMouse, CastleViewport, CastleTransform;
24
25 type
26 { Main view, where most of the application logic takes place. }
27 TViewMain = class(TCastleView)
28 published
29 { Components designed using CGE editor.
30 These fields will be automatically initialized at Start. }
31 LabelFps: TCastleLabel;
32 Viewport: TCastleViewport;
33 PlaneSoundSource: TCastleTransform;
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 function Motion(const Event: TInputMotion): 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 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
67 end;
68
69 function TViewMain.Press(const Event: TInputPressRelease): Boolean;
70 begin
71 Result := inherited;
72 if Result then Exit; // allow the ancestor to handle keys
73
74 if Event.IsMouseButton(buttonLeft) then
75 begin
76 PlaneSoundSource.TranslationXY := Viewport.PositionTo2DWorld(Event.Position, true);
77 Exit(true);
78 end;
79 end;
80
81 function TViewMain.Motion(const Event: TInputMotion): Boolean;
82 begin
83 Result := inherited;
84 if Result then Exit; // allow the ancestor to handle event
85
86 if buttonLeft in Event.Pressed then
87 begin
88 PlaneSoundSource.TranslationXY := Viewport.PositionTo2DWorld(Event.Position, true);
89 Exit(true);
90 end;
91 end;
92
93 end.