Sign in to follow this  
MintyAnt

XNA - Player states and Map drawing

Recommended Posts

MintyAnt    102
Hello,

I had a few questions while programming trying to re-create Megaman X in XNA (For purposes of teaching myself game development :D)

I was going to program my player to have different states. Given the current enviroment and/or user input, I would calculate the players current state. Then I would determine what to do programming wise with the given states.
For instance, if he is holding down right key, then he is in a moveRight state. Then I say if state == moveRight, pos.x += speed

However using one state lead me to a few collisions when I thought it over.

What if he is:
Moving right
Jumping
Shooting

Thats three states right?
Does that mean I should then have 3 current states of a character? Like this:
MovementX
MovementY
Action

And each has one the following states
MovementX - moveLeft, moveRight, onWall (For wall kicking/gripping. Like megaman x)
MovementY - Jumping, Falling, WallKick
Action - Shooting, Charging, ChargeShot

(Also, should I have the moveLeft and moveRight, or just Move, calculating the direction afterwards?)




The second thing was map drawing:
Most people seem to draw maps with either small tiles or screen sized tiles.
They load up the next tile and loop to that. After it reaches a point, it ditches the first tile and loads the next, and so on.

In megaman they have these large maps they scroll through.
Is there a way I can just scroll through this whole map, without bogging down my program? Or is it more efficient for me to destruct the map into different game window sized tiles?

And finally, how can I give the game some boundaries, like the floors and walls? Do I need to ascociate some kind of data file with the map?


Thanks for the help,

-Minty

Share this post


Link to post
Share on other sites
EJH    315
[quote name='MintyAnt' timestamp='1307536446' post='4820912']
However using one state lead me to a few collisions when I thought it over.

What if he is:
Moving right
Jumping
Shooting

Thats three states right?
Does that mean I should then have 3 current states of a character? Like this:
MovementX
MovementY
Action

And each has one the following states
MovementX - moveLeft, moveRight, onWall (For wall kicking/gripping. Like megaman x)
MovementY - Jumping, Falling, WallKick
Action - Shooting, Charging, ChargeShot

(Also, should I have the moveLeft and moveRight, or just Move, calculating the direction afterwards?)
[/quote]

You will need an animation for each state (walk left, walk right, jump left, jump right, etc..) so maybe keep it simple and make every animation state a player state as well? Shooting can occur during just about any state, so that would need to be separate.


[quote name='MintyAnt' timestamp='1307536446' post='4820912']
Most people seem to draw maps with either small tiles or screen sized tiles.
They load up the next tile and loop to that. After it reaches a point, it ditches the first tile and loads the next, and so on.

In megaman they have these large maps they scroll through.
Is there a way I can just scroll through this whole map, without bogging down my program? Or is it more efficient for me to destruct the map into different game window sized tiles?
[/quote]

If you are doing tiles, then the easiest way to optimize is probably a grid (or tree) that partitions your complete map into pieces. So assuming it is level-based like Mega-man:

- load all partitions of the current level into memory
- only draw partitions of the map that the player is in, and the nearby partitions

You should use the partitioning scheme to optimize everything else as well. E.g. only play sounds in nearby partitions to the player, only spawn special effects in nearby partitions to the player, only collide objects with the player in nearby partitions, and you can even suspend NPC physics and AI updates in all partitions except those near the player.

[quote name='MintyAnt' timestamp='1307536446' post='4820912']
And finally, how can I give the game some boundaries, like the floors and walls? Do I need to ascociate some kind of data file with the map?
[/quote]

Yes. In addition to visual tiles your level will need collision information. An easy way to start would be with each tile being collidable or not. Thus you only need to collide with boxes. Use your grid system above to collide the player only with a limited subset of tiles every update.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this