Hey ! I have a question, I'm making a Dragon Ball Z SFLM(2.4.2) game and I want to implement :
If the Player pressed "Z", the attack(Projectile) will trigger in the face of the Player(not really in the face, like some distance) and it will continue to go as long as it doesn't hit the wall, if it reaches the wall it will vanish and return to the player coordinates.
Notes : The Projectile(attack) will go ahead the player ( the x coord.).
The Player will not be able to move while the attack is active.
The Player must hit "Z" only once and the attack will go to the wall.
Sorry for my bad english .
When I keep pressed "Z" too much the windows gives me a blue screen for 1 second and it restarts my laptop, Why ?
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
using namespace std;
int main()
{
int x = 0;
int MinX = 0;
int MaxXS = 800 - 39;
int MaxXR = 800 - 49;
int MinY = 0;
int MaxYS = 600 - 49;
int MaxYR = 600 - 41;
int y = 0;
int speed = 5.0;
bool vSyncEnabled = true;
RenderWindow window(VideoMode(800,600), "SFML works!");
window.setFramerateLimit(60);
window.setVerticalSyncEnabled(vSyncEnabled);
Texture texturaS;
if(!texturaS.loadFromFile("Stand.bmp"))
{
cout<<"ERROR"<<endl;
}
else
{
cout<<"TEXTURE LOADED"<<endl;
}
Sprite spritS;
spritS.setTexture(texturaS);
spritS.setOrigin(Vector2f(0, 0));
spritS.setPosition(400, 300);
Vector2f posS = spritS.getPosition();
Texture texturaR;
if(texturaR.loadFromFile("Run.bmp"))
{
cout<<"ERROR"<<endl;
}
else
{
cout<<"LOADED"<<endl;
}
Sprite spritR;
spritR.setTexture(texturaR);
spritR.setOrigin(Vector2f(0, 0));
spritR.setPosition(400, 300);
Vector2f pos = spritR.getPosition();
Texture texturaB;
if(texturaB.loadFromFile("BigBang.bmp"))
{
cout<<"ERROR"<<endl;
}
else
{
cout<<"LOADED"<<endl;
}
Sprite spritB;
spritB.setTexture(texturaB);
spritB.setOrigin(Vector2f(0, 0));
spritB.setPosition(pos.x,pos.y);
Vector2f posB = spritB.getPosition();
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
}
if(Keyboard::isKeyPressed(Keyboard::Left))
{
pos.x -= speed;
if(pos.x < MinX)
{
pos.x += speed;
}
cout<<"Pos. of x : "<<pos.x<<endl;
}
if(Keyboard::isKeyPressed(Keyboard::Right))
{
pos.x += speed;
if(pos.x > MaxXR)
{
pos.x -= speed;
}
else if(pos.x > MaxXS)
{
pos.x -= speed ;
}
cout<<"Pos. of x : "<<pos.x<<endl;
}
if(Keyboard::isKeyPressed(Keyboard::Up))
{
pos.y -= speed;
if(pos.y < MinY)
{
pos.y += speed;
}
cout<<"Pos. of y : "<<pos.y<<endl;
}
if(Keyboard::isKeyPressed(Keyboard::Down))
{
pos.y += speed;
if(pos.y > MaxYR)
{
pos.y -= speed;
}
else if(pos.y > MaxYS)
{
pos.y -= speed ;
}
cout<<"Pos. of y : "<<pos.y<<endl;
}
if(Keyboard::isKeyPressed(Keyboard::Z))
{
if(posB.x < 800)
{
posB.x += speed;
}
if(posB.x >= 800)
{
posB.x = pos.x;
posB.y = pos.y;
}
cout<<"Pos. of Z : "<<posB.x<<endl;
}
spritS.setPosition(pos.x , pos.y);
spritR.setPosition(pos.x , pos.y);
spritB.setPosition(posB.x , posB.y);
if(Keyboard::isKeyPressed(Keyboard::Down) || Keyboard::isKeyPressed(Keyboard::Up) || Keyboard::isKeyPressed(Keyboard::Left) || Keyboard::isKeyPressed(Keyboard::Right))
{
window.clear();
window.draw(spritR);
}
if(!Keyboard::isKeyPressed(Keyboard::Down) && !Keyboard::isKeyPressed(Keyboard::Up) && !Keyboard::isKeyPressed(Keyboard::Left) && !Keyboard::isKeyPressed(Keyboard::Right))
{
window.clear();
window.draw(spritS);
}
if(Keyboard::isKeyPressed(Keyboard::Z))
{
window.clear();
window.draw(spritS);
window.draw(spritB);
}
window.display();
}
return 0;
}