var window : int := Window.Open ("graphics:1000;668")
var chars : array char of boolean
var x1, y1, x2, y2, intX, intY : int
var intColor1, intColor2 : int
x1 := 200
y1 := 668 div 2
x2 := 800
y2 := 668 div 2
locatexy (420, 335)
put "*The colors cannot be the same*"
locatexy (395, 330)
put "Enter the color of Player 1 (1 to 255)"
locatexy (395, 310)
get intColor1
locatexy (395, 290)
put "Enter the color of Player 2 (1 to 255)"
locatexy (395, 270)
get intColor2
if intColor1 = intColor2 then
quit
end if
cls
var gametime : int := Time.Sec
View.Set ("offscreenonly")
loop
Input.KeyDown (chars)
%Player 1
if chars (KEY_UP_ARROW) then
y1 := y1 + 1
end if
if chars (KEY_DOWN_ARROW) then
y1 := y1 - 1
end if
if chars (KEY_LEFT_ARROW) then
x1 := x1 - 1
end if
if chars (KEY_RIGHT_ARROW) then
x1 := x1 + 1
end if
%Boundary
if (x1 + 10) >= maxx or (x1 - 10) <= -1 then
x1 *= -1
elsif (y1 + 10) >= maxy or (y1 - 10) <= -1 then
y1 *= -1
end if
%Player 2
if chars ('w') then
y2 := y2 + 1
end if
if chars ('s') then
y2 := y2 - 1
end if
if chars ('a') then
x2 := x2 - 1
end if
if chars ('d') then
x2 := x2 + 1
end if
%Boundary
if (x2 + 10) >= maxx or (x2 - 10) <= -1 then
x2 *= -1
elsif (y2 + 10) >= maxy or (y2 - 10) <= -1 then
y2 *= -1
end if
Draw.FillOval (x1, y1, 10, 10, intColor1)
Draw.FillOval (x2, y2, 10, 10, intColor2)
View.Update
%Collision
if whatdotcolor (x1, y1) = intColor2 then
cls
locatexy (420, 354)
put "Your game lasted ", Time.Sec - gametime, " seconds."
locatexy (465, 334)
put "Player 1 Loses!"
locatexy (465, 330)
put "Player 2 Wins!"
delay (1000)
locatexy (480, 310)
put "Game Over!"
delay (2000)
exit
elsif whatdotcolor (x2, y2) = intColor1 then
cls
locatexy (420, 354)
put "Your game lasted ", Time.Sec - gametime, " seconds."
locatexy (465, 334)
put "Player 2 Loses!"
locatexy (465, 330)
put "Player 1 Wins!"
delay (1000)
locatexy (480, 310)
put "Game Over!"
delay (2000)
exit
end if
end loop |