Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » 2d RPG type games

This thread is locked; no one can reply to it. rss feed Print
 1   2 
2d RPG type games
Rick
Member #3,572
June 2003
avatar

How to games like the below:
{"name":"img.php","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/4\/449218d8066452ffd7bdc35bffabd454.png","w":320,"h":240,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/4\/449218d8066452ffd7bdc35bffabd454"}img.php

handle collision?

My thought was that objects (but not characters) are bound to the grid with a passable/not passable flag. These games, like this one, often simulate depth. If you look at the 2 people standing by the buildings you can see their heads are "on" the building. How do they handle this? Do you just give characters a collision rectangle around their feet and do a BB collision check with their feet rectangle against actual grid squares that these non passable objects are on? Then draw non character objects first, then characters so they are drawn overlapping these objects? I'm just thinking there is a standard way of making a game like the above and I'm curious of what it is.

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

LennyLen
Member #5,313
December 2004
avatar

From what I've played of games like that, I doubt they even do bounding box collision, but just don't allow movement at all into such tiles.

As to the drawing, imagine that he screen is horizontal and you are at the bottom (front). Once you've drawn your background tiles, draw any objects from the back first.

Rick
Member #3,572
June 2003
avatar

The above game doesn't seem to move characters from tile to tile. It seems to have free movement, so some sort of checking would need to be done to see if a character can move on a tile? If it's free movement and doesn't use BB collision, how else would you do that?

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

X-G
Member #856
December 2000
avatar

Uh, what exactly is the problem? Throw a bounding box that only partially covers the sprite (like around the feet) and go to town, sorting sprites by depth before you draw them?

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Rick
Member #3,572
June 2003
avatar

There is no problem, I was just curious on how these games handle collision.

Quote:

Throw a bounding box that only partially covers the sprite (like around the feet) and go to town, sorting sprites by depth before you draw them?

Depth being the top of the sprite or the BB of the sprite, or another given variable about the sprite?

In this game you can walk "behind" the top of the building giving it more of a "depth".

Am I right to assume the building is bound to the map grid and made up of smaller squares. If so do you BB each of those squares or do you make a big BB around the entire building.

I'm just curious on how these things are done, and how others would do them.

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

CursedTyrant
Member #7,080
April 2006
avatar

It can be done like this:

for (int ty=0; ty<TILESY; ty++)
{
for (int tx=0; tx<TILESX; tx++)
{
  int x = tx*TILESIZE;
  int y = ty*TILESIZE;
  
  if (abs(charx-x)<=BBOX_W/2 && abs(chary-y)<=BBOX_H/2 && !Tiles[tx][ty]->Passable)
  {
    StopMovement();
  }
}
}

It should work fine, I remember doing something like this in one of my games. Of course it could be wrong, I didn't test it and I am a bit tired. Of course it would vary depending on the pivot point of your tiles, so you'd have to adjust a few things.

EDIT: Not entirely sure if it's even on-topic... need more sleep.

---------
Signature.
----
[My Website] | [My YouTube Channel]

X-G
Member #856
December 2000
avatar

You just make certain tiles unwalkable, and make certain tiles always overlap NPCs; yes, you cheat. Assuming the base of your buildings are wide enough no one will ever notice.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Rick
Member #3,572
June 2003
avatar

So if you are doing free movement of characters (they aren't tied to any tile), do you do BB collision between the characters BB and actual tile areas?

I would think after you place your building tiles down, making 1 big rect the BB on that building would speed things up, since now you have 1 check (player BB vs building BB) as opposed to the player BB vs each tile the building is made up of. Does that seem logical or would it not make a difference really?

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

X-G
Member #856
December 2000
avatar

With actual tile areas. It's really not as slow as you might think, since at most you need to check four tiles for walkability (assuming the player's bounding box is smaller than one tile), which cuts down the time you need to spend drastically.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

OICW
Member #4,069
November 2003
avatar

You may look at AGDN on the tutorials, there is nice tutorial where he makes engine like that you posted screenie. There's some sort of free movement.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

Paul whoknows
Member #5,081
September 2004
avatar

A few boxes are enough.

{"name":"590582","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/5\/6576b097f2a239ecbe1e2755e0492529.png","w":320,"h":240,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/5\/6576b097f2a239ecbe1e2755e0492529"}590582

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

KnightWhoSaysNi
Member #7,339
June 2006
avatar

I am working on the somewhat of the same thing. What I am trying to do is sort of like what Paul whoknows posted. I have 6 tile layers: 3 ground (below sprites grass, dirt, etc), 2 sky (above sprites tree branches, bridges) and 1 collision.

The collision layer is invisible in the game but not in the editor. I have a seperate tile sheet with different shapes and sizes: boxes, rectangles, circles all colored yellow. They are drawn onto the map just like an other tile but in the collision layer.

I have not implemented the collision yet because I have not learned about pixel perfect collision only bounding boxes plus I haven't made the game I have only made the editor. The collision tile layer is updated and moved just like the other layers. Instead of drawing it to the screen I am going to draw it to a seperate bitmap and check collison from there.

Mordredd
Member #5,291
December 2004
avatar

See, there are many people working on similar projects. Anyways, the result is half an engine instead of a complete game. I recommend you to fuse to a single developer team. That is what I think will lead you you to success. Btw, I love pixelling 2d tiles. In case there will be a group of at least three programmers (and thus a real chance to get such a game finished), I`d love to help out.

Simon Parzer
Member #3,330
March 2003
avatar

My tile engine works with collision detection.

Every tile has a flag "walkable". If it's false the player can't step on it. I have some sort of a movement queue implemented, so it only checks the tile you would be walking over next. And yes, the player doesn't "jump" from tile to tile, he really "walks". With animation and everything. I can share the code and/or a small techdemo if anyone cares.

@Micah: Two people are slower than one person. Three people are slower than two people. At least when it comes to conception and planning, which is the foundation of making a game. I'd rather have half an engine or a poor game than nothing at all.
Obvious exception is when you really know the people you work with. Personally. And when you meet them frequently.

Elverion
Member #6,239
September 2005
avatar

I've played around with these sorts of things plenty a long time ago, and I found the simplest method was to have the map be just a grid of walkable/non-walkable tiles as you have stated, and the character represented by x,y coordinates rather than a bounding box. When moving, just do something like this:

  if( key[KEY_UP] )
  {
    if( is_free(x, y - MOVE_SPEED )
    {
      do_animation();
      y -= MOVE_SPEED;
    }
  }

  do other keys here.

Where is_free(x, y) checks if the position is not in contact with a non-walkable tile or some sort of solid object(such as an NPC). If you want the character to move over full tiles rather than just a speed(or, "free movement" as someone called it), just use newx and newy variables and interpolate rather than changing the coordinates right away.

And for handling depth, when the map is loaded, you should assign each tile a depth. depth = -(y); works very well. Movable objects should, of course, update their depth each time they are moved, and when drawing, the array needs to be sorted.

Most of what I have said is probably stuff you already knew, but it reaffirms your thoughts that they can work rather well. I've had good experiences with them, at least.

--
SolarStrike Software - MicroMacro home - Automation software.

Ceagon Xylas
Member #5,495
February 2005
avatar

My two cents. Don't move your character and then check for collision, if collided then move them back. That can get buggy.

//Not good method
if(key[KEY_RIGHT]) {
  player.x++;
  if(collided(player.x,player.y))
    player.x--;
}

Rather, check for the collision first, and permit passage if there's no collision.

if(key[KEY_RIGHT]) {
  if(collided(player.x+1,player.y)
    player.x++;
}

Mordredd
Member #5,291
December 2004
avatar

Of course, working in a group is different from working alone. It seems that people do not understand that 15 minutes of gameplay can't be called a game. On the inet everyone is a pro and working on his big deal, but in fact you`re not getting more than a crappy tileengine, which itself makes half an engine.

When it comes down to splitting tasks you could supply even a team of ten hobbyist developers: Webdesign and Webmastering, Engine ( 2 programmers ), Scripting, Storywriting, Music, Music Handling, Graphics ( Ingame, GUI )...
If that is not enough let one programmer go through the code and clean it.

Engine writing should be modular, so you can split tasks again. You see: if programmer a let`s say is going to write on the rendering routines where programmer b works on the ai, there is no need for knowing each other personally. Often every programmer wants to do everything, so this will lead to chaos. But that is not my idea's weakness...

Simon Parzer
Member #3,330
March 2003
avatar

Quote:

Engine writing should be modular, so you can split tasks again. You see: if programmer a let`s say is going to write on the rendering routines where programmer b works on the ai, there is no need for knowing each other personally. Often every programmer wants to do everything, so this will lead to chaos. But that is not my idea's weakness...

Ok, let's try it. Open a "new team project" thread and I'm in. I can supply working code for drawing routines and a tile engine. Furthermore I have several great game ideas, some really innovative stuff. I'm sure we'll find another programmer, then you do the graphics. Musicians and webmasters should be easy to find, too.
Oh, wait.. isn't it Monday today? ::) :-X

About the "Engine writing should be modular":
It SHOULD be modular but it isn't. A good game engine is built bottom-up. GFX/Sound/Input layer, on top of that a tile engine, on top of that basic game logic like collision detection, on top of that maybe a scripting engine utilizing the lower-level functions and on top of that the high-level logic. Notice the many "on top of that"s? You gotta know the entire existing code base if you want to work on a new layer. Yeah, or you have a good design plan -- the architecture of the finished engine before you start coding.

{"name":"590595","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/3\/835938715af9625fe3deb744a3b70866.png","w":700,"h":300,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/3\/835938715af9625fe3deb744a3b70866"}590595
Image: Modular vs. Bottom-up

Rick
Member #3,572
June 2003
avatar

Would it be valid to create depth for static objects vs moveable objects at the editor level? Like for a tree I can put it's branches and leafs on a foreground level, so when the player walks on it they always get drawn over the player.

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

piccolo
Member #3,163
January 2003
avatar

it is valid and that is what i am doing in my game http://www.allegro.cc/depot/Thegame/.

my game is what i came up with after i looked at the AGDN rpg tutorial.

i will up data it now so you get fresh example.

wow
-------------------------------
i am who you are not am i

Elverion
Member #6,239
September 2005
avatar

As piccolo said, it is valid. In fact, many old RPGs done it this way. Typically, the depth of each tile is determined by which layer it is on. The problem arises with larger, movable sprites, though. Consider if, for example, a larger than normal creature of some sort were to walk in front of the tree. If part of its sprite is taler than the tile width, then he would appear in front of the tree stump, but underneath the tree's branches. To counteract this, I would suggest you still take Y position into consideration when calculating the depth value for your tiles.

--
SolarStrike Software - MicroMacro home - Automation software.

Rick
Member #3,572
June 2003
avatar

I didn't think about that Elverion. The problem is my tree is placed as x amount of separate tiles. To use the whole Y value sorting thing I would have to have the tree as one image it seems.

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

Elverion
Member #6,239
September 2005
avatar

Ideally, yes. But you can also use the layer to find out the correct depth, and that should work with multiple tiles.

depth = -( y + layer offset )
where layer offset is computed as:
layer offset = ( layer - base layer ) * TILE_SIZE
where base layer is assumed to be the layer where the NPCs would normally walk around.

So, as long as you place the stumps at the base layer (which you should, because they would represent a non-walkable tile), and the branches a layer above that, I think that should work. This might be a bit more work than is necessary, so you might just use the simple method with layers.

--
SolarStrike Software - MicroMacro home - Automation software.

Rick
Member #3,572
June 2003
avatar

I think I'll just put all "objects" on the same layer and just sort by the y value of it's collision rectangle.

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

Ceagon Xylas
Member #5,495
February 2005
avatar

You'll wind up putting layers in later :P

 1   2 


Go to: