Computer Science Canada

More than just 1 appear, and not all dispear after maxy

Author:  amz_best [ Fri Sep 05, 2014 10:58 am ]
Post subject:  More than just 1 appear, and not all dispear after maxy

What is it you are trying to achieve?
im trying to shoot bullets (more than 1 on screen), and i want each seperate bullet to disapear when they reach maxy

What is the problem you are having?
a) only one bullet will show up
b) if i do figure out how to add moar bullets, i expect they will all dispear when only 1 reaches maxy, any way to prevent?


Describe what you have tried to solve this problem
boolean and int values to see if anything would change

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
unfortunately, i cant attach files so here is my code...

Turing:


%sey.mo.raz << neccesary to open file DO NOT DELETE!

View.Set("offscreenonly")
setscreen ("graphics:max;max,") 

%PICTURES TO UPLOAD

var ShipC  :int := Pic.FileNew ("ShipC.jpg")
var ShipL3 :int := Pic.FileNew ("ShipL3.jpg")
var ShipR3 :int := Pic.FileNew ("ShipR3.jpg")
var ShipL2 :int := Pic.FileNew ("ShipL2.jpg")
var ShipR2 :int := Pic.FileNew ("ShipR2.jpg")
var ShipL1 :int := Pic.FileNew ("ShipL1.jpg")
var ShipR1 :int := Pic.FileNew ("ShipR1.jpg")

var bullet :int := Pic.FileNew ("bullet.jpg")



%ARRAYS, CONSTANTS, BOOLEAN AND INT VAR'S
var b_KeyUp : boolean:= false
var b_notMoving: boolean:= false

var i_bulletsOnScreen: int
var i_spacebar: int
var i_cd : int   
var i_cd1: int
var x, y :int
var x2, y2 :int


const c_NumberOfStars := 400
var starX : array 1 .. c_NumberOfStars of int
var starY : array 1 .. c_NumberOfStars of int
var chars : array char of boolean



%GIVING VALUES (I PUT IT HERE INSTEAD OF BESIDE THE INTS FOR CLARITY)   
 i_spacebar := 1
 i_bulletsOnScreen := 0   
 i_cd := 6
 i_cd1:= 6
       
 x  :=maxx-850
 y  :=100
     
 y2 := y
 x2 := x


%     P     L     A     Y     E     R


    %  THIS IS OUTSIDE LOOP OTHERWISE STARS WILL NOT SLOW DOWN ON SCREEN
    for star : 1 .. c_NumberOfStars
    starX (star) := Rand.Int (0, maxx)
    starY (star) := Rand.Int (0, maxy)
    end for
   
   
   
    loop
               Input.KeyDown (chars)
           
               
          %MOVE SHIP UP
          if chars (KEY_UP_ARROW) then       
          y:=y+10
          end if
             
          %MOVE SHIP RIGHT
          if chars (KEY_RIGHT_ARROW) then     
          x:=x+20
          b_KeyUp := true
          i_cd -= 1
          Pic.Draw (ShipR2, x, y, picCopy)
          end if
           
          %MOVE SHIP LEFT
          if chars (KEY_LEFT_ARROW) then     
          if i_cd = 6 then
          x:=x-20
          i_cd1 -= 1
          b_KeyUp := true
          else b_KeyUp:=false
          end if
          end if
 
          %MOVE SHIP DOWN
          if chars (KEY_DOWN_ARROW) then     
          y:=y-10         
          end if

         
         
         
         
          %MAKE SURE SHIP DOESNT LEAVE THE SCREEN
            if x > maxx-85 then
            x := maxx-85
            end if
            if x < -10 then
            x := -10
            end if

            if y > maxy-100 then
            y := maxy-100
            end if
            if y < -10 then
            y := -10
            end if
         
           
          %MAKE SURE CHANGING PICTURE OF SHIP REMAINS SMOOTH AND NOT GLITCHED...
            if b_KeyUp = false then
            i_cd := 6
            i_cd1 := 6
            end if
       
            if b_KeyUp = true then
            b_KeyUp := false
            end if

            if i_cd < 0 then
            delay (1)
            i_cd := 0
            end if
       
            if i_cd1 < 0 then
            delay (1)
            i_cd1 := 0
            end if

           
           
          %SHOOT BULLET INTO ENEMY
          if chars (' ') then                 
          y-=20
          y+=15
          i_spacebar:=1
          end if

       
            delay(10)
           
 %MAKES PREVIOUS STARS DISAPEAR (THE PREVIOUS DONT UPDATES...)           
    cls
    Draw.FillBox (0, 0, maxx, maxy, black)
   
%               E  N  T  I  T  I  E  S 
%               E  N  T  I  T  I  E  S     
%               E  N  T  I  T  I  E  S 


    %entities cannot be made before cls otherways they will not appear
     
%BULLET CREATE
    if i_spacebar = 1 then
    Pic.Draw (bullet, x2+35, y2, picCopy)
    i_bulletsOnScreen += 1
    y2 += 10   
    if y2 > maxy then
    i_spacebar := 2
    y2 := y
    x2 := x
    end if
    end if
       
       
       
%SHIP CREATE/ SHIP TURN LEFT OR RIGHT CREATE ASWELL...       
if i_cd > 0 and i_cd1 > 0 then
b_notMoving := true
Pic.Draw (ShipC,x,y,picCopy)

elsif i_cd < 1 then
Pic.Draw (ShipR3, x, y, picCopy)
b_notMoving := false

