% Ryan Murray TIK2O
% December 8, 2004
% pinball.t
cls
View.Set ("offscreenonly")
var xchange : int
var ychange : int
var count : int
var kolor : int
var count1 : int
var x : int
var y : int
var size : int
var col : int
var speed : int
col := 42
count := 0
count1 := 5
speed := 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process ping
var chars : array char of boolean
View.Set ("offscreenonly")
var x, x2 : int
x := 320
x2 := 260
loop
Input.KeyDown (chars)
drawfillbox (x, 10, x2, 20, black)
if chars (KEY_RIGHT_ARROW) then
x := x + 10
x2 := x2 + 10
end if
if chars (KEY_LEFT_ARROW) then
x := x - 10
x2 := x2 - 10
end if
if chars (KEY_ENTER) then
col := black
end if
drawfillbox (x, 10, x2, 20, white)
View.Update
delay (20)
exit when count1 = 0
end loop
end ping
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process ball
% this loop sets up a random value for the change in the x direction
% the reason for the loop with the exit is to allow values from -5 to +5 - but NOT allow 0
loop
xchange := speed % sets a random speed for the ball (between -5 and 5)
exit when xchange not= 0
end loop
loop
ychange := speed
exit when ychange not= 0
end loop
% you should add a loop here to randomly assign a ychange value
Draw.FillBox (5, 5, maxx - 5, maxy - 5, black)
colorback (black)
cls
kolor := red % sets a random colour for the ball (between 1 and 15)
size := 6 % sets a random size for the ball (between 5 and 10)
x := maxx div 2 % sets x position to half way across the screen
y := maxy div 2 % sets y position to half way up the screen
Draw.FillOval (x, y, size, size, kolor) % colours the background black
loop
drawfillbox (100, 100, 200, 200, col)
drawfillbox (90, 90, 190, 190, black)
drawfillbox (400, 100, 500, 200, col)
drawfillbox (410, 90, 510, 190, black)
drawfillbox (100, 300, 200, 210, col)
drawfillbox (90, 300, 190, 220, black)
drawfillbox (400, 300, 500, 210, col)
drawfillbox (410, 300, 500, 220, black)
delay (11)
% the next if statement checks to see if the ball has hit the right wall
% (maxx less 5 less the size of the ball less the speed of the ball)
% or the left wall ( 5 away from 0 + size - speed)
% when it hits a vertical wall, the x direction reverses.
if (x >= maxx - 5 - size - xchange) or (x <= 5 + size - xchange) then
xchange := -xchange
end if
if (y >= maxy - 5 - size - ychange) then
ychange := -ychange
end if
if (y <= 5 + size - ychange) then
count1 := count1 - 1
ychange := -ychange
end if
if xchange > 0 then
if whatdotcolor (x + xchange + size, y) not= black then
xchange := -xchange
count := count + 1
end if
else
if
whatdotcolor (x + xchange - size, y) not= black then
xchange := -xchange
count := count + 1
end if
end if
if ychange > 0 then
if whatdotcolor (x, y + ychange + size) not= black then
ychange := -ychange
count := count + 1
end if
else
if
whatdotcolor (x, y + ychange - size) not= black then
ychange := -ychange
count := count + 1
end if
end if
if count1 = 2 then
kolor := yellow
end if
if count1 = 5 then
kolor := blue
end if
if count1 = 1 then
kolor := 12
end if
if count1 = 0 then
kolor := black
end if
locate (1, 1)
color (green)
put "Score:", count
put "Lives:", count1
% erase old ball by covering it up with black
Draw.FillOval (x, y, size, size, black)
x := x + xchange
y := y + ychange
% draw new ball
Draw.FillOval (x, y, size, size, kolor)
View.Update
if count1 = 0 then
cls
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put " -------------------"
put " GameOver "
put " Your Score is:", count
put " -------------------"
exit
end if
if count = 50 then
cls
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put " -------------------"
put " Level 2 "
put " -------------------"
delay (1000)
cls
exit
end if
end loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
xchange := speed % sets a random speed for the ball (between -5 and 5)
exit when xchange not= 0
end loop
loop
ychange := speed
exit when ychange not= 0
end loop
kolor := red % sets a random colour for the ball (between 1 and 15)
size := 6 % sets a random size for the ball (between 5 and 10)
x := maxx div 2 % sets x position to half way across the screen
y := maxy div 2 % sets y position to half way up the screen
Draw.FillOval (x, y, size, size, kolor) % colours the background black
loop
drawfilloval (100, 250, 100, 100, red)
drawfilloval (150, 250, 100, 100, black)
drawfilloval (540, 250, 100, 100, red)
drawfilloval (490, 250, 100, 100, black)
drawfillbox(250,200,375,300,42)
drawfillbox(275,225,350,275,black)
drawfillbox(290,200,340,275,black)
delay (11)
% the next if statement checks to see if the ball has hit the right wall
% (maxx less 5 less the size of the ball less the speed of the ball)
% or the left wall ( 5 away from 0 + size - speed)
% when it hits a vertical wall, the x direction reverses.
if (x >= maxx - 5 - size - xchange) or (x <= 5 + size - xchange) then
xchange := -xchange
end if
if (y >= maxy - 5 - size - ychange) then
ychange := -ychange
end if
if (y <= 5 + size - ychange) then
count1 := count1 - 1
ychange := -ychange
end if
if xchange > 0 then
if whatdotcolor (x + xchange + size, y) not= black then
xchange := -xchange
count := count + 1
end if
else
if
whatdotcolor (x + xchange - size, y) not= black then
xchange := -xchange
count := count + 1
end if
end if
if ychange > 0 then
if whatdotcolor (x, y + ychange + size) not= black then
ychange := -ychange
count := count + 1
end if
else
if
whatdotcolor (x, y + ychange - size) not= black then
ychange := -ychange
count := count + 1
end if
end if
if count1 = 2 then
kolor := yellow
end if
if count1 = 5 then
kolor := blue
end if
if count1 = 1 then
kolor := 12
end if
if count1 = 0 then
kolor := black
end if
locate (1, 1)
color (green)
put "Score:", count
put "Lives:", count1
% erase old ball by covering it up with black
Draw.FillOval (x, y, size, size, black)
x := x + xchange
y := y + ychange
% draw new ball
Draw.FillOval (x, y, size, size, kolor)
View.Update
if count1 = 0 then
cls
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put " -------------------"
put " GameOver "
put " Your Score is:", count
put " -------------------"
exit
end if
end loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end ball
fork ball
fork ping
|