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/Animals/Flicky.txt
1481 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Flicky 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 0x30000 : ANIMAL_XVEL
26
private alias -0x60000 : 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 Flicky_DebugDraw
40
reserve function Flicky_DebugSpawn
41
42
43
// ========================
44
// Function Definitions
45
// ========================
46
47
private function Flicky_DebugDraw
48
DrawSprite(2)
49
end function
50
51
52
private function Flicky_DebugSpawn
53
CreateTempObject(TypeName[Flicky], 0, object.xpos, object.ypos)
54
55
GetBit(temp0, object.direction, 0)
56
if temp0 == FACING_RIGHT
57
object[tempObjectPos].state = ANIMAL_BOUNCING_FIXED
58
object[tempObjectPos].xvel = ANIMAL_XVEL
59
object[tempObjectPos].yvel = ANIMAL_YVEL
60
61
Rand(checkResult, 32)
62
if checkResult < 16
63
object[tempObjectPos].direction = FACING_LEFT
64
FlipSign(object[tempObjectPos].xvel)
65
end if
66
else
67
object[tempObjectPos].state = ANIMAL_BOUNCING_FOLLOW
68
end if
69
end function
70
71
72
// ========================
73
// Events
74
// ========================
75
76
event ObjectUpdate
77
switch object.state
78
case ANIMAL_WAIT
79
if object.timer < object.delay
80
object.timer++
81
else
82
object.xvel = ANIMAL_XVEL
83
84
if object.randomizeDir == true
85
object.drawOrder = 4
86
87
Rand(checkResult, 32)
88
if checkResult < 16
89
object.direction = FACING_LEFT
90
FlipSign(object.xvel)
91
end if
92
else
93
object.direction = FACING_LEFT
94
FlipSign(object.xvel)
95
end if
96
97
object.yvel = -0x40000
98
object.state++
99
end if
100
break
101
102
case ANIMAL_FALL
103
object.ypos += object.yvel
104
object.yvel += 0x3800
105
106
if object.yvel > 0
107
ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)
108
if checkResult == true
109
object.yvel = ANIMAL_YVEL
110
object.state++
111
end if
112
end if
113
break
114
115
case ANIMAL_BOUNCING_FOLLOW
116
if player[0].xpos < object.xpos
117
object.direction = FACING_LEFT
118
else
119
object.direction = FACING_RIGHT
120
end if
121
// [Fallthrough]
122
case ANIMAL_BOUNCING_PLACED
123
case ANIMAL_BOUNCING_FIXED
124
case ANIMAL_BOUNCING_FREE
125
object.xpos += object.xvel
126
object.ypos += object.yvel
127
object.yvel += 0x3800
128
129
if object.yvel > 0
130
ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)
131
if checkResult == true
132
if object.state == ANIMAL_BOUNCING_FIXED
133
if object.bounceDir == FACING_LEFT
134
FlipSign(object.xvel)
135
object.direction ^= FACING_LEFT
136
end if
137
138
object.bounceDir ^= FACING_LEFT
139
end if
140
141
object.yvel = ANIMAL_YVEL
142
end if
143
end if
144
145
object.frame = object.animationTimer
146
object.frame >>= 2
147
object.animationTimer++
148
object.animationTimer &= 7
149
break
150
151
end switch
152
153
if object.state < ANIMAL_BOUNCING_FIXED
154
if object.outOfBounds == true
155
object.type = TypeName[Blank Object]
156
end if
157
end if
158
159
end event
160
161
162
event ObjectDraw
163
switch object.state
164
case ANIMAL_WAIT
165
case ANIMAL_FALL
166
DrawSprite(2)
167
break
168
169
case ANIMAL_BOUNCING_PLACED
170
case ANIMAL_BOUNCING_FIXED
171
case ANIMAL_BOUNCING_FOLLOW
172
case ANIMAL_BOUNCING_FREE
173
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
174
break
175
176
end switch
177
end event
178
179
180
event ObjectStartup
181
LoadSpriteSheet("Global/Items.gif")
182
SpriteFrame(-8, -8, 16, 16, 183, 99)
183
SpriteFrame(-8, -8, 16, 16, 183, 116)
184
SpriteFrame(-7, -12, 16, 20, 183, 78)
185
186
foreach (TypeName[Flicky], arrayPos0, ALL_ENTITIES)
187
if object[arrayPos0].propertyValue == 1
188
object[arrayPos0].state = ANIMAL_BOUNCING_FIXED
189
object[arrayPos0].xvel = ANIMAL_XVEL
190
object[arrayPos0].yvel = ANIMAL_YVEL
191
192
Rand(checkResult, 32)
193
if checkResult < 16
194
object[arrayPos0].direction = FACING_LEFT
195
FlipSign(object[arrayPos0].xvel)
196
end if
197
else
198
if object[arrayPos0].propertyValue == 2
199
object[arrayPos0].state = ANIMAL_BOUNCING_FOLLOW
200
end if
201
202
if object[arrayPos0].propertyValue == 3
203
object[arrayPos0].state = ANIMAL_BOUNCING_FREE
204
object[arrayPos0].xvel = ANIMAL_XVEL
205
FlipSign(object[arrayPos0].xvel)
206
object[arrayPos0].direction = FACING_LEFT
207
end if
208
end if
209
210
object[arrayPos0].propertyValue = 0
211
next
212
213
SetTableValue(TypeName[Flicky], DebugMode_ObjCount, DebugMode_TypesTable)
214
SetTableValue(Flicky_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
215
SetTableValue(Flicky_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
216
DebugMode_ObjCount++
217
218
end event
219
220
221
// ========================
222
// Editor Events
223
// ========================
224
225
event RSDKEdit
226
if editor.returnVariable == true
227
switch editor.variableID
228
case EDIT_VAR_PROPVAL // property value
229
checkResult = object.propertyValue
230
break
231
232
case 0 // behaviour
233
checkResult = object.propertyValue
234
break
235
236
end switch
237
else
238
switch editor.variableID
239
case EDIT_VAR_PROPVAL // property value
240
object.propertyValue = editor.variableValue
241
break
242
243
case 0 // behaviour
244
object.propertyValue = editor.variableValue
245
break
246
247
end switch
248
end if
249
end event
250
251
252
event RSDKDraw
253
DrawSprite(0)
254
end event
255
256
257
event RSDKLoad
258
LoadSpriteSheet("Global/Items.gif")
259
SpriteFrame(-7, -12, 16, 20, 183, 78)
260
261
AddEditorVariable("behavior")
262
SetActiveVariable("behavior")
263
AddEnumVariable("Placed", 0)
264
AddEnumVariable("Fixed", 1)
265
AddEnumVariable("Follow", 2)
266
AddEnumVariable("Free", 3)
267
end event
268
269