feat(laser): created laser object

Created laser object without any collision detection
This commit is contained in:
2024-01-09 12:26:42 +01:00
parent 0fed252afd
commit 9b0a7a78bb
10 changed files with 103 additions and 27 deletions
+31 -8
View File
@@ -7,21 +7,44 @@ int main()
window.setVerticalSyncEnabled(true);
Player player(window);
Inputs inputs(window, player);
vector<RectangleShape> lasers;
Inputs inputs(player, lasers);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
inputs.HandleInputs(event);
window.clear(Color::Black);
player.DrawPlayer();
window.display();
if (event.type == sf::Event::Closed)
{
window.close();
}
}
// Handle user's inputs
inputs.HandleInputs();
window.clear(Color::Black);
// Draw everything
player.drawPlayer();
for (vector<RectangleShape>::iterator it = lasers.begin(); it < lasers.end();) {
window.draw(*it);
it->move(0, -5);
if (it->getPosition().y < -it->getScale().y) {
it = lasers.erase(it);
}
else {
lasers[distance(lasers.begin(), it)] = *it;
++it;
}
}
// Display window
window.display();
}
return 0;