Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/SBZ/ForceField.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Force Field Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
// Bit of a note: The less transparency you have, the more opaque you are
13
private alias object.value1 : object.transparency
14
15
private alias 0 : FORCEFIELD_SOLID
16
private alias 1 : FORCEFIELD_WAITFORPLAYER
17
private alias 2 : FORCEFIELD_FADEIN
18
private alias 3 : FORCEFIELD_ACTIVE
19
20
// Player Aliases
21
private alias object.xpos : player.xpos
22
private alias object.xvel : player.xvel
23
private alias object.speed : player.speed
24
private alias object.direction : player.direction
25
26
27
// ========================
28
// Function Declarations
29
// ========================
30
31
reserve function ForceField_DebugDraw
32
reserve function ForceField_DebugSpawn
33
34
35
// ========================
36
// Function Definitions
37
// ========================
38
39
private function ForceField_DebugDraw
40
// Backup a few values
41
temp6 = object.inkEffect
42
temp7 = object.alpha
43
44
// Turn the object into an alpha blending one
45
object.inkEffect = INK_ADD
46
47
temp1 = oscillation
48
temp1 <<= 2
49
Sin(temp0, temp1)
50
object.alpha = temp0
51
object.alpha >>= 5
52
object.alpha += 0x50
53
DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
54
DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)
55
56
object.alpha = temp0
57
object.alpha >>= 5
58
object.alpha += 0x90
59
DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)
60
DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)
61
62
object.alpha = temp0
63
object.alpha >>= 4
64
object.alpha += 0xC0
65
DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)
66
67
// Restore those backed up values from earlier
68
object.alpha = temp7
69
object.inkEffect = temp6
70
end function
71
72
73
private function ForceField_DebugSpawn
74
CreateTempObject(TypeName[Force Field], 0, object.xpos, object.ypos)
75
object[tempObjectPos].drawOrder = 5
76
object[tempObjectPos].inkEffect = INK_ADD
77
end function
78
79
80
// ========================
81
// Events
82
// ========================
83
84
event ObjectUpdate
85
switch object.state
86
case FORCEFIELD_SOLID
87
// Active - simply act as a box
88
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
89
BoxCollisionTest(C_SOLID, object.entityPos, -8, -80, 8, 80, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
90
next
91
break
92
93
case FORCEFIELD_WAITFORPLAYER
94
// Check if the player is 64 pixels past the right of this
95
temp0 = object.xpos
96
temp0 += 0x400000
97
if player[0].xpos > temp0
98
object.state = FORCEFIELD_FADEIN
99
end if
100
break
101
102
case FORCEFIELD_FADEIN
103
// "Fading in" state where force field starts force fielding
104
if object.transparency > 0
105
object.transparency--
106
else
107
object.state = FORCEFIELD_ACTIVE
108
end if
109
break
110
111
case FORCEFIELD_ACTIVE
112
temp0 = object.xpos
113
temp0 += 0x160000
114
115
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
116
if player[currentPlayer].xpos < temp0
117
BoxCollisionTest(C_TOUCH, object.entityPos, -256, -80, 8, 80, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
118
if checkResult == true
119
if player[currentPlayer].xvel < 0x20000
120
player[currentPlayer].xvel = 0x20000
121
player[currentPlayer].speed = 0x20000
122
player[currentPlayer].direction = FACING_RIGHT
123
end if
124
end if
125
else
126
BoxCollisionTest(C_SOLID, object.entityPos, -8, -80, 8, 80, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
127
end if
128
next
129
break
130
131
end switch
132
end event
133
134
135
event ObjectDraw
136
temp1 = oscillation
137
temp1 <<= 2
138
Sin(temp0, temp1)
139
object.alpha = temp0
140
object.alpha >>= 5
141
object.alpha += 0x50
142
object.alpha >>= object.transparency
143
DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
144
DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)
145
146
object.alpha = temp0
147
object.alpha >>= 5
148
object.alpha += 0x90
149
object.alpha >>= object.transparency
150
DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)
151
DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)
152
153
object.alpha = temp0
154
object.alpha >>= 4
155
object.alpha += 0xC0
156
object.alpha >>= object.transparency
157
DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)
158
end event
159
160
161
event ObjectStartup
162
LoadSpriteSheet("SBZ/Objects.gif")
163
164
// Force Field frames
165
SpriteFrame(-8, -72, 2, 144, 382, 266)
166
SpriteFrame(-6, -72, 3, 144, 384, 266)
167
SpriteFrame(-3, -72, 6, 144, 387, 266)
168
SpriteFrame(3, -72, 3, 144, 393, 266)
169
SpriteFrame(6, -72, 2, 144, 396, 266)
170
171
// Set up values for every Force Field object
172
foreach (TypeName[Force Field], arrayPos0, ALL_ENTITIES)
173
object[arrayPos0].drawOrder = 5
174
object[arrayPos0].inkEffect = INK_ADD
175
176
if object[arrayPos0].propertyValue == 1
177
object[arrayPos0].state = FORCEFIELD_WAITFORPLAYER
178
object[arrayPos0].transparency = 10
179
end if
180
next
181
182
// Add the object to the debug mode item list
183
SetTableValue(TypeName[Force Field], DebugMode_ObjCount, DebugMode_TypesTable)
184
SetTableValue(ForceField_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
185
SetTableValue(ForceField_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
186
DebugMode_ObjCount++
187
end event
188
189
190
// ========================
191
// Editor Events
192
// ========================
193
194
event RSDKEdit
195
if editor.returnVariable == true
196
switch editor.variableID
197
case EDIT_VAR_PROPVAL // property value
198
checkResult = object.propertyValue
199
checkResult &= 3
200
break
201
202
case 0 // type
203
checkResult = object.propertyValue
204
checkResult &= 3
205
break
206
207
end switch
208
else
209
switch editor.variableID
210
case EDIT_VAR_PROPVAL // property value
211
object.propertyValue = editor.variableValue
212
object.propertyValue &= 3
213
break
214
215
case 0 // type
216
object.propertyValue = editor.variableValue
217
object.propertyValue &= 3
218
break
219
220
end switch
221
end if
222
end event
223
224
225
event RSDKDraw
226
object.inkEffect = INK_ADD
227
if object.propertyValue == 1
228
object.transparency = 10
229
else
230
object.transparency = 0
231
end if
232
233
Sin(temp0, 0)
234
object.alpha = temp0
235
object.alpha >>= 5
236
object.alpha += 0x50
237
object.alpha >>= object.transparency
238
DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
239
DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)
240
241
object.alpha = temp0
242
object.alpha >>= 5
243
object.alpha += 0x90
244
object.alpha >>= object.transparency
245
DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)
246
DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)
247
248
object.alpha = temp0
249
object.alpha >>= 4
250
object.alpha += 0xC0
251
object.alpha >>= object.transparency
252
DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)
253
end event
254
255
256
event RSDKLoad
257
LoadSpriteSheet("SBZ/Objects.gif")
258
SpriteFrame(-8, -72, 2, 144, 382, 266)
259
SpriteFrame(-6, -72, 3, 144, 384, 266)
260
SpriteFrame(-3, -72, 6, 144, 387, 266)
261
SpriteFrame(3, -72, 3, 144, 393, 266)
262
SpriteFrame(6, -72, 2, 144, 396, 266)
263
264
AddEditorVariable("type")
265
SetActiveVariable("type")
266
AddEnumVariable("Always Active", 0)
267
AddEnumVariable("Active On Enter", 1)
268
end event
269
270