Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 2/Scripts/Animals/Locky.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Locky Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
private alias object.propertyValue : object.delay
13
14
private alias object.value0 : object.timer // its this in ANIMAL_WAIT
15
private alias object.value0 : object.bounceDir // its this in every other state
16
private alias object.value1 : object.randomizeDir
17
18
private alias 0 : ANIMAL_WAIT
19
private alias 1 : ANIMAL_FALL
20
private alias 2 : ANIMAL_BOUNCING_PLACED
21
private alias 3 : ANIMAL_BOUNCING_FIXED
22
private alias 4 : ANIMAL_BOUNCING_FOLLOW
23
private alias 5 : ANIMAL_BOUNCING_FREE
24
25
private alias 0x28000 : ANIMAL_XVEL
26
private alias -0x30000 : ANIMAL_YVEL
27
28
// Player Aliases
29
private alias object.xpos : player.xpos
30
31
// Path ID Aliases
32
private alias 0 : PATH_A
33
34
35
// ========================
36
// Function Declarations
37
// ========================
38
39
reserve function Locky_DebugDraw
40
reserve function Locky_DebugSpawn
41
42
43
// ========================
44
// Function Definitions
45
// ========================
46
47
private function Locky_DebugDraw
48
DrawSprite(2)
49
end function
50
51
52
private function Locky_DebugSpawn
53
CreateTempObject(TypeName[Locky], 0, object.xpos, object.ypos)
54
GetBit(temp0, object.direction, 0)
55
if temp0 == FACING_RIGHT
56
object[tempObjectPos].state = ANIMAL_BOUNCING_FIXED
57
object[tempObjectPos].xvel = ANIMAL_XVEL
58
object[tempObjectPos].yvel = ANIMAL_YVEL
59
60
Rand(checkResult, 32)
61
if checkResult < 16
62
object[tempObjectPos].direction = FACING_LEFT
63
FlipSign(object[tempObjectPos].xvel)
64
end if
65
else
66
object[tempObjectPos].state = ANIMAL_BOUNCING_FOLLOW
67
end if
68
end function
69
70
71
// ========================
72
// Events
73
// ========================
74
75
event ObjectUpdate
76
switch object.state
77
case ANIMAL_WAIT
78
if object.timer < object.delay
79
object.timer++
80
else
81
object.xvel = ANIMAL_XVEL
82
if object.randomizeDir == true
83
object.drawOrder = 4
84
85
Rand(checkResult, 32)
86
if checkResult < 16
87
object.direction = FACING_LEFT
88
FlipSign(object.xvel)
89
end if
90
else
91
object.direction = FACING_LEFT
92
FlipSign(object.xvel)
93
end if
94
95
object.yvel = -0x40000
96
object.state++
97
end if
98
break
99
100
case ANIMAL_FALL
101
object.ypos += object.yvel
102
object.yvel += 0x3800
103
104
if object.yvel > 0
105
ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)
106
if checkResult == true
107
object.yvel = ANIMAL_YVEL
108
object.state++
109
end if
110
end if
111
break
112
113
case ANIMAL_BOUNCING_FOLLOW
114
if player[0].xpos < object.xpos
115
object.direction = FACING_LEFT
116
else
117
object.direction = FACING_RIGHT
118
end if
119
// Fall through
120
case ANIMAL_BOUNCING_PLACED
121
case ANIMAL_BOUNCING_FIXED
122
case ANIMAL_BOUNCING_FREE
123
object.xpos += object.xvel
124
object.ypos += object.yvel
125
object.yvel += 0x3800
126
if object.yvel > 0
127
ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)
128
if checkResult == true
129
if object.state == ANIMAL_BOUNCING_FIXED
130
if object.bounceDir == FACING_LEFT
131
FlipSign(object.xvel)
132
object.direction ^= FACING_LEFT
133
end if
134
135
object.bounceDir ^= FACING_LEFT
136
end if
137
138
object.yvel = ANIMAL_YVEL
139
end if
140
end if
141
142
object.frame = object.animationTimer
143
object.frame >>= 1
144
object.animationTimer++
145
object.animationTimer &= 3
146
break
147
148
end switch
149
150
if object.state < ANIMAL_BOUNCING_FIXED
151
if object.outOfBounds == true
152
object.type = TypeName[Blank Object]
153
end if
154
end if
155
end event
156
157
158
event ObjectDraw
159
switch object.state
160
case ANIMAL_WAIT
161
case ANIMAL_FALL
162
DrawSprite(2)
163
break
164
165
case ANIMAL_BOUNCING_PLACED
166
case ANIMAL_BOUNCING_FIXED
167
case ANIMAL_BOUNCING_FOLLOW
168
case ANIMAL_BOUNCING_FREE
169
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
170
break
171
172
end switch
173
end event
174
175
176
event ObjectStartup
177
LoadSpriteSheet("Global/Items2.gif")
178
SpriteFrame(-8, -8, 16, 15, 32, 239)
179
SpriteFrame(-8, -7, 16, 15, 49, 239)
180
SpriteFrame(-7, -12, 15, 24, 34, 213)
181
182
foreach (TypeName[Locky], arrayPos0, ALL_ENTITIES)
183
if object[arrayPos0].propertyValue == 1
184
object[arrayPos0].state = ANIMAL_BOUNCING_FIXED
185
object[arrayPos0].xvel = ANIMAL_XVEL
186
object[arrayPos0].yvel = ANIMAL_YVEL
187
188
Rand(checkResult, 32)
189
if checkResult < 16
190
object[arrayPos0].direction = FACING_LEFT
191
FlipSign(object[arrayPos0].xvel)
192
end if
193
else
194
if object[arrayPos0].propertyValue == 2
195
object[arrayPos0].state = ANIMAL_BOUNCING_FOLLOW
196
end if
197
198
if object[arrayPos0].propertyValue == 3
199
object[arrayPos0].state = ANIMAL_BOUNCING_FREE
200
object[arrayPos0].xvel = ANIMAL_XVEL
201
FlipSign(object[arrayPos0].xvel)
202
object[arrayPos0].direction = FACING_LEFT
203
end if
204
end if
205
206
object[arrayPos0].propertyValue = 0
207
next
208
209
SetTableValue(TypeName[Locky], DebugMode_ObjCount, DebugMode_TypesTable)
210
SetTableValue(Locky_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
211
SetTableValue(Locky_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
212
DebugMode_ObjCount++
213
end event
214
215
216
// ========================
217
// Editor Events
218
// ========================
219
220
event RSDKEdit
221
if editor.returnVariable == true
222
switch editor.variableID
223
case EDIT_VAR_PROPVAL // property value
224
checkResult = object.propertyValue
225
break
226
227
case 0 // behavior
228
checkResult = object.propertyValue
229
break
230
231
end switch
232
else
233
switch editor.variableID
234
case EDIT_VAR_PROPVAL // property value
235
object.propertyValue = editor.variableValue
236
break
237
238
case 0 // behavior
239
object.propertyValue = editor.variableValue
240
break
241
242
end switch
243
end if
244
end event
245
246
247
event RSDKDraw
248
DrawSprite(0)
249
end event
250
251
252
event RSDKLoad
253
LoadSpriteSheet("Global/Items2.gif")
254
SpriteFrame(-7, -12, 15, 24, 34, 213)
255
256
AddEditorVariable("behavior")
257
SetActiveVariable("behavior")
258
AddEnumVariable("Placed", 0)
259
AddEnumVariable("Fixed", 1)
260
AddEnumVariable("Follow", 2)
261
AddEnumVariable("Free", 3)
262
end event
263
264