1
Graphics / Re: Enemy Sprites spawn but don't move and can't be killed
« on: September 29, 2024, 12:38:28 pm »
I figured out the problem. There is a bug in the github code and I believe in the book itself. In the Zombie.cpp file the m_Alive boolean is never initialized. All I had to do was set m_Alive = true; in the void Zombie::spawn() type like so:
void Zombie::spawn(float startX, float startY, int type, int seed)
{
m_Alive = true;
switch(type)
{
case 0:
// Bloater
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/bloater.png"));
m_Speed = BLOATER_SPEED;
m_Health = BLOATER_HEALTH;
break;
case 1:
// Chaser
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/chaser.png"));
m_Speed = CHASER_SPEED;
m_Health = CHASER_HEALTH;
break;
case 2:
// Crawler
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/crawler.png"));
m_Speed = CRAWLER_SPEED;
m_Health = CRAWLER_HEALTH;
break;
}
{
m_Alive = true;
switch(type)
{
case 0:
// Bloater
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/bloater.png"));
m_Speed = BLOATER_SPEED;
m_Health = BLOATER_HEALTH;
break;
case 1:
// Chaser
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/chaser.png"));
m_Speed = CHASER_SPEED;
m_Health = CHASER_HEALTH;
break;
case 2:
// Crawler
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/crawler.png"));
m_Speed = CRAWLER_SPEED;
m_Health = CRAWLER_HEALTH;
break;
}