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/LZ/PushButton.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Push Button 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.value0 : object.stood
13
14
// Player Aliases
15
private alias object.ypos : player.ypos
16
private alias object.yvel : player.yvel
17
private alias object.gravity : player.gravity
18
private alias object.collisionBottom : player.collisionBottom
19
20
21
// ========================
22
// Function Declarations
23
// ========================
24
25
reserve function PushButton_DebugDraw
26
reserve function PushButton_DebugSpawn
27
28
29
// ========================
30
// Function Definitions
31
// ========================
32
33
private function PushButton_DebugDraw
34
DrawSprite(0)
35
end function
36
37
38
private function PushButton_DebugSpawn
39
CreateTempObject(TypeName[Push Button], 0, object.xpos, object.ypos)
40
end function
41
42
43
// ========================
44
// Events
45
// ========================
46
47
event ObjectUpdate
48
object.stood = false
49
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
50
if object.frame == 0
51
BoxCollisionTest(C_SOLID, object.entityPos, -14, -4, 14, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
52
if checkResult == COL_TOP
53
object.stood = true
54
player[currentPlayer].ypos += 400000
55
PlaySfx(SfxName[Button Press], false)
56
57
switch object.propertyValue
58
default
59
case 0 // Generic, up to the other [+1] object to change
60
break
61
62
case 1 // Open LZ3 Path
63
// Uses hardcoded tile positions :(
64
GetTileLayerEntry(temp0, 0, 12, 5)
65
if temp0 == 302
66
PlaySfx(SfxName[Large Wall], false)
67
SetTileLayerEntry(30, 0, 12, 5)
68
SetTileLayerEntry(31, 0, 13, 5)
69
end if
70
break
71
72
case 2 // Unused
73
break
74
75
case 3 // Set Belt Dir
76
LZSetup_beltdirection = FACING_LEFT
77
break
78
79
end switch
80
end if
81
else
82
if player[currentPlayer].yvel >= 0
83
BoxCollisionTest(C_PLATFORM, object.entityPos, -14, -4, 14, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
84
if checkResult == true
85
object.stood = true
86
player[currentPlayer].ypos += 0x20000
87
else
88
BoxCollisionTest(C_TOUCH, object.entityPos, -20, -12, 20, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
89
if checkResult == true
90
player[currentPlayer].ypos = player[currentPlayer].collisionBottom
91
FlipSign(player[currentPlayer].ypos)
92
player[currentPlayer].ypos <<= 16
93
player[currentPlayer].ypos += object.ypos
94
player[currentPlayer].ypos -= 0x20000
95
player[currentPlayer].gravity = GRAVITY_AIR
96
end if
97
end if
98
end if
99
end if
100
next
101
102
foreach (TypeName[Push Block], arrayPos0, ACTIVE_ENTITIES)
103
BoxCollisionTest(C_TOUCH, object.entityPos, -16, -12, 16, 8, arrayPos0, -16, -16, 16, 16)
104
if checkResult == true
105
// I think this is a leftover from MZ/SYZ, this should probably set object.stood instead of object.propertyValue (which was object.stood in MZ/SYZ)
106
object.propertyValue = 1
107
if object.frame == 0
108
PlaySfx(SfxName[Button Press], false)
109
end if
110
end if
111
next
112
end event
113
114
115
event ObjectDraw
116
object.frame = object.stood
117
DrawSprite(object.frame)
118
end event
119
120
121
event ObjectStartup
122
LoadSpriteSheet("LZ/Objects.gif")
123
SpriteFrame(-16, -8, 32, 16, 1, 84)
124
SpriteFrame(-16, -4, 32, 12, 85, 160)
125
126
SetTableValue(TypeName[Push Button], DebugMode_ObjCount, DebugMode_TypesTable)
127
SetTableValue(PushButton_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
128
SetTableValue(PushButton_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
129
DebugMode_ObjCount++
130
end event
131
132
133
// ========================
134
// Editor Events
135
// ========================
136
137
event RSDKEdit
138
if editor.returnVariable == true
139
switch editor.variableID
140
case EDIT_VAR_PROPVAL // property value
141
checkResult = object.propertyValue
142
checkResult &= 3
143
break
144
145
case 0 // type
146
checkResult = object.propertyValue
147
checkResult &= 3
148
break
149
150
end switch
151
else
152
switch editor.variableID
153
case EDIT_VAR_PROPVAL // property value
154
object.propertyValue = editor.variableValue
155
object.propertyValue &= 3
156
break
157
158
case 0 // type
159
object.propertyValue = editor.variableValue
160
object.propertyValue &= 3
161
break
162
163
end switch
164
end if
165
end event
166
167
168
event RSDKDraw
169
DrawSprite(0)
170
end event
171
172
173
event RSDKLoad
174
LoadSpriteSheet("LZ/Objects.gif")
175
SpriteFrame(-16, -8, 32, 16, 1, 84)
176
177
AddEditorVariable("type")
178
SetActiveVariable("type")
179
AddEnumVariable("Generic", 0)
180
AddEnumVariable("Open LZ3 Path", 1)
181
// AddEnumVariable("unused?", 2) // as far as I know this does nothing special so... (it's placed in LZ3 once but it acts the same as prop val 0)
182
AddEnumVariable("Swap Belt Platform Dir", 3)
183
end event
184
185