Ejemplo n.º 1
0
void optlayout_destroy (EntComponent comp, EntSpeech speech)
{
	struct optlayout
		* opt = component_getData (comp);
	// FIXME: entities that destroy other entities in their destruction code can probably lead to a double-free bug if they're only destroyed when everything is destroyed (or alternately they could cause the entity list to get into a bad state if they destroy entities while other code is iterating through it) - xph 2012 02 05
	dynarr_map (opt->options, (void (*)(void *))entity_destroy);
	dynarr_destroy (opt->options);
	entity_destroy (opt->cancel);
	entity_destroy (opt->confirm);
	xph_free (opt);

	component_clearData (comp);
}
Ejemplo n.º 2
0
int esys_del(struct esys* esys, ocn_entity_token_t token)
{
    if(token >= OCN_MAX_ENTITIES)
        return OCN_ENTITY_ERR_RANGE;

    pthread_spin_lock(&esys->lock);

    struct entityslot* slot = &esys->slots[token];

    if(!FLAG_GET(slot->flags, ENTITYSLOT_FLAG_USED))
    {
        pthread_spin_unlock(&esys->lock);
        return OCN_ENTITY_ERR_NONEXIST;
    }

    if(FLAG_GET(slot->flags, ENTITYSLOT_FLAG_ISOLATED))
    {
        pthread_spin_unlock(&esys->lock);
        return OCN_ENTITY_ERR_ISOLATED;
    }

    /* --- */

    entity_t* entity = &slot->entity;
    slot->flags = 0lu;
    esys->count--;

    /* --- */

    pthread_spin_unlock(&esys->lock);

    entity_destroy(entity);

    return OCN_OK;
}
Ejemplo n.º 3
0
AS3_Val destroyEntity( void* self, AS3_Val args )
{
	SceneNode * node;

	node = AS3_PtrValue(args);

	entity_destroy(&node->entity);

	sceneNode_destroy(&node);

	return 0;
}
// The player is alive
void
alive(Player * me)
{
	InputState * is;
	Camera * cam;
	EntitySet * others;
	Level world;

	unsigned int mousex;
	unsigned int mousey;

	float playerx, playery;

	float fake_lookx, fake_looky;
	float lookx, looky;
	unsigned int dir;

	float x, y;

	float dx = 0;
	float dy = 0;

	gboolean shoot;
	gboolean firing;

	Entity * target;

	is = me->is;
	cam = me->cam;
	others = me->others;
	world = me->world;

	firing = mouse_press(is);
	shoot = expired(me->attack_timer); 

	// Get the mouse position
	mouse_position(is, &mousex, &mousey);

	// Get the mouse position with regards to the level.
	camera_inverse_transform(cam, mousex, mousey, &fake_lookx, &fake_looky);
	lookx = fake_lookx / square_size;
	looky = fake_looky / square_size;

	entity_position(me->body, &playerx, &playery);

	dir = look(playerx, playery, lookx, looky);

	// Set the direction of the player with regards to key presses
	if (key_down(is, SDLK_a) || key_down(is, SDLK_LEFT))
	{
		dx = -1;
	} else if (key_down(is, SDLK_d) || key_down(is, SDLK_RIGHT))
	{
		dx = 1;
	}

	if (key_down(is, SDLK_w) || key_down(is, SDLK_UP))
	{
		dy = -1;
	} else if (key_down(is, SDLK_s) || key_down(is, SDLK_DOWN))
	{
		dy = 1;
	}

	entity_set_direction(me->body, dx, dy);

	// Try to shoot a KITTY!
	if (firing)
	{
		if (shoot)
		{
			play_wav(me->fire);

			entity_position(me->body, &x, &y);

			if (can_see(world, x, y, lookx, looky))
			{
				target = collision(me->body, lookx, looky, others);



				if (target)
				{
					entity_destroy(target);
					me->score ++;
				}
			}
		}


		if (dx != 0 || dy != 0)
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "shoot_walk_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "shoot_walk_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "shoot_walk_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "shoot_walk_down");
			}
		}
		else
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "shoot_idle_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "shoot_idle_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "shoot_idle_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "shoot_idle_down");
			}

		}
	}
	else
	{
		if (dx != 0 || dy != 0)
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "walk_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "walk_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "walk_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "walk_down");
			}
		}
		else
		{
			if (dir == LEFT)
			{
				set_animation(me->body, (char *) "idle_left");
			}
			else if (dir == RIGHT)
			{
				set_animation(me->body, (char *) "idle_right");
			}
			else if (dir == UP)
			{
				set_animation(me->body, (char *) "idle_up");
			}
			else if (dir == DOWN)
			{
				set_animation(me->body, (char *) "idle_down");
			}

		}

	}

}