Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/PathSwap.txt
1319 views
1
//-----------------Sonic CD Path Swap Script------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Do note, these are not the same genre of "Path Swappers" as used in loops!
6
// Although in Sonic 1/Sonic 2 they're dedicated objects that can be placed, in Sonic CD the chunks are instead swapped in real-time, just like the original game
7
// And, the system used in R7's loops is handled in the stage's respective [R7X Setup] script, not here
8
// This object is just the little Sonic sign that you can jump at
9
10
// Aliases
11
#alias 0 : PATHSWAP_IDLE
12
#alias 1 : PATHSWAP_SPINNING
13
14
#alias Object.Value0 : Object.Timer
15
16
// If the Player has touched this Path Swapper last frame, used to distinguish new touches from old touches
17
#alias Object.Value7 : Object.PrevTouch
18
19
#alias Object.Value1 : Object.ChunkX1
20
#alias Object.Value3 : Object.ChunkX2
21
#alias Object.Value2 : Object.ChunkY1
22
#alias Object.Value4 : Object.ChunkY2
23
24
// Holds the chunk ID of what's already there on the level map, New holds what it should be replaced with
25
#alias Object.Value5 : Object.ChunkIDOld
26
#alias Object.Value6 : Object.ChunkIDNew
27
28
// Priority
29
#alias 0 : PRIORITY_BOUNDS
30
#alias 1 : PRIORITY_ACTIVE
31
32
33
sub ObjectMain
34
if Object.State == PATHSWAP_SPINNING
35
if Object.Timer < 39
36
Object.Timer++
37
else
38
Object.State = PATHSWAP_IDLE
39
Object.Timer = 0
40
Object.Priority = PRIORITY_BOUNDS
41
end if
42
43
PathSwap_Frame = Object.Timer
44
PathSwap_Frame /= 5
45
end if
46
47
if PathSwap_Flag == false
48
TempValue0 = Object.ChunkIDOld
49
else
50
TempValue0 = Object.ChunkIDNew
51
end if
52
53
if Object.PropertyValue != 1
54
SetTileLayerEntry(TempValue0, 0, Object.ChunkX1, Object.ChunkY1)
55
TempValue0++
56
SetTileLayerEntry(TempValue0, 0, Object.ChunkX2, Object.ChunkY1)
57
TempValue0++
58
SetTileLayerEntry(TempValue0, 0, Object.ChunkX1, Object.ChunkY2)
59
TempValue0++
60
SetTileLayerEntry(TempValue0, 0, Object.ChunkX2, Object.ChunkY2)
61
end if
62
63
end sub
64
65
66
sub ObjectPlayerInteraction
67
68
if Object.PropertyValue < 2
69
if Object.State == PATHSWAP_IDLE
70
if PathSwap_Frame == 0
71
PlayerObjectCollision(C_TOUCH, -16, -16, 16, 16)
72
if CheckResult == true
73
if Object.PrevTouch == false
74
Object.State = PATHSWAP_SPINNING
75
Object.Priority = PRIORITY_ACTIVE
76
Object.PrevTouch = true
77
78
// This is a weird way to do it... but sure
79
// A `^= true` would work just as well here too, though you don't see those all too often in CD
80
PathSwap_Flag++
81
PathSwap_Flag &= true
82
83
#platform: Use_Haptics
84
// Give the player a bit of a shake to really convey the feeling that they've hit a sign, y'know?
85
86
HapticEffect(19, 0, 0, 0)
87
#endplatform
88
89
end if
90
else
91
Object.PrevTouch = false
92
end if
93
end if
94
end if
95
end if
96
97
end sub
98
99
100
sub ObjectDraw
101
if Object.PropertyValue < 2
102
DrawSprite(PathSwap_Frame)
103
end if
104
end sub
105
106
107
sub ObjectStartup
108
109
LoadSpriteSheet("R7/Objects.gif")
110
111
// Path Swapper Frames
112
SpriteFrame(-24, -15, 48, 40, 109, 18)
113
SpriteFrame(-24, -11, 48, 36, 158, 22)
114
SpriteFrame(-24, -7, 48, 32, 207, 26)
115
SpriteFrame(-24, -11, 48, 36, 158, 63)
116
SpriteFrame(-24, -15, 48, 40, 109, 59)
117
SpriteFrame(-24, -11, 48, 36, 158, 63)
118
SpriteFrame(-24, -7, 48, 32, 207, 26)
119
SpriteFrame(-24, -11, 48, 36, 158, 22)
120
121
PathSwap_Flag = false
122
PathSwap_Frame = 0
123
124
ArrayPos0 = 32
125
while ArrayPos0 < 1056
126
if Object[ArrayPos0].Type == TypeName[Path Swap]
127
128
// Setup chunk positions
129
130
Object[ArrayPos0].ChunkX1 = Object[ArrayPos0].iXPos
131
Object[ArrayPos0].ChunkX1 >>= 8
132
Object[ArrayPos0].ChunkX1 <<= 1
133
134
Object[ArrayPos0].ChunkX2 = Object[ArrayPos0].ChunkX1
135
Object[ArrayPos0].ChunkX2++
136
137
Object[ArrayPos0].ChunkY1 = Object[ArrayPos0].iYPos
138
Object[ArrayPos0].ChunkY1 >>= 8
139
Object[ArrayPos0].ChunkY1 <<= 1
140
141
Object[ArrayPos0].ChunkY2 = Object[ArrayPos0].ChunkY1
142
Object[ArrayPos0].ChunkY2++
143
144
// Setup chunk IDs
145
146
// Get the base chunk ID
147
GetTileLayerEntry(Object[ArrayPos0].ChunkIDOld, 0, Object[ArrayPos0].ChunkX1, Object[ArrayPos0].ChunkY1)
148
149
// The chunk's B replacement is always 4 chunks immediately after it
150
Object[ArrayPos0].ChunkIDNew = Object[ArrayPos0].ChunkIDOld
151
Object[ArrayPos0].ChunkIDNew += 4
152
153
end if
154
155
ArrayPos0++
156
loop
157
158
end sub
159
160
161
// ========================
162
// Editor Subs
163
// ========================
164
165
sub RSDKEdit
166
if Editor.ReturnVariable == true
167
switch Editor.VariableID
168
case EDIT_VAR_PROPVAL // Property Value
169
case 0 // Type
170
CheckResult = Object.PropertyValue
171
break
172
end switch
173
else
174
switch Editor.VariableID
175
case EDIT_VAR_PROPVAL // Property Value
176
case 0 // Type
177
Object.PropertyValue = Editor.VariableValue
178
break
179
end switch
180
end if
181
end sub
182
183
184
sub RSDKDraw
185
GetBit(Object.InkEffect, Object.PropertyValue, 1) // Invis types get to be blended
186
DrawSpriteFX(0, FX_INK, Object.XPos, Object.YPos)
187
end sub
188
189
190
sub RSDKLoad
191
LoadSpriteSheet("R7/Objects.gif")
192
SpriteFrame(-24, -15, 48, 40, 109, 18)
193
194
AddEditorVariable("Type")
195
SetActiveVariable("Type")
196
197
// Bit of a guess here -
198
// Subtype 0 is used just about everywhere, 2 is used in SSZ1B once, and then 2 is completely unused it seems?
199
200
AddEnumVariable("Normal", 0)
201
AddEnumVariable("Decoration", 1)
202
AddEnumVariable("Invisible", 2) // Used to update chunks but without the sign being visible there
203
end sub
204
205