setscreen ("graphics:1200;1200")
% Variables for game state
var gameRunning
, showStartScreen
, showEndScreen
: boolean
showEndScreen := false
gameRunning := false
font := Font.New("monospaced:50:bold")
% Variables for player positions
var x
, y
, x2
, y2
, picID
, picID2
, spriteID
, spriteID2
: int
x := maxx div 2 + 50
y := maxy div 2 - 600
x2 := maxx div 2 - 100
y2 := maxy div 2 - 600
% Variables for cars
const NUM_CARS := 5
var carX
: array
1 .. NUM_CARS of int
var carY
: array
1 .. NUM_CARS of int
var carSpeed
: array
1 .. NUM_CARS of int
for i : 1 .. NUM_CARS
carX(i) := -50 - (i - 1) * 200
carY(i) := 150 + (i - 1) * 80
carSpeed(i) := 5 + i % 3 % Different speeds for cars
end for
% Input tracking
var inputKey
: array char of boolean
% Starting screen
procedure displayStartScreen
cls
drawfillbox (0, 0, maxx, maxy, black)
Draw.Text("Pedestrian Crossing", 600, 500, font, black)
Draw.Text("Press SPACE to Start", 600, 550, font, black)
end displayStartScreen
% Restart screen
procedure displayEndScreen (winner : int)
cls
drawfillbox (0, 0, maxx, maxy, black)
if winner = 1 then
Draw.Text("Player 1 Wins!", 600, 500,font,black)
else
Draw.Text("Player 2 Wins!", 600, 500,font,black)
end if
Draw.Text("Press R to Restart", 600, 550, font,black)
end displayEndScreen
% Main game loop
loop
if showStartScreen then
displayStartScreen
Input.KeyDown (inputKey)
if inputKey (' ') then
showStartScreen := false
end if
elsif showEndScreen then
displayEndScreen (winner)
Input.KeyDown (inputKey)
if inputKey ('r') then
showEndScreen := false
% Reset game state
x := maxx div 2 + 50
y := maxy div 2 - 600
x2 := maxx div 2 - 100
y2 := maxy div 2 - 600
for i : 1 .. NUM_CARS
carX(i) := -50 - (i - 1) * 200
end for
end if
elsif gameRunning then
cls
% Draw map
drawfillbox (0, 0, 1200, 100, 2) % Starting Grass
drawfillbox (0, 100, 1200, 500, darkgrey) % First Road
for m : 0 .. 4
drawfillbox (100 + 400 * m, 180, 300 + 400 * m, 185, white) % Road Marks
end for
drawfillbox (0, 500, 1200, 600, 2) % Middle Grass
drawfillbox (0, 600, 1200, 1100, darkgrey) % Second Road
for m : 0 .. 4
drawfillbox (100 + 400 * m, 680, 300 + 400 * m, 685, white) % Road Marks
end for
drawfillbox (0, 1100, 1200, 1200, 2) % End Grass
% Draw cars
for i : 1 .. NUM_CARS
drawfillbox (carX(i), carY(i), carX(i) + 50, carY(i) + 30, red) % Car body
drawfillbox (carX(i) + 10, carY(i) + 5, carX(i) + 40, carY(i) + 20, blue) % Windows
drawfillbox (carX(i) + 5, carY(i) - 5, carX(i) + 15, carY(i) + 5, black) % Left wheel
drawfillbox (carX(i) + 35, carY(i) - 5, carX(i) + 45, carY(i) + 5, black) % Right wheel
carX(i) += carSpeed(i)
if carX(i) > maxx then
carX(i) := -50
end if
end for
% Draw players
Sprite.SetPosition (spriteID, x, y, false)
Sprite.SetPosition (spriteID2, x2, y2, false)
% Player movement
Input.KeyDown (inputKey)
if inputKey (KEY_UP_ARROW) then
y := y + 5
elsif inputKey (KEY_DOWN_ARROW) then
y := y - 5
elsif inputKey (KEY_LEFT_ARROW) then
x := x - 5
elsif inputKey (KEY_RIGHT_ARROW) then
x := x + 5
end if
if inputKey ('w') then
y2 := y2 + 5
elsif inputKey ('s') then
y2 := y2 - 5
elsif inputKey ('a') then
x2 := x2 - 5
elsif inputKey ('d') then
x2 := x2 + 5
end if
% Win conditions
if y >= 1100 then
winner := 1
gameRunning := false
elsif y2 >= 1100 then
winner := 2
gameRunning := false
end if
% Border collision
if x < 0 or x > maxx or y < 0 or y > maxy then
winner := 2
gameRunning := false
elsif x2 < 0 or x2 > maxx or y2 < 0 or y2 > maxy then
winner := 1
gameRunning := false
end if
end if
delay (20)
end loop
c2V0c2NyZWVuICgiZ3JhcGhpY3M6MTIwMDsxMjAwIikKCiUgVmFyaWFibGVzIGZvciBnYW1lIHN0YXRlCnZhciBnYW1lUnVubmluZywgc2hvd1N0YXJ0U2NyZWVuLCBzaG93RW5kU2NyZWVuIDogYm9vbGVhbgpzaG93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ICAgICBzaG93RW5kU2NyZWVuIDo9IGZhbHNlCiAgICAgICAgICAgIHNob3dTdGFydFNjcmVlbiA6PSB0cnVlCiAgICAgICAgICAgICUgUmVzZXQgZ2FtZSBzdGF0ZQogICAgICAgICAgICB4IDo9IG1heHggZGl2IDIgKyA1MAogICAgICAgICAgICB5IDo9IG1heHkgZGl2IDIgLSA2MDAKICAgICAgICAgICAgeDIgOj0gbWF4eCBkaXYgMiAtIDEwMAogICAgICAgICAgICB5MiA6PSBtYXh5IGRpdiAyIC0gNjAwCiAgICAgICAgICAgIGZvciBpIDogMSAuLiBOVU1fQ0FSUwogICAgICAgICAgICAgICAgY2FyWChpKSA6PSAtNTAgLSAoaSAtIDEpICogMjAwCiAgICAgICAgICAgIGVuZCBmb3IKICAgICAgICBlbmQgaWYKICAgIGVsc2lmIGdhbWVSdW5uaW5nIHRoZW4KICAgICAgICBjbHMKICAgICAgICAlIERyYXcgbWFwCiAgICAgICAgZHJhd2ZpbGxib3ggKDAsIDAsIDEyMDAsIDEwMCwgMikgJSBTdGFydGluZyBHcmFzcwogICAgICAgIGRyYXdmaWxsYm94ICgwLCAxMDAsIDEyMDAsIDUwMCwgZGFya2dyZXkpICUgRmlyc3QgUm9hZAogICAgICAgIGZvciBtIDogMCAuLiA0CiAgICAgICAgICAgIGRyYXdmaWxsYm94ICgxMDAgKyA0MDAgKiBtLCAxODAsIDMwMCArIDQwMCAqIG0sIDE4NSwgd2hpdGUpICUgUm9hZCBNYXJrcwogICAgICAgIGVuZCBmb3IKICAgICAgICBkcmF3ZmlsbGJveCAoMCwgNTAwLCAxMjAwLCA2MDAsIDIpICUgTWlkZGxlIEdyYXNzCiAgICAgICAgZHJhd2ZpbGxib3ggKDAsIDYwMCwgMTIwMCwgMTEwMCwgZGFya2dyZXkpICUgU2Vjb25kIFJvYWQKICAgICAgICBmb3IgbSA6IDAgLi4gNAogICAgICAgICAgICBkcmF3ZmlsbGJveCAoMTAwICsgNDAwICogbSwgNjgwLCAzMDAg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IElucHV0LktleURvd24gKGlucHV0S2V5KQogICAgICAgIGlmIGlucHV0S2V5IChLRVlfVVBfQVJST1cpIHRoZW4KICAgICAgICAgICAgeSA6PSB5ICsgNQogICAgICAgIGVsc2lmIGlucHV0S2V5IChLRVlfRE9XTl9BUlJPVykgdGhlbgogICAgICAgICAgICB5IDo9IHkgLSA1CiAgICAgICAgZWxzaWYgaW5wdXRLZXkgKEtFWV9MRUZUX0FSUk9XKSB0aGVuCiAgICAgICAgICAgIHggOj0geCAtIDUKICAgICAgICBlbHNpZiBpbnB1dEtleSAoS0VZX1JJR0hUX0FSUk9XKSB0aGVuCiAgICAgICAgICAgIHggOj0geCArIDUKICAgICAgICBlbmQgaWYKCiAgICAgICAgaWYgaW5wdXRLZXkgKCd3JykgdGhlbgogICAgICAgICAgICB5MiA6PSB5MiArIDUKICAgICAgICBlbHNpZiBpbnB1dEtleSAoJ3MnKSB0aGVuCiAgICAgICAgICAgIHkyIDo9IHkyIC0gNQogICAgICAgIGVsc2lmIGlucHV0S2V5ICgnYScpIHRoZW4KICAgICAgICAgICAgeDIgOj0geDIgLSA1CiAgICAgICAgZWxzaWYgaW5wdXRLZXkgKCdkJykgdGhlbgogICAgICAgICAgICB4MiA6PSB4MiArIDUKICAgICAgICBlbmQgaWYKCiAgICAgICAgJSBXaW4gY29uZGl0aW9ucwogICAgICAgIGlmIHkgPj0gMTEwMCB0aGVuCiAgICAgICAgICAgIHdpbm5lciA6PSAxCiAgICAgICAgICAgIHNob3dFbmRTY3JlZW4gOj0gdHJ1ZQogICAgICAgICAgICBnYW1lUnVubmluZyA6PSBmYWxzZQogICAgICAgIGVsc2lmIHkyID49IDExMDAgdGhlbgogICAgICAgICAgICB3aW5uZXIgOj0gMgogICAgICAgICAgICBzaG93RW5kU2NyZWVuIDo9IHRydWUKICAgICAgICAgICAgZ2FtZVJ1bm5pbmcgOj0gZmFsc2UKICAgICAgICBlbmQgaWYKCiAgICAgICAgJSBCb3JkZXIgY29sbGlzaW9uCiAgICAgICAgaWYgeCA8IDAgb3IgeCA+IG1heHggb3IgeSA8IDAgb3IgeSA+IG1heHkgdGhlbgogICAgICAgICAgICB3aW5uZXIgOj0gMgogICAgICAgICAgICBzaG93RW5kU2NyZWVuIDo9IHRydWUKICAgICAgICAgICAgZ2FtZVJ1bm5pbmcgOj0gZmFsc2UKICAgICAgICBlbHNpZiB4MiA8IDAgb3IgeDIgPiBtYXh4IG9yIHkyIDwgMCBvciB5MiA+IG1heHkgdGhlbgogICAgICAgICAgICB3aW5uZXIgOj0gMQogICAgICAgICAgICBzaG93RW5kU2NyZWVuIDo9IHRydWUKICAgICAgICAgICAgZ2FtZVJ1bm5pbmcgOj0gZmFsc2UKICAgICAgICBlbmQgaWYKICAgIGVuZCBpZgogICAgZGVsYXkgKDIwKQplbmQgbG9vcAo=