Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Working with big maps...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Fri Mar 03, 2006 3:08 am   Post subject: Working with big maps...

Normally when i am useing maps, ill screenshot them so there much faster to reload...

But, how do i make a big map fast especially when you want to move it?
if you screen shot it, and move the map, theres no variable and crash, without screenshot, its so slow and laggish... I need some opinions, Heres my example:

code:

setscreen ("Graphics:max;max,offscreenonly")

%%%Variables
var TileSize := 10
var TileRow, TileColumn : int := 100
var file : int
var TileLoc : array 1 .. TileRow, 1 .. TileColumn of int
var mapx, mapy : int := 0
var Scroll_Rate : int := 5
var ScreenShot : int

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
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
                Draw.FillBox (x * TileSize + leftx, y * TileSize + bottomy, (x + 1) * TileSize + leftx, (y + 1) * TileSize + bottomy, green)
            elsif tile (x, y) = 2 then  %%cliff
                Draw.FillBox (x * TileSize + leftx, y * TileSize + bottomy, (x + 1) * TileSize + leftx, (y + 1) * TileSize + bottomy, gray)
            elsif tile (x, y) = 9 then  %%Minerals
                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


**add your text file 100x100 w/ spaces : eg: 0 0 0 0 0 0
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Fri Mar 03, 2006 10:20 am   Post subject: (No subject)

Your problem is two fold:

- as you mentioned, using a pic stream (ScreenShot) causes an error. This error is quite simple: the bounds of your picture are off the screen!
So, instead of starting with the pic at (-20, -20), draw it at (0, 0) (with the screen sized so that it perfectly fits the picture), take a screenie of it (from (0, 0) -> (maxx, maxy)) and store that in ScreenShot.
- now, in your loop, remove all calls to draw_map(), and instead have a single call drawing ScreenShot at (mapx, mapy) outside of the if-structure.

Add in the necassary View.Updates, delays, and cls and you're good to go.
TokenHerbz




PostPosted: Fri Mar 03, 2006 10:51 am   Post subject: (No subject)

Delos i attempted this, when i move the cursor to the right, that map is supposed to move to the left, thus revealing more of the map (like in Brood War) . thats when i get errors...
Delos




PostPosted: Fri Mar 03, 2006 11:13 am   Post subject: (No subject)

Code please...(I've tried it and it works, so perhaps you're doing something wrong.)
TokenHerbz




PostPosted: Fri Mar 03, 2006 11:22 am   Post subject: (No subject)

i get errors when i move the screen to a direction greater then the max
Delos




PostPosted: Fri Mar 03, 2006 5:41 pm   Post subject: (No subject)

Ok, I'll try be a little clearer this time:

I've editted your code and got it to work, doing exactly what you wanted it to. Now, to be able to help you do the same, we would need you to post your updated code.

Your saying something to the effect of:
Quote:

...to a direction greater then [sic] the max...

is really hard to work off. Max-what? 'maxx', 'maxy', the edge of your screen, the size of your map? See what I mean.
Posting code, along with a description of your errors, why you think you're getting them, and other relevant info makes helping you so much easier.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: