View.Set ("offscreenonly")
const RADIUS : int := 5
const NUM_BALLS : int := 3
var x, y, dx, dy, clr : array 1 .. NUM_BALLS of int
var box_x1, box_x2, box_y1, box_y2 : int := 0
var barX, barY, button, left, middle, right : int
var barCreator := true
var a, b : int := 0
var c1, c2 := false
var d1, d2 := false
var drawFill := true
var topCounterx, bottomCounterx,topCountery, bottomCountery := 0
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), y (i)) = red or whatdotcolour (x (i), y (i)) = green then
return
end if
%Completed Wall Collision
if x (i) + dx (i) >= box_x1 and x (i) + dx (i) <= box_x2 and whatdotcolour (x (i), y (i)) = blue then
dx (i) *= -1
end if
if y (i) + dy (i) >= box_y1 and y (i) + dy (i) <= box_y2 and whatdotcolour (x (i), y (i)) = blue then
dy (i) *= -1
end if
x (i) := x (i) + dx (i)
y (i) := y (i) + dy (i)
%Draw Ball
Draw.FillOval (x (i), y (i), RADIUS, RADIUS, black)
end for
View.Update
delay (10)
cls
%Wall Creation
Mouse.ButtonChoose ("multibutton")
Mouse.Where (barX, barY, button)
left := button mod 10 % left = 0 or 1
middle := (button - left) mod 100 % middle = 0 or 10
right := button - middle - left % right = 0 or 100
if barCreator = true then
if left = 1 and whatdotcolour (barX, barY) not= blue then
a := 0
b := 0
button := 0
box_x1 := barX
box_x2 := barX
box_y1 := barY
box_y2 := box_y1 + 10
if (box_x1 + a) <= maxx then
c1 := true
else
c1 := false
end if
if (box_x1 - b) >= 0 then
d1 := true
else
d1 := false
end if
end if
end if
if c1 = true then
barCreator := false
a += 3
end if
if d1 = true then
barCreator := false
b += 3
end if
if c1 = true then
if box_x1 + a >= maxx then
Draw.FillBox (box_x1 + a, box_y1, box_x2, box_y2, blue)
else
Draw.FillBox (box_x1 + a, box_y1, box_x2, box_y2, red)
end if
end if
if d1 = true then
if box_x1 - b <= 0 then
Draw.FillBox (box_x1 - b, box_y1, box_x2, box_y2, blue)
else
Draw.FillBox (box_x1 - b, box_y1, box_x2, box_y2, green)
end if
end if
%Which side to fill in upon completion of wall
if box_x1 + a >= maxx and box_x1 - b <= 0 then
for i : 1 .. NUM_BALLS
if y (i) > box_y2 then
topCountery += 1
elsif y (i) < box_y1 then
bottomCountery += 1
end if
end for
if topCountery >= 1 and bottomCountery >= 1 then
drawFill := false
else
drawFill:=true
end if
if drawFill = true then
for i : 1 .. NUM_BALLS
if y (i) >= box_y1 then
Draw.Fill (box_x1,box_y1-1,blue, blue)
elsif drawFill = true and y (i) <= box_y1 then
Draw.Fill (box_x2,box_y2+1,blue, blue)
end if
end for
end if
end if
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if barCreator = true then
if right = 100 and whatdotcolour (barX, barY) not= blue then
a := 0
b := 0
button := 0
box_x1 := barX
box_x2 := box_x1 + 10
box_y1 := barY
box_y2 := barY
if (box_y1 + a) <= maxx then
c2 := true
else
c2 := false
end if
if (box_y1 - b) >= 0 then
d2 := true
else
d2 := false
end if
end if
end if
if c2 = true then
barCreator := false
a += 3
end if
if d2 = true then
barCreator := false
b += 3
end if
if c2 = true then
if box_y1 + a >= maxy then
Draw.FillBox (box_x1, box_y1 + a, box_x2, box_y2, blue)
else
Draw.FillBox (box_x1, box_y1 + a, box_x2, box_y2, red)
end if
end if
if d2 = true then
if box_y1 - b <= 0 then
Draw.FillBox (box_x1, box_y1 - b, box_x2, box_y2, blue)
else
Draw.FillBox (box_x1, box_y1 - b, box_x2, box_y2, green)
end if
end if
%Which side to fill in upon completion of wall
if box_y1 + a >= maxx and box_y1 - b <= 0 then
for i : 1 .. NUM_BALLS
if x (i) > box_x2 then
topCounterx += 1
elsif x (i) < box_x1 then
bottomCounterx += 1
end if
end for
if topCounterx >= 1 and bottomCounterx >= 1 then
drawFill := false
else
drawFill:=true
end if
if drawFill = true then
for i : 1 .. NUM_BALLS
if x (i) >= box_x1 then
Draw.Fill (box_x1-1,box_y1,blue, blue)
elsif x (i) <= box_x1 then
Draw.Fill (box_x2+1,box_y2,blue, blue)
end if
end for
end if
end if
end loop
|