
-----------------------------------
Mr. T
Sun Oct 23, 2005 5:10 pm

Flexible Arrays
-----------------------------------
In my jezzball game, I made the parameters of Mouse.Where ( ) as elements of a flexible array.  I did this with the hope that every time I would click the screen, the array would add an element to itself, and a new bar would be drawn without deleting the previous.  My issue is that the flexible array doesnt seem to be doing anything(previous bar is deleted every time a new bar is drawn).  Can anyone see why?

const RADIUS : int := 5
const NUM_BALLS : int := 2
var x, y, dx, dy, clr : array 1 .. NUM_BALLS of int
var barX, barY : flexible array 1 .. 1 of int
var barXStore, barYStore, barXFinished1, barXFinished2, button, left, middle, right : int := 0
var horizontalBar := false
var grow1, grow2, topCounterY, bottomCounterY : int := 0
var score : int := 3
var fontScore : int
fontScore := Font.New ("tahoma:80")
View.Set ("offscreenonly,nobuttonbar,graphics,title:JezzBall           Score: " + intstr (score))

for i : 1 .. NUM_BALLS
    x (i) := Rand.Int (RADIUS, maxx - RADIUS)
    y (i) := Rand.Int (RADIUS, maxy - RADIUS)
    dx (i) := Rand.Int (-5, 5)
    dy (i) := Rand.Int (-5, 5)
    clr (i) := Rand.Int (1, 15)
end for

loop
    %Frame
    Draw.Box (0, 0, maxx, maxy, blue)

    %Outer Boundary Collision
    for i : 1 .. NUM_BALLS
        if x (i) + dx (i) < RADIUS or
                x (i) + dx (i) > maxx - RADIUS then
            dx (i) := -dx (i)
        end if
        if y (i) + dy (i) < RADIUS or
                y (i) + dy (i) > maxy - RADIUS then
            dy (i) := -dy (i)
        end if

        %Incompleted Wall Collision
        if whatdotcolour (x (i) + RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) + RADIUS) = red or whatdotcolour (x (i) - RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) - RADIUS) = red then
            score -= 1 %lose 1 life
            View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score))
            grow1 := 0 %reset
            %grow2 := 0 %reset
            horizontalBar := false %new wall can now be created
        elsif whatdotcolour (x (i) + RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) + RADIUS) = green or whatdotcolour (x (i) - RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) - RADIUS) 
            = green then
            score -= 1 %lose 1 life
            View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score))
            %grow1 := 0 %reset
            grow2 := 0 %reset
            horizontalBar := false %new wall can now be created
        end if

        %Gameover
        if score = barXStore and whatdotcolour (x (i) - RADIUS, y (i)) = blue then
            dx (i) *= -1
        end if

        if x (i) + dx (i) = barYStore and whatdotcolour (x (i), y (i) - RADIUS) = blue then
            dy (i) *= -1
        end if

        if y (i) + dy (i)  maxx - RADIUS then
            dx (i) := -dx (i)
        end if
        if y (i) + dy (i) < RADIUS or
                y (i) + dy (i) > maxy - RADIUS then
            dy (i) := -dy (i)
        end if

        %Incompleted Wall Collision
        if whatdotcolour (x (i) + RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) + RADIUS) = red or whatdotcolour (x (i) - RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) - RADIUS) = red then
            score -= 1 %lose 1 life
            View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score))
            grow1 := 0 %reset
            %grow2 := 0 %reset
            horizontalBar := false %new wall can now be created
        elsif whatdotcolour (x (i) + RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) + RADIUS) = green or whatdotcolour (x (i) - RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) - RADIUS)
                = green then
            score -= 1 %lose 1 life
            View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score))
            %grow1 := 0 %reset
            grow2 := 0 %reset
            horizontalBar := false %new wall can now be created
        end if

        %Gameover
        if score = wallArray (a).barXStore and whatdotcolour (x (i) - RADIUS, y (i)) = blue then
                    dx (i) *= -1
                end if

                if x (i) + dx (i) = wallArray (a).barYStore and whatdotcolour (x (i), y (i) - RADIUS) = blue then
                    dy (i) *= -1
                end if

                if y (i) + dy (i)  maxx - RADIUS then 
            dx (i) := -dx (i) 
        end if 
        if y (i) + dy (i) < RADIUS or 
                y (i) + dy (i) > maxy - RADIUS then 
            dy (i) := -dy (i) 
        end if 

        %Incompleted Wall Collision 
        if whatdotcolour (x (i) + RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) + RADIUS) = red or whatdotcolour (x (i) - RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) - RADIUS) = red then 
            score -= 1 %lose 1 life 
            View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score)) 
            grow1 := 0 %reset 
            %grow2 := 0 %reset 
            horizontalBar := false %new wall can now be created 
        elsif whatdotcolour (x (i) + RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) + RADIUS) = green or whatdotcolour (x (i) - RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) - RADIUS) 
                = green then 
            score -= 1 %lose 1 life 
            View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score)) 
            %grow1 := 0 %reset 
            grow2 := 0 %reset 
            horizontalBar := false %new wall can now be created 
        end if 

        %Gameover 
        if score = wallArray (a).barXStore and whatdotcolour (x (i) - RADIUS, y (i)) = blue then 
                    dx (i) *= -1 
                end if 

                if x (i) + dx (i) = wallArray (a).barYStore and whatdotcolour (x (i), y (i) - RADIUS) = blue then 
                    dy (i) *= -1 
                end if 

                if y (i) + dy (i)  maxx - RADIUS then
            dx (i) := -dx (i)
        end if
        if y (i) + dy (i) < RADIUS or
                y (i) + dy (i) > maxy - RADIUS then
            dy (i) := -dy (i)
        end if

        %Incompleted Wall Collision
        for a : 1 .. upper (wallArray)
            if whatdotcolour (x (i) + RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) + RADIUS) = red or whatdotcolour (x (i) - RADIUS, y (i)) = red or whatdotcolour (x (i), y (i) - RADIUS) = red
                    then
                score -= 1 %lose 1 life
                View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score))
                wallArray (a).grow1 := 0 %reset
                %grow2 := 0 %reset
                wallArray (a).horizontalBar := false %new wall can now be created
            elsif whatdotcolour (x (i) + RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) + RADIUS) = green or whatdotcolour (x (i) - RADIUS, y (i)) = green or whatdotcolour (x (i), y (i) -
                    RADIUS)
                    = green then
                score -= 1 %lose 1 life
                View.Set ("offscreenonly,graphics,title:JezzBall           Score: " + intstr (score))
                %grow1 := 0 %reset
                wallArray (a).grow2 := 0 %reset
                wallArray (a).horizontalBar := false %new wall can now be created
            end if
        end for
        %Gameover
        if score = wallArray (a).barXStore and whatdotcolour (x (i) - RADIUS, y (i)) = blue then
                    dx (i) *= -1
                end if

                if x (i) + dx (i) = wallArray (a).barYStore and whatdotcolour (x (i), y (i) - RADIUS) = blue then
                    dy (i) *= -1
                end if

                if y (i) + dy (i) 