// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: H Propeller Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

// Player Aliases
private alias object.state : player.state
private alias object.ypos : player.ypos
private alias object.xvel : player.xvel
private alias object.yvel : player.yvel
private alias object.speed : player.speed
private alias object.gravity : player.gravity
private alias object.animation : player.animation
private alias object.tileCollisions : player.tileCollisions

private alias object.value1  : player.timer


// ========================
// Function Declarations
// ========================

reserve function HPropeller_DebugDraw
reserve function HPropeller_DebugSpawn


// ========================
// Function Definitions
// ========================

private function HPropeller_DebugDraw
	DrawSprite(0)
end function


private function HPropeller_DebugSpawn
	CreateTempObject(TypeName[H Propeller], 0, object.xpos, object.ypos)
end function


// ========================
// Events
// ========================

event ObjectUpdate
	GetTableValue(temp0, 10, StageSetup_oscillationTable)
	temp0 >>= 8
	temp0 -= 112

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -64, temp0, 64, 56, currentPlayer, -1, -1, 1, 1)
		if checkResult == true
			player[currentPlayer].animation 		= ANI_FANROTATE
			player[currentPlayer].state 			= Player_State_Air
			player[currentPlayer].gravity 			= 1
			player[currentPlayer].tileCollisions 	= true
			player[currentPlayer].speed 			= player[currentPlayer].xvel
			player[currentPlayer].timer 			= 0
			player[currentPlayer].yvel 				= 0

			temp0 <<= 16
			temp0 += object.ypos
			temp0 -= player[currentPlayer].ypos
			temp0 >>= 4
			player[currentPlayer].ypos += temp0
		end if
	next
end event


event ObjectDraw
	DrawSprite(WFZSetup_hPropellerFrame)

	temp0 = object.ypos
	temp0 += 0x100000
	DrawSpriteXY(WFZSetup_hPropellerFrame, object.xpos, temp0)
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-62, -2, 124, 5, 1, 171)
	SpriteFrame(-40, -2, 78, 5, 1, 177)
	SpriteFrame(-24, -2, 46, 5, 1, 183)
	SpriteFrame(-11, -1, 22, 4, 1, 189)
	SpriteFrame(-22, -2, 46, 5, 1, 194)
	SpriteFrame(-39, -2, 79, 5, 1, 200)

	foreach (TypeName[H Propeller], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 5
	next

	SetTableValue(TypeName[H Propeller], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(HPropeller_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(HPropeller_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-62, -2, 124, 5, 1, 171)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
