Can someone help me fix this code? enemySpawnTimer... and forgive me if this is not how i am supposed to post code. please inform me
Error C2143 syntax error: missing ';' before '{' SFMLlearning2 C:\Users\lando\source\repos\SFMLlearning2\SFMLlearning2\main.cpp 82
Error (active) E0020 identifier "enemySpawnTimer" is undefined SFMLlearning2 C:\Users\lando\source\repos\SFMLlearning2\SFMLlearning2\main.cpp 81
Error C2947 expecting '>' to terminate template-argument-list, found '>=' SFMLlearning2 C:\Users\lando\source\repos\SFMLlearning2\SFMLlearning2\main.cpp 81
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <vector>
#include <cstdlib>
using namespace sf;
int main()
{
srand(time(NULL));
sf::RenderWindow window(sf::VideoMode(640, 480), "Simple Game");
window.setFramerateLimit(60);
//Balls
CircleShape projectile;
projectile.setFillColor(Color::Red);
projectile.setRadius(5.f);
RectangleShape enemy;
enemy.setFillColor(Color::Magenta);
enemy.setSize(Vector2f(50.f, 50.f));
CircleShape player;
player.setFillColor(Color::White);
player.setRadius(50.f);
player.setPosition(window.getSize().x / 2 - player.getRadius(), window.getSize().y - player.getRadius() * 2 - 10.f);
Vector2f playerCenter;
int shootTimer = 0;
std::vector<CircleShape> projectiles;
projectiles.push_back(CircleShape(projectile));
std::vector<RectangleShape>enemies;
enemies.push_back(RectangleShape(enemy));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//update
playerCenter = Vector2f(player.getPosition().x + player.getRadius(), player.getPosition().y + player.getRadius());
player.setPosition(Mouse::getPosition(window).x, player.getPosition().y);
{
projectile.setPosition(playerCenter);
projectiles.push_back(CircleShape(projectile));
shootTimer = 0;
}
if (Mouse::isButtonPressed(Mouse::Left) && shootTimer >= 3)
{
projectile.setPosition(playerCenter);
projectiles.push_back(CircleShape(projectile));
shootTimer = 0;
}
for (size_t i = 0; i < projectiles.size(); i++)
{
projectiles[i].move(0.f, -10.f);
if (projectiles[i].getPosition().y <= 0)
projectiles.erase(projectiles.begin() + i);
}
[color=red][b]
//ENemies
if (enemySpawnTimer < 20)
enemySpawnTimer++;
if (enemySpawnTimer >= 20)
{
enemy.setPosition((rand() % int(window.getSize().x - enemy.getSize().x)), 0.f);
enemies.push_back(RectangleShape(enemy));
int enemySpawnTimer = 0;
}[/b][/color]
for (size_t i = 0; i < enemies.size(); i++)
{
enemies[i].move(0.f, 5.f);
if (enemies[i].getPosition().y > window.getSize().y);
enemies.erase(enemies.begin() + i);
}
//update ball
//Collision
for (size_t i = 0; i < projectiles.size(); i++)
{
for (size_t k = 0; k < enemies.size(); k++)
{
if (projectiles[i].getGlobalBounds().intersects(enemies[k].getGlobalBounds()));
{
projectiles.erase(projectiles.begin() + i);
enemies.erase(enemies.begin() + i);
}
}
}
//Draw
window.clear();
window.draw(player);
for (size_t i = 0; i < enemies.size(); i++)
{
window.draw(enemies[i]);
}
for (size_t i = 0; i < projectiles.size(); i++)
{
window.draw(projectiles[i]);
}
window.display();
}
return 0;
}