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/Global/Ring.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Ring 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.isGHZAchievement
13
14
private alias object.value1 : object.targetPlayer
15
16
private alias 0 : RING_NORMAL
17
private alias 1 : RING_ATTRACT
18
19
// Player aliases
20
private alias object.state : player.state
21
private alias object.animation : player.animation
22
private alias object.value0 : player.rings
23
private alias object.value37 : player.shield
24
25
private alias 4 : SHIELD_LIGHTNING
26
27
// Game Mode Aliases
28
private alias 2 : MODE_TIMEATTACK
29
30
// Music Events
31
private alias 25 : SLOT_MUSICEVENT_CHANGE
32
33
private alias 2 : MUSICEVENT_TRANSITION
34
35
// Achievement Aliases
36
private alias 0 : ACHIEVEMENT_RAMPRINGACRO
37
private alias 4 : ACHIEVEMENT_RINGKING
38
39
40
// ========================
41
// Function Declarations
42
// ========================
43
44
reserve function Ring_DebugDraw
45
reserve function Ring_DebugSpawn
46
47
48
// ========================
49
// Function Declarations
50
// ========================
51
52
private function Ring_DebugDraw
53
DrawSprite(0)
54
end function
55
56
57
private function Ring_DebugSpawn
58
CreateTempObject(TypeName[Ring], 0, object.xpos, object.ypos)
59
object[tempObjectPos].drawOrder = 4
60
end function
61
62
63
// ========================
64
// Events
65
// ========================
66
67
event ObjectUpdate
68
// Bug Details:
69
// - The loop doesn't check to see if the ring's been obtained already, so
70
// if two players touch the ring at the same time, then the ring will count twice
71
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
72
// Check if the player should be able to collect rings
73
74
// Player 1 can't be hurt...
75
CheckEqual(player[0].state, Player_State_Hurt)
76
temp0 = checkResult
77
78
// ...nor can the current player be recoiling either
79
CheckEqual(player[currentPlayer].state, Player_State_Hurt)
80
temp0 = checkResult
81
CheckEqual(player[currentPlayer].state, Player_State_GotHit)
82
temp0 |= checkResult
83
84
if temp0 == false
85
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
86
if checkResult == true
87
// Make the ring disappear
88
object.type = TypeName[Ring Sparkle]
89
90
// Add to the player's ring count
91
player[0].rings++
92
93
// Max 999 rings
94
if player[0].rings > 999
95
player[0].rings = 999
96
end if
97
98
// Give the player an extra life if needed
99
if player[0].rings >= ringExtraLife
100
if options.gameMode != MODE_TIMEATTACK
101
#platform: USE_ORIGINS
102
if game.coinMode == false
103
player.lives++
104
else
105
CallNativeFunction2(NotifyCallback, NOTIFY_ADD_COIN, 1)
106
end if
107
#endplatform
108
#platform: USE_STANDALONE
109
player.lives++
110
#endplatform
111
PlaySfx(SfxName[Life], false)
112
PauseMusic()
113
ResetObjectEntity(SLOT_MUSICEVENT_CHANGE, TypeName[Music Event], MUSICEVENT_TRANSITION, 0, 0)
114
object[SLOT_MUSICEVENT_CHANGE].priority = PRIORITY_ACTIVE
115
end if
116
117
if stage.debugMode == false
118
if player[0].rings >= 200
119
// Grant the "Ring King" Achievement
120
CallNativeFunction2(SetAchievement, ACHIEVEMENT_RINGKING, 100)
121
end if
122
end if
123
124
ringExtraLife += 100
125
if ringExtraLife > 300
126
ringExtraLife = 1000
127
end if
128
end if
129
130
// Update achievment collection
131
if object.isGHZAchievement == true
132
if stage.debugMode == false
133
if options.attractMode == false
134
if currentPlayer == 0
135
if player[0].animation == ANI_JUMPING
136
achieveRingCount++
137
if achieveRingCount == 30
138
// Grant the "Ramp Ring Acrobatics" Achievement
139
CallNativeFunction2(SetAchievement, ACHIEVEMENT_RAMPRINGACRO, 100)
140
achieveRingCount = 0
141
end if
142
end if
143
end if
144
end if
145
end if
146
end if
147
148
// Play the ring chime
149
if ringPan == 0
150
PlaySfx(SfxName[Ring L], false)
151
SetSfxAttributes(SfxName[Ring L], -1, -100)
152
ringPan = 1
153
else
154
PlaySfx(SfxName[Ring R], false)
155
SetSfxAttributes(SfxName[Ring R], -1, 100)
156
ringPan = 0
157
end if
158
else
159
if object.state == RING_NORMAL
160
// Does the player have the lightning shield?
161
if player[currentPlayer].shield == SHIELD_LIGHTNING
162
// Check if this ring falls within the lightning shield attraction range
163
BoxCollisionTest(C_TOUCH, object.entityPos, -64, -64, 64, 64, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
164
if checkResult == true
165
object.state = RING_ATTRACT
166
object.targetPlayer = currentPlayer
167
end if
168
end if
169
end if
170
end if
171
end if
172
next
173
174
if object.state == RING_ATTRACT
175
// Check if the player's lost their lightning shield
176
arrayPos0 = object.targetPlayer
177
if player[arrayPos0].shield != SHIELD_LIGHTNING
178
// Make the ring fall to the ground
179
object.type = TypeName[Lose Ring]
180
object.animationSpeed = 128
181
object.alpha = 256
182
183
else
184
// Move to the player
185
arrayPos0 = object.targetPlayer
186
if object.xpos > object[arrayPos0].xpos
187
if object.xvel > 0
188
object.xvel -= 0xC000
189
else
190
object.xvel -= 0x3000
191
end if
192
else
193
if object.xvel < 0
194
object.xvel += 0xC000
195
else
196
object.xvel += 0x3000
197
end if
198
end if
199
200
if object.ypos > object[arrayPos0].ypos
201
if object.yvel > 0
202
object.yvel -= 0xC000
203
else
204
object.yvel -= 0x3000
205
end if
206
else
207
if object.yvel < 0
208
object.yvel += 0xC000
209
else
210
object.yvel += 0x3000
211
end if
212
end if
213
214
object.xpos += object.xvel
215
object.ypos += object.yvel
216
end if
217
end if
218
end event
219
220
221
event ObjectDraw
222
DrawSprite(ringFrame)
223
end event
224
225
226
event ObjectStartup
227
LoadSpriteSheet("Global/Items.gif")
228
229
// (Doesn't mean much, but this is one of the few times in v4 scripts that extra code is between LoadSpriteSheet and SpriteFrames)
230
foreach (TypeName[Ring], arrayPos0, ALL_ENTITIES)
231
object[arrayPos0].drawOrder = 4
232
next
233
234
// Reset the achievment value
235
achieveRingCount = 0
236
237
// Ring frames
238
SpriteFrame(-8, -8, 16, 16, 1, 1)
239
SpriteFrame(-8, -8, 16, 16, 1, 18)
240
SpriteFrame(-8, -8, 16, 16, 1, 35)
241
SpriteFrame(-8, -8, 16, 16, 1, 52)
242
SpriteFrame(-8, -8, 16, 16, 1, 69)
243
SpriteFrame(-8, -8, 16, 16, 1, 86)
244
SpriteFrame(-8, -8, 16, 16, 1, 103)
245
SpriteFrame(-8, -8, 16, 16, 1, 120)
246
247
// Add the ring to the stage's debug mode list
248
SetTableValue(TypeName[Ring], DebugMode_ObjCount, DebugMode_TypesTable)
249
SetTableValue(Ring_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
250
SetTableValue(Ring_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
251
DebugMode_ObjCount++
252
end event
253
254
255
// ========================
256
// Editor Events
257
// ========================
258
259
event RSDKEdit
260
if editor.returnVariable == true
261
switch editor.variableID
262
case EDIT_VAR_PROPVAL // property value
263
checkResult = object.propertyValue
264
break
265
266
case 0 // achievementType
267
checkResult = object.propertyValue
268
break
269
270
end switch
271
else
272
switch editor.variableID
273
case EDIT_VAR_PROPVAL // property value
274
object.propertyValue = editor.variableValue
275
break
276
277
case 0 // achievementType
278
object.propertyValue = editor.variableValue
279
break
280
281
end switch
282
end if
283
end event
284
285
286
event RSDKDraw
287
DrawSprite(0)
288
end event
289
290
291
event RSDKLoad
292
LoadSpriteSheet("Global/Items.gif")
293
SpriteFrame(-8, -8, 16, 16, 1, 1)
294
295
AddEditorVariable("achievementType")
296
SetActiveVariable("achievementType")
297
AddEnumVariable("None", 0)
298
AddEnumVariable("GHZ Achievement", 1)
299
end event
300
301