// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Spike Logs Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

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

private alias object.value1 : object.spikedLog


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

reserve function SpikeLogs_DebugDraw
reserve function SpikeLogs_DebugSpawn


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

private function SpikeLogs_DebugDraw
	DrawSprite(0)
end function


private function SpikeLogs_DebugSpawn
	CreateTempObject(TypeName[Spike Logs], 0, object.xpos, object.ypos)
end function


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

event ObjectUpdate
	object.spikedLog = GHZSetup_spikeLogsCounter
	object.spikedLog >>= 1
	object.spikedLog &= 7
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		checkResult = false
		switch object.spikedLog
		default
			break
			
		case 0
			BoxCollisionTest(C_TOUCH, object.entityPos, -2, -16, 2, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		case 1
			BoxCollisionTest(C_TOUCH, object.entityPos, 14, -16, 18, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		case 2
			BoxCollisionTest(C_TOUCH, object.entityPos, 30, -16, 34, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		case 3
			BoxCollisionTest(C_TOUCH, object.entityPos, 46, -16, 50, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		case 4
			BoxCollisionTest(C_TOUCH, object.entityPos, 62, -16, 66, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		case 5
			BoxCollisionTest(C_TOUCH, object.entityPos, 78, -16, 82, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		case 6
			BoxCollisionTest(C_TOUCH, object.entityPos, 94, -16, 98, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		case 7
			BoxCollisionTest(C_TOUCH, object.entityPos, 110, -16, 114, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			break
			
		end switch

		if checkResult == true
			CallFunction(Player_Hit)
		end if
	next
end event


event ObjectDraw
	temp0 = 16
	temp0 -= GHZSetup_spikeLogsCounter
	temp0 >>= 1
	temp1 = object.xpos
	DrawSpriteXY(temp0, temp1, object.ypos)

	temp0++
	temp1 += 0x100000
	DrawSpriteXY(temp0, temp1, object.ypos)

	temp0++
	temp1 += 0x100000
	DrawSpriteXY(temp0, temp1, object.ypos)

	temp0++
	temp1 += 0x100000
	DrawSpriteXY(temp0, temp1, object.ypos)

	temp0++
	temp1 += 0x100000
	DrawSpriteXY(temp0, temp1, object.ypos)

	temp0++
	temp1 += 0x100000
	DrawSpriteXY(temp0, temp1, object.ypos)

	temp0++
	temp1 += 0x100000
	DrawSpriteXY(temp0, temp1, object.ypos)

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


event ObjectStartup
	LoadSpriteSheet("GHZ/Objects.gif")
	
	// Log Frames, with the latter half a duplicate of the first half for ease in drawing the Logs
	SpriteFrame(-8, -8, 16, 16, 167, 1)
	SpriteFrame(-8, -8, 16, 19, 115, 18)
	SpriteFrame(-8, -8, 16, 24, 132, 18)
	SpriteFrame(-8, -8, 16, 20, 149, 18)
	SpriteFrame(-8, -8, 0, 0, 149, 18)
	SpriteFrame(-8, -24, 16, 30, 166, 18)
	SpriteFrame(-8, -24, 16, 30, 115, 38)
	SpriteFrame(-8, -24, 16, 30, 132, 43)
	
	SpriteFrame(-8, -8, 16, 16, 167, 1)
	SpriteFrame(-8, -8, 16, 19, 115, 18)
	SpriteFrame(-8, -8, 16, 24, 132, 18)
	SpriteFrame(-8, -8, 16, 20, 149, 18)
	SpriteFrame(-8, -8, 0, 0, 149, 18)
	SpriteFrame(-8, -24, 16, 30, 166, 18)
	SpriteFrame(-8, -24, 16, 30, 115, 38)
	SpriteFrame(-8, -24, 16, 30, 132, 43)

	SetTableValue(TypeName[Spike Logs], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(SpikeLogs_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(SpikeLogs_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	temp0 = 0
	temp1 = object.xpos
	
	while temp0 < 8
		DrawSpriteXY(temp0, temp1, object.ypos)

		temp1 += 0x100000
		temp0++
	loop
end event


event RSDKLoad
	LoadSpriteSheet("GHZ/Objects.gif")
	SpriteFrame(-8, -8, 16, 16, 167, 1)
	SpriteFrame(-8, -8, 16, 19, 115, 18)
	SpriteFrame(-8, -8, 16, 24, 132, 18)
	SpriteFrame(-8, -8, 16, 20, 149, 18)
	SpriteFrame(-8, -8, 0, 0, 149, 18)
	SpriteFrame(-8, -24, 16, 30, 166, 18)
	SpriteFrame(-8, -24, 16, 30, 115, 38)
	SpriteFrame(-8, -24, 16, 30, 132, 43)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
