
-----------------------------------
Alex C.
Wed Jan 18, 2012 12:57 pm

Projectile Shooting... STILL -.-*
-----------------------------------
Sigh... I STILL can't figure out how to shoot a projectile :cry: ... I have looked through several help topics with minimal sucess and I just dont understand how to make my object shoot... please help

oh, I'm using 4.1



View.Set ("nobuttonbar,offscreenonly")
colorback (30)
var shipx, shipy : int := 0

var font1 : int := Font.New ("verdana:12")
var ship : int := Pic.FileNew ("Cargo_Ship.gif")
var BULLET : int := Pic.FileNew ("Bullets.gif")
var chars : array char of boolean

var Bullets : int := 1
var Bulletx, Bullety : flexible array 1 .. 10 of int
var BulletCount : int := 0
var Reloading : int := 0
var x, y : array 1 .. 10 of int
for i : 1 .. 10
    x (i) := maxx div 2
end for
for i : 1 .. 10
    y (i) := 15
end for

loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        shipy := shipy + 3
    end if
    if chars (KEY_RIGHT_ARROW) then
        shipx := shipx + 3
    end if
    if chars (KEY_LEFT_ARROW) then
        shipx := shipx - 3
    end if
    if chars (KEY_DOWN_ARROW) then
        shipy := shipy - 3
    end if
    if chars (chr (27)) then
        `close (1)
    end if
    if chars (' ') and Reloading = 0 then
        if Bullets mod 2 = 0 then     
            for i : -Bullets .. Bullets by 2
                if i not= 0 then
                    BulletCount += 1
                    Bulletx (BulletCount) := x (1) + i * 4
                    Bullety (BulletCount) := y (1) - abs (i) * 5
                    Reloading := 20
                end if
            end for
        else
            for i : -Bullets div 2 .. Bullets div 2
                BulletCount += 1
                Bulletx (BulletCount) := x (1) + i * 8
                Bullety (BulletCount) := y (1) - round (abs (i) * 2.5)
                Reloading := 20
            end for
        end if
        if Reloading > 0 then
            Reloading -= 1
        end if
    end if


    if shipx = maxx - 100 then
        shipx -= 3
    end if
    if shipy = maxy - 100 then
        shipy -= 3
    end if
    Font.Draw ("Use the arrow keys to move the ship,", 5, maxy - 30, font1, brightblue)
    Font.Draw ("and press ESC to exit", 5, maxy - 48, font1, brightblue)
    Pic.Draw (ship, shipx, shipy, 2)
    for q : 1 .. max (BulletCount, 1)
        if q = maxy then
                Bulletx (q) := Bulletx (BulletCount)
                Bullety (q) := Bullety (BulletCount)
                Bullety (q) += 10
                BulletCount -= 1
            end if
        end if
    end for
    delay (10)
    View.Update
    cls
end loop





Please specify what version of Turing you are using


-----------------------------------
Alex C.
Thu Jan 19, 2012 8:47 am

RE:Projectile Shooting... STILL -.-*
-----------------------------------
um... help please?

-----------------------------------
Alex C.
Thu Jan 19, 2012 9:01 am

RE:Projectile Shooting... STILL -.-*
-----------------------------------
:(

-----------------------------------
Raknarg
Thu Jan 19, 2012 10:42 am

RE:Projectile Shooting... STILL -.-*
-----------------------------------
Ok. So explain to me the logic behind how you're shooting the bullets.

-----------------------------------
Alex C.
Thu Jan 19, 2012 12:20 pm

Re: Projectile Shooting... STILL -.-*
-----------------------------------
um... i'm sorry but i don't understand (i sorta fail at progrmming)
but i did figure out how to shoot  bullets in relation to my ship...

the problem is now i can't figure out how to erase it once it hits the maxy...

 
View.Set ("nobuttonbar,offscreenonly")
colorback (30)
var shipx, shipy : int := 0

var font1 : int := Font.New ("bank_gothic:12")
var ship : int := Pic.FileNew ("Cargo_Ship.gif")
var BULLET : int := Pic.FileNew ("Bullets.gif")
var chars : array char of boolean

var bullets : int := 0
var bulletx : flexible array 1 .. 3 of int 
var bullety : flexible array 1 .. 3 of int 
var Reloading : int := 20
var x, y : array 1 .. 10 of int
for i : 1 .. 10
    x (i) := maxx div 2
end for
for i : 1 .. 10
    y (i) := 15
end for

loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        shipy := shipy + 3
    end if
    if chars (KEY_RIGHT_ARROW) then
        shipx := shipx + 3
    end if
    if chars (KEY_LEFT_ARROW) then
        shipx := shipx - 3
    end if
    if chars (KEY_DOWN_ARROW) then
        shipy := shipy - 3
    end if
    if chars (chr (27)) then
        Window.Hide (defWinID)
    end if
    if chars (' ') and Reloading >= 20 and bullets < 3
      then
        Reloading := 0
        bullets += 1
         bulletx (bullets) := shipx
        bullety (bullets) := shipy
        put bullets

    end if

    % Slight collison detection to make sure the ship is within boundaries
    if shipx = maxx - 100 then
        shipx -= 3
    end if
    if shipy = maxy - 100 then
        shipy -= 3
    end if
    Font.Draw ("Use the arrow keys to move the ship,", 5, maxy - 30, font1, brightblue)
    Font.Draw ("and press ESC to exit", 5, maxy - 48, font1, brightblue)
    Pic.Draw (ship, shipx, shipy, 2)

    % Moves your bullet forward
    if bullets > 0 then
        for i : 1 .. bullets
            bullety (i) += 5
        end for
    end if

    % Draws the bullet in relation to the ship
    put bullets
    if bullets > 0 then
        for b : 1 .. bullets
            Pic.Draw (BULLET, bulletx (b) + 40, bullety (b) + 75, 2)
        end for
    end if

    % The reload counter with delay...
    Reloading += 1
    delay (10)

    % Updates the scren then refreshes it...
    View.Update
    cls

end loop



-----------------------------------
Alex C.
Thu Jan 19, 2012 1:09 pm

RE:Projectile Shooting... STILL -.-*
-----------------------------------
never mind, i'm succesful! :D

 
View.Set ("nobuttonbar,offscreenonly")
colorback (30)
var shipx, shipy : int := 0

var font1 : int := Font.New ("bank_gothic:12")
var ship : int := Pic.FileNew ("Cargo_Ship.gif")
var BULLET : int := Pic.FileNew ("Bullets.gif")
var chars : array char of boolean

var bullets : array 1 .. 3 of boolean := init (false, false, false)
var bulletx : array 1 .. 3 of int:= init (0, 0, 0)
var bullety : array 1 .. 3 of int:= init (0, 0, 0)
var Reloading : int := 20
var x, y : array 1 .. 10 of int
for i : 1 .. 10
    x (i) := maxx div 2
end for
for i : 1 .. 10
    y (i) := 15
end for

loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        shipy := shipy + 3
    end if
    if chars (KEY_RIGHT_ARROW) then
        shipx := shipx + 3
    end if
    if chars (KEY_LEFT_ARROW) then
        shipx := shipx - 3
    end if
    if chars (KEY_DOWN_ARROW) then
        shipy := shipy - 3
    end if
    if chars (chr (27)) then
        Window.Hide (defWinID)
    end if
    if chars (' ') and Reloading >= 20 then
        if bullets (1) = false then
            Reloading := 0
            bullets (1) := true
            bulletx (1) := shipx
            bullety (1) := shipy
        elsif bullets (2) = false then
            Reloading := 0
            bullets (2) := true
            bulletx (2) := shipx
            bullety (2) := shipy
        elsif bullets (3) = false then
            Reloading := 0
            bullets (3) := true
            bulletx (3) := shipx
            bullety (3) := shipy
        end if
    end if

    % Moves your bullet forward
    for i : 1 .. 3
        if bullets (i) = true then
            bullety (i) += 5
        end if
    end for

    % Slight collison detection to make sure the ship is within boundaries
    if shipx = maxx - 100 then
        shipx -= 3
    end if
    if shipy = maxy - 100 then
        shipy -= 3
    end if

    % Destroys the bullet if it is off screen
    for d : 1 .. 3
        if bullety (d) >= maxy then
            bullets (d) := false
        end if
    end for

    % LOLZ  :P
    Font.Draw ("Use the arrow keys to move the ship,", 5, maxy - 30, font1, brightblue)
    Font.Draw ("and press ESC to exit", 5, maxy - 48, font1, brightblue)
    Pic.Draw (ship, shipx, shipy, 2)

    % Draws the bullet in relation to the ship
    for b : 1 .. 3
        if bullets (b) = true then
            Pic.Draw (BULLET, bulletx (b) + 40, bullety (b) + 70, 2)
        end if
    end for

    % The reload counter with delay...
    Reloading += 2
    delay (10)

    % Updates the scren then refreshes it...
    View.Update
    cls

end loop



-----------------------------------
Beastinonyou
Thu Jan 19, 2012 1:10 pm

Re: Projectile Shooting... STILL -.-*
-----------------------------------
Wouldn't it be as simple as:


if bulletX 