How to implement an attack ?

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 ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#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 texturaBackGround;
    if(!texturaBackGround.loadFromFile("BackGround.png"))
    {
        cout<<"ERRROR"<<endl;
    }
    else
    {
        cout<<"LOADED"<<endl;
    }
    Sprite spritBackground;
    spritBackground.setTexture(texturaBackGround);
    Texture texturaS;
    if(!texturaS.loadFromFile("Stand.png"))
    {
        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.png"))
    {
        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.png"))
    {
        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 + 30;
                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);
        //window.draw(spritBackground);
        if(Keyboard::isKeyPressed(Keyboard::Down) || Keyboard::isKeyPressed(Keyboard::Up) || Keyboard::isKeyPressed(Keyboard::Left) || Keyboard::isKeyPressed(Keyboard::Right))
        {
        window.clear();
        window.draw(spritBackground);
        window.draw(spritR);
        }
        if(!Keyboard::isKeyPressed(Keyboard::Down) && !Keyboard::isKeyPressed(Keyboard::Up) && !Keyboard::isKeyPressed(Keyboard::Left) && !Keyboard::isKeyPressed(Keyboard::Right))
        {
            window.clear();
            window.draw(spritBackground);
            window.draw(spritS);
        }
        if(Keyboard::isKeyPressed(Keyboard::Z))
        {
            window.clear();
            window.draw(spritBackground);
            window.draw(spritS);
            window.draw(spritB);
        }
        window.display();
    }
    return 0;
}
Last edited on
Topic archived. No new replies allowed.