Jump to content
  • Advertisement
Sign in to follow this  
four_star00

viewing part of a map

This topic is 4833 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

Here's my problem I am making an rpg type game using C# I want to only let the user view a part of my displayed map but I don;t know what code to use to do that. Any help please.

Share this post


Link to post
Share on other sites
Advertisement
So say you have a map of size 10x10, and you want the viewspace to be 5x5 tiles. You could draw tiles [x][y] to [x+4][y+4] where x,y is the upper left hand corner tile, updating x and y as the player moves. So if the upper lefthand tile is 0,0 it would draw tiles:

[0,0] [1,0] [2,0] [3,0] [4,0]
[0,1] [1,1] [2,1] [3,1] [4,1]
[0,2] [1,2] [2,2] [3,2] [4,2]
[0,3] [1,3] [2,3] [3,3] [4,3]
[0,4] [1,4] [2,4] [3,4] [4,4]

Then if the player moves right you update the upper left tile to be 1,0 and it would draw the tiles:

[1,0] [2,0] [3,0] [4,0] [5,0]
[1,1] [2,1] [3,1] [4,1] [5,1]
[1,2] [2,2] [3,2] [4,2] [5,2]
[1,3] [2,3] [3,3] [4,3] [5,3]
[1,4] [2,4] [3,4] [4,4] [5,4]

To determine where to draw the tiles on screen you can do something like multiply their index by their width/height. So if they were 40x40 tile 0,0 would be drawn at screen coordinates 0,0. Tile 0,1 would be drawn at screen coordinates 0,40. Tile 0,2 would be drawn at screen coordinates 0,80. etc.

edited: had my x's and y's all mixed up. fixed

Share this post


Link to post
Share on other sites
So there is no simple code to view a part of the form from a certain coordinate point to a another corrdinate point when I run my form using Visual C#.Net?

Share this post


Link to post
Share on other sites
Well, the problem with what (it seems) you're saying is that to have a map of any size, you'll need a HUGE form with tons of individual images... not a good idea. Omnibus's suggestion is good, however. Keep your 2d array to keep track of the whole map, and have yourself a viewing area on your form that contains X number of tiles in each direction (like the 10 that Omnibus refered to). Then, all you need to do is change the images on those 100 image controls (10x10, as per the example) to reflect the tiles that are surrounding the player. Thus, your player never actually moves (being always located in the middle), the map just moves around him.

Share this post


Link to post
Share on other sites
Finally have my view space working, thanks for the info

My next question deals woth an image list

This is my working array
I have set my array to 40, 40 and am using an image list to hold my
images for my tiles that I am going to place at each number

My problem is that last line of code, the blue rectangele is for testing purposes

First off, I am trying to draw a blue colored rectangle but the last line does not work

Any pointers?





int[,] testArray = new int[firstNumber, secondNumber];

for (int i = 0; i < secondNumber; i++)
{

for (int j = 0; j < firstNumber; j++)
{

testArray[j, i] = i + j + 1;
Graphics dc = this.CreateGraphics();
this.Show();
Pen bluepen = new Pen(Color.Blue, 3);
testArray[0,0] == dc.DrawRectangle(bluepen, 50, 50);
}

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!