Computer Science Canada

flexible

Author:  upthescale [ Tue Jun 06, 2006 4:16 pm ]
Post subject:  flexible

ok i wanna benable ot shot and have multiple bullets come otu leik a machine gun my code is as follows:

code:

setscreen ("offscreenonly")
var x, y : int := 100
var chars : array char of boolean
var Bullet : boolean := false
var bullet : flexible array 1 .. 1 of
    record
        bulletx : int
        bullety : int
    end record
for i : 1 .. 1
    bullet (i).bulletx := x
    bullet (i).bullety := y
end for

loop
    Input.KeyDown (chars)
    cls
    drawfilloval (x, y, 12, 12, 7)




    for i : 1 .. 1
        if chars (KEY_ENTER) then

            drawfilloval (bullet (i).bulletx, bullet (i).bullety, 4, 4, 12)
            Bullet := true
        end if

        if Bullet = true then
            bullet (i).bulletx += 1
        end if
    end for


    View.Update
end loop




y is the ball dissapeared? y aernt there more than one bullet?

Author:  Clayton [ Tue Jun 06, 2006 4:20 pm ]
Post subject: 

there isnt more than one bullet because you only ever have a maximum upper bound to your array of 1, so you therefore need a new statement to increase the upper bounds of your array and add another bullet to the screen, also, you dont get another bullet because the x value of your bullet is never reset to its original coordinate, causing it to be drawn further and further off the screen Very Happy

Author:  Clayton [ Tue Jun 06, 2006 4:22 pm ]
Post subject: 

oops double post, but anyway,

in that second for loop (the one inside your main loop) you should have the upper bounds of the for be upper(arrayName) instead of a hardcoded 1 because you are only accessing the data for the first bullet in your array and you can therefore not draw anymore than the first bullet


: