Alien Attack is a small fixed shooter I built with C++ and SFML. It was a way to practice organizing behavior across classes while working with movement, projectiles, collisions, and a game loop.
- Built with
- C++, SFML, CMake
- Focus
- Classes, movement, collisions, debugging
Building and debugging it
One part I spent time on was the alien movement. A few dropped down immediately when the game began. I could have made the aliens move as one group, but I wanted each one to move on its own. I narrowed down which aliens were causing the problem.
The issue involved their starting directions and edge checks. Working through gameplay clips and the movement code helped me make a smaller fix that preserved the independent movement. I also worked on making movement depend on elapsed time rather than frame rate.
// Only the last alien's direction was initialized.isAlienRight[ALIEN_COUNT - 1] = { false };// The edge checks ignored which way the alien was moving.if (alien->getMyPixie()->getX() > WINDOW_WIDTH - 10) { isAlienRight[i] = true; alien->getMyPixie()->setPosition(WINDOW_WIDTH - 30, alien->getMyPixie()->getY() + 35);}else if (alien->getMyPixie()->getX() <= 0) { isAlienRight[i] = false; alien->getMyPixie()->setPosition(0, alien->getMyPixie()->getY() + 35);}// Give every alien a starting direction.std::fill_n(isAlienRight, ALIEN_COUNT, false);// Check the edge in the direction this alien is moving.if (!isAlienRight[i] && alien->getMyPixie()->getX() > WINDOW_WIDTH - 10) { isAlienRight[i] = true; alien->getMyPixie()->setPosition(WINDOW_WIDTH - 30, alien->getMyPixie()->getY() + 35);}else if (isAlienRight[i] && alien->getMyPixie()->getX() <= 0) { isAlienRight[i] = false; alien->getMyPixie()->setPosition(0, alien->getMyPixie()->getY() + 35);}Takeaways
A few aliens dropped as soon as the game started. I traced it to their starting directions and edge checks, then fixed it without changing the independent movement I wanted.