View.Set ("offscreenonly,nobuttonbar")
proc drawBar (barX, barY, a, b, colRight, colLeft : int)
Draw.FillBox (barX, barY, barX + a, barY + 10, colRight)
Draw.FillBox (barX, barY, barX - b, barY + 10, colLeft)
end drawBar
const RADIUS : int := 5
type ballData :
record
x : int
y : int
dx : int
dy : int
end record
var ballMovement : flexible array 1 .. 2 of ballData
for i : 1 .. upper (ballMovement)
ballMovement (i).x := Rand.Int (RADIUS + 10, maxx - RADIUS - 10)
ballMovement (i).y := Rand.Int (RADIUS + 10, maxy - RADIUS - 10)
ballMovement (i).dx := Rand.Int (-5, 5)
ballMovement (i).dy := Rand.Int (-5, 5)
end for
var clickX, clickY, button, left, middle, right : int := 0
var barX, barY, a, b, barStoreA, barStoreB : int := 0
var boolMoveRed, boolMoveGreen := false
var boolClick := true
var topCounter, bottomCounter := 0
loop
View.Update
delay (10)
cls
%Draw Border
Draw.Box (10, 10, maxx - 10, maxy - 10, black)
Draw.Fill (5, 5, black, black)
%Mouse Controls
Mouse.ButtonChoose ("multibutton")
Mouse.Where (clickX, clickY, 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
%Wall Movement Flags
if left = 1 and boolClick = true and whatdotcolour (clickX, clickY) not= black and whatdotcolour (clickX, clickY) not= blue then
barX := clickX
barY := clickY
boolMoveRed := true
boolMoveGreen := true
boolClick := false
end if
if boolMoveRed = true then
a += 5
barStoreA := barX + a
drawBar (barX, barY, a, b, red, green)
end if
if boolMoveGreen = true then
b += 5
barStoreB := barX - b
drawBar (barX, barY, a, b, red, green)
end if
%Wall Movement Collision
if whatdotcolour (barStoreA + 1, barY) = 7 then
boolMoveRed := false
if boolMoveGreen = false then
drawBar (barX, barY, a, b, blue, blue)
elsif boolMoveGreen = true then
drawBar (barX, barY, a, b, blue, green)
end if
end if
if whatdotcolour (barStoreB - 1, barY) = 7 then
boolMoveGreen := false
if boolMoveRed = false then
drawBar (barX, barY, a, b, blue, blue)
elsif boolMoveRed = true then
drawBar (barX, barY, a, b, red, blue)
end if
end if
%Wall Completion
if whatdotcolour (barStoreA + 1, barY) = 7 and whatdotcolour (barStoreB - 1, barY) = 7 then
%Box Creation Counter (above, below, or none)
for i : 1 .. upper (ballMovement)
if ballMovement (i).y > barY then %Balls above wall
topCounter += 1
elsif ballMovement (i).y < barY then %Balls below wall
bottomCounter += 1
end if
%Drawing Completed Wall
if topCounter not= 0 and bottomCounter not= 0 then %balls are located ABOVE and BELOW the bar
%No change
elsif topCounter not= 0 then %balls are located ABOVE the bar
Draw.FillBox (10, 10, maxx - 10, barY, blue)
elsif bottomCounter not= 0 then %balls are located BELOW the bar
Draw.FillBox (10, barY, maxx - 10, maxy - 10, blue)
end if
end for
end if
%Various Ball Collisions
for i : 1 .. upper (ballMovement)
%Balls to Bar Collision (for balls BELOW the bar)
if ballMovement (i).y + RADIUS >= barY and whatdotcolour (ballMovement (i).x, ballMovement (i).y + RADIUS) = blue then
ballMovement (i).dy := -ballMovement (i).dy
end if
%Balls to Bar Collision (for balls ABOVE the bar)
if ballMovement (i).y - RADIUS >= barY and whatdotcolour (ballMovement (i).x, ballMovement (i).y - RADIUS) = blue then
ballMovement (i).dy := -ballMovement (i).dy
end if
%Outer Boundary Collision for Balls
if ballMovement (i).x + ballMovement (i).dx - 10 < RADIUS or
ballMovement (i).x + ballMovement (i).dx > maxx - 10 - RADIUS then
ballMovement (i).dx := -ballMovement (i).dx
end if
if ballMovement (i).y + ballMovement (i).dy - 10 < RADIUS or
ballMovement (i).y + ballMovement (i).dy > maxy - 10 - RADIUS then
ballMovement (i).dy := -ballMovement (i).dy
end if
%Change Direction of Balls
ballMovement (i).x := ballMovement (i).x + ballMovement (i).dx
ballMovement (i).y := ballMovement (i).y + ballMovement (i).dy
%Draw Balls
Draw.FillOval (ballMovement (i).x, ballMovement (i).y, RADIUS, RADIUS, black)
end for
end loop |