Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/Stalactite.txt
1319 views
1
//-----------------Sonic CD Stalactite Script-----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.YVelocity
7
#alias Object.Value1 : Object.YOriginPos
8
9
// HUD Alias
10
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
11
12
// States
13
#alias 0 : STALACTITE_IDLE
14
#alias 1 : STALACTITE_FALLING
15
#alias 2 : STALACTITE_OFFSCREEN
16
17
// Time Periods
18
#alias 0 : TIME_PRESENT
19
#alias 1 : TIME_PAST
20
#alias 2 : TIME_GOOD_FUTURE
21
#alias 3 : TIME_BAD_FUTURE
22
23
// Priority
24
#alias 0 : PRIORITY_BOUNDS
25
#alias 1 : PRIORITY_ACTIVE
26
27
28
sub ObjectMain
29
30
switch Object.State
31
32
// State STALACTITE_IDLE doesn't really do anything...
33
// Instead, falling is triggered over in ObjectPlayerInteraction
34
35
case STALACTITE_FALLING
36
// Update Gravity, maximum velocity of 8 pixels
37
if Object.YVelocity < 0x80000
38
// Gravity rate of 0.25 pixels per frame
39
Object.YVelocity += 0x4000
40
end if
41
42
Object.YPos += Object.YVelocity
43
44
if Object.OutOfBounds == true
45
// If this object goes offscreen, then put it back at its starting position and into the temp buffer state
46
Object.State = STALACTITE_OFFSCREEN
47
Object.YPos = Object.YOriginPos
48
end if
49
break
50
51
case STALACTITE_OFFSCREEN
52
// This state is here just in case the Stalactite fell off screen, but the Player is still near it too
53
// In this case, we need the Object to stay away just a bit longer so that it doesn't suddenly snap back to position
54
55
if Object.OutOfBounds == true
56
// It's safe to go back now, restore
57
Object.Priority = PRIORITY_BOUNDS
58
Object.State = STALACTITE_IDLE
59
end if
60
break
61
62
end switch
63
64
end sub
65
66
67
sub ObjectPlayerInteraction
68
69
switch Object.State
70
case STALACTITE_IDLE
71
// First check if the player's within falling trigger range
72
PlayerObjectCollision(C_TOUCH, -4, 0, 4, 96)
73
if CheckResult == true
74
// Make the Stalactite start falling
75
76
// Make it always active, since it'll end up falling out of bounds
77
Object.Priority = PRIORITY_ACTIVE
78
79
// Reset its falling properties
80
Object.YVelocity = 0
81
Object.State = STALACTITE_FALLING
82
end if
83
84
// [Fallthrough]
85
86
case STALACTITE_FALLING
87
88
// Just act as a plain 'ol hitbox too, in case the player jumps at it for whatever reason
89
PlayerObjectCollision(C_TOUCH, -8, -24, 8, 20)
90
91
if CheckResult == true
92
CallFunction(Player_Hit)
93
end if
94
break
95
96
end switch
97
98
end sub
99
100
101
sub ObjectDraw
102
103
switch Object.State
104
case STALACTITE_IDLE
105
case STALACTITE_FALLING
106
DrawSprite(0)
107
break
108
109
end switch
110
111
end sub
112
113
114
sub ObjectStartup
115
LoadSpriteSheet("R5/Objects.gif")
116
117
// Use different frames for the different time period
118
switch HUD.CurrentTimePeriod
119
case TIME_PRESENT
120
SpriteFrame(-8, -24, 16, 48, 172, 207)
121
break
122
123
case TIME_PAST
124
SpriteFrame(-8, -24, 16, 48, 189, 207)
125
break
126
127
case TIME_GOOD_FUTURE
128
SpriteFrame(-8, -24, 16, 48, 172, 207) // Same as Present, is this supposed to be the frame next to the Flowers instead?
129
break
130
131
case TIME_BAD_FUTURE
132
SpriteFrame(-8, -24, 16, 48, 155, 207)
133
break
134
135
end switch
136
137
// Cycle through all Stalactite Objects in the level
138
ArrayPos0 = 32
139
while ArrayPos0 < 1056
140
if Object[ArrayPos0].Type == TypeName[Stalactite]
141
142
// Store its Starting Position, this will be needed for restoration after the Object falls
143
Object[ArrayPos0].YOriginPos = Object[ArrayPos0].YPos
144
145
end if
146
147
ArrayPos0++
148
loop
149
150
end sub
151
152
153
// ========================
154
// Editor Subs
155
// ========================
156
157
sub RSDKDraw
158
DrawSprite(0)
159
end sub
160
161
162
sub RSDKLoad
163
LoadSpriteSheet("R5/Objects.gif")
164
165
// TODO: support other time periods
166
// Surely there's a better way to do it than 10 separate checkCurrentStageFolder checks?
167
SpriteFrame(-8, -24, 16, 48, 172, 207)
168
169
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
170
end sub
171
172