Debian Codegraph @

examples/platformer/code/gameinitialize.pas

raw
1 {
2 Copyright 2021-2021 Andrzej Kilijański, 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 { Game initialization.
17 This unit is cross-platform.
18 It will be used by the platform-specific program or library file. }
19 unit GameInitialize;
20
21 interface
22
23 implementation
24
25 uses SysUtils,
26 CastleApplicationProperties, CastleColors, CastleConfig, CastleControls,
27 CastleImages, CastleFilesUtils, CastleKeysMouse, CastleLog, CastleScene,
28 CastleSceneCore, CastleSoundEngine, CastleUIControls,
29 CastleVectors, CastleWindow,
30 GameSound
31 {$region 'Castle Initialization Uses'}
32 // The content here may be automatically updated by CGE editor.
33 , GameViewMenu
34 , GameViewPlay
35 , GameViewGameOver
36 , GameViewLevelComplete
37 , GameViewPause
38 , GameViewOptions
39 , GameViewCredits
40 , GameViewControlsHelp
41 {$endregion 'Castle Initialization Uses'};
42
43 var
44 Window: TCastleWindow;
45
46 { One-time initialization of resources. }
47 procedure ApplicationInitialize;
48 begin
49 { Adjust container settings for a scalable UI (adjusts to any window size in a smart way). }
50 Window.Container.LoadSettings('castle-data:/CastleSettings.xml');
51
52 { Load settings }
53 UserConfig.Load;
54
55 { Sounds initialization }
56 InitializeSounds;
57 SoundEngine.Volume := UserConfig.GetFloat('volume', 1.0);
58 SoundEngine.LoopingChannel[0].Volume := UserConfig.GetFloat('music', 1.0);
59
60 { Adjust theme }
61 Theme.TextColor := White;
62 Theme.ImagesPersistent[tiButtonNormal].Url := 'castle-data:/ui/red_button06.png';
63 Theme.ImagesPersistent[tiButtonNormal].ProtectedSides.AllSides := 6;
64 Theme.ImagesPersistent[tiButtonFocused].Url := 'castle-data:/ui/red_button08.png';
65 Theme.ImagesPersistent[tiButtonFocused].ProtectedSides.AllSides := 6;
66 Theme.ImagesPersistent[tiButtonPressed].Url := 'castle-data:/ui/red_button07.png';
67 Theme.ImagesPersistent[tiButtonPressed].ProtectedSides.AllSides := 6;
68
69 { Create views (see https://castle-engine.io/views ). }
70 {$region 'Castle View Creation'}
71 // The content here may be automatically updated by CGE editor.
72 ViewPlay := TViewPlay.Create(Application);
73 ViewMenu := TViewMenu.Create(Application);
74 ViewGameOver := TViewGameOver.Create(Application);
75 ViewLevelComplete := TViewLevelComplete.Create(Application);
76 ViewPause := TViewPause.Create(Application);
77 ViewOptions := TViewOptions.Create(Application);
78 ViewCredits := TViewCredits.Create(Application);
79 ViewControlsHelp := TViewControlsHelp.Create(Application);
80 {$endregion 'Castle View Creation'}
81
82 Window.Container.View := ViewMenu;
83 end;
84
85 initialization
86 { This initialization section configures:
87 - Application.OnInitialize
88 - Application.MainWindow
89 - determines initial window size
90
91 You should not need to do anything more in this initialization section.
92 Most of your actual application initialization (in particular, any file reading)
93 should happen inside ApplicationInitialize. }
94
95 Application.OnInitialize := @ApplicationInitialize;
96
97 Window := TCastleWindow.Create(Application);
98 Application.MainWindow := Window;
99
100 { Optionally, adjust window fullscreen state and size at this point.
101 Examples:
102
103 Run fullscreen:
104
105 Window.FullScreen := true;
106
107 Run in a 600x400 window:
108
109 Window.FullScreen := false; // default
110 Window.Width := 600;
111 Window.Height := 400;
112
113 Run in a window taking 2/3 of screen (width and height):
114
115 Window.FullScreen := false; // default
116 Window.Width := Application.ScreenWidth * 2 div 3;
117 Window.Height := Application.ScreenHeight * 2 div 3;
118
119 Note that some platforms (like mobile) ignore these window sizes.
120 }
121
122 { Handle command-line parameters like --fullscreen and --window.
123 By doing this last, you let user to override your fullscreen / mode setup. }
124 Window.ParseParameters;
125 end.