All pastes #26571 Raw Edit

Anonymous

public text v1 · immutable
#26571 ·published 2005-10-25 03:50 UTC
rendered paste body
setscreen ("Graphics:max;max,offscreenonly")
%%%Variables
var TileSize := 50
var TileRow, TileColumn : int := 20
var file : int
var TileLoc : array 1 .. TileRow, 1 .. TileColumn of int
var mapx, mapy : int := 0
var Scroll_Rate: int := 5

%%pic variables
var pictures: array 1 .. 5 of int
    pictures(1):= Pic.FileNew ("Pictures/grass1.bmp")
    pictures(2):= Pic.FileNew ("Pictures/grass2.bmp")
    pictures(3):= Pic.FileNew ("Pictures/cliff1.bmp")
    pictures(4):= Pic.FileNew ("Pictures/mineral1.bmp")
    pictures(5):= Pic.FileNew ("Pictures/mineral2.bmp")
for i: 1 .. 5
    pictures(i) := Pic.Scale (pictures(i), TileSize, TileSize)
  %  Pic.Free(pictures(i))
end for

%%Calls the map
open : file, "map1.txt", get
for x : 1 .. upper (TileLoc, 1)
    for y : 1 .. upper (TileLoc, 2)
        get : file, TileLoc(x, y)
    end for
end for
close : file

%%Procs
proc draw_map(leftx, bottomy: int, tile: array 1 .. *, 1 .. * of int)
    cls
    for x : 1 .. upper (tile, 1)
        for y : 1 .. upper (tile, 2)
            if tile(x,y) = 0 then       %%borders
                Draw.FillBox(x*TileSize+leftx, y*TileSize+bottomy, (x+1)*TileSize+leftx, (y+1)*TileSize+bottomy, black)
            elsif tile(x,y) = 1 then    %%grass
                Pic.Draw (pictures(1), x*TileSize+leftx, y*TileSize+bottomy, picCopy)
                %Draw.FillBox(x*TileSize+leftx, y*TileSize+bottomy, (x+1)*TileSize+leftx, (y+1)*TileSize+bottomy, green)
            elsif tile(x,y) = 2 then    %%cliff
                Pic.Draw (pictures(3), x*TileSize+leftx, y*TileSize+bottomy, picCopy)
                %Draw.FillBox(x*TileSize+leftx, y*TileSize+bottomy, (x+1)*TileSize+leftx, (y+1)*TileSize+bottomy, gray)
            elsif tile(x,y) = 9 then    %%Minerals
                Pic.Draw (pictures(4), x*TileSize+leftx, y*TileSize+bottomy, picCopy)
                %Draw.FillBox(x*TileSize+leftx, y*TileSize+bottomy, (x+1)*TileSize+leftx, (y+1)*TileSize+bottomy, blue)
            end if
        end for
    end for
end draw_map

%%Main program
draw_map (-20, -20, TileLoc)
loop
    var mx, my, mb : int        %%Mouse variables
    Mouse.Where(mx, my, mb)     %%Detects the mouse
    if my >= maxy - 40 then     %%moves map up with mouse
        mapy -= Scroll_Rate
        draw_map(mapx, mapy, TileLoc)
    elsif my <= 40 then         %%moves map down with mosue
        mapy += Scroll_Rate
        draw_map(mapx, mapy, TileLoc)
    end if
    if mx >= maxx - 40 then     %%moves map right with mouse
        mapx -= Scroll_Rate
        draw_map(mapx, mapy, TileLoc)
    elsif mx <= 40 then         %%moves map left with mouse
        mapx += Scroll_Rate
        draw_map(mapx, mapy, TileLoc)
    end if
    View.Update
    delay(20)
end loop