-
Notifications
You must be signed in to change notification settings - Fork 5
/
Level Editor.ahk
264 lines (227 loc) · 8.29 KB
/
Level Editor.ahk
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#NoEnv
/*
Copyright 2011-2012 Anthony Zhang <[email protected]>
This file is part of ProgressPlatformer. Source code is available at <https://github.com/Uberi/ProgressPlatformer>.
ProgressPlatformer is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#Include %A_ScriptDir%
#Include ProgressEngine.ahk
#Include Environment.ahk
#Warn All
#Warn LocalSameAsGlobal, Off
LevelBackground := "Clouds"
Gui, +Resize +LastFound +OwnDialogs
Gui, Show, w800 h600, ProgressPlatformer
Editor := new ProgressEngine(WinExist())
Editor.Hue := 0.05, Editor.Saturation := 0.1
Editor.Layers[1] := new ProgressEngine.Layer
Environment[LevelBackground](Editor.Layers[1])
Editor.Layers[2] := new ProgressEngine.Layer
Editor.Layers[3] := new ProgressEngine.Layer
Editor.Layers[3].Entities.Insert(new EditingPane(7,2,2.5,6,"Level Editor"))
Loop
{
Result := Editor.Start()
If Result = 1 ;save
SaveLevel(Editor.Layers[2])
Else If Result = 2 ;change background
{
Editor.Layers[1] := new ProgressEngine.Layer
Environment[LevelBackground](Editor.Layers[1])
}
}
ExitApp
GuiClose:
Try Editor.__Delete() ;wip: this is related to a limitation of the reference counting mechanism in AHK (Although references in static and global variables are released automatically when the program exits, references in non-static local variables or on the expression evaluation stack are not. These references are only released if the function or expression is allowed to complete normally.). normal exiting (game complete) works fine though
Catch
{
}
ExitApp
SaveLevel(Layer)
{
Precision := 3
Entities := Object()
For Index, Entity In Layer.Entities
{
If Entity.__Class = "Block" || Entity.__Class = "Goal"
Entities.Blocks .= "Entities.Insert(new GameEntities." . Entity.__Class . "("
. Round(Entity.X,Precision)
. "," . Round(Entity.Y,Precision)
. "," . Round(Entity.W,Precision)
. "," . Round(Entity.H,Precision) . "))`n"
Else If Entity.__Class = "Platform"
Entities.Blocks .= "Entities.Insert(new GameEntities.Platform("
. Round(Entity.X,Precision)
. "," . Round(Entity.Y,Precision)
. "," . Round(Entity.W,Precision)
. "," . Round(Entity.H,Precision)
. "," . Round(Entity.RangeW ? "1" : "0",Precision)
. "," . Round(Entity.RangeW ? Entity.RangeX : Entity.RangeY,Precision)
. "," . Round(Entity.RangeW ? Entity.RangeW : Entity.RangeH,Precision)
. "," . Round(Entity.Speed,Precision) . "))`n"
Else If Entity.__Class = "Box" || Entity.__Class = "Player" || Entity.__Class = "Enemy"
Entities.Blocks .= "Entities.Insert(new GameEntities." . Entity.__Class . "("
. Round(Entity.X,Precision)
. "," . Round(Entity.Y,Precision)
. "," . Round(Entity.W,Precision)
. "," . Round(Entity.H,Precision)
. "," . Round(Entity.SpeedX,Precision)
. "," . Round(Entity.SpeedY,Precision) . "))`n"
}
Result := Entities.Blocks . Entities.Platforms . Entities.Goals . Entities.Players . Entities.Enemies
Code =
(
#NoEnv
StartLevel := 1
Loop
{
If StartLevel
{
Game.Layers[1] := new ProgressEngine.Layer
Game.Layers[2] := new ProgressEngine.Layer
Game.Layers[3] := new ProgressEngine.Layer
Game.Layers[1].Entities.Insert(new KeyboardController)
Environment.%LevelBackground%(Game.Layers[1])
Entities := Game.Layers[2].Entities
%Result%
Game.Layers[3].Entities.Insert(new GameEntities.HealthBar(Game.Layers[2]))
}
Result := Game.Start()
StartLevel := 1
If Result = 1 ;reached goal
Break
If Result = 2 ;out of health
MessageScreen(Game,"Try again","Press Space to restart the level.")
Else If Result = 3 ;out of bounds
MessageScreen(Game,"Out of bounds","Press Space to restart the level.")
Else If Result = 4 ;game paused
MessageScreen(Game,"Paused","Press Space to resume."), StartLevel := 0
}
Game.Layers := []
)
Return, Code
}
class EditingPane extends ProgressEntities.Container
{
__New(X,Y,W,H,Title)
{
base.__New()
this.X := X
this.Y := Y
this.W := W
this.H := H
this.Layers[1] := new ProgressEngine.Layer
this.Layers[1].Entities.Insert(new this.Background)
this.Layers[1].Entities.Insert(new this.Title(Title))
this.Layers[1].Entities.Insert(new Button(0.5,1.5,9,1,"Add"))
}
class Background extends ProgressEntities.Rectangle
{
__New()
{
base.__New()
this.X := 0
this.Y := 0
this.W := 10
this.H := 10
this.Color := 0x555555
}
}
class Title extends ProgressEntities.Text
{
__New(Text)
{
base.__New()
this.X := 5
this.Y := 1
this.W := 10
this.H := 2
this.Color := 0xFFFFFF
this.Weight := 100
this.Typeface := "Georgia"
this.Text := Text
}
}
}
class Button extends ProgressEntities.Container
{
__New(X,Y,W,H,Text)
{
base.__New()
this.X := X
this.Y := Y
this.W := W
this.H := H
this.Layers[1] := new ProgressEngine.Layer
this.Layers[1].Entities.Insert(new this.Background)
this.Layers[1].Entities.Insert(new this.Label(Text))
}
class Background extends ProgressEntities.Rectangle
{
__New()
{
base.__New()
this.X := 0
this.Y := 0
this.W := 10
this.H := 10
this.Color := 0x888888
}
Step(Delta,Layer,Viewport)
{
If GetKeyState("LButton","P") && this.MouseHovering
ToolTip Hovering!
Else
ToolTip Not hovering!
}
}
class Label extends ProgressEntities.Text
{
__New(Text)
{
base.__New()
this.X := 5
this.Y := 1
this.W := 10
this.H := 2
this.Color := 0xFFFFFF
this.Weight := 100
this.Typeface := "Georgia"
this.Text := Text
}
}
}
ColorTint(Color)
{
global Editor
Hue := Editor.Hue, Saturation := Editor.Saturation
Red := Color >> 16, Green := (Color >> 8) & 0xFF, Blue := Color & 0xFF
Value := (Red > Green) ? ((Red > Blue) ? Red : Blue) : ((Green > Blue) ? Green : Blue)
Sector := Floor(Hue)
FractionalHue := Hue - Sector
Component1 := Round(Value * (1 - Saturation))
Component2 := Round(Value * (1 - (Saturation * FractionalHue)))
Component3 := Round(Value * (1 - (Saturation * (1 - FractionalHue))))
If Sector = 0 ;zeroth sector
Red := Value, Green := Component3, Blue := Component1
Else If Sector = 1 ;first sector
Red := Component2, Green := Value, Blue := Component1
Else If Sector = 2 ;second sector
Red := Component1, Green := Value, Blue := Component3
Else If Sector = 3 ;third sector
Red := Component1, Green := Component2, Blue := Value
Else If Sector = 4 ;fourth sector
Red := Component3, Green := Component1, Blue := Value
Else ;If Sector = 5 ;fifth sector
Red := Value, Green := Component1, Blue := Component2
Return, (Red << 16) | (Green << 8) | Blue
}