Path: blob/master/Sonic 2/Scripts/Enemies/Coconuts.txt
1479 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Coconuts Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.targetDelay13private alias object.value2 : object.throwID14private alias object.value3 : object.startPos.x15private alias object.value4 : object.startPos.y16private alias object.value5 : object.targetPlayer17private alias object.value6 : object.unused18private alias object.value7 : object.targetDistance1920// States21private alias 0 : COCONUTS_AWAITPLAYER22private alias 1 : COCONUTS_MOVING23private alias 2 : COCONUTS_THROW24private alias 3 : COCONUTS_HASTHROWN2526// Player Aliases27private alias object.xpos : player.xpos28private alias object.value38 : player.hitboxLeft29private alias object.value39 : player.hitboxRight30private alias object.value40 : player.hitboxTop31private alias object.value41 : player.hitboxBottom323334// ========================35// Function Declarations36// ========================3738reserve function Coconuts_DebugDraw39reserve function Coconuts_DebugSpawn404142// ========================43// Tables44// ========================4546private table Coconuts_throwDelays4732, 24, 16, 40, 32, 1648end table495051// ========================52// Function Definitions53// ========================5455private function Coconuts_DebugDraw56DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)57end function585960private function Coconuts_DebugSpawn61CreateTempObject(TypeName[Coconuts], 0, object.xpos, object.ypos)62end function636465// ========================66// Events67// ========================6869event ObjectUpdate70switch object.state71case COCONUTS_AWAITPLAYER72object.priority = PRIORITY_ACTIVE73object.targetDistance = 0x7FFFFFFF74object.targetPlayer = 075object.unused = 0xFFFF76foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)77temp0 = player[currentPlayer].xpos78temp0 -= object.xpos79if temp0 < 080temp1 = FLIP_NONE81FlipSign(temp0)82else83temp1 = FLIP_X84end if8586if temp0 < object.targetDistance87object.targetDistance = temp088object.targetPlayer = currentPlayer89object.direction = temp190end if91next9293temp0 = false94if object.targetDelay == 095if object.targetDistance > -0x60000096if object.targetDistance < 0x60000097object.timer = 898object.targetDelay = 3299object.frame = 1100object.state = COCONUTS_THROW101temp0 = true102end if103end if104else105object.targetDelay--106end if107108if temp0 == false109object.timer--110if object.timer < 0111GetBit(temp0, object.throwID, 0)112if temp0 == false113object.yvel = -0x10000114else115object.yvel = 0x10000116end if117118GetTableValue(object.timer, object.throwID, Coconuts_throwDelays)119120object.throwID++121if object.throwID > 5122object.throwID = 0123end if124125object.state = COCONUTS_MOVING126end if127end if128break129130case COCONUTS_MOVING131object.animationTimer++132if object.animationTimer == 6133object.frame = 1134end if135136if object.animationTimer == 12137object.frame = 0138object.animationTimer = 0139end if140141object.ypos += object.yvel142143object.timer--144if object.timer < 0145object.timer = 16146object.state = COCONUTS_AWAITPLAYER147end if148break149150case COCONUTS_THROW151object.timer--152if object.timer < 0153CreateTempObject(TypeName[Coconut], 0, object.xpos, object.ypos)154if object.direction == FLIP_NONE155object[tempObjectPos].xpos += 0xB0000156object[tempObjectPos].xvel = -0x10000157else158object[tempObjectPos].xpos -= 0xB0000159object[tempObjectPos].xvel = 0x10000160end if161object[tempObjectPos].ypos -= 0xD0000162object[tempObjectPos].yvel = -0x10000163object[tempObjectPos].direction = object.direction164object[tempObjectPos].priority = PRIORITY_ACTIVE165object.timer = 8166object.frame = 2167object.state = COCONUTS_HASTHROWN168end if169break170171case COCONUTS_HASTHROWN172object.timer--173if object.timer < 0174GetBit(temp0, object.throwID, 0)175if temp0 == false176object.yvel = -0x10000177else178object.yvel = 0x10000179end if180181GetTableValue(object.timer, object.throwID, Coconuts_throwDelays)182object.throwID++183if object.throwID > 5184object.throwID = 0185end if186187object.frame = 0188object.state = COCONUTS_MOVING189end if190break191192end switch193194if object.outOfBounds == true195temp0 = object.xpos196temp1 = object.ypos197object.xpos = object.startPos.x198object.ypos = object.startPos.y199200if object.outOfBounds == true201object.targetDelay = 0202object.timer = 16203object.state = COCONUTS_AWAITPLAYER204object.priority = PRIORITY_BOUNDS205else206object.xpos = temp0207object.ypos = temp1208end if209end if210211foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)212BoxCollisionTest(C_TOUCH, object.entityPos, -12, -16, 12, 16, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)213if checkResult == true214CallFunction(Player_BadnikBreak)215end if216next217end event218219220event ObjectDraw221DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)222end event223224225event ObjectStartup226CheckCurrentStageFolder("Zone01")227if checkResult == true228LoadSpriteSheet("EHZ/Objects.gif")229SpriteFrame(-8, -14, 26, 45, 1, 63)230SpriteFrame(-8, -14, 26, 45, 28, 63)231SpriteFrame(-8, -14, 26, 45, 55, 63)232else233LoadSpriteSheet("MBZ/Objects.gif")234SpriteFrame(-8, -14, 26, 45, 50, 256)235SpriteFrame(-8, -14, 26, 45, 77, 256)236SpriteFrame(-8, -14, 26, 45, 104, 256)237end if238239foreach (TypeName[Coconuts], arrayPos0, ALL_ENTITIES)240object[arrayPos0].startPos.x = object[arrayPos0].xpos241object[arrayPos0].startPos.y = object[arrayPos0].ypos242object[arrayPos0].timer = 16243244// this is a lie, its later set based on what dir the player is in anyway so this doesn't matter much245// that is also a lie sorta, the propertyValues in the scene are like "30" so it was prolly smth related to movement anyway LOL246if object[arrayPos0].propertyValue == 0247object[arrayPos0].direction = FLIP_NONE248else249object[arrayPos0].direction = FLIP_X250end if251next252253SetTableValue(TypeName[Coconuts], DebugMode_ObjCount, DebugMode_TypesTable)254SetTableValue(Coconuts_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)255SetTableValue(Coconuts_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)256DebugMode_ObjCount++257end event258259260// ========================261// Editor Events262// ========================263264event RSDKDraw265DrawSprite(0)266end event267268269event RSDKLoad270CheckCurrentStageFolder("Zone01")271if checkResult == true272LoadSpriteSheet("EHZ/Objects.gif")273SpriteFrame(-8, -14, 26, 45, 1, 63)274else275LoadSpriteSheet("MBZ/Objects.gif")276SpriteFrame(-8, -14, 26, 45, 50, 256)277end if278279// Not "technically" unused, but it doesn't do anything meaningful280SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")281end event282283284