#include "entity_crumbler.h"

/* Initializes a Crumbler entity. */
void
entity_crumbler_init(ECS* ecs, u32 id, vec3 position, u32 level, Vector* entityList)
{
	ComponentEnemy* enemy;
	ComponentLevel* componentLevel;
	ComponentGameObject* gameObject;
	ComponentActionOnHeightDamageDisable* actionOnHeightDamageDisable;

	enemy = ecs_component_add(ecs, ECS_COMPONENT_ENEMY, id);
	gameObject = ecs_component_get(ecs, ECS_COMPONENT_GAME_OBJECT, id);
	actionOnHeightDamageDisable = ecs_component_add(ecs, ECS_COMPONENT_ACTION_ON_HEIGHT_DAMAGE_DISABLE, id);

	component_enemy_init
	(
		enemy,
		ecs,
		ecs->game->resources.textures[TEXTURE_CRUMBLER],
		(s32*)CRUMBLER_FRAME_SIZE,
		(s32*)CRUMBLER_ATLAS_SIZE,
		(f32*)CRUMBLER_SIZE,
		(f32*)CRUMBLER_PHYSICS_SIZE,
		position,
		CRUMBLER_FRICTION,
		CRUMBLER_VELOCITY_MAX,
		CRUMBLER_HEALTH_MAX,
		CRUMBLER_IS_BOUNCE,
		CRUMBLER_IS_AFFECTED_BY_GRAVITY,
		CRUMBLER_IS_SOLID,
		CRUMBLER_GOODIE_COUNT,
		level,
		entityList
	);

	componentLevel = ecs_component_get(ecs, ECS_COMPONENT_LEVEL, id);

	gameObject->height = CRUMBLER_HEIGHT;
	gameObject->gravity = CRUMBLER_GRAVITY + (CRUMBLER_LEVEL_GRAVITY_MULTIPLIER * (componentLevel->value - 1));

	gameObject->gravity = MIN(gameObject->gravity, CRUMBLER_GRAVITY_MAX);

	component_action_on_height_damage_disable_init(actionOnHeightDamageDisable, CRUMBLER_DAMAGE_HEIGHT);

	ComponentGameEntityType* gameEntityType;

	gameEntityType = ecs_component_add(ecs, ECS_COMPONENT_GAME_ENTITY_TYPE, id);

	component_game_entity_type_init
	(
		gameEntityType, 
		GAME_ENTITY_CRUMBLER
	);

	sound_play(&ecs->game->resources.sounds[SOUND_CRUMBLER_WHOOSH], SOUND_SPECIAL);

}
