Hello people! I have two problems that are making my a little bit angry.
1. Problem with fast and dynamic background displaying. When I try to display it (while the sprites are colliding)... It doesn't appear as many time as it should appear. What should I do to improve this?
2. Problems with dynamic sprite movement. When I subtract some points (during the collision) the speed of moving of sprites is getting slower. How can I prevent that?
Code:
1.
void game1()
{
srand(time(0));
window.clear(Color::Black);
RectangleShape collision1;
collision1.setFillColor(Color(140, 10, 10, 105));
collision1.setSize(Vector2f(1280, 720));
collision1.setPosition(Vector2f(0, 0));
player.drawPlayer(*playerXPointer, *playerYPointer);
for (int i = 0; i < 20; i++)
{
if (g1_collision == true)
{
window.draw(collision1);
}
}
for (int i = 0; i < 20; i++)
{
asteroidsX[i] = rand() % 1280 + 1;
asteroidsY = rand() % 720 + 1;
asteroidsSpeedX = rand() % 2 + 1;
}
for (int i = 0; i < 20; i++)
{
asteroids.setRadius(20);
asteroids.setPosition(Vector2f(asteroidsSpeedX * asteroidsMoveX + asteroidsX, asteroidsY));
asteroids.setFillColor(Color::Black);
asteroids.setOutlineColor(Color::White);
asteroids.setOutlineThickness(2);
window.draw(asteroids);
}
}
2.
if (g1_asteroids == true)
{
for (int i = 0; i < 20; i++)
{
asteroidsMoveX[i] -= 1;
}
for (int i = 0; i < 20; i++)
{
if (asteroidsMoveX[i] + asteroidsX[i] < -1)
{
asteroidsMoveX[i] = 1280;
}
}
for (int i = 0; i < 20; i++)
{
if (asteroidsX[i] + asteroidsMoveX[i] >= playerX && asteroidsX[i] + asteroidsMoveX[i] <= playerX + 80 && asteroidsY[i] >= playerY && asteroidsY[i] <= playerY + 80)
{
g1_collision = true;
*pointsPointer -= 1;
cout << *pointsPointer << endl;
}
else
{
g1_collision = false;
}
}
}