Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Animals/R7_Rabbit.txt
1319 views
1
//------------------Sonic CD Rabbit 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.Bounces
8
9
// HUD alias
10
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
11
12
// States
13
#alias 0 : RABBIT_HOPRIGHT
14
#alias 1 : RABBIT_HOPLEFT
15
16
// Collision Side Aliases
17
#alias 0 : CSIDE_FLOOR
18
19
// Time Period Aliases
20
#alias 2 : TIME_GOOD_FUTURE
21
22
23
sub ObjectMain
24
25
// Note: As with the other animals, this Rabbit is always running, regardless of the stage's or generator's state
26
// However, it's just set not to draw if it's in a scenario it shouldn't, although it is always being updated all the same
27
28
// Update the Y movement of the Rabbit
29
Object.YPos += Object.YVelocity
30
31
// Apply a gravity of ~0.17 pixels per frame
32
Object.YVelocity += 0x2C00
33
34
switch Object.State
35
case RABBIT_HOPRIGHT
36
37
// Move the Rabbit right at a speed of 1 pixel per frame
38
Object.XPos += 0x10000
39
40
// The Rabbit can only interact with the floor if it's falling at a rate of 4 pixels per frame or more
41
if Object.YVelocity > 0x40000
42
43
// Check to see if the Rabbit's landed
44
ObjectTileCollision(CSIDE_FLOOR, 0, 8, 0)
45
46
if CheckResult == true
47
// If the Rabbit's landed, then bounce it back up again at a rate of 5 px per frame
48
Object.YVelocity = -0x50000
49
50
// Incerase the Bounce count so that the Rabbit will be able to turn around again when needed
51
Object.Bounces++
52
53
if Object.Bounces == 2
54
// If this is the Rabbit's third bounce in this direction, then turn it around
55
56
Object.Bounces = 0
57
58
Object.State = RABBIT_HOPLEFT
59
Object.Direction = FACING_LEFT
60
end if
61
end if
62
end if
63
break
64
65
case RABBIT_HOPLEFT
66
67
// Move the Rabbit left at a 1 pixel per frame rate
68
Object.XPos -= 0x10000
69
70
// The Rabbit's only allowed to bounce when going downards at a rate of 4 pixels per frame or more
71
if Object.YVelocity > 0x40000
72
73
// Check to see if the Rabbit's landed
74
ObjectTileCollision(CSIDE_FLOOR, 0, 8, 0)
75
76
if CheckResult == true
77
// The Rabbit's on the floor, so shoot it up again with a velocity of 5 pixels upwards per frame
78
Object.YVelocity = -0x50000
79
80
// Add to the Bounce count, in order to know when to turn around
81
Object.Bounces++
82
83
if Object.Bounces == 2
84
// The Rabbit should bounce twice, then turn around
85
86
Object.Bounces = 0
87
88
Object.State = RABBIT_HOPRIGHT
89
Object.Direction = FACING_RIGHT
90
end if
91
end if
92
end if
93
break
94
95
end switch
96
97
end sub
98
99
100
sub ObjectDraw
101
102
// Only draw if the stage's generator has been destroyed or we're in the Good Future right now
103
104
if MetalSonic_Destroyed == true
105
if Object.YVelocity < 0
106
DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos)
107
else
108
DrawSpriteFX(1, FX_FLIP, Object.XPos, Object.YPos)
109
end if
110
else
111
if HUD.CurrentTimePeriod == TIME_GOOD_FUTURE
112
if Object.YVelocity < 0
113
DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos)
114
else
115
DrawSpriteFX(1, FX_FLIP, Object.XPos, Object.YPos)
116
end if
117
end if
118
end if
119
120
end sub
121
122
123
sub ObjectStartup
124
LoadSpriteSheet("R7/Objects.gif")
125
126
// Rabbit Frames
127
SpriteFrame(-8, -12, 16, 24, 1, 232)
128
SpriteFrame(-8, -12, 16, 24, 18, 232)
129
130
// Used to be below LoadSpriteSheet, moved here for consistency
131
ArrayPos0 = 32
132
while ArrayPos0 < 1056
133
if Object[ArrayPos0].Type == TypeName[Rabbit]
134
Object[ArrayPos0].YVelocity = -0x50000
135
Object[ArrayPos0].Direction = FACING_RIGHT
136
end if
137
ArrayPos0++
138
loop
139
140
end sub
141
142
143
// ========================
144
// Editor Subs
145
// ========================
146
147
sub RSDKDraw
148
DrawSprite(0)
149
end sub
150
151
152
sub RSDKLoad
153
LoadSpriteSheet("R7/Objects.gif")
154
SpriteFrame(-8, -12, 16, 24, 1, 232)
155
156
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
157
end sub
158
159