Computer Science Canada

Rand Ball proggy help plz

Author:  Lazarus [ Tue Apr 19, 2005 11:57 am ]
Post subject:  Rand Ball proggy help plz

k, I'm sure anyone of you could get this done in a few seconds, but I have a brain cramp, so no matter what I do it's not working properly, I know I have to get it to choose weither it will be positive or negative a rand. But I'm confuzzled, here's what I got:

code:
cls

var x : int := 600
var y : int := 100

loop
    x := x + -1 
    y := y + 1
    Draw.FillOval (x , y , 10, 10, red)
    delay (100)
    Draw.FillOval (x , y , 10, 10, white)
end loop

Author:  Martin [ Tue Apr 19, 2005 12:15 pm ]
Post subject: 

I'm not entirely sure what you're trying to do. Do you mean that you want it to start moving in a random direction from a random point on the screen?

Author:  Lazarus [ Tue Apr 19, 2005 12:20 pm ]
Post subject: 

Completely Random, Start at a Random point, move to a random location, then move from that location to an other Random location. All I need to do is find out how to make it decide weither or not it to be positive or negative, and it cannot go off the screen.

Author:  Martin [ Tue Apr 19, 2005 12:27 pm ]
Post subject: 

Type Rand.Int and press F10.

You'll want to generate 4 numbers: the start x and y location, and the end x and y location. Then figure out the slope of the line connecting the two points (remember grade 9?) and you're set.

Author:  Lazarus [ Tue Apr 19, 2005 12:29 pm ]
Post subject: 

This does not help, because it will not be completely Random.

Author:  Martin [ Tue Apr 19, 2005 12:39 pm ]
Post subject: 

I don't understand what you mean by completely random. Like, you want it to just shake around on the screen?

Author:  Lazarus [ Tue Apr 19, 2005 12:41 pm ]
Post subject: 

Yep yep, but I got it, my brain cramp left me lol

code:
setscreen ("nooffscreenonly")
cls
var x : int := Rand.Int (100,600)
var y : int := Rand.Int (100,400)
loop
    x := x + (Rand.Int (-10,10))
    y := y + (Rand.Int (-10,10))
    Draw.FillOval (x, y, 10, 10, red)
    delay (100)
    Draw.FillOval (x, y, 10, 10, white)
end loop


now all I have to do is make a boundry so it doesn't go off the screen, how would I?

Author:  Martin [ Tue Apr 19, 2005 12:53 pm ]
Post subject: 

code:
setscreen ("nooffscreenonly")
cls
var x : int := Rand.Int (100,600)
var y : int := Rand.Int (100,400)
var xchange, ychange : int
loop
    xchange := Rand.Int (-10, 10)
    ychange := Rand.Int (-10, 10)
    if (x + xchange) > 0 and (x + xchange) < maxx then
        x := x + xchange
    end if
    if (y + ychange) > 0 and (y + ychange) < maxy then
        y := y + ychange
    end if
    Draw.FillOval (x, y, 10, 10, red)
    delay (100)
    Draw.FillOval (x, y, 10, 10, white)
end loop


: