Path: blob/master/Sonic 2/Scripts/DEZ/DERTarget.txt
1479 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: DER Target 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.sfxTimer13private alias object.value2 : object.sfxDelay // Gradually decreases in order to make the SFX play more and more often14private alias object.value3 : object.reticleFrame1516// States17private alias 0 : DERTARGET_INIT18private alias 1 : DERTARGET_TRACKING19private alias 2 : DERTARGET_TARGETTED // No longer moving, this is where the DER's gonna land2021// Player aliases22private alias 0 : SLOT_PLAYER123private alias object.xpos : player.xpos24private alias object.ypos : player.ypos252627// ========================28// Tables29// ========================3031private table DERTarget_xpos_backups320, 0, 0, 033end table3435private table DERTarget_ypos_backups360, 0, 0, 037end table383940// ========================41// Events42// ========================4344event ObjectUpdate45switch object.state46case DERTARGET_INIT47object.timer = 16048object.sfxDelay = 2449object.sfxTimer = 245051object.xpos = player[SLOT_PLAYER1].xpos52object.ypos = player[SLOT_PLAYER1].ypos5354// Set all the table values to just be P1's pos right now55SetTableValue(player[SLOT_PLAYER1].xpos, 0, DERTarget_xpos_backups)56SetTableValue(player[SLOT_PLAYER1].ypos, 0, DERTarget_ypos_backups)57SetTableValue(player[SLOT_PLAYER1].xpos, 1, DERTarget_xpos_backups)58SetTableValue(player[SLOT_PLAYER1].ypos, 1, DERTarget_ypos_backups)59SetTableValue(player[SLOT_PLAYER1].xpos, 2, DERTarget_xpos_backups)60SetTableValue(player[SLOT_PLAYER1].ypos, 2, DERTarget_ypos_backups)61SetTableValue(player[SLOT_PLAYER1].xpos, 3, DERTarget_xpos_backups)62SetTableValue(player[SLOT_PLAYER1].ypos, 3, DERTarget_ypos_backups)6364object.drawOrder = 565object.priority = PRIORITY_ACTIVE66object.state = DERTARGET_TRACKING67break6869case DERTARGET_TRACKING70object.timer--71if object.timer < 072object.state++73object.timer = 6474object.sfxTimer = 47576object.xpos = player[SLOT_PLAYER1].xpos77object.ypos = player[SLOT_PLAYER1].ypos78else79// In order to make the target have a delay when following the player,80// there's this whole table to store old player pos's8182// Make this target's position be where the player was 3 cycles ago83GetTableValue(object.xpos, 3, DERTarget_xpos_backups)84GetTableValue(object.ypos, 3, DERTarget_ypos_backups)8586// Shift all the values by 1 around the table87GetTableValue(temp0, 2, DERTarget_xpos_backups)88GetTableValue(temp1, 2, DERTarget_ypos_backups)89SetTableValue(temp0, 3, DERTarget_xpos_backups)90SetTableValue(temp1, 3, DERTarget_ypos_backups)91GetTableValue(temp0, 1, DERTarget_xpos_backups)92GetTableValue(temp1, 1, DERTarget_ypos_backups)93SetTableValue(temp0, 2, DERTarget_xpos_backups)94SetTableValue(temp1, 2, DERTarget_ypos_backups)95GetTableValue(temp0, 0, DERTarget_xpos_backups)96GetTableValue(temp1, 0, DERTarget_ypos_backups)97SetTableValue(temp0, 1, DERTarget_xpos_backups)98SetTableValue(temp1, 1, DERTarget_ypos_backups)99100// And then put the _actual_ player position at the front of the table101SetTableValue(player[SLOT_PLAYER1].xpos, 0, DERTarget_xpos_backups)102SetTableValue(player[SLOT_PLAYER1].ypos, 0, DERTarget_ypos_backups)103end if104105object.sfxTimer--106if object.sfxTimer < 0107object.sfxDelay--108object.sfxTimer = object.sfxDelay109PlaySfx(SfxName[Beep], false)110end if111break112113case DERTARGET_TARGETTED114object.timer--115if object.timer < 0116// Object [-6] is the Death Egg Robot, make it land where its target shows117object[-6].timer = 1118object[-6].xpos = object.xpos119120// Reset this object, not needed anymore121object.state = 0122object.type = TypeName[Blank Object]123else124object.sfxTimer--125126if object.sfxTimer < 0127object.sfxTimer = 4128PlaySfx(SfxName[Beep], false)129end if130end if131break132133end switch134135// Update the object's animation136object.animationTimer++137if object.animationTimer == 4138object.animationTimer = 0139object.frame++140if object.frame >= 5141object.frame = 0142end if143object.reticleFrame ^= 1144end if145end event146147148event ObjectDraw149DrawSprite(object.frame)150151if object.state == 2152// Draw the inner reticle153temp0 = object.reticleFrame154temp0 += 5155DrawSprite(temp0)156end if157end event158159160event ObjectStartup161CheckCurrentStageFolder("Zone12")162if checkResult == true163LoadSpriteSheet("DEZ/Objects.gif")164165// 0-4 - Target Frames166SpriteFrame(-53, -53, 106, 106, 249, 149)167SpriteFrame(-45, -45, 90, 90, 158, 165)168SpriteFrame(-37, -37, 74, 74, 82, 181)169SpriteFrame(-29, -29, 58, 58, 23, 197)170SpriteFrame(-21, -21, 42, 42, 356, 213)171172// 5-6 - Inner Reticle Frames173SpriteFrame(-8, -8, 16, 16, 356, 196)174SpriteFrame(-8, -8, 16, 16, 373, 196)175else176LoadSpriteSheet("MBZ/Objects.gif")177178// 0-4 - Target Frames179SpriteFrame(-53, -53, 106, 106, 761, 149)180SpriteFrame(-45, -45, 90, 90, 670, 165)181SpriteFrame(-37, -37, 74, 74, 594, 181)182SpriteFrame(-29, -29, 58, 58, 535, 197)183SpriteFrame(-21, -21, 42, 42, 868, 213)184185// 5-6 - Inner Reticle Frames186SpriteFrame(-8, -8, 16, 16, 868, 196)187SpriteFrame(-8, -8, 16, 16, 885, 196)188end if189end event190191192// ========================193// Editor Events194// ========================195196event RSDKDraw197DrawSprite(0)198end event199200201event RSDKLoad202CheckCurrentStageFolder("Zone12")203if checkResult == true204LoadSpriteSheet("DEZ/Objects.gif")205SpriteFrame(-21, -21, 42, 42, 356, 213)206else207LoadSpriteSheet("MBZ/Objects.gif")208SpriteFrame(-21, -21, 42, 42, 868, 213)209end if210211SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")212end event213214215