Path: blob/master/Sonic 1/Scripts/Global/Ring.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Ring Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.propertyValue : object.isGHZAchievement1213private alias object.value1 : object.targetPlayer1415private alias 0 : RING_NORMAL16private alias 1 : RING_ATTRACT1718// Player aliases19private alias object.state : player.state20private alias object.animation : player.animation21private alias object.value0 : player.rings22private alias object.value37 : player.shield2324private alias 4 : SHIELD_LIGHTNING2526// Game Mode Aliases27private alias 2 : MODE_TIMEATTACK2829// Music Events30private alias 25 : SLOT_MUSICEVENT_CHANGE3132private alias 2 : MUSICEVENT_TRANSITION3334// Achievement Aliases35private alias 0 : ACHIEVEMENT_RAMPRINGACRO36private alias 4 : ACHIEVEMENT_RINGKING373839// ========================40// Function Declarations41// ========================4243reserve function Ring_DebugDraw44reserve function Ring_DebugSpawn454647// ========================48// Function Declarations49// ========================5051private function Ring_DebugDraw52DrawSprite(0)53end function545556private function Ring_DebugSpawn57CreateTempObject(TypeName[Ring], 0, object.xpos, object.ypos)58object[tempObjectPos].drawOrder = 459end function606162// ========================63// Events64// ========================6566event ObjectUpdate67// Bug Details:68// - The loop doesn't check to see if the ring's been obtained already, so69// if two players touch the ring at the same time, then the ring will count twice70foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)71// Check if the player should be able to collect rings7273// Player 1 can't be hurt...74CheckEqual(player[0].state, Player_State_Hurt)75temp0 = checkResult7677// ...nor can the current player be recoiling either78CheckEqual(player[currentPlayer].state, Player_State_Hurt)79temp0 = checkResult80CheckEqual(player[currentPlayer].state, Player_State_GotHit)81temp0 |= checkResult8283if temp0 == false84BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)85if checkResult == true86// Make the ring disappear87object.type = TypeName[Ring Sparkle]8889// Add to the player's ring count90player[0].rings++9192// Max 999 rings93if player[0].rings > 99994player[0].rings = 99995end if9697// Give the player an extra life if needed98if player[0].rings >= ringExtraLife99if options.gameMode != MODE_TIMEATTACK100#platform: USE_ORIGINS101if game.coinMode == false102player.lives++103else104CallNativeFunction2(NotifyCallback, NOTIFY_ADD_COIN, 1)105end if106#endplatform107#platform: USE_STANDALONE108player.lives++109#endplatform110PlaySfx(SfxName[Life], false)111PauseMusic()112ResetObjectEntity(SLOT_MUSICEVENT_CHANGE, TypeName[Music Event], MUSICEVENT_TRANSITION, 0, 0)113object[SLOT_MUSICEVENT_CHANGE].priority = PRIORITY_ACTIVE114end if115116if stage.debugMode == false117if player[0].rings >= 200118// Grant the "Ring King" Achievement119CallNativeFunction2(SetAchievement, ACHIEVEMENT_RINGKING, 100)120end if121end if122123ringExtraLife += 100124if ringExtraLife > 300125ringExtraLife = 1000126end if127end if128129// Update achievment collection130if object.isGHZAchievement == true131if stage.debugMode == false132if options.attractMode == false133if currentPlayer == 0134if player[0].animation == ANI_JUMPING135achieveRingCount++136if achieveRingCount == 30137// Grant the "Ramp Ring Acrobatics" Achievement138CallNativeFunction2(SetAchievement, ACHIEVEMENT_RAMPRINGACRO, 100)139achieveRingCount = 0140end if141end if142end if143end if144end if145end if146147// Play the ring chime148if ringPan == 0149PlaySfx(SfxName[Ring L], false)150SetSfxAttributes(SfxName[Ring L], -1, -100)151ringPan = 1152else153PlaySfx(SfxName[Ring R], false)154SetSfxAttributes(SfxName[Ring R], -1, 100)155ringPan = 0156end if157else158if object.state == RING_NORMAL159// Does the player have the lightning shield?160if player[currentPlayer].shield == SHIELD_LIGHTNING161// Check if this ring falls within the lightning shield attraction range162BoxCollisionTest(C_TOUCH, object.entityPos, -64, -64, 64, 64, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)163if checkResult == true164object.state = RING_ATTRACT165object.targetPlayer = currentPlayer166end if167end if168end if169end if170end if171next172173if object.state == RING_ATTRACT174// Check if the player's lost their lightning shield175arrayPos0 = object.targetPlayer176if player[arrayPos0].shield != SHIELD_LIGHTNING177// Make the ring fall to the ground178object.type = TypeName[Lose Ring]179object.animationSpeed = 128180object.alpha = 256181182else183// Move to the player184arrayPos0 = object.targetPlayer185if object.xpos > object[arrayPos0].xpos186if object.xvel > 0187object.xvel -= 0xC000188else189object.xvel -= 0x3000190end if191else192if object.xvel < 0193object.xvel += 0xC000194else195object.xvel += 0x3000196end if197end if198199if object.ypos > object[arrayPos0].ypos200if object.yvel > 0201object.yvel -= 0xC000202else203object.yvel -= 0x3000204end if205else206if object.yvel < 0207object.yvel += 0xC000208else209object.yvel += 0x3000210end if211end if212213object.xpos += object.xvel214object.ypos += object.yvel215end if216end if217end event218219220event ObjectDraw221DrawSprite(ringFrame)222end event223224225event ObjectStartup226LoadSpriteSheet("Global/Items.gif")227228// (Doesn't mean much, but this is one of the few times in v4 scripts that extra code is between LoadSpriteSheet and SpriteFrames)229foreach (TypeName[Ring], arrayPos0, ALL_ENTITIES)230object[arrayPos0].drawOrder = 4231next232233// Reset the achievment value234achieveRingCount = 0235236// Ring frames237SpriteFrame(-8, -8, 16, 16, 1, 1)238SpriteFrame(-8, -8, 16, 16, 1, 18)239SpriteFrame(-8, -8, 16, 16, 1, 35)240SpriteFrame(-8, -8, 16, 16, 1, 52)241SpriteFrame(-8, -8, 16, 16, 1, 69)242SpriteFrame(-8, -8, 16, 16, 1, 86)243SpriteFrame(-8, -8, 16, 16, 1, 103)244SpriteFrame(-8, -8, 16, 16, 1, 120)245246// Add the ring to the stage's debug mode list247SetTableValue(TypeName[Ring], DebugMode_ObjCount, DebugMode_TypesTable)248SetTableValue(Ring_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)249SetTableValue(Ring_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)250DebugMode_ObjCount++251end event252253254// ========================255// Editor Events256// ========================257258event RSDKEdit259if editor.returnVariable == true260switch editor.variableID261case EDIT_VAR_PROPVAL // property value262checkResult = object.propertyValue263break264265case 0 // achievementType266checkResult = object.propertyValue267break268269end switch270else271switch editor.variableID272case EDIT_VAR_PROPVAL // property value273object.propertyValue = editor.variableValue274break275276case 0 // achievementType277object.propertyValue = editor.variableValue278break279280end switch281end if282end event283284285event RSDKDraw286DrawSprite(0)287end event288289290event RSDKLoad291LoadSpriteSheet("Global/Items.gif")292SpriteFrame(-8, -8, 16, 16, 1, 1)293294AddEditorVariable("achievementType")295SetActiveVariable("achievementType")296AddEnumVariable("None", 0)297AddEnumVariable("GHZ Achievement", 1)298end event299300301