setscreen ("graphics:max,max,nobuttonbar,offscreenonly")
cls
var Xex, Yex : int
var YesNo : string (2)
var Font1 : int := Font.New ("Arial:50")
var Font2 : int := Font.New ("Arial:20")
var Count1, Count2 : nat := 0
var X1, Y1, X2, Y2 : int
var Health1, Health2 : int := 0
var XS1, XS2, YS1, YS2 : int
var Hit1, Hit2, Bang, Bang2 : boolean := false
var Right2, Left2, Up2, Down2 : boolean := false
var Right1, Left1, Up1, Down1 : boolean := false
var Key : array char of boolean
var Ch : char
procedure Pause
Ch := getchar
end Pause
% sound
process Beep
sound (200, 100)
end Beep
% shooting
process Shot2
Hit2 := true
XS2 := X2
YS2 := Y2
if Up2 = true then
loop
Count2 += 1
YS2 := YS2 + 1
exit when Count2 >= 3000
end loop
elsif Down2 = true then
loop
Count2 += 1
YS2 := YS2 - 1
exit when Count2 >= 3000
end loop
elsif Right2 = true then
loop
Count2 += 1
XS2 := XS2 + 1
exit when Count2 >= 3000
end loop
elsif Left2 = true then
loop
Count2 += 1
XS2 := XS2 - 1
exit when Count2 >= 3000
end loop
end if
Count2 := 0
Bang2 := false
Hit2 := false
end Shot2
process Shot1
Hit1 := true
XS1 := X1
YS1 := Y1
if Up1 = true then
loop
Count1 += 1
YS1 := YS1 + 1
exit when Count1 >= 3000
end loop
elsif Down1 = true then
loop
Count1 += 1
YS1 := YS1 - 1
exit when Count1 >= 3000
end loop
elsif Right1 = true then
loop
Count1 += 1
XS1 := XS1 + 1
exit when Count1 >= 3000
end loop
elsif Left1 = true then
loop
Count1 += 1
XS1 := XS1 - 1
exit when Count1 >= 3000
end loop
end if
Count1 := 0
Hit1 := false
Bang := false
end Shot1
const Midx := maxx div 2
const Midy := maxy div 2
colorback (7)
loop
cls
Font.Draw ("TANK-FIGHTERZ", 50, Midy, Font1, 10)
Font.Draw ("press any key to continue", 50, Midy - 100, Font2, 12)
Font.Draw ("made by Peter Watt", 50, Midy - 200, Font2, 0)
View.Update
Pause
Health1 := 0
Health2 := 0
X1 := 10
Y1 := Midy + 100
X2 := maxx - 10
Y2 := Midy - 100
Left1 := true
Right2 := true
cls
color (0)
put " the object of this game is to destroy your apponent "
put ""
put ""
color (12)
put "Player1 controls "
put ""
put "Up : Up arrow "
put "Down : Down arrow"
put "Left : Left Arrow"
put "Right : Right Arrow"
put "Shoot : Enter Key"
put ""
put ""
color (10)
put "Player 2 controls"
put "Up : w key "
put "Down : s key"
put "Left : a key"
put "Right : d key"
put "Shoot : Space bar"
color (0)
put "press any key to continue"
View.Update
Pause
loop
cls
%player boundries
if X1 >= maxx then
X1 := X1 - 1
elsif X1 <= 1 then
X1 := X1 + 1
elsif Y1 >= maxy then
Y1 := Y1 - 1
elsif Y1 <= 1 then
Y1 := Y1 + 1
end if
if X2 >= maxx then
X2 := X2 - 1
elsif X2 <= 1 then
X2 := X2 + 1
elsif Y2 >= maxy then
Y2 := Y2 - 1
elsif Y2 <= 1 then
Y2 := Y2 + 1
end if
Input.KeyDown (Key)
if Key (KEY_DOWN_ARROW) then
Down1 := true
Up1 := false
Right1 := false
Left1 := false
Y1 := Y1 - 1
elsif Key (KEY_UP_ARROW) then
Up1 := true
Down1 := false
Right1 := false
Left1 := false
Y1 := Y1 + 1
elsif Key (KEY_LEFT_ARROW) then
Up1 := false
Down1 := false
Right1 := false
Left1 := true
X1 := X1 - 1
elsif Key (KEY_RIGHT_ARROW) then
Up1 := false
Down1 := false
Right1 := true
Left1 := false
X1 := X1 + 1
end if
% player 2 controls
if Key ('s') then
Down2 := true
Up2 := false
Right2 := false
Left2 := false
Y2 := Y2 - 1
elsif Key ('w') then
Up2 := true
Down2 := false
Right2 := false
Left2 := false
Y2 := Y2 + 1
elsif Key ('a') then
Up2 := false
Down2 := false
Right2 := false
Left2 := true
X2 := X2 - 1
elsif Key ('d') then
Up2 := false
Down2 := false
Right2 := true
Left2 := false
X2 := X2 + 1
end if
if Key (' ') and Hit2 = false and Bang2 = false then
fork Shot2
end if
if Hit2 = true and Bang2 = false then
drawfilloval (XS2, YS2, 5, 5, 10)
end if
if Key (KEY_ENTER) and Hit1 = false and Bang2 = false then
fork Shot1
end if
if Hit1 = true and Bang = false then
drawfilloval (XS1, YS1, 5, 5, 12)
end if
% draw player 1
if Up1 = true then
% lefty WIng
drawfillbox (X1 - 5, Y1 - 20, X1 - 10, Y1 + 7, 15)
%righty
drawfillbox (X1 + 5, Y1 - 20, X1 + 10, Y1 + 7, 15)
% BODY
drawfillbox (X1 - 5, Y1 - 14, X1 + 5, Y1 + 5, red)
%COCKPIT
drawfillbox (X1 - 2, Y1 - 5, X1 + 2, Y1 + 10, 15)
drawfilloval (X1, Y1 - 3, 4, 4, 15)
elsif Down1 = true then
% lefty WIng
drawfillbox (X1 - 5, Y1 - 17, X1 - 10, Y1 + 10, 15)
%righty
drawfillbox (X1 + 5, Y1 - 17, X1 + 10, Y1 + 10, 15)
% BODY
drawfillbox (X1 - 5, Y1 - 14, X1 + 5, Y1 + 5, red)
%COCKPIT
drawfillbox (X1 - 2, Y1 - 2, X1 + 2, Y1 - 19, 15)
drawfilloval (X1, Y1 - 5, 4, 4, 15)
elsif Left1 = true then
% lefty WIng
drawfillbox (X1 - 17, Y1 + 5, X1 + 10, Y1 + 10, 15)
%righty
drawfillbox (X1 - 17, Y1 - 5, X1 + 10, Y1 - 10, 15)
% BODY
drawfillbox (X1 - 14, Y1 - 5, X1 + 5, Y1 + 5, red)
%COCKPIT
drawfillbox (X1 - 2, Y1 - 2, X1 - 19, Y1 + 2, 15)
drawfilloval (X1 - 5, Y1, 4, 4, 15)
elsif Right1 = true then
% lefty WIng
drawfillbox (X1 - 20, Y1 + 5, X1 + 8, Y1 + 10, 15)
%righty
drawfillbox (X1 - 20, Y1 - 5, X1 + 8, Y1 - 10, 15)
% BODY
drawfillbox (X1 - 14, Y1 - 5, X1 + 5, Y1 + 5, red)
%COCKPIT
drawfillbox (X1 - 2, Y1 - 2, X1 + 12, Y1 + 2, 15)
drawfilloval (X1 - 5, Y1, 4, 4, 15)
end if
%drawplayer 2
if Up2 = true then
% lefty WIng
drawfillbox (X2 - 5, Y2 - 20, X2 - 10, Y2 + 7, 15)
%righty
drawfillbox (X2 + 5, Y2 - 20, X2 + 10, Y2 + 7, 15)
% BODY
drawfillbox (X2 - 5, Y2 - 14, X2 + 5, Y2 + 5, 2)
%COCKPIT
drawfillbox (X2 - 2, Y2 - 5, X2 + 2, Y2 + 10, 15)
drawfilloval (X2, Y2 - 3, 4, 4, 15)
elsif Down2 = true then
% lefty WIng
drawfillbox (X2 - 5, Y2 - 17, X2 - 10, Y2 + 10, 15)
%righty
drawfillbox (X2 + 5, Y2 - 17, X2 + 10, Y2 + 10, 15)
% BODY
drawfillbox (X2 - 5, Y2 - 14, X2 + 5, Y2 + 5, 2)
%COCKPIT
drawfillbox (X2 - 2, Y2 - 2, X2 + 2, Y2 - 19, 15)
drawfilloval (X2, Y2 - 5, 4, 4, 15)
elsif Left2 = true then
% lefty WIng
drawfillbox (X2 - 17, Y2 + 5, X2 + 10, Y2 + 10, 15)
%righty
drawfillbox (X2 - 17, Y2 - 5, X2 + 10, Y2 - 10, 15)
% BODY
drawfillbox (X2 - 14, Y2 - 5, X2 + 5, Y2 + 5, 2)
%COCKPIT
drawfillbox (X2 - 2, Y2 - 2, X2 - 19, Y2 + 2, 15)
drawfilloval (X2 - 5, Y2, 4, 4, 15)
elsif Right2 = true then
% lefty WIng
drawfillbox (X2 - 20, Y2 + 5, X2 + 8, Y2 + 10, 15)
%righty
drawfillbox (X2 - 20, Y2 - 5, X2 + 8, Y2 - 10, 15)
% BODY
drawfillbox (X2 - 14, Y2 - 5, X2 + 5, Y2 + 5, 2)
%COCKPIT
drawfillbox (X2 - 2, Y2 - 2, X2 + 12, Y2 + 2, 15)
drawfilloval (X2 - 5, Y2, 4, 4, 15)
end if
if Hit1 = true and Bang = false and YS1 > Y2 - 20 and YS1 < Y2 + 20 and XS1 > X2 - 20 and XS1 < X2 + 20 then
Health1 += 5
fork Beep
Bang := true
end if
if Hit2 = true and Bang2 = false and YS2 > Y1 - 20 and YS2 < Y1 + 20 and XS2 > X1 - 20 and XS2 < X1 + 20 then
Health2 += 5
fork Beep
Bang2 := true
end if
color (10)
put "Green tanks damage: ", Health1, " %" : 10 ..
color (12)
put "Red tanks damage: ", Health2, " %"
exit when Health1 >= 100 or Health2 >= 100
View.Update
end loop
if X1 > X2 - 50 and X1 <= X2 + 50 and Y1 <= Y2 + 50 and Y1 > Y2 - 50 then
Font.Draw ("Both tanks were destroyed", 1, Midy, Font1, 0)
else
if Health2 >= 100 then
drawfilloval (XS2, YS2, 2, 2, 7)
Font.Draw ("The green tank wins!", 1, Midy, Font1, 10)
elsif Health1 >= 100 then
Font.Draw ("The red tank wins!", 1, Midy, Font1, 12)
end if
end if
put " Would you like to play again? (y/n?"
View.Update
get YesNo
exit when YesNo = "n"
end loop
|