Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/BGSwapper.txt
1319 views
1
//-----------------Sonic CD BG Swapper Script-----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// ========================
6
// Aliases
7
// ========================
8
9
// Layer Aliases, correspond to BG layers in the scene file
10
#alias 1 : LAYER_INSIDE
11
#alias 2 : LAYER_OUTSIDE
12
13
14
// ========================
15
// Events
16
// ========================
17
18
sub ObjectDraw
19
if Object.PropertyValue == 0
20
// Inside to the left of the BG Swapper object, outside to the right
21
22
if Player.XPos > Object.XPos
23
Stage.ActiveLayer[0] = LAYER_OUTSIDE
24
else
25
Stage.ActiveLayer[0] = LAYER_INSIDE
26
end if
27
else
28
// Outside to the left of the BG Swapper object, inside to the right
29
30
if Player.XPos > Object.XPos
31
Stage.ActiveLayer[0] = LAYER_INSIDE
32
else
33
Stage.ActiveLayer[0] = LAYER_OUTSIDE
34
end if
35
end if
36
end sub
37
38
39
sub ObjectStartup
40
// In this setup, we're gonna find what the initial BG should be when starting the level
41
// This is based on seeing what BG Swapper checkpoints the player spawns between
42
43
// TempValue0 is iXPos of first BG Swapper
44
// (Default of 64 chunks in)
45
// TempValue1 is iXPos of last BG Swapper
46
// (Default of level's start itself)
47
TempValue0 = 0x4000
48
TempValue1 = 0
49
50
// (We can use iXPos because the last few bytes of the BG Swapper's position aren't important)
51
52
// Cycle throuh all BG Swapper Objects in the level
53
ArrayPos0 = 32
54
while ArrayPos0 < 1056
55
if Object[ArrayPos0].Type == TypeName[BG Swapper]
56
if Object[ArrayPos0].iXPos < TempValue0
57
TempValue0 = Object[ArrayPos0].iXPos
58
end if
59
60
if Object[ArrayPos0].iXPos > TempValue1
61
TempValue1 = Object[ArrayPos0].iXPos
62
end if
63
end if
64
65
ArrayPos0++
66
loop
67
68
// Get the Player's truncated XPos
69
// In this case, we can't use iXPos because Player position is too important to shave the last few bits off of
70
TempValue2 = Player.XPos
71
TempValue2 >>= 16
72
73
// See which BG Swappers the player is inbetween and set the Background accordingly
74
if TempValue2 > TempValue0
75
if TempValue2 > TempValue1
76
Stage.ActiveLayer[0] = LAYER_INSIDE
77
else
78
Stage.ActiveLayer[0] = LAYER_OUTSIDE
79
end if
80
else
81
Stage.ActiveLayer[0] = LAYER_INSIDE
82
end if
83
end sub
84
85
86
// ========================
87
// Editor Subs
88
// ========================
89
90
sub RSDKEdit
91
if Editor.ReturnVariable == true
92
switch Editor.VariableID
93
case EDIT_VAR_PROPVAL // Property Value
94
CheckResult = Object.PropertyValue
95
break
96
97
case 0 // Type
98
CheckResult = Object.PropertyValue
99
break
100
101
end switch
102
else
103
switch Editor.VariableID
104
case EDIT_VAR_PROPVAL // Property Value
105
Object.PropertyValue = Editor.VariableValue
106
break
107
108
case 0 // Type
109
Object.PropertyValue = Editor.VariableValue
110
break
111
112
end switch
113
end if
114
end sub
115
116
117
sub RSDKDraw
118
Editor.DrawingOverlay = true
119
120
// draw a cool little line behind the Trigger icon
121
TempValue0 = Object.YPos
122
TempValue0 -= 0x80000
123
124
DrawRectWorld(Object.XPos, TempValue0, 1, 16, 255, 255, 255, 255)
125
126
Editor.DrawingOverlay = false
127
128
// and then draw the Trigger icon, atop the line
129
DrawSprite(0)
130
end sub
131
132
133
sub RSDKLoad
134
LoadSpriteSheet("Global/Display.gif")
135
SpriteFrame(-8, -8, 16, 16, 173, 67) // "T" (rigger) icon
136
137
AddEditorVariable("Type")
138
SetActiveVariable("Type")
139
AddEnumVariable("Inside on left, Outside on right", 0)
140
AddEnumVariable("Outside on left, Inside on right", 1)
141
end sub
142
143