-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgamegeneral.pas
148 lines (110 loc) · 4.7 KB
/
gamegeneral.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
{
Copyright 2003-2017 Michalis Kamburelis.
This file is part of "malfunction".
"malfunction" is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"malfunction" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with "malfunction"; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
----------------------------------------------------------------------------
}
unit GameGeneral;
{ some general things, consts and funcs for "Malfunction" game.
Ten modul NIE MOZE zalezec od jakiegokolwiek modulu ktory odwoluje
sie do obiektu glw w swoim initialization (np. aby zrobic
Window.OnInitList.Add()). To dlatego ze glw jest tworzony w
initialization niniejszego modulu i jezeli tamten modul bedzie zalezal
od GameGeneral a GameGeneral od niego to nie jest pewne ktore
initialization zostanie wykonane jako pierwsze - a przeciez
obiekt glw musi byc utworzony zanim sie do niego odwolasz.
}
interface
uses SysUtils, CastleWindow, CastleNotifications;
const
Version = '1.3.0';
DisplayApplicationName = 'malfunction';
var
{ Whole program uses this window.
This is created and destroyed in init/fini of this module. }
Window: TCastleWindowCustom;
{ Game modes.
At every time, the program is in some "mode".
Each mode has a specific callbacks to control
window, each mode can also init some OpenGL state for itself.
Events OnOpen, OnClose, OnCloseQuery are defined in this unit
and cannot be redefined by modes. Other events are initialized to nil
before calling GameModeEnter (so you don't have to set them to nil
in every gameModeExit), and every gameModeEnter[] can set them
to some mode-specific callbacks.
As for OnResize : RasizeAllowed = raOnlyAtOpen. So we don't have to do
anything in OnResize. So we register no OnResize callback.
@bold(Every mode must) define some projection inside modeEnter.
modeNone is a very specific mode : this is the initial mode
when program starts. Never do SetGameMode(modeNone).
You should terminate any TCastleWindowCustom event handling after SetGameMode call. }
type
TGameMode = (modeNone, modeMenu, modeGame);
function GameMode: TGameMode;
procedure SetGameMode(value: TGameMode);
var
{ gameModeEnter i Exit - inicjowana w initialization odpowiednich modulow
mode*Unit, wszedzie indziej readonly. W czasie dzialania tych procedur
GameMode bedzie ciagle rowne staremu mode'owi. }
gameModeEnter, gameModeExit: array[TGameMode]of TProcedure;
{ ----------------------------------------------------------------------------
zainicjowane w niszczone w tym module. Wyswietlane i Update'owane w ModeGameUnit.
Moze byc uzywane z kazdego miejsca. }
var
Notifications: TCastleNotifications;
implementation
uses CastleGLUtils, CastleUtils, CastleMessages, CastleProgress,
CastleWindowProgress, CastleFonts, CastleRectangles, CastleColors;
var fGameMode: TGameMode = modeNone;
function GameMode: TGameMode;
begin result := fGameMode end;
procedure SetGameMode(value: TGameMode);
begin
Check(value <> modeNone, 'Can''t SetGameMode to modeNone');
if gameModeExit[fGameMode] <> nil then gameModeExit[fGameMode];
Window.OnRender := nil;
Window.OnPress := nil;
Window.OnRelease := nil;
Window.OnUpdate := nil;
if gameModeEnter[value] <> nil then gameModeEnter[value];
fGameMode := value;
Window.Invalidate;
end;
{ events --------------------------------------------------------------------- }
procedure CloseQuery(Container: TUIContainer);
begin
if MessageYesNo(Window, 'Are you sure you want to quit ?') then Window.Close;
end;
procedure Close(Container: TUIContainer);
begin
if (fGameMode <> modeNone) and
(gameModeExit[fGameMode] <> nil) then gameModeExit[fGameMode];
fGameMode := modeNone;
end;
initialization
Window := TCastleWindowCustom.Create(nil);
Window.FpsShowOnCaption := true;
Window.OnCloseQuery := @CloseQuery;
Window.OnClose := @Close;
Window.ResizeAllowed := raOnlyAtOpen;
Notifications := TCastleNotifications.Create(Window);
Notifications.MaxMessages := 10;
Notifications.Anchor(hpMiddle);
Notifications.Anchor(vpTop, -10);
Notifications.TextAlignment := hpMiddle;
Notifications.Color := Yellow;
Application.MainWindow := Window;
Progress.UserInterface := WindowProgressInterface;
finalization
FreeAndNil(Window);
end.