Exemple #1
0
static void handle_move_to(action_header_t *actn_hdr, le_entity_t *ent, double dt)
{
	cd_position_t *pos = entity_get_component(ent, COMP_FAMILY_POSITION);
	if (!pos)
		return;
	
	cd_actn_move_to_t *actn = actn_hdr->action;
	
	if (actn_hdr->duration == 0.0)
	{
		pos->pos = actn->dest;
		return;
	}
	
	if (!actn_hdr->initialized)
	{
		vec2d_t d;
		d.x = actn->dest.x - pos->pos.x;
		d.y = actn->dest.y - pos->pos.y;
		
		actn->_ups_x = d.x / actn_hdr->duration;
		actn->_ups_y = d.y / actn_hdr->duration;
		actn_hdr->initialized = true;
	}
	
	pos->pos.x += actn->_ups_x * dt;
	pos->pos.y += actn->_ups_y * dt;
}
Exemple #2
0
action_header_t *action_system_add_action_to_entity(le_action_system_t *sys, le_entity_t *ent)
{
	cd_action_container_t *cont = entity_get_component(ent, COMP_FAMILY_ACTION_CONTAINER);
	if (!cont)
	{
		le_component_header_t *comp_hdr = entity_add_component(ent, COMP_FAMILY_ACTION_CONTAINER);
		comp_hdr->component = malloc(sizeof(cd_action_container_t));
		comp_hdr->component_deallocator = free_action_container;
		memset(comp_hdr->component,0x00,sizeof(cd_action_container_t));
		cont = comp_hdr->component;
	}
	
	action_header_t *a_hdr = NULL;
	for (int i = 0; i < NUM_ACTIONS_PER_CONTAINER; i++)
	{
		if (!cont->headers[i])
		{
			cont->headers[i] = malloc(sizeof(action_header_t));
			memset(cont->headers[i], 0x00, sizeof(action_header_t));
			a_hdr = cont->headers[i];
			break;
		}
	}
	
	if (!a_hdr)
	{
		printf("couldn't find empty header slot ...\n");
		abort();
		return NULL;
	}
	
	return a_hdr;
}
void system_gameobject_draw(unsigned int event_id, entity* target_entity) {
	if (event_id == 0) { /* only activate for draw event */
		/* here we will query the entity components and then draw the entity. */

		component_position* entity_position = entity_get_component(target_entity, component_position_type);
		component_gameobject* entity_gameobject = entity_get_component(target_entity, component_gameobject_type);
		component_primitive* entity_primitive = entity_get_component(target_entity, component_primitive_type);
		component_texture* entity_texture = entity_get_component(target_entity, component_texture_type);

		global* global_handle = global_get_singleton();
		window* window_handle = global_get(global_handle, GLOBAL_WINDOW);
		hl_render* hl_render_handle = global_get(global_handle, GLOBAL_HL_RENDER);

		float current_time = time_get_elapsed(window_handle);
		if ((current_time - entity_texture->time_point) * 1000.0f >= entity_texture->interval[entity_texture->current_animation]) {
			entity_texture->time_point = current_time;
			entity_texture->current_frame++; /* Add loop-around! */

			if (entity_texture->current_frame >= entity_texture->frame_count[entity_texture->current_animation]) {
				entity_texture->current_frame = 0;
			}
		}

		texture* current_texture = entity_texture->texture_buffer[entity_texture->current_animation][entity_texture->current_frame];

		hl_render_batch render_batch;

		render_batch.x = entity_position->x;
		render_batch.y = entity_position->y;
		render_batch.angle = entity_position->angle;

		render_batch.z = entity_gameobject->layer;
		render_batch.render_prim = entity_primitive->primitive_handle;
		render_batch.render_texture = current_texture;

		hl_render_add_batch(hl_render_handle, &render_batch);
	}
}
void system_entity_global(unsigned int event_id, entity* entity_handle) {
	switch (event_id) {
	case EVENT_PRE_LOGIC:
		{
			/* If the entity global component value is not the special undef. value ("__undef__") we set the index in entity_global. */

			component_global* component_global_handle = entity_get_component(entity_handle, component_global_type);

			if (strcmp(component_global_handle->id, "__undef__") && !component_global_handle->set) {
				entity* global_entity_handle = entity_global_get(global_get(global_get_singleton(), GLOBAL_ENTITY_GLOBAL), component_global_handle->id);

				if (global_entity_handle) {
					debug_warning("[system_entity_global] collision between entity %X and %X, fighting for [%s]", entity_handle, global_entity_handle, component_global_handle->id);
				}

				debug_message("[system_entity_global] set global id [%s] to %x", component_global_handle->id, entity_handle);
				entity_global_set(global_get(global_get_singleton(), GLOBAL_ENTITY_GLOBAL), component_global_handle->id, entity_handle);
				component_global_handle->set = 1;
			}
		}
		break;
	}
}