/*
	This script file is part of the Sonic 3 A.I.R. script software distribution.
	Copyright (C) 2017-2024 by Eukaryot

	Published under the GNU GPLv3 open source software license, see license.txt
	or https://www.gnu.org/licenses/gpl-3.0.en.html
*/



//# address-hook(0x03c25c) end(0x03c2a0)
function void fn03c25c()
{
	objA0.mapping_offset = 0x03c328
	objA0.sprite_attributes = (sprite_attribute.PALETTE.LINE1 | 0x031b)
	objA0.render_flags |= render_flag.WORLD
	objA0.box_size.x = 0x20
	objA0.box_size.y = 0x20
	objA0.sprite_priority = 0x0280
	u16[A0 + 0x44] = objA0.position.x.u16

	D0 = objA0.subtype2c * 8
	u16[A0 + 0x34] = D0.u16
	D0.u16 = (D0.u16 & 0xff80) + 0x0200
	u16[A0 + 0x36] = D0.u16

	objA0.update_address = 0x03c2a6
	fn03c2a6()
}


//# address-hook(0x03c2a6) end(0x03c322)
function void fn03c2a6()
{
	u16 backup_px = objA0.position.x.u16
	if (u8[A0 + 0x30] != 0)
	{
		objA0.value32 -= 0x02
		if (objA0.value32 == 0)
		{
			u8[A0 + 0x30] = 0
		}
	}
	else
	{
		objA0.value32 += 0x02
		D0.u16 = u16[A0 + 0x34]
		if (D0.u16 == objA0.value32)
		{
			u8[A0 + 0x30] = 0x01
		}
	}

	D0.u16 = u16[A0 + 0x44] - objA0.value32
	objA0.position.x.u16 = D0.u16
	D1 = objA0.box_size.x + 11
	D2 = objA0.box_size.y
	D3.u16 = D2.u16 + 1
	D4.u16 = backup_px
	fn01dc56()

	D0.u16 = (u16[A0 + 0x44] & 0xff80) - level.despawn_position.x
	if (D0.u16 <= u16[A0 + 0x36])
	{
		DrawObject()
	}
	else
	{
		if (objA0.respawn_entry)
		{
			A2 = 0xffff0000 + objA0.respawn_entry
			u8[A2] &= ~0x80
		}
		UnloadObject()
	}
}
