|
Tile-based RPG woes. |
Taiko Keiji
Member #8,307
February 2007
|
I'm creating a tile-based RPG, it's 16*16 and I originally had it so that the caracter moved two pixels every time the D*pad was pressed. but I ran into a few problems with that,namely walking through items because it hadn't registered that the character was over it yet. But I was wondering if anyone had any sugestions as to how I can get the carachter to still move in this way but move over 1 tile. Just turn on your gameboy and pop in pokemon, you'll understand what I mean. Life could be better, machines could program themselves. Taiko Keiji- |
OICW
Member #4,069
November 2003
|
It's simple, character x and y position would represent map indicies instead of real coordinates. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
bamccaig
Member #7,536
July 2006
|
You just need to know how many pixels a tile is... Then you move in whatever direction that many pixels. You can either hard code it or get it directly from your BITMAP if a tile is exactly sized.
Keep in mind it's easier and cleaner if your character BITMAP is size of a tile also, even if there is magic pink whitespace around the outside. Keep in mind this was a very messy example. I usually use objects to represent game objects so it's easier to keep track of relationships, etc.
int main(void) { PLAYER *objPlayer = new PLAYER(); ... if(keys[KEY_RIGHT]) { objPlayer.MoveRight(); } ... return 0; }
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Taiko Keiji
Member #8,307
February 2007
|
Yes but I dont want it to be so jerky, I dont want it to "jump" from one tile to the next. It should look like he's walking to the next tile. Life could be better, machines could program themselves. Taiko Keiji- |
OICW
Member #4,069
November 2003
|
Oh, but you didn't say that. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
ngiacomelli
Member #5,114
October 2004
|
I imagine the easiest way to do it would be to calculate the distance (in pixels) to the next tile. Once you've got that, just make the player move x pixels in a series of small increments. Figure out which tile the player is currently on (the map coordinates). Then, if the player were moving right, figure out the map coordinates for the tile to the right of the player (x+1). Get the actual pixel location for that tile. Subtract the players location from that value, to give you the distance. Then simply move the player in small increments, to cover that distance.
|
bamccaig
Member #7,536
July 2006
|
For this you'll need to keep track of what he's doing so in each frame you can animate and move him a bit. When he reaches the next tile you unset a variable so he stops walking. Taiko Keiji said: But I was wondering if anyone had any sugestions as to how I can get the carachter to still move in this way but move over 1 tile. What did you mean then? If he's still walking normally what does it matter if the map is tile based or not? Unless you mean detecting which tile he's on... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Taiko Keiji
Member #8,307
February 2007
|
I couldn't figure out a way for him to move 16 pixels across the screen when a button was pressed, I wanted him to walk over to the next tile when you press the key much like in pokemon when to little character moves. Life could be better, machines could program themselves. Taiko Keiji- |
Kibiz0r
Member #6,203
September 2005
|
If you switch your engine to something like that described in Game Coding Complete, this is easy. Basically, you should set up your actions as cooperative multitasking. Make an interface class called Process that will add itself to a list of Processes that will be run every iteration of the loop. This makes it easy to derive from the class and implement a MoveCharacterProcess class that locks movement input while it's running and moves the character from tile to tile. That's a neat and clean way of doing it, however it may force you to change the way you think about engine design. Regardless, you should buy that book I mentioned because it's a great resource. It's being republished again soon since demand has gotten high enough for another round of books. --- |
bamccaig
Member #7,536
July 2006
|
If you know the distance he is supposed to travel you should also be able to just set a destination distance and decrement from it every frame. Or, for example, knowing the distance of a tile and the distance covered in a "footstep" (i.e. one frame) you can determine the number of footsteps required and track the distance remaining:
I don't really have time to run over that... But I think it should work if it's clear enough to understand... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Taiko Keiji
Member #8,307
February 2007
|
That's basically what I did.
obviously this isn't the actual code but it works the same way. Life could be better, machines could program themselves. Taiko Keiji- |
|