fork download
  1. setscreen ("graphics:1200;1200")
  2.  
  3. % Variables for game state
  4. var gameRunning, showStartScreen, showEndScreen : boolean
  5. showStartScreen := true
  6. showEndScreen := false
  7. gameRunning := false
  8. var winner : int := 0
  9. var font : int
  10. font := Font.New("monospaced:50:bold")
  11. % Variables for player positions
  12. var x, y, x2, y2, picID, picID2, spriteID, spriteID2 : int
  13. x := maxx div 2 + 50
  14. y := maxy div 2 - 600
  15. x2 := maxx div 2 - 100
  16. y2 := maxy div 2 - 600
  17.  
  18. % Variables for cars
  19. const NUM_CARS := 5
  20. var carX : array 1 .. NUM_CARS of int
  21. var carY : array 1 .. NUM_CARS of int
  22. var carSpeed : array 1 .. NUM_CARS of int
  23.  
  24. for i : 1 .. NUM_CARS
  25. carX(i) := -50 - (i - 1) * 200
  26. carY(i) := 150 + (i - 1) * 80
  27. carSpeed(i) := 5 + i % 3 % Different speeds for cars
  28. end for
  29.  
  30. % Input tracking
  31. var inputKey : array char of boolean
  32.  
  33. % Starting screen
  34. procedure displayStartScreen
  35. cls
  36. drawfillbox (0, 0, maxx, maxy, black)
  37. Draw.Text("Pedestrian Crossing", 600, 500, font, black)
  38. Draw.Text("Press SPACE to Start", 600, 550, font, black)
  39. end displayStartScreen
  40.  
  41. % Restart screen
  42. procedure displayEndScreen (winner : int)
  43. cls
  44. drawfillbox (0, 0, maxx, maxy, black)
  45. if winner = 1 then
  46. Draw.Text("Player 1 Wins!", 600, 500,font,black)
  47. else
  48. Draw.Text("Player 2 Wins!", 600, 500,font,black)
  49. end if
  50. Draw.Text("Press R to Restart", 600, 550, font,black)
  51. end displayEndScreen
  52.  
  53. % Main game loop
  54. loop
  55. if showStartScreen then
  56. displayStartScreen
  57. Input.KeyDown (inputKey)
  58. if inputKey (' ') then
  59. showStartScreen := false
  60. gameRunning := true
  61. end if
  62. elsif showEndScreen then
  63. displayEndScreen (winner)
  64. Input.KeyDown (inputKey)
  65. if inputKey ('r') then
  66. showEndScreen := false
  67. showStartScreen := true
  68. % Reset game state
  69. x := maxx div 2 + 50
  70. y := maxy div 2 - 600
  71. x2 := maxx div 2 - 100
  72. y2 := maxy div 2 - 600
  73. for i : 1 .. NUM_CARS
  74. carX(i) := -50 - (i - 1) * 200
  75. end for
  76. end if
  77. elsif gameRunning then
  78. cls
  79. % Draw map
  80. drawfillbox (0, 0, 1200, 100, 2) % Starting Grass
  81. drawfillbox (0, 100, 1200, 500, darkgrey) % First Road
  82. for m : 0 .. 4
  83. drawfillbox (100 + 400 * m, 180, 300 + 400 * m, 185, white) % Road Marks
  84. end for
  85. drawfillbox (0, 500, 1200, 600, 2) % Middle Grass
  86. drawfillbox (0, 600, 1200, 1100, darkgrey) % Second Road
  87. for m : 0 .. 4
  88. drawfillbox (100 + 400 * m, 680, 300 + 400 * m, 685, white) % Road Marks
  89. end for
  90. drawfillbox (0, 1100, 1200, 1200, 2) % End Grass
  91.  
  92. % Draw cars
  93. for i : 1 .. NUM_CARS
  94. drawfillbox (carX(i), carY(i), carX(i) + 50, carY(i) + 30, red) % Car body
  95. drawfillbox (carX(i) + 10, carY(i) + 5, carX(i) + 40, carY(i) + 20, blue) % Windows
  96. drawfillbox (carX(i) + 5, carY(i) - 5, carX(i) + 15, carY(i) + 5, black) % Left wheel
  97. drawfillbox (carX(i) + 35, carY(i) - 5, carX(i) + 45, carY(i) + 5, black) % Right wheel
  98. carX(i) += carSpeed(i)
  99. if carX(i) > maxx then
  100. carX(i) := -50
  101. end if
  102. end for
  103.  
  104. % Draw players
  105. Sprite.SetPosition (spriteID, x, y, false)
  106. Sprite.SetPosition (spriteID2, x2, y2, false)
  107.  
  108. % Player movement
  109. Input.KeyDown (inputKey)
  110. if inputKey (KEY_UP_ARROW) then
  111. y := y + 5
  112. elsif inputKey (KEY_DOWN_ARROW) then
  113. y := y - 5
  114. elsif inputKey (KEY_LEFT_ARROW) then
  115. x := x - 5
  116. elsif inputKey (KEY_RIGHT_ARROW) then
  117. x := x + 5
  118. end if
  119.  
  120. if inputKey ('w') then
  121. y2 := y2 + 5
  122. elsif inputKey ('s') then
  123. y2 := y2 - 5
  124. elsif inputKey ('a') then
  125. x2 := x2 - 5
  126. elsif inputKey ('d') then
  127. x2 := x2 + 5
  128. end if
  129.  
  130. % Win conditions
  131. if y >= 1100 then
  132. winner := 1
  133. showEndScreen := true
  134. gameRunning := false
  135. elsif y2 >= 1100 then
  136. winner := 2
  137. showEndScreen := true
  138. gameRunning := false
  139. end if
  140.  
  141. % Border collision
  142. if x < 0 or x > maxx or y < 0 or y > maxy then
  143. winner := 2
  144. showEndScreen := true
  145. gameRunning := false
  146. elsif x2 < 0 or x2 > maxx or y2 < 0 or y2 > maxy then
  147. winner := 1
  148. showEndScreen := true
  149. gameRunning := false
  150. end if
  151. end if
  152. delay (20)
  153. end loop
  154.  
Success #stdin #stdout #stderr 0.03s 7028KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/NMVmVR/prog:153:8: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit