Adding enemies
In order to keep our player from walking the world lonely and un-attacked, we must add enemies to the game. Once again, let's begin with the header file:
#pragma once #include "Character.h" class Enemy : public Character{ public: Enemy(EntityManager* l_entityMgr); ~Enemy(); void OnEntityCollision(EntityBase* l_collider, bool l_attack); void Update(float l_dT); private: sf::Vector2f m_destination; bool m_hasDestination; };
It's the same basic idea here as it was in the player class. This time, however, the enemy class needs to specify its own version of the Update
method. It also has two private data members, one of which is a destination vector. It is a very simple attempt at adding basic artificial intelligence to the game. All it will do is keep track of a destination position, which the Update
method will randomize every now and then to simulate wandering entities. Let's implement this:
Enemy::Enemy(EntityManager* l_entityMgr) :Character(l_entityMgr...