View.Set ("graphics:500,500")
View.Set ("position:middle,middle")
setscreen ("offscreenonly")
var pervasive inc, v, x, y, xforbullet, c2,collisioncount,font1, collision : int
var pervasive distance, x1, y2 : real
var pervasive strcollision : string
var chars : array char of boolean
x := 250
y := 10
c2 := 75
xforbullet := 0
collisioncount := 0
process paddlemove
drawfilloval (x, y, 10, 10, 255)
loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
if x + 10 < 500 then
delay (30)
drawfilloval (x, y, 10, 10, 0)
View.Update
x := x + 10
drawfilloval (x, y, 10, 10, 255)
View.Update
end if
end if
if chars (KEY_LEFT_ARROW) then
if x - 10 > 0 then
delay (30)
drawfilloval (x, y, 10, 10, 0)
View.Update
x := x - 10
drawfilloval (x, y, 10, 10, 255)
View.Update
end if
end if
end loop
end paddlemove
collision := 0
process squaretohit
inc := 50
v := 1
loop
if v = 1 then
inc += 10
elsif v = 0 then
inc -= 10
end if
if inc > 500 then
v := 0
end if
if inc < 0 then
v := 1
end if
x1 := (xforbullet - inc) ** 2
y2 := (c2 - 250) ** 2
distance := sqrt (x1 + y2)
if distance > 56 then
drawfilloval (inc, 250, 50, 50, 50)
View.Update
delay (30)
drawfilloval (inc, 250, 50, 50, 0)
View.Update
end if
if distance < 56 then
collision := collision + 1
locatexy(20,20)
put "Hits:",collision
end if
end loop
end squaretohit
process shooting
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
xforbullet := x
c2 := 75
loop
drawoval (xforbullet, c2, 6, 6, 255)
View.Update
delay (30)
drawoval (xforbullet, c2, 6, 6, 0)
View.Update
exit when c2 + 10 >= 500
c2 := c2 + 10
end loop
end if
end loop
end shooting
font1 := Font.New("arial:12")
assert font1 > 0
fork paddlemove
fork shooting
fork squaretohit
|