Merge pull request #4 from Ninjaws/develop
[Updated] Enemies to make the game a bit more beginner-friendly
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
font-size: larger;
|
||||
font-family: 'Press Start 2P', cursive;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.links {
|
||||
@@ -107,6 +108,10 @@
|
||||
return canvas;
|
||||
})()
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
document.getElementById('canvas').focus();
|
||||
};
|
||||
</script>
|
||||
<script src=game.js async></script>
|
||||
</body>
|
||||
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
uint8_t health;
|
||||
uint8_t maxHealth = 5;
|
||||
Vector2 velocity = {0, 0};
|
||||
float spottingRange = 300; // From how far away enemies can spot the player
|
||||
float spottingRange = 280.0f; // From how far away enemies can spot the player
|
||||
float gravity = 0.6f;
|
||||
float moveSpeed = 1.5f;
|
||||
float animationDelay = 0.2f; // In seconds
|
||||
|
||||
@@ -152,8 +152,8 @@ void Enemy::detectPlayer()
|
||||
bool spotted = false;
|
||||
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 (this->spriteAnimation.y == Left && this->texture.getPosition().x - player.getTexture().getPosition().x <= spottingRange &&
|
||||
this->texture.getPosition().x - player.getTexture().getPosition().x > 55 && this->texture.getPosition().y + this->texture.getSize().y >= player.getTexture().getPosition().y)
|
||||
if (this->spriteAnimation.y == Left && this->texture.getPosition().x - player.getTexture().getPosition().x <= this->spottingRange &&
|
||||
this->texture.getPosition().x - player.getTexture().getPosition().x > 55 && this->texture.getPosition().y + this->texture.getSize().y + 5 >= player.getTexture().getPosition().y)
|
||||
{
|
||||
spotted = true;
|
||||
float gunRotationLeft = atan2(playerCenter.y - enemyCenter.y,
|
||||
@@ -161,8 +161,8 @@ void Enemy::detectPlayer()
|
||||
float target = -gunRotationLeft * 180 / M_PI;
|
||||
this->gunLeft.setRotation(std::min(this->gunLeft.getRotation() + aimSpeed, target));
|
||||
}
|
||||
else if (spriteAnimation.y == Right && player.getTexture().getPosition().x - this->texture.getPosition().x <= spottingRange &&
|
||||
player.getTexture().getPosition().x - this->texture.getPosition().x > 55 && this->texture.getPosition().y + this->texture.getSize().y >= player.getTexture().getPosition().y)
|
||||
else if (spriteAnimation.y == Right && player.getTexture().getPosition().x - this->texture.getPosition().x <= this->spottingRange &&
|
||||
player.getTexture().getPosition().x - this->texture.getPosition().x > 55 && this->texture.getPosition().y + this->texture.getSize().y + 5 >= player.getTexture().getPosition().y)
|
||||
{
|
||||
spotted = true;
|
||||
float gunRotationRight = atan2(playerCenter.y - enemyCenter.y,
|
||||
@@ -188,8 +188,7 @@ void Enemy::detectPlayer()
|
||||
}
|
||||
}
|
||||
|
||||
void Enemy::shoot()
|
||||
{
|
||||
void Enemy::shoot() {
|
||||
Player &player = PlayerService::getInstance().getPlayer();
|
||||
/** Stop shooting if the player is dead (and falling out of the map) */
|
||||
if (player.getHealth() > 0 && playerSpotted && GetTime() - this->lastShot >= (1 / this->shotsPerSecond))
|
||||
|
||||
@@ -14,7 +14,7 @@ void EnemyService::initEnemies()
|
||||
this->enemies[1].getObject().setPosition({51.0f * tileSize, 10.0f * tileSize});
|
||||
this->enemies[2].getObject().setPosition({56.0f * tileSize, 5.0f * tileSize});
|
||||
this->enemies[3].getObject().setPosition({78.0f * tileSize, 10.0f * tileSize});
|
||||
this->enemies[4].getObject().setPosition({82.0f * tileSize, 15.0f * tileSize});
|
||||
this->enemies[4].getObject().setPosition({81.0f * tileSize, 15.0f * tileSize});
|
||||
this->enemies[5].getObject().setPosition({88.0f * tileSize, 4.0f * tileSize});
|
||||
this->enemies[6].getObject().setPosition({98.0f * tileSize, 11.0f * tileSize});
|
||||
this->enemies[7].getObject().setPosition({103.0f * tileSize, 15.0f * tileSize});
|
||||
|
||||
Reference in New Issue
Block a user