Ejemplo n.º 1
0
void obj_talker::update()
{
	if (sprite != NULL && phrases.size() > 0)
	{
		if (collisionAt(x,y,OBJ_PLAYER))
		{
			if (type != OBJ_PORTAL)
				level->talking = this;
			scaletick += .2f;
			scaleX = 1.f+.1f*cos(scaletick);
			scaleY = 1.f+.1f*sin(scaletick);
			drawX = x - .05f*sprite->getWidth()*cos(scaletick);
			drawY = y - .1f*sprite->getHeight()*sin(scaletick);
		}
		else
		{
			currentPhrase = 0;
			scaleX = 1;
			scaleY = 1;
			drawX = x;
			drawY = y;
		}
	}
}
Ejemplo n.º 2
0
void cPlayer::move(float relativeX, float relativeY, bool recursive)
{
    float nx = this->x + relativeX;
    float ny = this->y + relativeY;
    float moveAmount = (relativeX != 0 ? fabs(relativeX) : fabs(relativeY));

    // Collision testing
    bool colTL = false, colTR = false, colBL = false, colBR = false, colMap = false;
    this->collideHappened = false;

    // ... with map objects

    if(collisionAt(nx + this->collisionBox.x1, ny - this->collisionBox.y1))  // Top left
    {
        colTL = true;
    }
    if(collisionAt(nx + this->collisionBox.x2, ny - this->collisionBox.y1))  // Top right
    {
        colTR = true;
    }
    if(collisionAt(nx + this->collisionBox.x1, ny - this->collisionBox.y2))  // Bottom left
    {
        colBL = true;
    }
    if(collisionAt(nx + this->collisionBox.x2, ny - this->collisionBox.y2))  // Bottom right
    {
        colBR = true;
    }


    // ... with map bounds
    cMap &map = getMapRef();
    cRect &mapBounds = map.getBounderies();

    if(nx + this->collisionBox.x1 / 2 < mapBounds.x1)
    {
        colMap = true;
    }
    else if(nx + this->collisionBox.x2 / 2 > mapBounds.x2)
    {
        colMap = true;
    }
    if(ny + this->collisionBox.y1 / 2 < mapBounds.y1)
    {
        colMap = true;
    }
    else if(ny + this->collisionBox.y2 / 2 > mapBounds.y2)
    {
        colMap = true;
    }

    if(colTL || colTR || colBL || colBR || colMap)
    {
        this->collideHappened = true;

        if((! recursive) && (! colMap))
        {
            if(relativeY != 0)
            {
                if((colBR && ! colBL) || (colTR && ! colTL))
                {
                    move(-moveAmount, 0, true);
                }
                else if((colBL && ! colBR) || (colTL && ! colTR))
                {
                    move(moveAmount, 0, true);
                }
            }
            else
            {
                if((colTL && ! colBL) || (colTR && ! colBR))
                {
                    move(0, -moveAmount, true);
                }
                else if((colBL && ! colTL) || (colBR && ! colTR))
                {
                    move(0, moveAmount, true);
                }
            }
        }
    }
    else
    {
        this->x += relativeX;
        this->y += relativeY;
    }
}