Movement on Rails

Started by
1 comment, last by GBGames 18 years, 4 months ago
I'm working on what was supposed to be a simple puzzle game. Basically, you control a character that moves around a room and kicks a ball around until you kick it into the exit. So I've got it working at the moment, but the movement code seems to allow too much freedom. It would be great in an adventure game, but I think I might need to add rails to my movement. For example, the Player can move in four directions. The room has tiles, and each tile is 64x64 pixels. Imagine you have a room like this: F W P F where F is the floor,W is the wall, and P is the player. Then if you move up, the sprite will be moved up, but you can stop after only moving a few pixels up. Well, now the Player can't move to the right. If he tries to move to the right, his head will hit the wall. It's not that big of a deal. The Player can just move down and then go to the right. It's the Ball that's the problem. F W B F F W Now there is only one tile between the walls, and if the ball moves to the right, it has to be precisely in the right spot or else it will bounce off the walls. I could make the ball smaller, but I still think it would make for a difficult time for the player. Like I said, this isn't an adventure or action game where precision should be important. So I want to put all movement on rails. I'm thinking along the lines of Bomberman or Dragon Warrior. When you moved, you moved from tile to tile. But it wasn't one-instant-you're-here-the-next-you're-here movement. It was interpolated. I'm assuming that the movement was implemented by checking an array representing the environment for obstacles. 0 if you could walk, 1 if an obstacle, or something like that. Then if you moved, say to the right, the player would be in a Move state. Each update, since you were in a Move state, the game would move your player from one point to another depending on the interpolation. Then once the movement is done, change out of the Move state to the Standing state or whatever. In that state you could then take other inputs. Now I am sure I can implement something like this, and it would actually make my game easier since I could add new objects easily (I think) and wouldn't have to worry about collision detection as much if at all. My question is if you think that maybe there is a better way to do what I want to do. Thanks for your time in advance
-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel
Advertisement
You could always do a hybrid -- have a tile based map but have per-pixel movement inside it. Just integer-divide your player's x and y location by the width and height (respectively) of the tile to get their (x,y) location on the tile map, and check to see if the tile they are about to step in is solid. That way you wouldn't have to interpolate and things will still look alright. This is the technique I use for my games. Now that I read your post again, I think this is what you are already doing however.

Of course, if you want to do more of a casual market or don't think free-ranging exploration is important at all, I would lock the game down to tile-by-tile movement and do some animation between them.
I'm using the Kyra library, and I think it does pixel perfect collision detection. I'm just realizing that my game, while it will animate in real time, doesn't need perfect detection. I can be happy if the Player's position on a tile would cause the Ball to stop moving, or if the Player doesn't move onto a tile that the Ball is moving onto at the time.

Thanks
-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel

This topic is closed to new replies.

Advertisement