Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 More than just 1 appear, and not all dispear after maxy
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
amz_best




PostPosted: 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/
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: 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
amz_best




PostPosted: 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
Zren




PostPosted: 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".
amz_best




PostPosted: 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
Zren




PostPosted: 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.
amz_best




PostPosted: 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 
Zren




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: 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.
amz_best




PostPosted: 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...
Zren




PostPosted: 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.
amz_best




PostPosted: 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.
Zren




PostPosted: 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.
amz_best




PostPosted: 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
Zren




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: