Sonic 1/Sonic 2 Save System Script
Sonic 1/Sonic 2 Save System Script
//-------Aliases-------//
private alias object.value0 : [Link]
private alias object.value1 : [Link]
private alias object.value3 : swoopin
private alias object.value4 : [Link]
public alias 12 : [Link]
//Saveslot 0 0-7
//Saveslot 1 8-15
//Saveslot 2 16-23
//Saveslot 3 24-31
//Saveslot 4 32 - 39
//Saveslot 5 40 - 47
// Function declarations
reserve function save_fadein
reserve function save_slotselect
reserve function save_stageselect
reserve function save_charaselect
reserve function save_loadsave
reserve function save_loadspecial
reserve function save_loadcomplete
reserve function save_loadnew
reserve function save_exit
reserve function nosave_highlight
reserve function nosave_charaselect
reserve function nosave_load
reserve function delete_highlight
reserve function delete_slotselect
reserve function delete_confirm
reserve function delete_execute
reserve function PlayRingSound
reserve function SlotTouch
// Static Values
public value [Link] = 0;
public value [Link] = 0;
public value [Link] = 0;
public value DeleteYesNo = 0;
public value [Link] = 0;
public value [Link] = 0;
public value [Link] = 0;
public value [Link] = 0;
public value [Link] = 0;
//Tables
function SlotTouch
if [Link] == 1
if [Link] < 20
[Link]++
else
checkResult = -1
foreach (TypeName[Save Slot], arrayPos0, ALL_ENTITIES)
if checkResult == -1
//find the slot on screen
temp0 = object[arrayPos0].ixpos
temp0 -= [Link]
temp2 = temp0
temp2 -= 45
if temp2 < 0
temp2 = 0
end if
temp0 += 45
if temp0 > [Link]
temp0 = [Link]
end if
if [Link] == object[arrayPos0].propertyValue
if [Link] == save_slotselect
if temp2 < [Link]
if temp0 > 0
CheckTouchRect(temp2, 62,
temp0, 180)
if checkResult > -1
[Link] = 0
[Link] = 1
end if
end if
end if
else
if [Link] == save_stageselect
if temp2 < [Link]
if temp0 > 0
temp3 = temp2
temp3 += 45
CheckTouchRect(temp3,
110, temp0, 160)
if checkResult > -1
[Link] = 0
[Link] =
1
else
[Link] = 1
end if
end if
end if
end if
else
if [Link] == save_charaselect
if temp2 < [Link]
if temp0 > 0
[Link] = 1
else
[Link] = 0
[Link] = 1
end if
end if
end if
end if
else
if [Link] ==
delete_confirm
temp3 =
object[arrayPos0].ixpos
temp3 -= [Link]
CheckTouchRect(temp2,
62, temp3, 180)
if checkResult > -1
[Link] = 0
if DeleteYesNo ==
1
CallFunction(delete_execute)
[Link]
= save_slotselect
else
DeleteYesNo
= 1
end if
else
[Link] = 0
[Link] = save_slotselect
PlaySfx(SfxName[Score Add], 0)
[Link] = object[arrayPos0].propertyValue
end if
end if
end if
end if
end if
end if
end if
end if
else
if temp2 < [Link]
if temp0 > 0
CheckTouchRect(temp2, 62, temp0,
180)
if checkResult > -1
[Link] = 0
[Link] =
save_slotselect
PlaySfx(SfxName[Score Add],
0)
[Link] =
object[arrayPos0].propertyValue
end if
end if
end if
end if
end if
next
if checkResult == -1
temp0 = [Link]
temp0 -= 59
temp1 = temp0
temp1 += 44
CheckTouchRect(temp0, 185, temp1, 240)
if checkResult > -1
[Link] = 1
[Link] = 0
end if
end if
if checkResult == -1
temp0 = [Link]
temp0 -= 134
temp1 = temp0
temp1 += 64
CheckTouchRect(temp0, 185, temp1, 240)
if checkResult > -1
[Link] = 0
if [Link] != nosave_charaselect
[Link] = nosave_charaselect
else
[Link] = 1
end if
else
if [Link] == nosave_charaselect
temp0 -= 70
temp1 -= 70
CheckTouchRect(temp0, 185, temp1, 240)
if checkResult > -1
[Link] = 1
end if
end if
end if
end if
if checkResult == -1
CheckTouchRect(0, 0, [Link], 40)
if checkResult > -1
[Link] = 0
[Link] = save_exit
end if
end if
end if
else
[Link] = 1000
end if
end function
function save_fadein
if [Link] == 0
[Link] = 384
end if
SetScreenFade(0, 0, 0, [Link])
[Link] -= 16
if [Link] <= 0
PlayMusic(1)
[Link] = 0
[Link] = save_slotselect
end if
end function
function save_slotselect
CallFunction(SlotTouch)
if [Link] == 1
[Link]--
PlaySfx(SfxName[Score Add], 0)
while [Link] < 0
[Link] += [Link]
loop
else
if [Link] == 1
[Link]++
PlaySfx(SfxName[Score Add], 0)
[Link] %= [Link]
end if
end if
if [Link] == 1
[Link] = save_exit
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
arrayPos0 = [Link]
arrayPos0 <<= 3
arrayPos0 += 1000
arrayPos1 = arrayPos0
arrayPos1 += 4
switch saveRAM[arrayPos1]
case 0//New Save
CallFunction(PlayRingSound)
[Link] = save_charaselect
[Link] = 0
[Link] = 0
[Link] = 0
[Link] = 0
break
case 20 //Complete Save
CallFunction(PlayRingSound)
[Link] = save_stageselect
break
default
if saveRAM[arrayPos1] > 127
[Link] = save_loadspecial
PlaySfx(SfxName[Warp], 0)
else
[Link] = save_loadsave
CallFunction(PlayRingSound)
end if
break
end switch
else
if [Link] == 1
PlaySfx(SfxName[Score Add], 0)
[Link] = nosave_highlight
else
if [Link] == 1
foreach (TypeName[Save Slot], arrayPos0,
ALL_ENTITIES)
if object[arrayPos0].propertyValue ==
[Link]
if object[arrayPos0].value0 == 0
[Link] = delete_confirm
CallFunction(PlayRingSound)
else
PlaySfx(SfxName[Bonus Points], 0)
end if
end if
next
end if
end if
end if
end if
end function
function save_stageselect
CallFunction(SlotTouch)
if [Link] == 1
[Link] = save_slotselect
else
if [Link] == 1
[Link]--
PlaySfx(SfxName[Score Add], 0)
while [Link] < 0
[Link] += 7
loop
else
if [Link] == 1
[Link]++
PlaySfx(SfxName[Score Add], 0)
[Link] %= 7
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
CallFunction(PlayRingSound)
[Link] = save_loadcomplete
end if
end if
end if
end if
end function
function save_charaselect
CallFunction(SlotTouch)
temp3 = 5
temp3 += saveRAM[412]
if [Link] == 1
[Link] = save_slotselect
else
if [Link] == 1
[Link]--
PlaySfx(SfxName[Score Add], 0)
while [Link] < 0
[Link] += temp3
loop
[Link] = 0
[Link] = 0
[Link] = 0
[Link] = 0
else
if [Link] == 1
[Link]++
PlaySfx(SfxName[Score Add], 0)
[Link] %= temp3
[Link] = 0
[Link] = 0
[Link] = 0
[Link] = 0
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
CallFunction(PlayRingSound)
[Link] = save_loadnew
end if
end if
end if
end if
end function
function save_loadsave
[Link] += 16
[Link] -= 2
SetScreenFade(0, 0, 0, [Link])
if [Link] >= 384
StopMusic()
[Link] = 1
[Link] = [Link]
[Link] = 0
lampPostID = 0
arrayPos0 = [Link]
arrayPos0 <<= 3
arrayPos0 += 1000
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
[Link]--
[Link] = REGULAR_STAGE
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
LoadStage()
end if
end function
function save_loadspecial
[Link] += 8
[Link] -= 2
SetScreenFade(color5, color7, color5, [Link])
if [Link] >= 384
StopMusic()
[Link] = 1
[Link] = [Link]
[Link] = 0
lampPostID = 0
arrayPos0 = [Link]
arrayPos0 <<= 3
arrayPos0 += 1000
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
temp0 = saveRAM[arrayPos1]
temp0 -= 129
[Link] = temp0
[Link] = SPECIAL_STAGE
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
[Link] = [Link]
LoadPalette("[Link]",0,0,0,128)
LoadStage()
end if
end function
function save_loadcomplete
[Link] += 16
[Link] -= 2
SetScreenFade(0, 0, 0, [Link])
if [Link] >= 384
StopMusic()
[Link] = 1
[Link] = [Link]
[Link] = 0
lampPostID = 0
arrayPos0 = [Link]
arrayPos0 <<= 3
arrayPos0 += 1000
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = 0
arrayPos0++
[Link] = 50000
arrayPos0++
[Link] = [Link]
[Link] *= 3
[Link] = REGULAR_STAGE
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
LoadStage()
end if
end function
function save_loadnew
[Link] += 16
[Link] -= 2
SetScreenFade(0, 0, 0, [Link])
if [Link] >= 384
StopMusic()
[Link] = 1
[Link] = [Link]
[Link] = 0
lampPostID = 0
arrayPos0 = [Link]
arrayPos0 <<= 3
arrayPos0 += 1000
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
[Link]--
[Link] = REGULAR_STAGE
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
arrayPos0++
[Link] = saveRAM[arrayPos0]
LoadStage()
end if
end function
function save_exit
[Link] += 16
[Link] -= 2
SetScreenFade(0, 0, 0, [Link])
if [Link] >= 384
StopMusic()
[Link] = PRESENTATION_STAGE
[Link] = 6
LoadStage()
end if
end function
function nosave_highlight
if [Link] == 1
[Link] = save_exit
else
if [Link] == 1
PlaySfx(SfxName[Score Add], 0)
[Link] = delete_highlight
else
if [Link] == 1
PlaySfx(SfxName[Score Add], 0)
[Link] = save_slotselect
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
CallFunction(PlayRingSound)
[Link] = nosave_charaselect
end if
end if
end if
end if
end function
function nosave_charaselect
CallFunction(SlotTouch)
temp3 = 5
temp3 += saveRAM[412]
if [Link] == 1
[Link] = nosave_highlight
else
if [Link] == 1
[Link]--
PlaySfx(SfxName[Score Add], 0)
while [Link] < 0
[Link] += temp3
loop
else
if [Link] == 1
[Link]++
PlaySfx(SfxName[Score Add], 0)
[Link] %= temp3
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
CallFunction(PlayRingSound)
[Link] = nosave_load
end if
end if
end if
end if
end function
function nosave_load
[Link] += 16
[Link] -= 2
SetScreenFade(0, 0, 0, [Link])
if [Link] >= 384
StopMusic()
[Link] = 0
[Link] = 0
lampPostID = 0
switch [Link]
case 0 //Sonic
[Link] = 0
break
case 1 //Tails
[Link] = 1
break
case 2 //Knuckles
[Link] = 2
break
case 3 //Amy
[Link] = 5
break
case 4 //Sonic and Tails
[Link] = 3
break
case 5 //Knuckles and Tails
[Link] = 4
break
end switch
[Link] = 3
[Link] = 0
[Link] = 50000
[Link] = 0
[Link] = REGULAR_STAGE
[Link] = 0
[Link] = 0
[Link] = 0
LoadStage()
end if
end function
function delete_highlight
if [Link] == 1
[Link] = save_exit
else
if [Link] == 1
PlaySfx(SfxName[Score Add], 0)
[Link] = nosave_highlight
else
if [Link] == 1
PlaySfx(SfxName[Score Add], 0)
[Link] = save_slotselect
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
CallFunction(PlayRingSound)
[Link] = delete_slotselect
end if
end if
end if
end if
end function
function delete_slotselect
if [Link] == 1
[Link]--
PlaySfx(SfxName[Score Add], 0)
while [Link] < 0
[Link] += [Link]
loop
else
if [Link] == 1
[Link]++
PlaySfx(SfxName[Score Add], 0)
[Link] %= [Link]
end if
end if
if [Link] == 1
[Link] = save_slotselect
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
foreach (TypeName[Save Slot], arrayPos0, ALL_ENTITIES)
if object[arrayPos0].propertyValue == [Link]
if object[arrayPos0].value0 == 0
[Link] = delete_confirm
CallFunction(PlayRingSound)
else
PlaySfx(SfxName[Bonus Points], 0)
end if
end if
next
end if
end if
end function
function delete_confirm
CallFunction(SlotTouch)
if [Link] == 1
[Link] = save_slotselect
DeleteYesNo = 0
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
DeleteYesNo ^= 1
else
temp0 = [Link]
temp0 |= [Link]
if temp0 == 1
if DeleteYesNo == 1
CallFunction(delete_execute)
end if
[Link] = save_slotselect
end if
end if
end if
end function
function delete_execute
arrayPos0 = [Link]
arrayPos0 <<= 3
arrayPos0 += 1000
temp1 = 0
while temp1 < 8
saveRAM[arrayPos0] = 0
arrayPos0++
temp1++
loop
PlaySfx(SfxName[Lose Rings], 0)
DeleteYesNo = 0
WriteSaveRAM()
end function
event ObjectMain
[Link]++
[Link] %= 60
CallFunction([Link])
if swoopin == 0
if [Link] < 0
[Link] += 40
if [Link] > 0
[Link] = 0
swoopin = 1
end if
end if
end if
end event
event ObjectDraw
//Draw Background
temp0 = 0
temp1 = 0
while temp0 < [Link]
while temp1 < [Link]
DrawSpriteScreenXY(0, temp0, temp1)
temp1 += 12
loop
temp1 = 0
temp0 += 12
loop
//Header
DrawRect(0, 0, [Link], 40, color5, color5, color7, 255)
DrawRect(0, 40, [Link], 10, 0, 0, 0, 255)
DrawRect(0, 45, [Link], 1, color7, color7, color7, 255)
DrawSpriteScreenXY(1, 0, 0)
DrawSpriteScreenXY(2, [Link], 16)
if [Link] == 1
DrawSpriteScreenXY(17, 0, 10)
end if
//Footer
DrawRect(0, 196, [Link], 44, 0, 0, 0, 255)
DrawRect(0, 198, [Link], 1, color7, 0, 0, 255)
DrawRect(0, 199, [Link], 1, color7, color7, color7, 255)
DrawRect(0, 238, [Link], 1, color7, color7, color7, 255)
DrawRect(0, 239, [Link], 1, color7, 0, 0, 255)
//No Save
temp3 = 0
temp0 = [Link]
temp0 -= 135
DrawSpriteScreenXY(3, temp0, [Link])
if [Link] == nosave_highlight
DrawSpriteScreenXY(4, temp0, [Link])
DrawSpriteScreenXY(5, temp0, [Link])
else
CheckEqual([Link], nosave_charaselect)
temp2 = checkResult
temp3 = checkResult
CheckEqual([Link], nosave_load)
temp2 |= checkResult
if temp2 == 1
temp1 = [Link]
temp1 += 6
DrawSpriteScreenXY(temp1, temp0, [Link])
DrawSpriteScreenXY(5, temp0, [Link])
if temp3 == 1
if [Link] < 30
DrawSpriteScreenXY(12, temp0, [Link])
end if
end if
end if
end if
temp3 &= [Link]
if temp3 == 1
if [Link] < 50
[Link] += 8
if [Link] >= 50
[Link] = 50
end if
end if
else
if [Link] > 0
[Link] -= 8
if [Link] <= 0
[Link] = 0
end if
end if
end if
temp0 -= 50
temp4 = [Link]
temp4 += 20
temp4 -= [Link]
DrawSpriteScreenXY(18, temp0, temp4)
//Delete
temp0 = [Link]
temp0 -= 60
DrawSpriteScreenXY(14, temp0, [Link])
CheckEqual([Link], delete_highlight)
temp2 = checkResult
CheckEqual([Link], delete_slotselect)
temp2 |= checkResult
CheckEqual([Link], delete_confirm)
temp2 |= checkResult
if temp2 == 1
DrawSpriteScreenXY(15, temp0, [Link])
DrawSpriteScreenXY(16, temp0, [Link])
end if
end event
event ObjectStartup
ReadSaveRAM()
LoadPalette("[Link]", 0, 0, 0, 256)
LoadSpriteSheet("Menus/[Link]")
//No Save
switch [Link]
case 0
SpriteFrame(0, -55, 66, 55, 1, 261) //3 No Save Frame
SpriteFrame(13, -44, 38, 26, 1, 372) //4 Red X
SpriteFrame(6, -13, 53, 11, 166, 261) //5 No Save Text
break
case 1
SpriteFrame(-14, -55, 85, 55, 182, 178) //3 No Save Frame
SpriteFrame(13, -44, 38, 26, 1, 372) //4 Red X
SpriteFrame(-3, -11, 71, 7, 166, 285) //5 No Save Text
break
case 2
SpriteFrame(-14, -55, 85, 55, 268, 178) //3 No Save Frame
SpriteFrame(13, -44, 38, 26, 1, 372) //4 Red X
SpriteFrame(-3, -11, 71, 7, 166, 301) //5 No Save Text
break
end switch
SpriteFrame(13, -44, 38, 26, 1, 344) //6 Sonic
SpriteFrame(13, -44, 38, 26, 40, 344) //7 Tails
SpriteFrame(13, -44, 38, 26, 79, 344) //8 Knuckles
SpriteFrame(13, -44, 38, 26, 196, 344) //9 Amy
SpriteFrame(13, -44, 38, 26, 118, 344) //10 Sonic and Tails
SpriteFrame(13, -44, 38, 26, 157, 344) //11 Knuckles and Tails
switch [Link]
case 0
SpriteFrame(7, -46, 50, 28, 115, 261) //12 Select Arrow
break
case 1
SpriteFrame(7, -46, 50, 28, 115, 261) //12 Select Arrow
break
case 2
SpriteFrame(7, -46, 50, 28, 115, 261) //12 Select Arrow
break
endswitch
SpriteFrame(13, -44, 38, 26, 1, 317) //13 Soink
//Delete
switch [Link]
case 0
SpriteFrame(0, -55, 46, 55, 68, 261) //14 Frame
SpriteFrame(12, -44, 24, 26, 40, 317) //15 Robotnik
SpriteFrame(1, -13, 44, 11, 166, 273) //16 Delete Text
break
case 1
SpriteFrame(0, -55, 46, 55, 238, 234) //14 Frame
SpriteFrame(12, -44, 24, 26, 40, 317) //15 Robotnik
SpriteFrame(2, -11, 42, 7, 166, 293) //16 Delete Text
break
case 2
SpriteFrame(0, -55, 46, 55, 285, 234) //14 Frame
SpriteFrame(12, -44, 24, 26, 40, 317) //15 Robotnik
SpriteFrame(3, -11, 40, 7, 166, 309) //16 Delete Text
break
end switch
[Link] = 1
SetMusicTrack("[Link]", 1, 92561)
function PlayRingSound
if ringPan == 0
PlaySfx(SfxName[Ring L], 0)
SetSfxAttributes(SfxName[Ring L], -1, -100)
ringPan = 1
else
PlaySfx(SfxName[Ring R], 0)
SetSfxAttributes(SfxName[Ring R], -1, 100)
ringPan = 0
end if
end function
event RSDKDraw
DrawSprite(0)
end event
event RSDKLoad
LoadSpriteSheet("Global/[Link]")
SpriteFrame(-16, -16, 32, 32, 1, 143)
end event