void Sprite::UpdateCollisionBox() { double cx = x - image->GetHandleX() * fabs(scalex); double cy = y - image->GetHandleY() * fabs(scaley); double cw = image->GetWidth() * fabs(scalex); double ch = image->GetHeight() * fabs(scaley); UpdateCollisionBox(cx, cy, cw, ch); }
void Sprite::Update(double elapsed, const Map* map) { // Informacion inicial de colision colSprite = NULL; collided = false; // TAREA: Actualizar animacion currentFrame+=elapsed * animFPS; if (currentFrame > lastFrame) currentFrame = firstFrame; // TAREA: Actualizar rotacion animada if (rotating) { angle+=elapsed * rotatingSpeed; angle= WrapValue(angle,360); anglesToRotate-=abs(elapsed * rotatingSpeed); if (anglesToRotate <= 0) rotating = false; } // TAREA: Actualizar movimiento animado if (moving) { x+= elapsed * movingSpeedX; y+= elapsed * movingSpeedY; if ((movingSpeedX > 0 && x >= toX) || (movingSpeedX < 0 && x <= toX)) x = toX; if ((movingSpeedY > 0 && y >= toY) || (movingSpeedY < 0 && y <= toY)) y = toY; if (x == toX && y == toY) moving = false; } //ESCALADO if (scaling) { scalex+= elapsed * scalingSpeedX; scaley+= elapsed * scalingSpeedY; if ((scalingSpeedX > 0 && scalex >= toScaleX) || (scalingSpeedX < 0 && scalex <= toScaleX)) scalex = toScaleX; if ((scalingSpeedY > 0 && scaley >= toScaleY) || (scalingSpeedY < 0 && scaley <= toScaleY)) scaley = toScaleY; if (scalex == toScaleX && scaley == toScaleY) scaling = false; } // Informacion final de colision UpdateCollisionBox(); }
void Sprite::Update(double elapsed, const Map* map) { // Informacion inicial de colision colSprite = NULL; collided = false; // Actualizar animacion this->currentFrame += GetFPS() * elapsed; if (this->currentFrame > this->lastFrame) { this->currentFrame -= (this->lastFrame - this->firstFrame); } else if (this->currentFrame < this->firstFrame) { this->currentFrame += (this->lastFrame - this->firstFrame); } // Actualizar rotacion animada if (IsRotating()) { double rot = elapsed * this->rotatingSpeed; if (rot < this->degreesToRotate) { SetAngle(this->angle + rot); this->degreesToRotate -= rot; } else { SetAngle(this->toAngle); } } // Actualizar movimiento animado if (IsMoving()) { prevX = GetX(); prevY = GetY(); double despX = this->x + elapsed * this->movingSpeedX; double despY = this->y + elapsed * this->movingSpeedY; // x if(this->x - this->toX != 0){ if (this->x < this->toX) { // Right if (despX > this->toX) despX = this->toX; } else if (this->x > this->toX) { // Left if (despX < this->toX) despX = this->toX; } SetX(despX); UpdateCollisionBox(); if (CheckCollision(map)) { SetX(prevX); } } // y if (this->y - this->toY != 0) { if (this->y < this->toY) { // Down if (despY > this->toY) { despY = this->toY; } } else if (this->y > this->toY) { // Up if (despY < this->toY){ despY = this->toY; } } SetY(despY); UpdateCollisionBox(); if (CheckCollision(map)) { SetY(prevY); } } //SetPosition(despX, despY); if (this->x - this->toX == 0 && this->y - this->toY == 0) this->moving = false; } // Informacion final de colision UpdateCollisionBox(); }