[Added] Ability to serve the project using nginx on localhost:4600
This commit is contained in:
+13
-60
@@ -73,23 +73,16 @@ std::vector<Vector2i> Enemy::getCorners()
|
||||
float top = texture.getPosition().y + velocity.y;
|
||||
|
||||
int tileSize = MapService::getInstance().getMap().getTileSize();
|
||||
// Vector2i leftTop(Vector2i((int)left / tileSize, (int)(top + 5) / tileSize));
|
||||
// Vector2i leftBottom(Vector2i((int)left / tileSize, (int)(bottom - 5) / tileSize));
|
||||
Vector2i leftCenter = Vector2i((int)(left -(spriteAnimation.y == Left ? gunLeft.getSize().x*(2.0f/3.0f) : 0.0f)) / tileSize, (int)(bottom - texture.getSize().y / 2.0) / tileSize);
|
||||
// Vector2i rightTop(Vector2i((int)right / tileSize, (int)(top + 5) / tileSize));
|
||||
// Vector2i rightBottom(Vector2i((int)right / tileSize, (int)(bottom - 5) / tileSize));
|
||||
Vector2i rightCenter = Vector2i((int)(right+ (spriteAnimation.y == Right ? gunRight.getSize().x*(2.0f/3.0f) : 0.0f)) / tileSize, (int)(bottom - texture.getSize().y / 2.0) / tileSize);
|
||||
Vector2i leftCenter = Vector2i((int)(left - (spriteAnimation.y == Left ? gunLeft.getSize().x * (2.0f / 3.0f) : 0.0f)) / tileSize, (int)(bottom - texture.getSize().y / 2.0) / tileSize);
|
||||
Vector2i rightCenter = Vector2i((int)(right + (spriteAnimation.y == Right ? gunRight.getSize().x * (2.0f / 3.0f) : 0.0f)) / tileSize, (int)(bottom - texture.getSize().y / 2.0) / tileSize);
|
||||
|
||||
Vector2i bottomLeft(Vector2i((int)(left + 5) / tileSize, (int)bottom / tileSize)); // +5 to separate bottom from side
|
||||
Vector2i bottomRight(Vector2i((int)(right - 5) / tileSize, (int)bottom / tileSize)); // -5 to separate bottom from side
|
||||
Vector2i bottomLeft(Vector2i((int)(left + 5) / tileSize, (int)bottom / tileSize));
|
||||
Vector2i bottomRight(Vector2i((int)(right - 5) / tileSize, (int)bottom / tileSize));
|
||||
|
||||
std::vector<Vector2i> corners;
|
||||
|
||||
corners.push_back(leftCenter);
|
||||
corners.push_back(rightCenter);
|
||||
// corners.push_back(leftBottom);
|
||||
// corners.push_back(rightTop);
|
||||
// corners.push_back(rightBottom);
|
||||
|
||||
corners.push_back(bottomLeft);
|
||||
corners.push_back(bottomRight);
|
||||
@@ -105,7 +98,6 @@ void Enemy::animate()
|
||||
Rectangle sourceRect = this->texture.getSourceRect();
|
||||
sourceRect.x = spriteAnimation.x * this->texture.getSize().x;
|
||||
sourceRect.y = spriteAnimation.y * this->texture.getSize().y;
|
||||
// sourceRect.x = std::fmod(sourceRect.x, 3 * this->texture.getSize().x);
|
||||
this->texture.setSourceRect(sourceRect);
|
||||
prevFrame = GetTime();
|
||||
}
|
||||
@@ -154,7 +146,6 @@ void Enemy::fall()
|
||||
|
||||
void Enemy::detectPlayer()
|
||||
{
|
||||
// playerSpotted = false;
|
||||
Player &player = PlayerService::getInstance().getPlayer();
|
||||
if (this->health > 0)
|
||||
{
|
||||
@@ -168,8 +159,6 @@ void Enemy::detectPlayer()
|
||||
float gunRotationLeft = atan2(playerCenter.y - enemyCenter.y,
|
||||
enemyCenter.x - playerCenter.x);
|
||||
float target = -gunRotationLeft * 180 / M_PI;
|
||||
// float delta = target - this->gunLeft.getRotation();
|
||||
// float sign = std::copysign(1.0f, delta);
|
||||
this->gunLeft.setRotation(std::min(this->gunLeft.getRotation() + aimSpeed, target));
|
||||
}
|
||||
else if (spriteAnimation.y == Right && player.getTexture().getPosition().x - this->texture.getPosition().x <= spottingRange &&
|
||||
@@ -179,8 +168,6 @@ void Enemy::detectPlayer()
|
||||
float gunRotationRight = atan2(playerCenter.y - enemyCenter.y,
|
||||
playerCenter.x - enemyCenter.x);
|
||||
float target = gunRotationRight * 180 / M_PI;
|
||||
|
||||
// this->gunRight.setRotation(gunRotationRight * 180 / M_PI);
|
||||
this->gunRight.setRotation(std::max(this->gunRight.getRotation() - aimSpeed, target));
|
||||
}
|
||||
|
||||
@@ -195,8 +182,8 @@ void Enemy::detectPlayer()
|
||||
{
|
||||
this->playerSpotted = false;
|
||||
/** Slowly ease the gun back to default position */
|
||||
this->gunLeft.setRotation(std::max(this->gunLeft.getRotation() - aimSpeed/2.0f, 0.0f));
|
||||
this->gunRight.setRotation(std::min(this->gunRight.getRotation() + aimSpeed/2.0f, 0.0f));
|
||||
this->gunLeft.setRotation(std::max(this->gunLeft.getRotation() - aimSpeed / 2.0f, 0.0f));
|
||||
this->gunRight.setRotation(std::min(this->gunRight.getRotation() + aimSpeed / 2.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,49 +202,15 @@ void Enemy::shoot()
|
||||
float offsetDistance = this->gunLeft.getSize().x - this->gunLeft.getSize().x / 3;
|
||||
Vector2 playerCenter = {player.getTexture().getPosition().x + player.getTexture().getSize().x / 2.0f, player.getTexture().getPosition().y + player.getTexture().getSize().y / 2.0f};
|
||||
Vector2 enemyCenter = {texture.getPosition().x + texture.getSize().x / 2.0f, texture.getPosition().y + texture.getSize().y / 2.0f};
|
||||
|
||||
|
||||
// if (spriteAnimation.y == Left)
|
||||
// {
|
||||
float angleShot = atan2(playerCenter.y - enemyCenter.y,
|
||||
playerCenter.x - enemyCenter.x);
|
||||
|
||||
float angleShot = atan2(playerCenter.y - enemyCenter.y,
|
||||
playerCenter.x - enemyCenter.x);
|
||||
float offsetX = cos(angleShot) * offsetDistance;
|
||||
float offsetY = sin(angleShot) * offsetDistance;
|
||||
Vector2 bulletStartLocation = {this->texture.getPosition().x + this->texture.getSize().x / 2.0f + offsetX,
|
||||
this->texture.getPosition().y + this->texture.getSize().y / 2.0f + offsetY};
|
||||
|
||||
// float gunRotationRadians = this->gunLeft.getRotation() * (M_PI / 180.0f); // Convert degrees to radians
|
||||
float offsetX = cos(angleShot) * offsetDistance;
|
||||
float offsetY = sin(angleShot) * offsetDistance;
|
||||
Vector2 bulletStartLocation = {this->texture.getPosition().x + this->texture.getSize().x / 2.0f + offsetX,
|
||||
this->texture.getPosition().y + this->texture.getSize().y / 2.0f + offsetY};
|
||||
|
||||
BulletService::getInstance().addEnemyBullet(bulletStartLocation, angleShot);
|
||||
// }
|
||||
|
||||
// if ((player.getTexture().getPosition().x > this->texture.getPosition().x + this->gunLeft.getSize().x && spriteAnimation.y == Right) ||
|
||||
// (player.getTexture().getPosition().x + (this->gunLeft.getSize().x / 2) < this->texture.getPosition().x && spriteAnimation.y == Left))
|
||||
// {
|
||||
|
||||
// // float gunRotationRight = atan2(GameService::getInstance().getMouseWorldPos().y - (this->texture.getPosition().y + this->texture.getSize().y / 2.0),
|
||||
// // GameService::getInstance().getMouseWorldPos().x - (this->texture.getPosition().x + this->texture.getSize().x / 2.0));
|
||||
// // this->gunRight.setRotation(gunRotationRight * 180 / M_PI);
|
||||
|
||||
// float angleShot = atan2(player.getTexture().getPosition().y - (this->texture.getPosition().y + this->texture.getSize().y / 2.0),
|
||||
// player.getTexture().getPosition().x - (this->texture.getPosition().x + this->texture.getSize().x / 2.0));
|
||||
|
||||
// // this->gunRight.setRotation(angleShot * 180 / M_PI);
|
||||
// // this->gunLeft.setRotation(-angleShot * 180 / M_PI);
|
||||
// /** Making the bullet originate from the gun's mouth */
|
||||
// float offsetDistance = this->gunLeft.getSize().x - this->gunLeft.getSize().x / 3;
|
||||
// float offsetX = cos(angleShot) * offsetDistance;
|
||||
// float offsetY = sin(angleShot) * offsetDistance;
|
||||
// Vector2 bulletStartLocation = {this->texture.getPosition().x + this->texture.getSize().x / 2.0f + offsetX,
|
||||
// this->texture.getPosition().y + this->texture.getSize().y / 2.0f + offsetY};
|
||||
|
||||
// // BulletService::getInstance().addEnemyBullet(bulletStartLocation, angleShot);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // this->gunRight.setRotation(0);
|
||||
// // this->gunLeft.setRotation(0);
|
||||
// }
|
||||
BulletService::getInstance().addEnemyBullet(bulletStartLocation, angleShot);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ void PBullet::objCollision()
|
||||
this->position.y + this->size > crate.getObject().getPosition().y && this->position.y-this->size < crate.getObject().getPosition().y + crate.getObject().getSize().y) {
|
||||
crate.setHit(true);
|
||||
AssetService::getInstance().playSound(ESound::CRATE_BREAK);
|
||||
AssetService::getInstance().playSound(ESound::JELLY_FREED);
|
||||
this->hasCollided = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user