elsif i_cd < 5 then
Pic.Draw (ShipR2, x, y, picCopy)
b_notMoving := false

elsif i_cd1 < 1 then
Pic.Draw (ShipL3, x, y, picCopy)
b_notMoving := false

elsif i_cd1 < 5 then
Pic.Draw (ShipL2, x, y, picCopy)
b_notMoving := false

end if


%RANDOMELY GENERATE STARS
    for star : 1 .. c_NumberOfStars
    starY (star) -= Rand.Int (1, 5)
    if starY (star) < 0 then
    starY (star) := maxy
    starY (star) := Rand.Int (100, maxx)
    end if
    Draw.FillOval (starX (star), starY (star) +starY (star), 1, 1, white)
    end for


View.Update
delay (10)
end loop 


Please specify what version of Turing you are using
http://tristan.hume.ca/openturing/

Author:  Zren [ Fri Sep 05, 2014 3:58 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

Quote:
const NoOfFlakes := 400


Ha. Someone found the compsci snowflake particle engine "contest" thread.

Since Turing has doesn't have any simple tools to add/remove items from an array, use a fixed sized array, along with another variable to represent the current index. The mod operator is used to wrap around to 0..

Eg:

Turing:

var bullets : array 1 .. 100 of Bullet
var currentBulletIndex := lower (bullets) % 1

initialize ()
loop
    % Input
    if onKeyPress (SHOOT_BULLET_KEY) then
        currentBulletIndex := (currentBulletIndex + 1)
        if currentBulletIndex > upper(bullets) then
            currentBulletIndex := lower (bullets)
        end if
        var bullet := bullets (currentBulletIndex)
        initBullet (bullet)
        bullet.pos.x := 234
    end if


Also, records are awesome. They allow you to bundle variables together as a new data type, which allows you to create an array of "a thing with lots of variables" much easier.

Incomplete Example

Turing:

type Vector2D :
    record
        x : real
        y : real
    end record

type Bullet :
    record
        pos : Vector2D % Position
        vel : Vector2D % Velocity
        visible : boolean
    end record

proc initBullet (var b : Bullet)
    b.pos.x := 0
    % ...
end initBullet

proc updateBullet (var b : Bullet)
    b.pos.x += b.vel.x
    b.pos.y += b.vel.y
end updateBullet

proc drawBullet (b : Bullet)
    if b.visible then
        % ...
    end if
end drawParticle

var bullets : array 1 .. 100 of Bullet
var currentBulletIndex := lower (bullets) % 1

initialize ()
loop
    % Input
    if onKeyPress (SHOOT_BULLET_KEY) then
        currentBulletIndex := (currentBulletIndex + 1)
        if currentBulletIndex > upper(bullets) then
            currentBulletIndex := lower (bullets)
        end if
        var bullet := bullets (currentBulletIndex)
        initBullet (bullet)
        bullet.pos.x := 234 % Align bullet with the player's ship
    end if

    % Update
    for i : lower (bullets) .. upper (bullets)
        updateBullet (bullets (i))
    end for

    % Draw Frame
    cls
    Draw.FillBox (0, 0, maxx, maxy, black)
    for i : lower (bullets) .. upper (bullets)
        drawBullet (bullets (i))
    end for
    View.Update ()

    Time.DelaySinceLast (1000 div 60) % ~60 FPS
end loop

Author:  amz_best [ Fri Sep 05, 2014 4:57 pm ]
Post subject:  Re: More than just 1 appear, and not all dispear after maxy

Wow, that seems really cool only, i dont undetstand it xD ik wat an array is, but i dont understand any of the code u wrote xD. im still new to turing and i hope u could explain dis 2 me more thourouly

Author:  Zren [ Fri Sep 05, 2014 5:18 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

Thought as much.

Here's a simplier example.

Press space to "Fire Bullets"

Turing:

var SHOOT_BULLET_KEY := ' '

var chars : array char of boolean
var bulletY : array 1 .. 10 of int
var bulletVisible : array 1 .. 10 of boolean
var currentBulletIndex := lower (bulletY) % lower() grabs the lowest index = 1

proc initialize ()
    for i : lower (bulletY) .. upper (bulletY)
        bulletY (i) := 0
        bulletVisible (i) := false
    end for
end initialize

View.Set ("offscreenonly")
initialize ()
loop
    % Input
    Input.KeyDown (chars)
    if chars (SHOOT_BULLET_KEY) then
        currentBulletIndex := (currentBulletIndex + 1)
        if currentBulletIndex > upper (bulletY) then
            currentBulletIndex := lower (bulletY)

            % Reset to "ship"
        end if
    end if

    % Update

    % Draw Frame
    cls
    put "currentBulletIndex: ", currentBulletIndex
    for i : lower (bulletY) .. upper (bulletY)
        put "bullets(", i : 3, "): y=", bulletY (i), "    visible=", bulletVisible (i), "    current=", i = currentBulletIndex
    end for
    View.Update ()

    Time.DelaySinceLast (1000 div 10) % ~10 FPS
end loop


Note how we cycle a limited number of "bullets".

The key is to make the array larger than the maximum number of bullets you'd ever need on the screen.

1. Make the bulletY(i) value increment every frame.
2. Make the bulletY(i) value increment every frame only if bulletVisible(i) is true.
3. Set bulletVisible(currentBulletIndex) to true when pressing the shoot key.
4. Set bulletVisible(i) to false when bulletY(i) is "off the screen".

Author:  amz_best [ Fri Sep 05, 2014 6:09 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

wow that is amazing. i can see wat u did and it makes so much moar sense! i got how it works and i typed it out already! except now i dunno how to add the photos when you press space or how 2 make them go up in their sepetrately xD

Author:  Zren [ Fri Sep 05, 2014 6:16 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

Quote:
them go up in their sepetrately


What's your code?

More steps:

5. Load Bullet Picture. Only use one picture for all bullets, as we can redraw it multiple times.
6. Add a bulletX array.
7. For each bullet the arrays, draw the bullet picture at ( bulletX(i), bulletY(i) ).
8. Only draw a bullet if bulletVisible(i) is true.

Author:  amz_best [ Fri Sep 05, 2014 6:27 pm ]
Post subject:  Re: More than just 1 appear, and not all dispear after maxy

Everytime i run it, it says argument is wrong type, is it becuz im using real numbers?



Turing:

%sey.mo.raz << neccesary to open file DO NOT DELETE!

View.Set("offscreenonly")
setscreen ("graphics:max;max,") 

%PICTURES TO UPLOAD

var ShipC  :int := Pic.FileNew ("ShipC.jpg")
var ShipL3 :int := Pic.FileNew ("ShipL3.jpg")
var ShipR3 :int := Pic.FileNew ("ShipR3.jpg")
var ShipL2 :int := Pic.FileNew ("ShipL2.jpg")
var ShipR2 :int := Pic.FileNew ("ShipR2.jpg")
var ShipL1 :int := Pic.FileNew ("ShipL1.jpg")
var ShipR1 :int := Pic.FileNew ("ShipR1.jpg")

var bullet :int := Pic.FileNew ("bullet.jpg")



%ARRAYS, CONSTANTS, BOOLEAN AND INT VAR'S
var b_KeyUp : boolean:= false
var b_notMoving: boolean:= false

var i_cd : int   
var i_cd1: int

var x, y, y2 :int
 
var bulletY : array 1 .. 10 of int
var bulletX : array 1 .. 10 of int
var bulletVisible : array 1 .. 10 of boolean
var currentBulletIndex := lower (bulletY)

const c_NumberOfStars := 400
var starX : array 1 .. c_NumberOfStars of int
var starY : array 1 .. c_NumberOfStars of int
var chars : array char of boolean



%GIVING VALUES (I PUT IT HERE INSTEAD OF BESIDE THE INTS FOR CLARITY)   
 i_cd := 6
 i_cd1:= 6
       
 x  :=maxx-850
 y  :=100
 y2 := y
 
 
 
 type Vector2D :
    record
        x : real
        y : real
    end record 
   
type Bullet :
    record
        pos : Vector2D % Position
        vel : Vector2D % Velocity
        visible : boolean
    end record
 
    proc drawBullet (b : Bullet)
    if b.visible then
    Pic.Draw (bullet,x,y,picCopy)
    end if
    end drawBullet
%     P     L     A     Y     E     R
   
    %  THIS IS OUTSIDE LOOP OTHERWISE STARS WILL NOT SLOW DOWN ON SCREEN
    for star : 1 .. c_NumberOfStars
    starX (star) := Rand.Int (0, maxx)
    starY (star) := Rand.Int (0, maxy)
    end for
   
    %  THIS IS TO HAVE BULLETS APPEAR AND DISAPEAR SEPERATELY
    proc initialize ()
    for i : lower (bulletY) .. upper (bulletY)
        bulletY (i) := 0
        bulletVisible (i) := false
    end for
    end initialize
   
    loop
               Input.KeyDown (chars)
           
               
          %MOVE SHIP UP
          if chars (KEY_UP_ARROW) then       
          y:=y+10
          end if
             
          %MOVE SHIP RIGHT
          if chars (KEY_RIGHT_ARROW) then     
          x:=x+20
          b_KeyUp := true
          i_cd -= 1
          Pic.Draw (ShipR2, x, y, picCopy)
          end if
           
          %MOVE SHIP LEFT
          if chars (KEY_LEFT_ARROW) then     
          if i_cd = 6 then
          x:=x-20
          i_cd1 -= 1
          b_KeyUp := true
          else b_KeyUp:=false
          end if
          end if
 
          %MOVE SHIP DOWN
          if chars (KEY_DOWN_ARROW) then     
          y:=y-10         
          end if

          %SHOOT BULLET
          if chars (' ') then
            currentBulletIndex := (currentBulletIndex + 1)
            if currentBulletIndex > upper (bulletY) then
            currentBulletIndex := lower (bulletY)
            end if
          end if
         
         
          %MAKE SURE SHIP DOESNT LEAVE THE SCREEN
            if x > maxx-85 then
            x := maxx-85
            end if
            if x < -10 then
            x := -10
            end if

            if y > maxy-100 then
            y := maxy-100
            end if
            if y < -10 then
            y := -10
            end if
         
           
          %MAKE SURE CHANGING PICTURE OF SHIP REMAINS SMOOTH AND NOT GLITCHED...
            if b_KeyUp = false then
            i_cd := 6
            i_cd1 := 6
            end if
       
            if b_KeyUp = true then
            b_KeyUp := false
            end if

            if i_cd < 0 then
            delay (1)
            i_cd := 0
            end if
       
            if i_cd1 < 0 then
            delay (1)
            i_cd1 := 0
            end if


       
       
    delay(10)             
    cls
    Draw.FillBox (0, 0, maxx, maxy, black) 
   
%               E  N  T  I  T  I  E  S 
%               E  N  T  I  T  I  E  S     
%               E  N  T  I  T  I  E  S 

for i : lower (bulletY) .. upper (bulletY)
    drawBullet (bulletY(i), bulletX(i) )
    end for




%RANDOMELY GENERATE STARS
  %entities cannot be made before cls otherways they will not appear
    for star : 1 .. c_NumberOfStars
    starY (star) -= Rand.Int (1, 5)
    if starY (star) < 0 then
    starY (star) := maxy
    starY (star) := Rand.Int (100, maxx)
    end if
    Draw.FillOval (starX (star), starY (star) +starY (star), 1, 1, white)
    end for

   

   
   
%SHIP CREATE/ SHIP TURN LEFT OR RIGHT CREATE ASWELL...       
if i_cd > 0 and i_cd1 > 0 then
b_notMoving := true
Pic.Draw (ShipC,x,y,picCopy)

elsif i_cd < 1 then
Pic.Draw (ShipR3, x, y, picCopy)
b_notMoving := false

elsif i_cd < 5 then
Pic.Draw (ShipR2, x, y, picCopy)
b_notMoving := false

elsif i_cd1 < 1 then
Pic.Draw (ShipL3, x, y, picCopy)
b_notMoving := false

elsif i_cd1 < 5 then
Pic.Draw (ShipL2, x, y, picCopy)
b_notMoving := false

end if




View.Update
delay (10)
end loop 

Author:  Zren [ Fri Sep 05, 2014 6:34 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

It's because of this code from my first example.

code:

 type Vector2D :
    record
        x : real
        y : real
    end record 
   
type Bullet :
    record
        pos : Vector2D % Position
        vel : Vector2D % Velocity
        visible : boolean
    end record
 
    proc drawBullet (b : Bullet)
    if b.visible then
    Pic.Draw (bullet,x,y,picCopy)
    end if
    end drawBullet


Because you're calling

code:
drawBullet (bulletY(i), bulletX(i) )


When the function is define as

code:
proc drawBullet (b : Bullet)


Don't use any of the code from my first example as it's incompatible with the code from the second one, as I removed a number of techniques to simplify it.

Since I don't think you understand procedures/functions very well, don't use them.

Instead of:
code:

%               E  N  T  I  T  I  E  S 
%               E  N  T  I  T  I  E  S     
%               E  N  T  I  T  I  E  S 

for i : lower (bulletY) .. upper (bulletY)
    drawBullet (bulletY(i), bulletX(i) )
    end for


Just do

code:

%               E  N  T  I  T  I  E  S 
%               E  N  T  I  T  I  E  S     
%               E  N  T  I  T  I  E  S 

for i : lower (bulletY) .. upper (bulletY)
    if bulletVisible(i) then
        % ...
    end if
end for

Author:  Zren [ Fri Sep 05, 2014 6:37 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

By the way. Press the indent button (often) in Turings menu bar.

Author:  amz_best [ Fri Sep 05, 2014 7:01 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

alrite, on the line u gave me,
"if bulletVisible(i) then"
it says variable has no value.
im sorry if u r fustrated in me...

Author:  Zren [ Fri Sep 05, 2014 7:06 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

Yeeeeeep. You really don' understand functions/procedures. xD You'll probably learn about them in the next few weeks.

Basically the code wasn't being run.

code:

    %  THIS IS TO HAVE BULLETS APPEAR AND DISAPEAR SEPERATELY
    proc initialize ()
    for i : lower (bulletY) .. upper (bulletY)
        bulletY (i) := 0
        bulletVisible (i) := false
    end for
    end initialize


As you never called the procedure like so:

code:
initialize()


Just move the code out of the procedure. Eg:

code:

proc initialize ()
    for i : lower (bulletY) .. upper (bulletY)
        bulletY (i) := 0
        bulletVisible (i) := false
    end for
end initialize

View.Set ("offscreenonly")
initialize ()
loop
    % Input
    Input.KeyDown (chars)
    if chars (SHOOT_BULLET_KEY) then
        currentBulletIndex := (currentBulletIndex + 1)
        if currentBulletIndex > upper (bulletY) then
            currentBulletIndex := lower (bulletY)


to

code:

View.Set ("offscreenonly")
for i : lower (bulletY) .. upper (bulletY)
    bulletY (i) := 0
    bulletVisible (i) := false
end for
loop
    % Input
    Input.KeyDown (chars)
    if chars (SHOOT_BULLET_KEY) then
        currentBulletIndex := (currentBulletIndex + 1)
        if currentBulletIndex > upper (bulletY) then
            currentBulletIndex := lower (bulletY)


Sorry for teasing you with so many advanced concepts when your still on your first week.

Author:  amz_best [ Fri Sep 05, 2014 7:12 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

As soon as i saw initialize(), i went back into my code and saw that its not initialized before the loop, so i simply added initialize() and now its working fine, but bullets dont appear when i press space.

Author:  Zren [ Fri Sep 05, 2014 7:20 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

Where exactly are you drawing the bullets? I wrote
code:
% ...
as I assume you'd fill in the blanks.

Might as well post your code again, this time make sure to click this button first.

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  amz_best [ Fri Sep 05, 2014 7:22 pm ]
Post subject:  Re: More than just 1 appear, and not all dispear after maxy

Turing:

%sey.mo.raz << neccesary to open file DO NOT DELETE!

View.Set ("offscreenonly")
setscreen ("graphics:max;max,")

%PICTURES TO UPLOAD

var ShipC : int := Pic.FileNew ("ShipC.jpg")
var ShipL3 : int := Pic.FileNew ("ShipL3.jpg")
var ShipR3 : int := Pic.FileNew ("ShipR3.jpg")
var ShipL2 : int := Pic.FileNew ("ShipL2.jpg")
var ShipR2 : int := Pic.FileNew ("ShipR2.jpg")
var ShipL1 : int := Pic.FileNew ("ShipL1.jpg")
var ShipR1 : int := Pic.FileNew ("ShipR1.jpg")

var bullet : int := Pic.FileNew ("bullet.jpg")



%ARRAYS, CONSTANTS, BOOLEAN AND INT VAR'S
var b_KeyUp : boolean := false
var b_notMoving : boolean := false

var i_cd : int
var i_cd1 : int

var x, y, y2 : int

var bulletY : array 1 .. 10 of int
var bulletX : array 1 .. 10 of int
var bulletVisible : array 1 .. 10 of boolean
var currentBulletIndex := lower (bulletY)

const c_NumberOfStars := 400
var starX : array 1 .. c_NumberOfStars of int
var starY : array 1 .. c_NumberOfStars of int
var chars : array char of boolean



%GIVING VALUES (I PUT IT HERE INSTEAD OF BESIDE THE INTS FOR CLARITY)
i_cd := 6
i_cd1 := 6

x := maxx - 850
y := 100
y2 := y



type Vector2D :
    record
        x : real
        y : real
    end record

type Bullet :
    record
        pos : Vector2D % Position
        vel : Vector2D % Velocity
        visible : boolean
    end record

proc drawBullet (b : Bullet)
    if b.visible then
        Pic.Draw (bullet, x, y, picCopy)
    end if
end drawBullet
%     P     L     A     Y     E     R

%  THIS IS OUTSIDE LOOP OTHERWISE STARS WILL NOT SLOW DOWN ON SCREEN
for star : 1 .. c_NumberOfStars
    starX (star) := Rand.Int (0, maxx)
    starY (star) := Rand.Int (0, maxy)
end for

%  THIS IS TO HAVE BULLETS APPEAR AND DISAPEAR SEPERATELY
proc initialize ()
    for i : lower (bulletY) .. upper (bulletY)
        bulletY (i) := 0
        bulletVisible (i) := false
    end for
end initialize
initialize ()
loop
    Input.KeyDown (chars)


    %MOVE SHIP UP
    if chars (KEY_UP_ARROW) then
        y := y + 10
    end if

    %MOVE SHIP RIGHT
    if chars (KEY_RIGHT_ARROW) then
        x := x + 20
        b_KeyUp := true
        i_cd -= 1
        Pic.Draw (ShipR2, x, y, picCopy)
    end if

    %MOVE SHIP LEFT
    if chars (KEY_LEFT_ARROW) then
        if i_cd = 6 then
            x := x - 20
            i_cd1 -= 1
            b_KeyUp := true
        else
            b_KeyUp := false
        end if
    end if

    %MOVE SHIP DOWN
    if chars (KEY_DOWN_ARROW) then
        y := y - 10
    end if

    %SHOOT BULLET
    if chars (' ') then
        currentBulletIndex := (currentBulletIndex + 1)
        if currentBulletIndex > upper (bulletY) then
            currentBulletIndex := lower (bulletY)
        end if
    end if


    %MAKE SURE SHIP DOESNT LEAVE THE SCREEN
    if x > maxx - 85 then
        x := maxx - 85
    end if
    if x < -10 then
        x := -10
    end if

    if y > maxy - 100 then
        y := maxy - 100
    end if
    if y < -10 then
        y := -10
    end if


    %MAKE SURE CHANGING PICTURE OF SHIP REMAINS SMOOTH AND NOT GLITCHED...
    if b_KeyUp = false then
        i_cd := 6
        i_cd1 := 6
    end if

    if b_KeyUp = true then
        b_KeyUp := false
    end if

    if i_cd < 0 then
        delay (1)
        i_cd := 0
    end if

    if i_cd1 < 0 then
        delay (1)
        i_cd1 := 0
    end if




    delay (10)
    cls
    Draw.FillBox (0, 0, maxx, maxy, black)


    %               E  N  T  I  T  I  E  S
    %               E  N  T  I  T  I  E  S
    %               E  N  T  I  T  I  E  S

    for i : lower (bulletY) .. upper (bulletY)
        if bulletVisible (i) then
            Pic.Draw (bullet, x + 35, y2, picCopy)
        end if
    end for




    %RANDOMELY GENERATE STARS
    %entities cannot be made before cls otherways they will not appear
    for star : 1 .. c_NumberOfStars
        starY (star) -= Rand.Int (1, 5)
        if starY (star) < 0 then
            starY (star) := maxy
            starY (star) := Rand.Int (100, maxx)
        end if
        Draw.FillOval (starX (star), starY (star) + starY (star), 1, 1, white)
    end for





    %SHIP CREATE/ SHIP TURN LEFT OR RIGHT CREATE ASWELL...
    if i_cd > 0 and i_cd1 > 0 then
        b_notMoving := true
        Pic.Draw (ShipC, x, y, picCopy)

    elsif i_cd < 1 then
        Pic.Draw (ShipR3, x, y, picCopy)
        b_notMoving := false

    elsif i_cd < 5 then
        Pic.Draw (ShipR2, x, y, picCopy)
        b_notMoving := false

    elsif i_cd1 < 1 then
        Pic.Draw (ShipL3, x, y, picCopy)
        b_notMoving := false

    elsif i_cd1 < 5 then
        Pic.Draw (ShipL2, x, y, picCopy)
        b_notMoving := false

    end if




    View.Update
    delay (10)
end loop

Author:  Zren [ Fri Sep 05, 2014 7:34 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

Why are you using the x, and y variable in

code:
Pic.Draw (bullet, x + 35, y2, picCopy)


?

As far as I can guess, x and y refer to the shipX, and shipY? Write variable names that are more descriptive.

What was the point of the bulletX and bulletY arrays? They are used to represent where all your bullets are.

Author:  amz_best [ Fri Sep 05, 2014 7:37 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

Pic.Draw (bullet, bulletX (i), bulletY (i), picCopy)
It loads game but...
still no bullet appear, it always did apear before when only 1 bullet shot xD

Author:  Zren [ Fri Sep 05, 2014 7:56 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

You've got a lot of other code in there (that you copy pasted) so I don't think you fully understand what they do.

So let's start from scratch, and only get the bullets working.


Game Loop
Turing:

View.Set ("offscreenonly")
initialize ()
loop
    % Input

    % Update

    % Draw Frame
    cls
    View.Update ()

    Time.DelaySinceLast (1000 div 10) % ~10 FPS
end loop




1 Bullet
Turing:

var bulletPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)

var bulletX : int
var bulletY : int

View.Set ("offscreenonly")
bulletX := 0
bulletY := 0
loop
    % Input

    % Update

    % Draw Frame
    cls
    Draw.FillBox(0, 0, maxx, maxy, black)
    Pic.Draw(bulletPicId, bulletX, bulletY, picMerge)
    View.Update ()

    Time.DelaySinceLast (1000 div 10) % ~10 FPS
end loop



10 Bullets (overlaping)

Turing:

var bulletPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)

var bulletX : array 1 .. 10 of int
var bulletY : array 1 .. 10 of int

View.Set ("offscreenonly")
for i : 1.. 10
    bulletX(i) := 0
    bulletY(i) := 0
end for
loop
    % Input

    % Update

    % Draw Frame
    cls
    Draw.FillBox(0, 0, maxx, maxy, black)
    for i : 1 .. 10
        Pic.Draw(bulletPicId, bulletX(i), bulletY(i), picMerge)
    end for
    View.Update ()

    Time.DelaySinceLast (1000 div 10) % ~10 FPS
end loop




Ship

Turing:

var bulletPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)
var shipPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)

var bulletX : array 1 .. 10 of int
var bulletY : array 1 .. 10 of int
var shipX : int
var shipY : int

View.Set ("offscreenonly")
for i : 1.. 10
    bulletX(i) := 0
    bulletY(i) := 0
end for
shipX := 0
shipY := 0
loop
    % Input

    % Update

    % Draw Frame
    cls
    Draw.FillBox(0, 0, maxx, maxy, black)
    Pic.Draw(shipPicId, shipX, shipY, picMerge)
    for i : 1 .. 10
        Pic.Draw(bulletPicId, bulletX(i), bulletY(i), picMerge)
    end for
    View.Update ()

    Time.DelaySinceLast (1000 div 10) % ~10 FPS
end loop



Basic Input. Move the ship

Turing:

var bulletPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)
var shipPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)

var bulletX : array 1 .. 10 of int
var bulletY : array 1 .. 10 of int
var shipX : int
var shipY : int
var chars : array char of boolean
var shipMoveSpeed : int

View.Set ("offscreenonly")
for i : 1.. 10
    bulletX(i) := 0
    bulletY(i) := 0
end for
shipX := 0
shipY := 0
shipMoveSpeed := 10
loop
    % Input
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) then       
        shipX -= shipMoveSpeed
    else if chars (KEY_RIGHT_ARROW) then   
        shipX += shipMoveSpeed   
    end if           

    % Update

    % Draw Frame
    cls
    Draw.FillBox(0, 0, maxx, maxy, black)
    Pic.Draw(shipPicId, shipX, shipY, picMerge)
    for i : 1 .. 10
        Pic.Draw(bulletPicId, bulletX(i), bulletY(i), picMerge)
    end for
    View.Update ()

    Time.DelaySinceLast (1000 div 10) % ~10 FPS
end loop




Homework:
1) Have bullets move upward every frame.
2) Move 1 bullet back to (shipX, shipY) when space is pressed.

DO NOT try to copy paste this into your own code until you fully understand it.

Turing:

var bulletPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)
var shipPicId := Pic.New(0, 0, 16, 16) % Pic.FileNew(...)

var bulletX : array 1 .. 10 of int
var bulletY : array 1 .. 10 of int
var shipX : int
var shipY : int
var chars : array char of boolean
var shipMoveSpeed : int

View.Set ("offscreenonly")
for i : 1.. 10
    bulletX(i) := 0
    bulletY(i) := 0
end for
shipX := 0
shipY := 0
shipMoveSpeed := 10
loop
    % Input
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) then       
        shipX -= shipMoveSpeed
    else if chars (KEY_RIGHT_ARROW) then   
        shipX += shipMoveSpeed   
    end if
    if chars (' ') then       
        % ... Spawn bullet
    end if

    % Update
    % ... Move bullets

    % Draw Frame
    cls
    Draw.FillBox(0, 0, maxx, maxy, black)
    Pic.Draw(shipPicId, shipX, shipY, picMerge)
    for i : 1 .. 10
        Pic.Draw(bulletPicId, bulletX(i), bulletY(i), picMerge)
    end for
    View.Update ()

    Time.DelaySinceLast (1000 div 10) % ~10 FPS
end loop

Author:  amz_best [ Fri Sep 05, 2014 8:32 pm ]
Post subject:  Re: More than just 1 appear, and not all dispear after maxy

ok, i will be back in like 2 days with my homework complete xD

Author:  amz_best [ Sun Sep 07, 2014 12:18 pm ]
Post subject:  Re: More than just 1 appear, and not all dispear after maxy

HOMEWORK COMPLETE! but now, we have a glitch :s everytime a shoot from what looks like
y=0..50
the bullet just stays there, on the bottom of the screen... and not move.... wat do i do?
Turing:

%sey.mo.raz << neccesary to open file DO NOT DELETE!





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ARRAYS, CONSTANTS, BOOLEAN AND INT VAR'S %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------%
%----------------------------------------------%
var b_KeyUp : boolean := false                 %
var b_notMoving : boolean := false             %
                                               %
var i_rightTurnCoolDown : int := 6             %
var i_leftTurnCoolDown : int  := 6             %
                                               %
var b_leftKeyDown : boolean := false           %
var b_rightKeyDown : boolean := false          %
                                               %
var shipReset: boolean := false                %
                                               %
var shipX: int := (maxx div 2)                 %
var shipY: int := (maxy div 8)                 %                     
var shipSpeedX: int  := 20                     %
var shipSpeedY: int  := 10                     %                                   
                                               %                             
var speed : int := 1                           %
var size : int := 10                           %
                                               %
var fire : boolean := false                    %
var firey : int := size                        %
var firespeed : int := 1                       %
var firesize : int := 3                        %
var firerate : real := 1                       %
                                               %
var control : array char of boolean            %
                                               %
var bulletX : array 0 .. 300 of int        %
var bulletY : array 0 .. 300 of int        %
var pos_array_size : int := -1                 %
                                               %
var time_after_shot : real := 0                %
                                               %
const c_NumberOfStars := 400                   %
var starX : array 1 .. c_NumberOfStars of int  %
var starY : array 1 .. c_NumberOfStars of int  %
var controls : array char of boolean           %
                                               %
%----------------------------------------------%
%----------------------------------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





View.Set ("offscreenonly")
setscreen ("graphics:max;max,")




%%%%%%%%%%%%%%%%%%%%%%
% PICTURES TO UPLOAD %
%%%%%%%%%%%%%%%%%%%%%%


%-------------------------------------------------
var ShipC : int := Pic.FileNew ("ShipC.jpg")     %
var ShipL3 : int := Pic.FileNew ("ShipL3.jpg")   %
var ShipR3 : int := Pic.FileNew ("ShipR3.jpg")   %
var ShipL2 : int := Pic.FileNew ("ShipL2.jpg")   %
var ShipR2 : int := Pic.FileNew ("ShipR2.jpg")   %
var ShipL1 : int := Pic.FileNew ("ShipL1.jpg")   %
var ShipR1 : int := Pic.FileNew ("ShipR1.jpg")   %
                                                 %
var bullet : int := Pic.FileNew ("bullet.jpg")   %
%-------------------------------------------------







%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  THE FOR STATEMENTS FOR THEM BULLETS AND THEM STARS%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%-------------------------------------------------
for i : 0..30
    bulletY(i) := 0
    bulletX(i) := 0
end for             

for star : 1 .. c_NumberOfStars        %
    starX (star) := Rand.Int (0, maxx) %
    starY (star) := Rand.Int (0, maxy) %
end for                         
%-------------------------------------------------






loop
 
    Input.KeyDown (controls)


    %MOVE SHIP UP
%--------------------------------------------------   
    if controls (KEY_UP_ARROW) then
        shipY += shipSpeedY
    end if
%--------------------------------------------------   
   
   
    %MOVE SHIP LEFT
%--------------------------------------------------   
    if controls (KEY_LEFT_ARROW) then
    b_leftKeyDown := true   
        if i_rightTurnCoolDown = 6 then
            shipX -= shipSpeedX
            i_leftTurnCoolDown -= 1
            b_KeyUp := true
        else
            b_KeyUp := false
        end if   
    end if
%--------------------------------------------------   
   
   

    %MOVE SHIP RIGHT
%--------------------------------------------------   
    if controls (KEY_RIGHT_ARROW) then
    b_rightKeyDown := true
        if i_leftTurnCoolDown = 6 then
            shipX += shipSpeedX
            i_rightTurnCoolDown -= 1
            b_KeyUp := true
        else
            b_KeyUp := false
        end if   
    end if
%--------------------------------------------------   
   
   
   
    %STOP HOLD LEFT AND RIGHT GLITCH
%--------------------------------------------------   
    if b_rightKeyDown = true and b_leftKeyDown = true then
        shipReset := true
        shipSpeedX := 0
        else
        shipSpeedX := 20
    end if
%--------------------------------------------------
   
   
   
    %MOVE SHIP DOWN
%--------------------------------------------------   
    if controls (KEY_DOWN_ARROW) then
        shipY -= shipSpeedY
    end if
%--------------------------------------------------
   
   
    %SHOOT BULLET
%--------------------------------------------------
 if controls (chr (32)) and fire = false then
        fire := true
        pos_array_size += 1
        bulletX(pos_array_size) := shipX + 30               
        bulletY(pos_array_size) := shipY
    end if
%--------------------------------------------------
   
   


    %MAKE SURE SHIP DOESNT LEAVE THE SCREEN
%-------------------------------------------
    if shipX > maxx - 85 then
        shipX := maxx - 85
    end if
    if shipX < -10 then
        shipX := -10
    end if

    if shipY > maxy - 100 then
        shipY := maxy - 100
    end if
    if shipY < -10 then
        shipY := -10
    end if
%-------------------------------------------

   
   
    %MAKE SURE CHANGING PICTURE OF SHIP REMAINS SMOOTH AND NOT GLITCHED...
    %-----------------------------------------
    if b_KeyUp = false then
        i_rightTurnCoolDown := 6
        i_leftTurnCoolDown := 6
    end if


    if b_KeyUp = true then
        b_KeyUp := false
    end if

    if b_rightKeyDown = true then
        b_rightKeyDown := false
    end if
   
    if b_leftKeyDown = true then
        b_leftKeyDown := false
    end if

   
   
    if i_rightTurnCoolDown < 0 then
        i_rightTurnCoolDown := 0
    end if

    if i_leftTurnCoolDown < 0 then
        i_leftTurnCoolDown := 0
    end if
    %--------------------------------------

   
   

%after cls, we actually put the drawing part.....
    cls
    Draw.FillBox (0, 0, maxx, maxy, black)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %            D  R  A  W         E  N  T  I  T  T  E  S           %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        %entities cannot be made before cls otherways they will not appear, LEARNED DIS DA HARD WAY!!!

%------------------------------------------------------------------------------
    %RANDOMELY GENERATE STARS                                                 %       
    for star : 1 .. c_NumberOfStars                                           %
        starY (star) -= Rand.Int (1, 5)                                       %
        if starY (star) < 0 then                                              %
            starY (star) := maxy                                              %
            starY (star) := Rand.Int (100, maxx)                              %
        end if                                                                %
        Draw.FillOval (starX (star), starY (star) + starY (star), 1, 1, white)%
    end for                                                                   %
%------------------------------------------------------------------------------   
   
 



 
   
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %     MAKE THEM BULLETS!!! MY BEUTIFUL BULLET MAKING CODE!     %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %-----------------------------------------------------------------------------------------------------------------------------------------------
   
            for i : 0..pos_array_size
        Pic.Draw (bullet, bulletX(i)+firesize, bulletY(i)+firesize, picCopy)
        if bulletY(i) >= 1 then
            bulletY(i) += 10
        end if
    end for
       
    for i : 0 ..pos_array_size
        if bulletY(i) > maxy then
            for a : 0 .. pos_array_size - i
                bulletY(i+a) := bulletY(i+a+1)
                bulletX(i+a) := bulletX(i+a+1)
            end for
            pos_array_size -=1
         end if
    end for
   
   
    if fire = true then
        time_after_shot += 0.08
    end if
       
   
    if time_after_shot >= firerate then
        fire := false
        time_after_shot := 0
    end if
    %-----------------------------------------------------------------------------------------------------------------------------------------------   
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   
   
   
   
   
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %    SHIP CREATE/ SHIP TURN LEFT OR RIGHT CREATE ASWELL...  %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   
   
   
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %-----------------------------------------------------------------------------------------------------------------------------------------------   
    if i_rightTurnCoolDown > 0 and i_leftTurnCoolDown > 0 or i_rightTurnCoolDown < 6 and i_leftTurnCoolDown < 6 then
        b_notMoving := true
        Pic.Draw (ShipC, shipX, shipY, picCopy)
   elsif i_rightTurnCoolDown < 1 then
        Pic.Draw (ShipR3, shipX, shipY, picCopy)
        b_notMoving := false
       
    elsif i_leftTurnCoolDown < 1 then
        Pic.Draw (ShipL3, shipX, shipY, picCopy)
        b_notMoving := false

    elsif i_rightTurnCoolDown < 5 and i_rightTurnCoolDown > 1 then
        Pic.Draw (ShipR2, shipX, shipY, picCopy)
        b_notMoving := false

    elsif i_leftTurnCoolDown < 5 and i_leftTurnCoolDown > 1 then
        Pic.Draw (ShipL2, shipX, shipY, picCopy)
        b_notMoving := false

       
    end if

    if shipReset = true then
        Pic.Draw (ShipC, shipX, shipY, picCopy)
        shipReset := false
    end if
    %-----------------------------------------------------------------------------------------------------------------------------------------------   
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   
   




   
    View.Update
    Time.DelaySinceLast (1000 div 60) %FPS!!!
end loop


oh, and i also did a bit organizing Smile

Author:  amz_best [ Sun Sep 07, 2014 12:28 pm ]
Post subject:  RE:More than just 1 appear, and not all dispear after maxy

for a temp fix, i simply added

%SHOOT BULLET
%--------------------------------------------------
if controls (chr (32)) and fire = false then
fire := true
pos_array_size += 1
bulletX(pos_array_size) := shipX + 30
bulletY(pos_array_size) := shipY
end if
%--------------------------------------------------


tooo:


%SHOOT BULLET
%--------------------------------------------------
if controls (chr (32)) and fire = false then
fire := true
pos_array_size += 1
bulletX(pos_array_size) := shipX + 30
bulletY(pos_array_size) := shipY + 50
end if
%--------------------------------------------------


: