Jump to content


2D RPG move map, keep player centered


5 replies to this topic

#1 Kekke88

    New Member

  • Members
  • PipPip
  • 29 posts

Posted 06 May 2011 - 04:56 PM

Hello everyone!

I have a question where I need some design help..

I am currently developing a 'fun' RPG game with a centered player that can move up, down, left and right.

But how do I move my map according to how the player moves?

How should my map look?

There should be non walkable places, and you should be able to throw things on the ground, what I was thinking was maybe have a class called something like cGroundUnit which was a 32x32 big texture that together with loads of them built a map.

But if I have let's say 1000 cGroundUnits and move them in a foreach loop, I think the ground will have glitches like the ground is falling apart.

Is there any standard way to do this that I am not aware of?

//Kekke

#2 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1615 posts

Posted 06 May 2011 - 05:42 PM

I think that's basically how they do it. I think you only show and move what's visible from a map array. The best way to do this kind of thing in my book is start with some 32X32 tiles and experiment with it. First move one, then a couple, then a section of a map. They're not going to fall apart if you move them each the same amount, but you have to decide when to add sections from the map and delete sections that are no longer visible.
You can probably also find tutorials or even engines that do that kind of thing, but it's sometimes more interesting to come up with your own ideas and implement them.
Currently using Blender and Unity.

#3 }:+()___ (Smile)

    Member

  • Members
  • PipPipPip
  • 169 posts

Posted 06 May 2011 - 06:15 PM

Do not move map, move player only. This way problem of moving all map tiles transforms to problem of displaying map correctly. Effectively it is moving only visible tiles. So, first, determine which tiles will be visible (in form xMin-xMax, yMin-yMax for example) and, second, draw these tiles with displacement of reverse player position (tile with world coordinates xTile, yTile draw at position xTile-xPlayer, yTile-yPlayer).
Sorry my broken english!

#4 Kekke88

    New Member

  • Members
  • PipPip
  • 29 posts

Posted 06 May 2011 - 11:00 PM

'}:+()___ [Smile said:

']Do not move map, move player only. This way problem of moving all map tiles transforms to problem of displaying map correctly. Effectively it is moving only visible tiles. So, first, determine which tiles will be visible (in form xMin-xMax, yMin-yMax for example) and, second, draw these tiles with displacement of reverse player position (tile with world coordinates xTile, yTile draw at position xTile-xPlayer, yTile-yPlayer).


Interesting.. are you saying like I should draw the player to center of the screen, BUT keep track of the X and Y coords (as in move player +5 X but keep drawing him in the center, and then draw mapX - playerX) and draw the map?

Will definitely try this tomorrow and post back how it goes..

fireside said:

I think that's basically how they do it. I think you only show and move what's visible from a map array. The best way to do this kind of thing in my book is start with some 32X32 tiles and experiment with it. First move one, then a couple, then a section of a map. They're not going to fall apart if you move them each the same amount, but you have to decide when to add sections from the map and delete sections that are no longer visible.
You can probably also find tutorials or even engines that do that kind of thing, but it's sometimes more interesting to come up with your own ideas and implement them.

That is true, and for me, it is always much more interesting to come up and think by yourself rather than using something created by someone else (even though I know most of the programmers don't wanna re-invent the wheel, I always want to re-invent it to learn before I use something already finished).

//Kekke

#5 }:+()___ (Smile)

    Member

  • Members
  • PipPipPip
  • 169 posts

Posted 07 May 2011 - 09:03 AM

Kekke88 said:

Interesting.. are you saying like I should draw the player to center of the screen, BUT keep track of the X and Y coords (as in move player +5 X but keep drawing him in the center, and then draw mapX - playerX) and draw the map?

Will definitely try this tomorrow and post back how it goes..

I suggest even to make the player one of the scene objects (derived from cMonster for example) and keep track of screen center in different pair of variables. Usually xScreen = xPlayer, yScreen = yPlayer, but you can easily handle special cases with the player displaced from the screen center (approaching map edge, earthquake, etc...).
Sorry my broken english!

#6 Kekke88

    New Member

  • Members
  • PipPip
  • 29 posts

Posted 07 May 2011 - 03:37 PM

Thanks for the help.

I made a big step and this is what I currently have;


Collision Detection Code:

//Move character etc..

if (TileCollision())
            {
                player.X = (int)oldPlayerPosition.X;
                player.Y = (int)oldPlayerPosition.Y;
            }

// I should change this into only comparing to visible tiles
public bool TileCollision()
        {
            foreach (cGroundUnit curGround in myMap.GroundUnits)
            {
                if (curGround.Intersect(this.player) && !curGround.Walkable)
                    return true;
            }

            return false;
        }

//Normal intersect from XNA
public bool Intersect(cPlayer player)
        {
            Rectangle test = this.CollBoundingBox(player);
            if (player.BoundingBox.Intersects(test))
                return true;
            else
                return false;
        }

Now I just need to make a map editor..





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users