Ejemplo n.º 1
0
bool CEntity::posValid(sf::Vector2f newPos) {
    bool Return = true;

	//Create new rectangle for bound
	sf::IntRect trialBound = bound;
	trialBound.left = ((int)newPos.x) + size.x/2 * mEntitySprite.getScale().x - bound.width/2;
	trialBound.top = ((int)newPos.y) + size.y/2 * mEntitySprite.getScale().y - bound.height/2;

    /*
    * Do collision against the Map
    */
    int startX = (trialBound.left)/TILE_SIZE;
    int startY = (trialBound.top)/TILE_SIZE;

    int EndX = ((trialBound.left + trialBound.width) - 1)/TILE_SIZE;
		int EndY = ((trialBound.top + trialBound.height) - 1)/TILE_SIZE;

    for(int iY = startY;iY <= EndY;iY++) {
        for(int iX = startX;iX <= EndX;iX++) {
            CTile* Tile = CArea::areaControl->getTile(iX * TILE_SIZE, iY * TILE_SIZE);
            if(posValidTile(Tile) == false) {
                Return = false;
            }
        }
    }

    /*
		* Do collision against other entities if entity
    * can collide with other entities
    */
    if(flags & ENTITY_FLAG_MAPONLY) {
    }else{
        //Check for collisions with entities
        for(size_t i = 0;i < EntityList.size();i++) {
            if(posValidEntity(EntityList[i], trialBound) == false) {
                Return = false;
            }
        }
    }
    return Return;
}
Ejemplo n.º 2
0
bool Entity::posValid(int newX, int newY)
{
    bool returnVal = true;
    int startX 	= (newX + col_X);
	int startY 	= (newY + col_Y);

	int endX	= ((newX + col_X) + width - col_Width - 1);
	int endY	= ((newY + col_Y) + height - col_Height - 1);


	if(flags & ENTITY_FLAG_MAPONLY) {
	}else{
		for(size_t i = 0;i < EntityList.size();i++) {
			if(posValidEntity(EntityList[i], newX, newY) == false) {
				returnVal = false;
			}
		}
	}

	return returnVal;
}