diff --git a/html/index.html b/html/index.html index 728fa2a..d738bf8 100644 --- a/html/index.html +++ b/html/index.html @@ -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(); + }; diff --git a/include/entities/Enemy.h b/include/entities/Enemy.h index a3c4d38..523fe43 100644 --- a/include/entities/Enemy.h +++ b/include/entities/Enemy.h @@ -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 diff --git a/src/entities/Enemy.cpp b/src/entities/Enemy.cpp index 7c85ccc..5a899b2 100644 --- a/src/entities/Enemy.cpp +++ b/src/entities/Enemy.cpp @@ -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)) diff --git a/src/services/EnemyService.cpp b/src/services/EnemyService.cpp index 646fde2..23e28bb 100644 --- a/src/services/EnemyService.cpp +++ b/src/services/EnemyService.cpp @@ -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});