setscreen ("graphics:600,300;offscreenonly")
var xsize, ysize : int
xsize := 30
ysize := 30
var tile : array 0 .. maxx div xsize, 0 .. maxy div ysize of int
var px, py, pdir : int
var chars : array char of boolean
var holding := false
px := 1
py := 1
pdir := 1
for x : 0 .. maxx div xsize
for y : 0 .. maxy div ysize
if y = white or x = white or x = maxx div xsize then
tile (x, y) := darkgrey
else
tile (x, y) := white
end if
tile (px, py) := red
tile (5, 1) := grey
tile (6, 1) := darkgrey
end for
end for
loop
cls
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
loop
Input.KeyDown (chars)
exit when ~chars (KEY_RIGHT_ARROW)
end loop
if tile (px + 1, py) = white and ~holding then
tile (px + 1, py) := red
tile (px, py) := white
px += 1
elsif tile (px + 1, py) = white and holding and tile (px + 1, py + 1) = white then
tile (px + 1, py) := red
tile (px, py) := white
tile (px + 1, py + 1) := grey
tile (px, py + 1) := white
px += 1
end if
pdir := 1
end if
if chars (KEY_LEFT_ARROW) then
loop
Input.KeyDown (chars)
exit when ~chars (KEY_LEFT_ARROW)
end loop
if tile (px - 1, py) = white and ~holding then
tile (px - 1, py) := red
tile (px, py) := white
px -= 1
elsif tile (px - 1, py) = white and holding and tile (px - 1, py + 1) = white then
tile (px - 1, py) := red
tile (px, py) := white
tile (px - 1, py + 1) := grey
tile (px, py + 1) := white
px -= 1
end if
pdir := -1
end if
if chars (KEY_UP_ARROW) then
loop
Input.KeyDown (chars)
exit when ~chars (KEY_UP_ARROW)
end loop
if tile (px + pdir, py) ~= white and tile (px + pdir, py + 1) = white and ~holding then
tile (px + pdir, py + 1) := red
tile (px, py) := white
px += pdir
py += 1
elsif tile (px + pdir, py) ~= white and tile (px + pdir, py + 1) = white and holding then
tile (px + pdir, py + 1) := red
tile (px, py) := white
tile (px + pdir, py + 2) := grey
tile (px, py + 1) := white
px += pdir
py += 1
end if
end if
if chars (KEY_DOWN_ARROW) then
loop
Input.KeyDown (chars)
exit when ~chars (KEY_DOWN_ARROW)
end loop
if tile (px + pdir, py) = grey and ~holding and tile (px + pdir, py + 1) = white then
holding := true
tile (px + pdir, py) := white
tile (px, py + 1) := grey
elsif holding and tile (px + pdir, py + 1) = white then
holding := false
tile (px, py + 1) := white
tile (px + pdir, py + 1) := grey
end if
end if
if tile (px, py - 1) = white and ~holding then
tile (px, py - 1) := red
tile (px, py) := white
py -= 1
elsif tile (px, py - 1) = white and holding then
tile (px, py - 1) := red
tile (px, py) := white
tile (px, py) := grey
tile (px, py + 1) := white
py -= 1
end if
for x : 0 .. maxx by xsize
for y : 0 .. maxy by ysize
drawfillbox (x, y, x + xsize, y + ysize, tile (x div xsize, y div ysize))
drawbox (x, y, x + xsize, y + ysize, 7)
if y ~= 0 and tile (x, y) ~= white and tile (x, y - 1) = white then
tile (x, y - 1) := tile (x, y)
tile (x, y) := white
end if
end for
end for
drawfilloval (px * xsize + (xsize div 2) + pdir * (xsize div 3), py * xsize + (ysize div 2), 5, 5, 7)
View.Update
end loop
|