// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Break Block Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 50 : TYPE_BREAKBLOCK

// Function declarations
reserve function BreakBlock_DebugDraw
reserve function BreakBlock_DebugSpawn

// Static Values

// Tables

function BreakBlock_DebugDraw
	DrawSprite(0)
end function


function BreakBlock_DebugSpawn
	CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
end function


event ObjectMain
	switch object.state
	case 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].value18 = 4
			end if
			if object[currentPlayer].animation == ANI_JUMPING
				BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					object[currentPlayer].yvel = -0x30000
					object[currentPlayer].gravity = GRAVITY_AIR
					CreateTempObject(TypeName[Object Score], object[currentPlayer].value19, object.xpos, object.ypos)
					object[tempObjectPos].drawOrder = 4
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos -= 8
					object[tempObjectPos].iypos -= 8
					object[tempObjectPos].xvel = -0x20000
					object[tempObjectPos].yvel = -0x20000
					object[tempObjectPos].state = 1
					object[tempObjectPos].drawOrder = 5
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos += 8
					object[tempObjectPos].iypos -= 8
					object[tempObjectPos].xvel = 0x20000
					object[tempObjectPos].yvel = -0x20000
					object[tempObjectPos].state = 2
					object[tempObjectPos].drawOrder = 5
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos -= 8
					object[tempObjectPos].iypos += 8
					object[tempObjectPos].xvel = -0x10000
					object[tempObjectPos].yvel = -0x10000
					object[tempObjectPos].state = 3
					object[tempObjectPos].drawOrder = 5
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos += 8
					object[tempObjectPos].iypos += 8
					object[tempObjectPos].xvel = 0x10000
					object[tempObjectPos].yvel = -0x10000
					object[tempObjectPos].state = 4
					object[tempObjectPos].drawOrder = 5
					object.state = 5
					arrayPos0 = 22
					if object[currentPlayer].value16 == 0
						arrayPos0 += currentPlayer
					end if
					switch object[currentPlayer].value19
					case 0
						player.score += 100
						break
					case 1
						player.score += 200
						break
					case 2
						player.score += 500
						break
					case 3
					case 4
					case 5
					case 6
					case 7
					case 8
					case 9
					case 10
					case 11
					case 12
					case 13
					case 14
						player.score += 1000
						break
					case 15
						player.score += 10000
						break
					end switch
					if object[currentPlayer].gravity == GRAVITY_AIR
						if object[currentPlayer].value19 < 15
							object[currentPlayer].value19++
						end if
					end if
					PlaySfx(SfxName[Block Break], 0)
				end if
			else
				BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			end if
		next
		break
	case 1
	case 2
	case 3
	case 4
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x3800
		if object.outOfBounds == 1
			object.type = TypeName[Blank Object]
		end if
		break
	case 5
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].value18 = 4
			end if
		next
		break
	end switch
end event


event ObjectDraw
	DrawSprite(object.state)
end event


event ObjectStartup
	LoadSpriteSheet("CPZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 165, 223)
	SpriteFrame(-8, -8, 16, 16, 165, 223)
	SpriteFrame(-8, -8, 16, 16, 181, 223)
	SpriteFrame(-8, -8, 16, 16, 165, 239)
	SpriteFrame(-8, -8, 16, 16, 181, 239)
	SpriteFrame(0, 0, 0, 0, 1, 1)
	SetTableValue(TypeName[Break Block], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(BreakBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(BreakBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
