Jump to content
  • Advertisement
Sign in to follow this  
JavaMava

Level editor, array out of range....

This topic is 4657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OKay so I'm making a level editor for a 2d side scroller. I have it so if you click off the map area it will scroll in the direction of the side you clicked on. My problem is if you scroll to far up or to the right my map array that stores what tile is what goes out of range. I was able to fix the problem for when it scrolled to far down or left, but the solution doesn't seem to be the same for up and down. Heres the code, it in turing so it might not loook familir import GUI var win := Window.Open ("graphics:max;max,nobuttonbar") View.Set ("offscreenonly") const MAPTILEX := 100 %amount of x tiles in the entire map const MAPTILEY := 25 %amount of y tiles in the entire map const TILESIZEX := 32 %Size of x tile in pixels const TILESIZEY := 32 %Size of x tile in pixels const SCREENHIEGHT := 14 %number of tile up on screen at once const SCREENWIDTH := 22 %number of tile across on screen at once var map : array 1 .. MAPTILEX of array 1 .. MAPTILEY of int %saves what tile is in each location var tile, tile1 : int := 0 %current tile being drawn var mouseX, mouseY, mouseButton : int var disX, disY : int := 1 % This is the displacement for when the world is scrolled over tile1 := Pic.FileNew ("tile.bmp") proc Initialize_Map for x : 1 .. MAPTILEX %Goes through every tile on the x for y : 1 .. MAPTILEY %Goes through every tule on the y map (x) (y) := 0 %assigns them all to 0 (no tile) end for end for end Initialize_Map proc Draw_Map for x : 1 .. SCREENWIDTH %Goes through every tile on the x on the screen for y : 1 .. SCREENHIEGHT %Goes through every tile on the y on the screen tile := map (x + disX) (y + disY) %Makes current tile being drawn equal to corresponding tile in map ****THIS IS THE LINE WHERE THE ARRAY GOES OUT OF RANGE**** if tile > 0 then %Skips drawing if the tile is not walkable Pic.Draw (tile, (x * TILESIZEX) + 12, y * TILESIZEY + 12, picCopy) %draws tile end if Draw.Box (TILESIZEX + 12, TILESIZEY + 12, (TILESIZEX * (SCREENWIDTH + 1)) + 12, (TILESIZEY * (SCREENHIEGHT + 1)) + 12, brightred) end for end for end Draw_Map proc Place_Tiles Mouse.Where (mouseX, mouseY, mouseButton) if mouseButton > 0 then if mouseX > (TILESIZEX * (SCREENWIDTH + 1) + 12) then %If you click off the map and to the right the screen will scroll that way disX += 1 elsif mouseX < (TILESIZEX + 12) then %If you click off the map and to the left the screen will scroll that way disX -= 1 elsif mouseY > (TILESIZEY * (SCREENHIEGHT + 1) + 12) then %If you click off the map and to the top the screen will scroll that way disY += 1 elsif mouseY < (TILESIZEY + 12) then %If you click off the map and to the bottom the screen will scroll that way disY -= 1 else %if you click on the map the tile you click on wil be changed to walkable map ((round (((mouseX + 12) - TILESIZEX) / TILESIZEX)) + disX) ((round (((mouseY + 12) - TILESIZEY) / TILESIZEY)) + disY) := tile1 end if end if %This makes sure the array doesn't go out of range, if it does it sets it back to what it was before if disY < 1 then disY := 1 elsif disY > MAPTILEY then disY := MAPTILEY elsif disX < 1 then disX := 1 elsif disX > MAPTILEX then disX := MAPTILEX end if end Place_Tiles Initialize_Map loop cls GUI.SetBackgroundColor (black) Place_Tiles Draw_Map View.Update delay (0) end loop So any ideas, or questions about the code? [Edited by - JavaMava on January 19, 2006 4:13:13 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by JavaMava
%This makes sure the array doesn't go out of range, if it does it sets it back to what it was before
if disY < 1 then
disY := 1
elsif disY > MAPTILEY then
disY := MAPTILEY
elsif disX < 1 then
disX := 1
elsif disX > MAPTILEX then
disX := MAPTILEX
end if

I quickly scanned through. That doesn't look right to me.
Perhaps:
    %This makes sure the array doesn't go out of range, if it does it sets it back to what it was before
if disY < 1 then
disY := 1
elsif disY > MAPTILEY then
disY := MAPTILEY
if disX < 1 then
disX := 1
elsif disX > MAPTILEX then
disX := MAPTILEX
end if

Share this post


Link to post
Share on other sites
Ahh sorry.

Anyways I just tried it and same problem as before. ANy ideas why it would work for left and bottome, but not top and right?

Share this post


Link to post
Share on other sites
I forgot to tell you guuys where it goes out of range, maybe this will help...

tile := map (x + disX) (y + disY) %Makes current tile being drawn equal to corresponding tile in map ****THIS IS THE LINE WHERE THE ARRAY GOES OUT OF RANGE****

Share this post


Link to post
Share on other sites
I figured it out, it was my logic was wrong.

if disY < 1 then
disY := 1
elsif disY > (MAPTILEY - SCREENHIEGHT) then
disY := (MAPTILEY - SCREENHIEGHT)
end if

if disX < 1 then
disX := 1
elsif disX > (MAPTILEX - SCREENWIDTH) then
disX := (MAPTILEX - SCREENWIDTH)
end if

is the proper way to do it, hahahaha.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!