Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/BreakSpikes.txt
1319 views
1
//----------------Sonic CD Break Spikes Script----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value1 : Object.XVelocity
7
#alias Object.Value2 : Object.YVelocity
8
#alias Object.Value3 : Object.YAcceleration
9
10
// Player Aliases
11
#alias Player.Value4 : Player.InvincibleTimer
12
13
// Property Values
14
// All non-zero property values are for individual spike pieces
15
#alias 0 : BREAKSPIKES_MAIN
16
#alias 1 : BREAKSPIKES_DEBRIS_1
17
#alias 2 : BREAKSPIKES_DEBRIS_2
18
#alias 3 : BREAKSPIKES_DEBRIS_3
19
#alias 4 : BREAKSPIKES_DEBRIS_4
20
21
// Ink Effects
22
#alias 2 : INK_ALPHA
23
24
// Stage SFX
25
#alias 7 : SFX_S_CRUMBLE
26
27
28
sub ObjectMain
29
if Object.PropertyValue == BREAKSPIKES_MAIN
30
31
// Compare Metal Sonic's position with that of the spikes' to see if they should be broken
32
33
// Take the spike's position and subtract 20 pixels from it
34
TempValue0 = Object.XPos
35
TempValue0 -= 0x140000
36
37
ArrayPos0 = MetalSonic_EntityNo
38
39
if Object[ArrayPos0].XPos > TempValue0
40
41
// Metal Sonic has passed these spikes, destroy them
42
43
// Play the Crumble SFX
44
PlayStageSfx(SFX_S_CRUMBLE, false)
45
46
#platform: Use_Haptics
47
// Do a strong shake
48
HapticEffect(96, 0, 0, 0)
49
#endplatform
50
51
// Create a bunch of spike fragments
52
// Their property value is what frame they should use
53
54
CreateTempObject(TypeName[Break Spikes], BREAKSPIKES_DEBRIS_1, Object.XPos, Object.YPos)
55
Object[TempObjectPos].XVelocity = 0x8000
56
Object[TempObjectPos].YVelocity = -0x20000
57
Object[TempObjectPos].YAcceleration = 0x3000
58
Object[TempObjectPos].InkEffect = INK_ALPHA
59
Object[TempObjectPos].Alpha = 254
60
61
CreateTempObject(TypeName[Break Spikes], BREAKSPIKES_DEBRIS_2, Object.XPos, Object.YPos)
62
Object[TempObjectPos].XVelocity = 0x10000
63
Object[TempObjectPos].YVelocity = -0x40000
64
Object[TempObjectPos].YAcceleration = 0x3000
65
Object[TempObjectPos].InkEffect = INK_ALPHA
66
Object[TempObjectPos].Alpha = 254
67
68
CreateTempObject(TypeName[Break Spikes], BREAKSPIKES_DEBRIS_3, Object.XPos, Object.YPos)
69
Object[TempObjectPos].XVelocity = 0x18000
70
Object[TempObjectPos].YVelocity = -0x20000
71
Object[TempObjectPos].YAcceleration = 0x2000
72
Object[TempObjectPos].InkEffect = INK_ALPHA
73
Object[TempObjectPos].Alpha = 254
74
75
CreateTempObject(TypeName[Break Spikes], BREAKSPIKES_DEBRIS_4, Object.XPos, Object.YPos)
76
Object[TempObjectPos].XVelocity = 0x20000
77
Object[TempObjectPos].YVelocity = -0x40000
78
Object[TempObjectPos].YAcceleration = 0x4000
79
Object[TempObjectPos].InkEffect = INK_ALPHA
80
Object[TempObjectPos].Alpha = 254
81
82
// Clear the main spikes object
83
ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, 0, 0)
84
end if
85
86
ArrayPos0 = 0
87
else
88
// Spike fragment
89
90
// Fade out
91
if Object.Alpha > 0
92
Object.Alpha -= 2
93
end if
94
95
// Update movement
96
Object.XPos += Object.XVelocity
97
Object.YPos += Object.YVelocity
98
99
// The top and bottom spikes get different gravities, which is why gravity is just stored as an Object Value in this case
100
Object.YVelocity += Object.YAcceleration
101
102
if Object.OutOfBounds == true
103
// Unload as soon as out of view, as at that point the Object's no longer needed
104
105
Object.Type = TypeName[Blank Object]
106
end if
107
end if
108
end sub
109
110
111
sub ObjectPlayerInteraction
112
// If the Spikes are all still together, then they can still damage Sonic
113
if Object.PropertyValue == BREAKSPIKES_MAIN
114
// Act as a box for the player
115
PlayerObjectCollision(C_BOX, -16, -15, 16, 16)
116
117
// And now check for actual touching of the sharp spikes
118
if Player.YVelocity > -1
119
if Player.InvincibleTimer == 0
120
PlayerObjectCollision(C_TOUCH, -15, -16, 15, -12)
121
122
if CheckResult == true
123
124
// Damage the player
125
Player.State = Player_State_GotHit
126
127
// Since the Player's been hit, they can no longer get the Heavy Metal Achievement
128
// (For refrence, the Heavy Metal Achievement has you get through the entire Metal Sonic race without getting hit)
129
Player.HeavyMetalFlag = false
130
131
// Decide knockback direction based on if the player's behind or in front of this object
132
// The X Positions used are based on the centers of both entities
133
if Player.XPos > Object.XPos
134
Player.Speed = 0x20000
135
else
136
Player.Speed = -0x20000
137
end if
138
139
end if
140
end if
141
end if
142
end if
143
144
// Spike fragments don't really do anything, so there's nothing for them here
145
end sub
146
147
148
sub ObjectDraw
149
DrawSpriteFX(Object.PropertyValue, FX_INK, Object.XPos, Object.YPos)
150
end sub
151
152
153
sub ObjectStartup
154
155
LoadSpriteSheet("Global/Items3.gif")
156
157
// Spike Frames
158
159
// 0 - Main Spikes frame
160
SpriteFrame(-16, -16, 32, 32, 50, 1)
161
162
// 1-3 - Individual Spike Frames
163
SpriteFrame(-16, -16, 8, 32, 50, 1)
164
SpriteFrame(-8, -16, 8, 32, 50, 1)
165
SpriteFrame(0, -16, 8, 32, 50, 1)
166
SpriteFrame(8, -16, 8, 32, 50, 1)
167
168
end sub
169
170
171
// ========================
172
// Editor Subs
173
// ========================
174
175
sub RSDKDraw
176
DrawSprite(0)
177
end sub
178
179
180
sub RSDKLoad
181
LoadSpriteSheet("Global/Items3.gif")
182
SpriteFrame(-16, -16, 32, 32, 50, 1)
183
184
// Although used by the object for its broken variants, it shouldn't be set by the editor
185
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
186
end sub
187
188