Computer Science Canada

Shoot multiple times

Author:  turinghelp123 [ Wed May 14, 2014 8:53 pm ]
Post subject:  Shoot multiple times

What is it you are trying to achieve?
<Make the program shoot multiple times>


What is the problem you are having?
<You can only shoot once then you have to wait till the bullet disappears to shoot again>


Describe what you have tried to solve this problem
<I've been trying to solve this for about 1 hour, and I've been having no luck>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


<
View.Set ("offscreenonly")

var chars : array char of boolean
var x, y, bullety, bulletx : int := 100
var shot : int := 0
forward proc movement

proc shoot
    loop
        shot := 1
        bullety += 1
        exit when bullety + 20 > maxy
        movement
    end loop
    shot := 0
end shoot

body proc movement
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and y + 64 < maxy then
        y := y + 1
    elsif chars (KEY_DOWN_ARROW) and y > 0 then
        y := y - 1
    elsif chars (KEY_LEFT_ARROW) and x > 0 then
        x := x - 1
    elsif chars (KEY_RIGHT_ARROW) and x + 64 < maxx then
        x := x + 1
    end if
    if chars (KEY_CTRL) and shot = 0 then
        bullety := y
        bulletx := x
        shoot
    end if
    cls
    if shot = 1 then
        drawoval (bulletx + 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx + 35, bullety, 10, 10, 7)
        drawoval (bulletx - 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx - 35, bullety, 10, 10, 7)
    end if
    drawfilloval (x, y, 20, 20, 7)
    View.Update
end movement

loop
    movement
end loop >



Please specify what version of Turing you are using
<4.1>

Author:  DemonWasp [ Wed May 14, 2014 9:27 pm ]
Post subject:  RE:Shoot multiple times

If you want to keep track of several things of the same type, you should look into arrays and records. Here's the Turing Walkthrough links:

http://compsci.ca/v3/viewtopic.php?t=14333

http://compsci.ca/v3/viewtopic.php?t=9636

Author:  turinghelp123 [ Wed May 14, 2014 9:30 pm ]
Post subject:  RE:Shoot multiple times

What do you mean? How does this help shooting multiple times?

Author:  Tony [ Wed May 14, 2014 11:03 pm ]
Post subject:  RE:Shoot multiple times

Right now you have only bullety. You want bullety_1, bullety_2, ..., etc. An array will let you group those related variables together, for much easier use.

Author:  turinghelp123 [ Wed May 14, 2014 11:09 pm ]
Post subject:  Re: RE:Shoot multiple times

Tony @ Wed May 14, 2014 11:03 pm wrote:
Right now you have only bullety. You want bullety_1, bullety_2, ..., etc. An array will let you group those related variables together, for much easier use.



Thanks tony, I just looked at arrays but I'm having trouble applying it to my program


: