Path: blob/master/Sonic 1/Scripts/Special/PlayerObject.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Player Object Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011public alias 0x100 : GROUP_PLAYERS12public alias 0x101 : GROUP_BLOCKS13public alias arrayPos6 : currentPlayer14public alias arrayPos7 : playerCount1516// Gravity17public alias 0 : GRAVITY_GROUND18public alias 1 : GRAVITY_AIR1920// Priority21public alias 0 : PRIORITY_BOUNDS22public alias 1 : PRIORITY_ACTIVE23public alias 2 : PRIORITY_ALWAYS24public alias 3 : PRIORITY_XBOUNDS25public alias 4 : PRIORITY_XBOUNDS_DESTROY26public alias 5 : PRIORITY_INACTIVE27public alias 6 : PRIORITY_BOUNDS_SMALL28public alias 7 : PRIORITY_ACTIVE_SMALL2930// Control Modes31public alias -1 : CONTROLMODE_NONE32public alias 0 : CONTROLMODE_P133public alias 1 : CONTROLMODE_P234public alias 2 : CONTROLMODE_P335public alias 3 : CONTROLMODE_P43637// Camera Styles38public alias 0 : CAMERASTYLE_FOLLOW39public alias 1 : CAMERASTYLE_EXTENDED40public alias 2 : CAMERASTYLE_EXTENDED_OFFSET_L41public alias 3 : CAMERASTYLE_EXTENDED_OFFSET_R42public alias 4 : CAMERASTYLE_HLOCKED4344// Ink Effects45public alias 0 : INK_NONE46public alias 1 : INK_BLEND47public alias 2 : INK_ALPHA48public alias 3 : INK_ADD49public alias 4 : INK_SUB5051// Flip Directions52public alias 0 : FLIP_NONE53public alias 1 : FLIP_X54public alias 2 : FLIP_Y55public alias 3 : FLIP_XY5657// Collision Sides58public alias 0 : CSIDE_FLOOR59public alias 1 : CSIDE_LWALL60public alias 2 : CSIDE_RWALL61public alias 3 : CSIDE_ROOF6263// Collision Modes64public alias 0 : CMODE_FLOOR65public alias 1 : CMODE_LWALL66public alias 2 : CMODE_ROOF67public alias 3 : CMODE_RWALL6869// Collision Directions70public alias 0 : COL_NONE71public alias 1 : COL_TOP72public alias 2 : COL_LEFT73public alias 3 : COL_RIGHT74public alias 4 : COL_BOTTOM7576// Variables77private alias object.type : player.type78private alias object.groupID : player.groupID // Normally GROUP_PLAYERS, unless in Debug Mode79private alias object.entityPos : player.entityPos // Where the player is on the object list - P1 should be 0, P2 should be 180private alias object.state : player.state81private alias object.priority : player.priority82private alias object.xpos : player.xpos // In total world-space position (0x10000 == 1.0)83private alias object.ypos : player.ypos84private alias object.ixpos : player.ixpos // In screen space position (1 == 1)85private alias object.iypos : player.iypos86private alias object.xvel : player.xvel // Based on world-space87private alias object.yvel : player.yvel88private alias object.speed : player.speed // Also based on world-space89private alias object.rotation : player.rotation90private alias object.direction : player.direction91private alias object.gravity : player.gravity92private alias object.frame : player.frame93private alias object.animation : player.animation94private alias object.animationSpeed : player.animationSpeed95private alias object.drawOrder : player.drawOrder96private alias object.controlMode : player.controlMode // See control mode aliases97private alias object.interaction : player.interaction // Will the object interact with other objects?98private alias object.tileCollisions : player.tileCollisions99100// *Object-wise* input, not to be confused with keyPress and keyDown101private alias object.jumpPress : player.jumpPress102private alias object.jumpHold : player.jumpHold103private alias object.up : player.up104private alias object.down : player.down105private alias object.left : player.left106private alias object.right : player.right107108private alias object.value0 : player.rings109private alias object.value1 : player.timer110private alias object.value2 : player.moveSpeed111private alias object.value3 : player.acceleration112private alias object.value5 : player.rollSpeed113// value6 is unused114private alias object.value7 : player.jumpStrength115private alias object.value8 : player.moveVelocity.x116private alias object.value9 : player.moveVelocity.y117private alias object.value10 : debugMode.currentSelection118private alias object.value11 : player.collisionFlags119private alias object.value12 : player.worldVelocity.x120private alias object.value13 : player.worldVelocity.y121private alias object.value14 : player.rotateBlockTimer122private alias object.value15 : player.upDownBlockTimer123124private alias 0 : SLOT_PLAYER1125126// Player List Pos Aliases127public alias 0 : PLAYER_SONIC_A128public alias 1 : PLAYER_TAILS_A129public alias 2 : PLAYER_KNUCKLES_A130public alias 3 : PLAYER_SONIC_TAILS_A131public alias 4 : PLAYER_KNUCKLES_TAILS_A132public alias 5 : PLAYER_AMY_A133public alias 6 : PLAYER_AMY_TAILS_A134135// TitleCard aliases136private alias 8 : TITLECARD_FADETOTITLE137138139// ========================140// Function Declarations141// ========================142143reserve function Player_ProcessUpdate144reserve function Player_State_Static145reserve function Player_HandleRollAnimSpeed146reserve function Player_State_SS_Roll147reserve function Player_SetupAttractDemo148reserve function Player_HandleGroundCollision149reserve function Player_HandleAirCollision150151152// ========================153// Static Values154// ========================155156public value Player_stageRotation = 0157public value Player_rotateSpeed = 0158public value Player_rotateDir = 0159public value Player_isWinner = 0160public value Player_attractTable = 0161public value Player_attractTablePos = 0162public value Player_attractTableSize = 0163public value Player_attractFrameCount = 0164public value Player_attractDuration = 0165public value Player_playerSlot = 0166167// All these below are unused168private value Player_unusedValue1 = 0169private value Player_unusedValue2 = 0170private value Player_unusedValue3 = 0171private value Player_unusedValue4 = 0172private value Player_unusedValue5 = 0173private value Player_unusedValue6 = 0174private value Player_unusedValue7 = 0175176177// ========================178// Function Definitions179// ========================180181public function Player_SetupAttractDemo182Player_attractTablePos = 2183Player_attractFrameCount = 1184185currentPlayer = 0186while currentPlayer < playerCount187GetTableValue(player[currentPlayer].xpos, 0, Player_attractTable)188GetTableValue(player[currentPlayer].ypos, 1, Player_attractTable)189player[currentPlayer].controlMode = CONTROLMODE_NONE190player[currentPlayer].up = false191player[currentPlayer].down = false192player[currentPlayer].left = false193player[currentPlayer].right = false194player[currentPlayer].jumpPress = false195player[currentPlayer].jumpHold = false196player[currentPlayer].timer = 0197currentPlayer++198loop199200// 0 = SLOT_PLAYER1201camera[0].xpos = player[0].ixpos202camera[0].ypos = player[0].iypos203end function204205206public function Player_ProcessUpdate207if options.attractMode == false208#platform: USE_STANDALONE209if options.touchControls == true210if player.controlMode == CONTROLMODE_P1211// Update virtual stick inputs212CheckTouchRect(0, 96, screen.xcenter, screen.ysize)213if checkResult > -1214arrayPos0 = checkResult215216temp0 = touchscreen[arrayPos0].xpos217temp0 -= saveRAM[39]218219temp1 = touchscreen[arrayPos0].ypos220temp1 -= saveRAM[40]221222ATan2(temp2, temp0, temp1)223224temp2 += 32225temp2 &= 255226temp2 >>= 6227228switch temp2229case 0230keyDown[1].right = true231break232233case 1234keyDown[1].down = true235break236237case 2238keyDown[1].left = true239break240241case 3242keyDown[1].up = true243break244end switch245end if246247// Check if the jump button is touched248CheckTouchRect(screen.xcenter, 96, screen.xsize, 240)249if checkResult > -1250keyDown[1].buttonA = true251end if252253if touchJump == false254// If the jump button only started being touched this frame, then update the press variable accordingly255keyPress[1].buttonA |= keyDown[1].buttonA256end if257258// And now store the current held state for next frame259touchJump = keyDown[1].buttonA260261if stage.debugMode == true262// And now to the same process for the B button (debug mode buttom)263CheckTouchRect(0, 0, 112, 56)264if checkResult > -1265keyDown[1].buttonB = true266end if267268if touchDebug == false269keyPress[1].buttonB |= keyDown[1].buttonB270end if271272touchDebug = keyDown[1].buttonB273end if274275CheckTouchRect(240, 0, screen.xsize, 40)276if checkResult > -1277PlaySfx(SfxName[Menu Back], false)278engine.state = 5279end if280281if keyPress[0].start == true282PlaySfx(SfxName[Menu Back], false)283engine.state = 5284end if285end if286end if287#endplatform288289#platform: USE_ORIGINS290if object.controlMode == CONTROLMODE_P1291if keyPress[0].start == true292// These are left over from the standalone versions, as evident by the fact you can't fly in special stages293StopSfx(SfxName[Flying])294StopSfx(SfxName[Jump])295296engine.state = 5297end if298end if299#endplatform300301ProcessObjectControl()302else303#platform: USE_STANDALONE304CheckTouchRect(0, 0, screen.xsize, screen.ysize)305if keyPress[0].start == true306checkResult = false307end if308309if checkResult > -1310if Player_attractDuration > 1311Player_attractDuration = 1312end if313end if314#endplatform315316if keyPress[0].start == true317Player_attractDuration = 1318end if319320Player_attractFrameCount--321if Player_attractFrameCount < 1322if Player_attractTablePos < Player_attractTableSize323GetTableValue(temp0, Player_attractTablePos, Player_attractTable)324GetBit(player.up, temp0, 0)325GetBit(player.down, temp0, 1)326GetBit(player.left, temp0, 2)327GetBit(player.right, temp0, 3)328GetBit(player.jumpPress, temp0, 4)329GetBit(player.jumpHold, temp0, 5)330Player_attractTablePos++331GetTableValue(Player_attractFrameCount, Player_attractTablePos, Player_attractTable)332Player_attractTablePos++333end if334else335if player.jumpPress == true336player.jumpPress = false337end if338end if339340if Player_attractDuration > 0341Player_attractDuration--342if Player_attractDuration < 1343arrayPos0 = Player_playerSlot344player[arrayPos0].type = TypeName[Title Card]345player[arrayPos0].state = TITLECARD_FADETOTITLE346player[arrayPos0].priority = PRIORITY_ACTIVE347player[arrayPos0].drawOrder = 6348end if349end if350end if351end function352353public function Player_State_Static354checkResult = false355end function356357358public function Player_HandleRollAnimSpeed359#platform: USE_STANDALONE360if stage.playerListPos == PLAYER_TAILS_A361#endplatform362#platform: USE_ORIGINS363// Bug Details:364// pretty sure this should be PLAYER_TAILS, this would be giving sonic a constant animation speed of 120 like Tails would.365if stage.playerListPos == PLAYER_SONIC366#endplatform367368player.animationSpeed = 120369else370player.animationSpeed = player.moveSpeed371Abs(player.animationSpeed)372player.animationSpeed *= 240373player.animationSpeed /= 0x60000374player.animationSpeed += 48375end if376end function377378379public function Player_HandleGroundCollision380if player.worldVelocity.x > 0381GetBit(temp0, player.collisionFlags, 2)382else383GetBit(temp0, player.collisionFlags, 3)384end if385386if temp0 != 0387player.worldVelocity.x = 0388player.gravity = GRAVITY_GROUND389end if390391if player.worldVelocity.y > 0392GetBit(temp0, player.collisionFlags, 1)393else394GetBit(temp0, player.collisionFlags, 4)395end if396397if temp0 != 0398player.worldVelocity.y = 0399player.gravity = GRAVITY_GROUND400end if401end function402403404public function Player_HandleAirCollision405// Get the nearest rotation quarter406temp0 = Player_stageRotation407temp0 >>= 1408temp0 -= 0xE0409temp0 &= 0xC0410switch temp0411case 0x00412if player.moveSpeed > 0413GetBit(temp0, player.collisionFlags, 2)414else415GetBit(temp0, player.collisionFlags, 3)416end if417break418419case 0x40420if player.moveSpeed > 0421GetBit(temp0, player.collisionFlags, 1)422else423GetBit(temp0, player.collisionFlags, 4)424end if425break426427case 0x80428if player.moveSpeed > 0429GetBit(temp0, player.collisionFlags, 3)430else431GetBit(temp0, player.collisionFlags, 2)432end if433break434435case 0xC0436if player.moveSpeed > 0437GetBit(temp0, player.collisionFlags, 4)438else439GetBit(temp0, player.collisionFlags, 1)440end if441break442443end switch444445if temp0 == true446player.moveSpeed = 0447end if448449player.collisionFlags = 0450end function451452453public function Player_State_SS_Roll454CallFunction(Player_HandleGroundCollision)455if player.gravity == GRAVITY_AIR456if player.rotateBlockTimer != 0457player.rotateBlockTimer--458end if459460if player.upDownBlockTimer != 0461player.upDownBlockTimer--462end if463end if464465temp2 = Player_stageRotation466temp2 &= 504467if player.gravity == GRAVITY_GROUND468if player.jumpPress == true469checkResult = true470else471checkResult = false472end if473else474checkResult = false475end if476477if checkResult == true478Sin(temp0, temp2)479temp0 *= player.jumpStrength480temp0 >>= 9481482Cos(temp1, temp2)483temp1 *= player.jumpStrength484temp1 >>= 9485486player.worldVelocity.x = 0487player.worldVelocity.x += temp0488player.worldVelocity.y = 0489player.worldVelocity.y -= temp1490PlaySfx(SfxName[Jump], false)491else492Sin(temp0, temp2)493temp0 *= player.rollSpeed494temp0 >>= 9495496Cos(temp1, temp2)497temp1 *= player.rollSpeed498temp1 >>= 9499500player.worldVelocity.x -= temp0501player.worldVelocity.y += temp1502end if503504CallFunction(Player_HandleAirCollision)505506temp0 = 0507if player.left == true508player.moveSpeed -= player.acceleration509if player.moveSpeed < -0x80000510player.moveSpeed = -0x80000511end if512513player.direction = FACING_LEFT514temp0 = true515end if516517if player.right == true518player.moveSpeed += player.acceleration519if player.moveSpeed > 0x80000520player.moveSpeed = 0x80000521end if522523player.direction = FACING_RIGHT524temp0 = true525end if526527if temp0 == false528if player.moveSpeed != 0529if player.moveSpeed > 0530player.moveSpeed -= player.acceleration531if player.moveSpeed < 0532player.moveSpeed = 0533end if534else535player.moveSpeed += player.acceleration536if player.moveSpeed > 0537player.moveSpeed = 0538end if539end if540end if541end if542543temp0 = Player_stageRotation544temp0 += 0x40545temp0 &= 0x180546547Cos(player.moveVelocity.x, temp0)548player.moveVelocity.x *= player.moveSpeed549player.moveVelocity.x >>= 9550551Sin(player.moveVelocity.y, temp0)552player.moveVelocity.y *= player.moveSpeed553player.moveVelocity.y >>= 9554555player.xvel = player.worldVelocity.x556player.xvel += player.moveVelocity.x557player.yvel = player.worldVelocity.y558player.yvel += player.moveVelocity.y559CallFunction(Player_HandleRollAnimSpeed)560end function561562563// ========================564// Events565// ========================566567event ObjectUpdate568if stage.debugMode == true569CallFunction(Player_ProcessUpdate)570if keyPress[0].buttonB == true571player.type = TypeName[Debug Mode]572573#platform: USE_STANDALONE574if stage.playerListPos == PLAYER_TAILS_A575#endplatform576#platform: USE_ORIGINS577// Bug Details:578// pretty sure this should be PLAYER_TAILS...?579if stage.playerListPos == PLAYER_SONIC580#endplatform581// Clear the following Tails Object if needed too582object[+1].type = TypeName[Blank Object]583end if584585player.moveSpeed = 0586player.rotation = 0587player.frame = 0588Player_stageRotation = 0589Player_rotateSpeed = 2590player.frame = debugMode.currentSelection591player.interaction = false592else593CallFunction(player.state)594ProcessAnimation()595596if player.state != Player_State_Static597ProcessObjectMovement()598end if599600player.gravity = GRAVITY_AIR601end if602else603CallFunction(Player_ProcessUpdate)604CallFunction(player.state)605ProcessAnimation()606607if player.state != Player_State_Static608ProcessObjectMovement()609end if610611player.gravity = GRAVITY_AIR612end if613end event614615616event ObjectDraw617DrawObjectAnimation()618end event619620621event ObjectStartup622LoadSpriteSheet("Global/Display.gif") // We don't even use any SpriteFrames, but go ahead and load the sheet anyway..?623624foreach (TypeName[Player Object], arrayPos0, ALL_ENTITIES)625#platform: USE_STANDALONE626if stage.playerListPos >= PLAYER_SONIC_TAILS_A627stage.playerListPos = PLAYER_SONIC_A628stage.player2Enabled = true629end if630#endplatform631632#platform: USE_ORIGINS633switch stage.playerListPos634case PLAYER_SONIC_TAILS_A635stage.playerListPos = PLAYER_SONIC636stage.player2Enabled = true637break638639case PLAYER_AMY_TAILS_A640stage.playerListPos = PLAYER_AMY641stage.player2Enabled = true642break643end switch644#endplatform645646647// 0 = SLOT_PLAYER1648ResetObjectEntity(SLOT_PLAYER1, TypeName[Player Object], 0, player[arrayPos0].xpos, player[arrayPos0].ypos)649camera[0].xpos = player[0].ixpos650camera[0].ypos = player[0].iypos651player[0].groupID = GROUP_PLAYERS652player[0].xvel = 0653player[0].yvel = 0654player[0].speed = 0655Player_playerSlot = player.entityPos656657switch stage.playerListPos658case PLAYER_SONIC_A659LoadAnimation("SonicSS.ani")660player[0].animationSpeed = 48661break662663case PLAYER_TAILS_A664LoadAnimation("TailsSS.ani")665player[0].animationSpeed = 120666break667668case PLAYER_KNUCKLES_A669LoadAnimation("KnucklesSS.ani")670player[0].animationSpeed = 48671break672673#platform: USE_ORIGINS674case PLAYER_AMY_A675LoadAnimation("AmySS.ani")676player[0].animationSpeed = 48677break678#endplatform679end switch680681// Note - player.animation never needs to be set since the desired animation is animation ID 0 in the file682683player[0].state = Player_State_SS_Roll684player[0].priority = PRIORITY_ACTIVE685player[0].drawOrder = 4686player[0].acceleration = 0xC00687player[0].jumpStrength = 0x68000688player[0].rollSpeed = 0x2A00689ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)690player[0].tileCollisions = false691player[0].gravity = GRAVITY_AIR692Player_stageRotation = 0693Player_rotateSpeed = 0694Player_rotateDir = 0695Player_isWinner = false696next697698options.touchControls = true699end event700701702// ========================703// Editor Events704// ========================705706event RSDKDraw707DrawSprite(0)708end event709710711event RSDKLoad712LoadSpriteSheet("Players/Sonic1.gif")713SpriteFrame(-16, -16, 32, 32, 42, 118)714715SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")716end event717718719