
-----------------------------------
AustinRF
Thu Jan 16, 2014 7:31 pm

Problem getting two obstacles being drawn on the same spot regardless of a for loop.
-----------------------------------
What is it you are trying to achieve?
To make a game for my Grade 11 Computer Science course.

As you can see, there is a loop drawing a line every time another line is 1/6th down the screen. the problem is the first line is drawing where the second one is as well.

What is the problem you are having?
Two obstacles are drawing on one spot regardless of the for loop "limiting" it to two separate ones.

Describe what you have tried to solve this problem
I've gone through my code trying to find my error and it seems I need a new persective on things.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




setscreen ("nocursor")
setscreen ("graphics:640;480")
View.Set ("offscreenonly")

type Line :
    record
        x : int
        y : int
        exists : boolean
    end record
    
var blacklines : array 1 .. 6 of Line
const upperBound := upper (blacklines)
const lowerBound := lower (blacklines)

var firstLineY : int := 0
var colours : int := Rand.Int (34,103)
var fourseventy : int := 470
var leftboxx, rightboxx : real
leftboxx := 0
rightboxx := 640

var randomnumber : real := Rand.Int (round (leftboxx + 20), round (rightboxx - 20))
var x, y, button : int

var font1 : int
font1 := Font.New ("calibri:12")
assert font1 > 0

for i : 1 .. 6
    blacklines (i).x := Rand.Int (round (leftboxx + 20), round (rightboxx - 20))
    blacklines (i).y := 480
    blacklines (i).exists := false
end for

blacklines (1).exists := true

loop
    firstLineY := blacklines (1).y
    
    for i : 1 .. 6
        if blacklines (i).y = 0 then
            blacklines (i).x := Rand.Int (round (leftboxx), round (rightboxx))
            blacklines (i).y := 480
        end if
    end for
    
    for i : 1 .. 6
        if blacklines (i).exists = true then
            blacklines (i).y -= 3
        end if
    end for
    
    for i : 1 .. 6
        if firstLineY 