setscreen ("graphics:790;540") % graphics screen mode var font : int := Font.New ("Comic Sans Ms:20") % two kinds var font2 : int := Font.New ("Comic Sans Ms:50") % of fonts var A, B : real := 0 % angle variables var x, y, xx, yy, x1, y1, x2, y2, r, a, b : int % various coorditates used in the program x := 65 y := 125 xx := 695 yy := 125 x1 := 65 y1 := 125 x2 := 725 y2 := 125 r := 30 a := 0 b := 0 var V, count, t : int := 0 % velocity variable var End := false var shot : boolean := false % shot is made with help of this variable var shotx, shoty : int % coordinates of cannonball var ch : string (1) % variable for input from keyboard var acc : int := 10 % acceleration of free fall var grav : string (3) % gravity for input from keyboard var g : int % game gravity var hillx : int := 150 var hillxx : int := 640 var hilly, col : int randint (hilly, 200, 500) loop randint (col, 0, 15) exit when col not= 7 and col not= 0 end loop var s : int := 1 var p1, p2 : int % percentage of power left in tanks p1 := 100 p2 := 100 var V1, V2, v : int % maximum allowed velocity V1 := 150 V2 := 150 v := 150 var cl : int % color of circling ball procedure Key % waits until keyboard's key is pressed var str : string (1) loop getch (str) exit when str not= "" end loop end Key procedure finish % game over var scorch : string cls Font.Draw ("GAME OVER", 240, 270, font2, red) if count mod 2 = 0 then Font.Draw ("BLUE PLAYER LOST", 295, 240, font, blue) else Font.Draw ("RED PLAYER LOST", 300, 240, font, blue) end if Key end finish procedure explode % explosion var cr : int loop randint (cr, 0, 15) exit when cr not= col and cr not= white % not empty explosion - should be colored end loop for j : 1 .. 40 drawfilloval (shotx, shoty, j, j, cr) delay (10) end for drawfilloval (shotx, shoty, 40, 40, white) % checking how close explosions are to tanks % and changing power level if explosions are too close if abs (shotx - x1) <= 105 and abs (shoty - y1) <= 105 then if abs (shotx - x1) <= 75 and abs (shoty - y1) <= 75 then if abs (shotx - x1) <= 50 and abs (shoty - y1) <= 50 then if abs (shotx - x1) <= 30 and abs (shoty - y1) <= 30 then if abs (shotx - x1) <= 15 and abs (shoty - y1) <= 15 then if abs (shotx - x1) <= 5 and abs (shoty - y1) <= 5 then V1 := V1 - 35 p1 := p1 - 25 end if V1 := V1 - 30 p1 := p1 - 20 end if V1 := V1 - 25 p1 := p1 - 17 end if V1 := V1 - 20 p1 := p1 - 14 end if V1 := V1 - 15 p1 := p1 - 8 end if V1 := V1 - 10 p1 := p1 - 6 end if if p1 <= 0 then V1 := 25 end if if abs (shotx - x2) <= 105 and abs (shoty - y2) <= 105 then if abs (shotx - x2) <= 75 and abs (shoty - y2) <= 75 then if abs (shotx - x2) <= 50 and abs (shoty - y2) <= 50 then if abs (shotx - x2) <= 30 and abs (shoty - y2) <= 30 then if abs (shotx - x2) <= 15 and abs (shoty - y2) <= 15 then if abs (shotx - x2) <= 5 and abs (shoty - y2) <= 5 then V2 := V2 - 35 p2 := p2 - 25 end if V2 := V2 - 30 p2 := p2 - 20 end if V2 := V2 - 25 p2 := p2 - 17 end if V2 := V2 - 20 p2 := p2 - 14 end if V2 := V2 - 15 p2 := p2 - 8 end if V2 := V2 - 10 p2 := p2 - 6 end if if p2 <= 0 then V2 := 25 end if if p2 <= 0 or p1 <= 0 then explode finish end if end explode procedure arc (var count : int, x, y, xx, yy : int, var g, V : int, A : real) % draws cannonball's trajectory, shows explosions and finishes game var i : real := 0 t := round (abs (2 * ( (V * sind (A)) / g))) % time g := strint (grav) loop if s not= 1 then if shotx < 790 and shotx > 0 and shoty < 540 and shoty > 97 then drawfilloval (shotx, shoty, 2, 2, white) drawfilloval (shotx + round (5 * cosd (B)), shoty + round (5 * sind (B)), 1, 1, white) drawfilloval (shotx + round (5 * cosd (B + 180)), shoty + round (5 * sind (B + 180)), 1, 1, white) % erasing previous cannonball - animation end if end if B := B + 10 % increasing rotation angle if B >= 3600 then % keeping number not too large B := 0 end if i := i + 0.1 % time parameter if count mod 2 = 0 then % firing turns shotx := x + round (V * i * cosd (A)) shoty := y + round (V * i * sind (A) - (g * i ** 2) / 2) else % coordinates of cannonball on its trajectory shotx := xx - round (V * i * cosd (A)) shoty := yy + round (V * i * sind (A) - (g * i ** 2) / 2) end if exit when shotx <= 0 or shotx >= 790 % exiting loop if cannonball flies offscreen in x-axis exit when shoty >= 540 % exiting loop if cannonball flies offscreen in y-axis if shoty <= 97 then % ground level explosion explode exit % exiting loop when cannonball hits ground end if if shotx < 790 and shotx > 0 and shoty < 540 and shoty > 97 then % drawing cannonball drawoval (shotx, shoty, 2, 2, black) loop randint (cl, 0, 15) exit when cl not= col and cl not= white end loop drawoval (shotx + round (5 * cosd (B)), shoty + round (5 * sind (B)), 1, 1, red) drawoval (shotx + round (5 * cosd (B + 180)), shoty + round (5 * sind (B + 180)), 1, 1, red) % 2 small balls flying around cannonball end if if whatdotcolor (shotx, shoty) = col then % explosion when cannonball hits color explode exit % exit loop if cannonball hits ground's color end if s := s + 1 delay (25) if (shotx <= 80 and shotx >= 50 and shoty <= 125 and shoty >= 97) or (shotx <= 740 and shotx >= 710 and shoty <= 125 and shoty >= 97) then % checking targets - both tanks % condition for hit explode finish End := true exit end if end loop shot := false count := count + 1 end arc procedure draw (var count : int, shot : boolean, x, y, xx, yy : int, var g, V : int, A : real) % draws tanks and ground, displays current values var c : int drawline (0, 97, 790, 97, col) % ground level drawfillbox (50, 100, 80, 117, yellow) % first tank drawfilloval (55, 100, 3, 3, blue) drawfilloval (65, 100, 3, 3, blue) drawfilloval (75, 100, 3, 3, blue) drawfillbox (55, 104, 75, 114, red) drawfillbox (60, 117, 70, 124, green) drawfillbox (710, 100, 740, 117, grey) % second tank drawfilloval (715, 100, 3, 3, red) drawfilloval (725, 100, 3, 3, red) drawfilloval (735, 100, 3, 3, red) drawfillbox (715, 104, 735, 114, blue) drawfillbox (720, 117, 730, 124, green) if count mod 2 = 0 then % whose turn? c := red else c := blue end if Font.Draw (intstr (p1), 40, 60, font, black) % percentage Font.Draw ("%", 80, 60, font, black) % of Font.Draw (intstr (p2), 700, 60, font, black) % power Font.Draw ("%", 740, 60, font, black) % left Font.Draw ("Power", 38, 35, font, red) Font.Draw ("Power", 698, 35, font, blue) Font.Draw ("Angle: ", 50, 480, font, black) % characteristics Font.Draw (realstr (A, 3), 110, 480, font, c) % of Font.Draw ("Velocity: ", 50, 430, font, black) % environment Font.Draw (intstr (V), 133, 430, font, c) % and Font.Draw ("Gravity: ", 640, 480, font, black) % current Font.Draw (intstr (g), 718, 480, font, green) % values drawline (x1, y1, x, y, black) % tanks' drawline (x2, y2, xx, yy, black) % cannons if shot = true then % condition for shot arc (count, x, y, xx, yy, g, V, A) end if end draw procedure distinguish (var count : int, shot : boolean, a, b : int, var g, V : int, A : real) % changing coordinates of cannons to move if count mod 2 = 0 then x := x1 + a y := y1 + b else xx := x2 - a yy := y2 + b end if draw (count, shot, x, y, xx, yy, g, V, A) end distinguish process point % displays animated turn pointer like atom with circling electrones var D : real := 0 var m, n : int % x - and y - coordinates of pointer m := x1 n := y1 + 50 var cp : int % color of pointer loop drawfilloval (m, n, 4, 4, white) drawfilloval (m + round (20 * cosd (D + 10)), n + round (10 * sind (D + 10)), 3, 1, white) drawfilloval (m + round (20 * cosd (D + 130)), n + round (10 * sind (D + 130)), 3, 1, white) drawfilloval (m + round (20 * cosd (D + 250)), n + round (10 * sind (D + 250)), 3, 1, white) drawfilloval (m + round (10 * cosd (D + 250)), n + round (20 * sind (D + 250)), 3, 1, white) if count mod 2 = 0 then m := x1 n := y1 + 50 cp := red else m := x2 n := y2 + 50 cp := blue end if drawfilloval (m, n, 4, 4, 10) drawfilloval (m + round (20 * cosd (D)), n + round (10 * sind (D)), 3, 1, cp) drawfilloval (m + round (20 * cosd (D + 120)), n + round (10 * sind (D + 120)), 3, 1, cp) drawfilloval (m + round (20 * cosd (D + 240)), n + round (10 * sind (D + 240)), 3, 1, cp) drawfilloval (m + round (10 * cosd (D + 240)), n + round (20 * sind (D + 240)), 3, 1, 9) D := D - 10 if D = 3600 then D := 0 end if delay (25) end loop end point process shield % provides partial shield from shots from above var u, v : int % coordinates of shield's centre u := x1 v := y1 + 50 var E : real := 0 % angle of rotation loop drawline (u - round (50 * cosd (E - 10)), v - round (20 * sind (E - 10)), u + round (50 * cosd (E - 10)), v + round (20 * sind (E - 10)), white) drawline (u - round (50 * cosd (E)), v - round (20 * sind (E)), u + round (50 * cosd (E)), v + round (20 * sind (E)), white) drawline (u - round (50 * cosd (E - 10)), v - round (20 * sind (E - 10)), u - round (50 * cosd (E)), v - round (20 * sind (E)), white) drawline (u + round (50 * cosd (E - 10)), v + round (20 * sind (E - 10)), u + round (50 * cosd (E)), v + round (20 * sind (E)), white) drawline (u - round (50 * cosd (E + 80)), v - round (20 * sind (E + 80)), u + round (50 * cosd (E + 80)), v + round (20 * sind (E + 80)), white) drawline (u - round (50 * cosd (E + 90)), v - round (20 * sind (E + 90)), u + round (50 * cosd (E + 90)), v + round (20 * sind (E + 90)), white) drawline (u - round (50 * cosd (E + 80)), v - round (20 * sind (E + 80)), u - round (50 * cosd (E + 90)), v - round (20 * sind (E + 90)), white) drawline (u + round (50 * cosd (E + 80)), v + round (20 * sind (E + 80)), u + round (50 * cosd (E + 90)), v + round (20 * sind (E + 90)), white) if count mod 2 = 0 then u := x2 v := y2 + 50 else u := x1 v := y1 + 50 end if drawline (u - round (50 * cosd (E)), v - round (20 * sind (E)), u + round (50 * cosd (E)), v + round (20 * sind (E)), col) drawline (u - round (50 * cosd (E + 10)), v - round (20 * sind (E + 10)), u + round (50 * cosd (E + 10)), v + round (20 * sind (E + 10)), col) drawline (u - round (50 * cosd (E)), v - round (20 * sind (E)), u - round (50 * cosd (E + 10)), v - round (20 * sind (E + 10)), col) drawline (u + round (50 * cosd (E)), v + round (20 * sind (E)), u + round (50 * cosd (E + 10)), v + round (20 * sind (E + 10)), col) drawline (u - round (50 * cosd (E + 90)), v - round (20 * sind (E + 90)), u + round (50 * cosd (E + 90)), v + round (20 * sind (E + 90)), col) drawline (u - round (50 * cosd (E + 100)), v - round (20 * sind (E + 100)), u + round (50 * cosd (E + 100)), v + round (20 * sind (E + 100)), col) drawline (u - round (50 * cosd (E + 90)), v - round (20 * sind (E + 90)), u - round (50 * cosd (E + 100)), v - round (20 * sind (E + 100)), col) drawline (u + round (50 * cosd (E + 90)), v + round (20 * sind (E + 90)), u + round (50 * cosd (E + 100)), v + round (20 * sind (E + 100)), col) E := E + 10 if E = 3600 then E := 0 end if delay (5) end loop end shield process symbol % displays symbol in form of planet with circling around it satellite var C : real := 0 % angle of satellite's revolution loop drawfilloval (395 + round (50 * cosd (C - 10)), 45 + round (30 * sind (C - 10)), 10, 10, col) % erasing previous satellite's appearance if col not= 1 then drawfilloval (395, 45, 20, 20, col - 1) % drawing planet end if drawfilloval (395 + round (50 * cosd (C)), 45 + round (30 * sind (C)), 10, 10, green) % satellite's revolution C := C + 10 if C >= 3600 then % keeping number not too large C := 0 end if delay (50) % making program work smoother end loop end symbol process cloud % displays clouds in the sky var i : int := 0 var j : real := 0 var sd : int := 525 var cn : int := 1 loop if cn mod 2 = 0 then i := 0 else i := 790 end if loop drawfilloval (i, sd + round (10 * sind (j)), 50, 10, 0) if cn mod 2 = 0 then i := i + 1 else i := i - 1 end if if j >= 3600 then j := 0 end if j := j + 5 drawfilloval (i, sd + round (10 * sind (j)), 50, 10, col - 7) if (i >= 830 and cn mod 2 = 0) or (i <= - 40 and cn mod 2 not= 0) then exit end if delay (10) end loop cn := cn + 1 end loop end cloud procedure getKey %waits until keyboard 's key is pressed and acts accordingly fork point % simultaneous fork shield % subpragrams' fork cloud % run var o, p, q, i, j : int o := 0 p := 97 i := 0 j := 0 randint (q, 100, 300) drawbox (0, 0, 790, 540, 7) loop exit when o >= 790 randint (i, - 20, 20) if o >= 300 and o <= 490 then drawline (o, p + j, 395, p + q, 7) o := o + 200 drawline (395, p + q, o, p + j, 7) end if drawline (o, p + j, o + 20, p + i, 7) j := i delay (50) o := o + 20 end loop drawfill (395, 10, col, 7) drawline (0, 97, 790, 97, col) fork symbol loop getch (ch) if ord (ch) = 205 then % arrow right A := A + 1 if A > 180 then A := 0 end if a := round (r * cosd (A)) b := round (r * sind (A)) elsif ord (ch) = 203 then % arrow left A := A - 1 if A < 0 then A := 180 end if a := round (r * cosd (A)) b := round (r * sind (A)) end if drawline (x1, y1, x, y, white) % redrawing drawline (x2, y2, xx, yy, white) % after drawfillbox (107, 485, 147, 505, white) % explosion drawfillbox (130, 435, 170, 455, white) % that drawfillbox (718, 485, 758, 505, white) % erases drawfillbox (40, 65, 75, 85, col) % some drawfillbox (700, 65, 735, 85, col) % screen drawline (0, 97, 790, 97, col) % elements if count mod 2 = 0 then % whose turn? maximum allowed cannonball velocity for each tank v := V1 else v := V2 end if if ord (ch) = 200 then % arrow up if V >= 0 and V < v then V := V + 1 elsif V = 0 then a := r b := 0 end if elsif ord (ch) = 208 then % arrow down if V > 0 and V <= v then V := V - 1 end if end if if ord (ch) = 32 then shot := true end if distinguish (count, shot, a, b, g, V, A) exit when End = true end loop end getKey process program var i : int for o : 0 .. 790 for p : 0 .. 540 randint (i, - 5, 5) drawdot (o, p + i, black) end for end for Font.Draw ("WILD TANKS", 220, 400, font2, red) Key cls drawline (0, 97, 790, 97, black) drawfillbox (50, 100, 80, 117, yellow) drawfilloval (55, 100, 3, 3, black) drawfilloval (65, 100, 3, 3, black) drawfilloval (75, 100, 3, 3, black) drawfillbox (55, 104, 75, 114, red) drawfillbox (60, 117, 70, 124, green) drawfillbox (710, 100, 740, 117, grey) drawfilloval (715, 100, 3, 3, red) drawfilloval (725, 100, 3, 3, red) drawfilloval (735, 100, 3, 3, red) drawfillbox (715, 104, 735, 114, blue) drawfillbox (720, 117, 730, 124, green) loop cls Font.Draw ("Enter gravity: ", 177, 450, font2, blue) get grav if grav = "" then g := acc Font.Draw (intstr (g), 517, 450, font2, red) else g := strint (grav) Font.Draw (intstr (g), 517, 450, font2, red) end if Key cls if grav = "0" then Font.Draw ("Invalid Gravity", 200, 450, font2, red) Key end if exit when grav not= "0" end loop Key cls getKey end program fork program