setscreen ("graphics:100;200,offscreenonly")
var Space : array 0 .. 9, 0 .. 19 of int
var tilex : flexible array 0 .. 0 of int
var tiley : flexible array 0 .. 0 of int
var key : array char of boolean
var player :
record
x, y : int
end record
player.x := 0
player.y := 0
var p : int := 0
for x : 0 .. 9
for y : 0 .. 19
Space (x, y) := 0
drawfillbox (10 * x, y * 10, 10 + 10 * x, y * 10 + 10, Space (x, y))
p += 1
end for
end for
var Piece : array 1 .. 3 of array 0 .. 10, 0 .. 20 of int
var fileName : string := "map.t"
var fileNo : int := 0
var e : int
open : fileNo, fileName, get
for decreasing y : 19 .. 0
for x : 0 .. 9
get : fileNo, Space (x, y)
if Space (x, y) > 0 then
for t : 0 .. 10
new tilex, upper (tilex) + 1
e := upper (tilex)
tilex (e) := 10 * x + t
new tiley, upper (tiley) + 1
e := upper (tiley)
tiley (e) := 10 * y + t
end for
end if
end for
end for
close : fileNo
proc redraw
for y : 0 .. 19
for x : 0 .. 9
if Space (x, y) = 0 then
drawfillbox (10 * x, y * 10, 10 + 10 * x, y * 10 + 10, black)
elsif Space (x, y) = 1 then
drawfillbox (10 * x, y * 10, 10 + 10 * x, y * 10 + 10, green)
elsif Space (x, y) = 2 then
drawfillbox (10 * x, y * 10, 10 + 10 * x, y * 10 + 10, red)
elsif Space (x, y) = 3 then
drawfillbox (10 * x, y * 10, 10 + 10 * x, y * 10 + 10, blue)
end if
end for
end for
end redraw
fcn collide (x, y : int) : boolean
var go : boolean := true
for tx : 1 .. upper (tilex)
if x = tilex (tx) then
for ty : 1 .. upper (tiley)
if y = tilex (ty) then
go := false
end if
end for
end if
end for
result go
end collide
loop
Input.KeyDown (key)
redraw
if key ('w') and collide (player.x, player.y + 5) then
player.y += 5
end if
if key ('s') and collide (player.x, player.y - 5) then
player.y -= 5
end if
if key ('d') and collide (player.x + 5, player.y) then
player.x += 5
end if
if key ('a') and collide (player.x - 5, player.y) then
player.x -= 5
end if
drawfillbox (player.x, player.y, player.x + 10, player.y + 10, yellow)
View.Update
Time.DelaySinceLast (50)
end loop
|