예제 #1
0
void ProjectileSystem::Update(float _dt)
{
	MouseInputComponent* mouse;
	PositionComponent* position;

	EntityMap::iterator it;
	for (it = m_entityMap.begin(); it != m_entityMap.end(); ++it)
	{
		Entity* e = it->second;
		if (e->GetState() != Entity::ALIVE)
			continue;

		mouse = e->GetComponent<MouseInputComponent>();
		if (mouse->m_controls.LeftButton == InputState::Pressed)
		{
			position = it->second->GetComponent<PositionComponent>();

			Entity* e = m_world->CreateEntity();
			EntityFactory::GetInstance()->CreateEntity(e, EntityFactory::BALL);
			e->GetComponent<VelocityComponent>()->m_velocity = VECTOR3(0, 40, 0);
			e->GetComponent<PositionComponent>()->SetPosition(VECTOR3(position->GetPosition().x, position->GetPosition().y + 2.0f, 0));

			m_world->AddEntity(e);
		}
	}
}
/**
 * @brief CollisionSystem::GetBins gets all bins in which an entity belongs
 * @param e the entity
 * @param bins the bins the entity belongs to, if return value is true
 * @return true if entity is completely in defined game world, false otherwise
 */
bool CollisionSystem::GetBins(Entity *e, std::set<unsigned int>& bins)
{
    bins.clear();
    ColliderComponent* cc = e->GetComponent<ColliderComponent>("Collider");
    PositionComponent* pc = e->GetComponent<PositionComponent>("Position");
    sf::Vector2f pos = pc->GetPosition() + cc->GetOffset();
    sf::Vector2f dim = cc->GetDimensions();

    unsigned int bin[4];
    bin[0] = (pos.y / _BinSize.y) * _NumBinsX + (pos.x / _BinSize.x);
    bin[1] = ((pos.y + dim.y) / _BinSize.y) * _NumBinsX + (pos.x / _BinSize.x);
    bin[2] = (pos.y / _BinSize.y) * _NumBinsX + ((pos.x + dim.x) / _BinSize.x);
    bin[3] = ((pos.y + dim.y) / _BinSize.y) * _NumBinsX + ((pos.x + dim.x) / _BinSize.x);

    for(unsigned int i = 0; i < 4; i++)
    {
        if(bin[i] >= _NumBins)
        {
            return false;
        }

        bins.insert(bin[i]);
    }
    return true;
}
예제 #3
0
    /**
     * @brief GetEntityPosition gets the position of a specified entity
     * @param L the calling lua thread
     * @return the entity position if available, an error string otherwise.
     */
    static int GetEntityPosition(lua_State* L)
    {
        if(lua_gettop(L) != 1)
        {
            lua_pushstring(L, "Error: incorrect number of parameters");
            return 1;
        }

        LuaAccessor la;
        unsigned int id = (unsigned int)lua_tonumber(L, 1);
        Entity* e = la.GetEntity(id);

        if(e)
        {
            PositionComponent* p = e->GetComponent<PositionComponent>("Position");

            if(p)
            {
                lua_pushnumber(L, p->GetPosition().x);
                lua_pushnumber(L, p->GetPosition().y);
                return 2;
            }

            else
            {
                lua_pushstring(L, "No position component");
                return 1;
            }
        }

        lua_pushstring(L, "Entity does not exist");
        return 1;
    }
예제 #4
0
void	Bomb::DropBonusComponent::Update()
{
  PositionComponent *pos
    = static_cast<PositionComponent *>(this->GetParent()->GetComponent(Position_c));
  LifeComponent *life
    = static_cast<LifeComponent *>(this->GetParent()->GetComponent(Life_c));
  enum GameObjectTag	bonusTab[3];

  bonusTab[0] = BonusSpeed_o;
  bonusTab[1] = BonusAddBomb_o;
  bonusTab[2] = BonusSizeBomb_o;
  ListObj	*list_world = G_ObjectsContainer->GetObjByTag(World_o);
  if (list_world && life && life->GetLife() <= 0 && !this->_dropped)
    {
      IEntity	*world = list_world->front();
      if (world)
	{
	  MapComponent	*map = static_cast<MapComponent *>(world->GetComponent(Map_c));
	  if (pos && map)
	    {
	      double posX = pos->GetPosition(PositionComponent::X);
	      double posY = pos->GetPosition(PositionComponent::Y);

	      if (rand() % 10 < 4)
		{
		  IEntity	*bonus = G_EntityFactory->Create(bonusTab[rand() % 3]);

		  if (bonus)
		    {
		      pos = static_cast<PositionComponent *>(bonus->GetComponent(Position_c));

		      G_ObjectsContainer->AddObj(bonus);
		      G_EvDispatcher->SendEvent(new Event::GraphicEvent(bonus, Graphic::MESHADD),
		      				Event::COMMON);
		      pos->SetPosition(posX, posY);
		      map->AddEntity(bonus, posX, posY);
		      bonus->Start();
		      this->_dropped = true;
		    }
		}
	    }
	}
    }
}