Computer Science Canada

Border and Ball...*Extreme Newb Question*

Author:  Hunter007 [ Sat Jan 17, 2004 1:35 pm ]
Post subject:  Border and Ball...*Extreme Newb Question*

I know this is a very pathetic question but i can't seem to figure out how to apply a border with the "for i: 1.." command. I would really appreciate the help as I can't find this question anywhere. I also want to move a ball horizantally within the border without using "process ball". Thanks.

Author:  rgothmog [ Sat Jan 17, 2004 2:06 pm ]
Post subject: 

Well if this is what u want here is one way of making a border using a for loop:
code:

View.Set ("graphics:350;350")
var bordersize : int := 10
for i : 1 .. 4
    if i = 1 then
        Draw.FillBox (0, 0, maxx, bordersize, black)
    elsif i = 2 then
        Draw.FillBox (maxx, bordersize, maxx - bordersize, maxy, black)
    elsif i = 3 then
        Draw.FillBox (maxx - bordersize, maxy, 0, maxy - bordersize, black)
    elsif i = 4 then
        Draw.FillBox (0, maxy - bordersize, bordersize, bordersize, black)
    end if
end for

It just draws 4 boxes around the edge of the page... probably an inefficient way to do it tho Very Happy ...compared to how some ppl would do it.

Author:  Hunter007 [ Sat Jan 17, 2004 2:11 pm ]
Post subject: 

Thanks, that's great but it has to be individual things like Draw.FillStar's or something, not just one big line. Like 10 stars going down the sides,across the top and on the bottom. *doesnt have to be 10, just an example*

Author:  Cervantes [ Sat Jan 17, 2004 2:18 pm ]
Post subject: 

taking the first part from the border....

code:
View.Set ("graphics:350;350")
var bordersize : int := 10
for i : 1 .. 4
    if i = 1 then
        Draw.FillBox (0, 0, maxx, bordersize, black)
    elsif i = 2 then
        Draw.FillBox (maxx, bordersize, maxx - bordersize, maxy, black)
    elsif i = 3 then
        Draw.FillBox (maxx - bordersize, maxy, 0, maxy - bordersize, black)
    elsif i = 4 then
        Draw.FillBox (0, maxy - bordersize, bordersize, bordersize, black)
    end if
end for
var x, y, dx : int
x := maxx div 2
y := maxy div 2
dx := 2 %this value will be added to x each time the loop restarts
View.Set ("offscreenonly")
loop
    x += dx %aka x := x + dx
    if x > maxx - 17 or x < 18 then %maxx - bordersize - ball radius - dx/ 1 + bordersize + ball radius + dx
        dx := -dx
    end if
    Draw.FillOval (x, y, 5, 5, 12) %Draw the Ball
    View.Update
    delay (10)
    Draw.FillOval (x, y, 5, 5, 0) %Preventing a line of balls
end loop



Cheers

Author:  Cervantes [ Sat Jan 17, 2004 2:22 pm ]
Post subject: 

code:
for i : 1 .. maxx by 15
    Draw.FillStar (5, i, 15, i + 10, 12)
end for


and do that for all the edges..


: