Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ferinorius

walkability for a side scroller questions...

This topic is 6067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have smooth scrolling, and I have certain tiles set up, and I have read through all the tuts on game dev, but nowwhere does it tell how to implement stuff like this. How can a person implement walkability. Think of it as a side scroller, and the routine needs to be able to tell if the next tile is walkable or not before the player is moved there. how is this done? at least show me a tutorial that HELPS inplement walkability.

Share this post


Link to post
Share on other sites
Advertisement
Since it''s a side-scroller I''m guessing that it''s also a platform type, yeah ?

Anyway, there are loads of methods, but here is one I used and It''s probably the fastest, or it doesn''t take too much processing. If you are using 256 colour (8-bit) then it''s handy.
Use your palete of colours and give them an order, say green (grass) is "walk", blue (water) is "nowalk", then...

if(player.position "nowalk")
{
if(player.going forward)
player.position--;
else
player.position++;
}


Hope this helps
djsomers

Share this post


Link to post
Share on other sites
Oops!

Just saw the ''Tile'' bit in your post.

That makes thinks more simple, Give each tile type a value..

  

struct tile
{
int width;
int height;
etc..
const char *walkability;
};




Now in your game loop:
do before blitting your sprite to mem/screen

  


if(player.pos==tile[x][y] && tile[x][y[y].walkability="nowalk")
{
don''t move player sprite;
}




This is better and relly just as fast in tile games.

djsomers

Share this post


Link to post
Share on other sites
ok, i do something like that, check my player''s positoin versus that and then I get this:



I think I have to tweak it a lot more, and experiment with some things.

As you can see, my color isn''t 8 bit unfortunately.



Neo-Toshi - The City That Never Sleeps

Share this post


Link to post
Share on other sites
when you check for walkability, you need to make sure that the player''s position is set to the top pixel of the tile they are walking on. that''s what your problem is in the screenshot. if i had time, i would pull up my engine code and give you some calculations on how to do that, but it really isn''t all that hard anyway. just set the player''s position to where his feet are touching the top of the tile he''s standing on.

sorry i couldn''t explain more...

dave

--
david@neonstar.net
neonstar entertainment

Share this post


Link to post
Share on other sites
Hey neonstar, its been a long time since i have heard from you...oh well. it is probably harder than it seems, but ill keep scraping my brains for it. see, i had a really crappy calculation

if (map[player.posx + world_camerax / TILE_SIZE][player.posy + world_cameray / TILE_SIZE] == 0) {

player isn''t standing on something keep falling
}
else {
player is standing,
}

and that is how it got me to where i am in the picture



Neo-Toshi - The City That Never Sleeps

Share this post


Link to post
Share on other sites
If your character is "below" where he/she/it should be standing, then you have a problem with which tile your comparing to be "solid". Play with the y (or x, whichever is the "up/down") and see how it needs to be offset to check the tile.
    
if (map[player.posx + world_camerax / TILE_SIZE][player.posy + TILE_SIZE + world_cameray / TILE_SIZE] == 0)
{
//player isn''t standing on something keep falling

}
else {
//player is standing

}

Note the +TILE_SIZE in the y dimension of the map array. This shifts our view to UNDER the player, instead of the map[][] your player was being drawn at.

Another really nice thing is that you have blank space set to 0- do you have any other "background/walkthrough" tiles in mind? If so, excellent! Try numbering them so that the first few (0-10 for example) are the walkable ones, and the others (11+) are the "solid/impassable" ones. Then change your "== 0" to a test for "walkable" things "< 11" and you can walk/fall through coins, illusionary walls, fake ground, et cet.

-Tok


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Feel free to email me HERE
*Howdy Kids, Do /YOU/ know what time it is? It''s tangent time* -Baldor the Bold

Share this post


Link to post
Share on other sites
Ok, switched some things around, changed a few states and still have nothing. I even but debugging junk up all over the screen to show me what tiles were what. I think my problem now lies in the fact that my collision detection isnt scrolling, but still I am not entirely positive about that for sure.

after changing that bit of code, the numbers are all haywire, and spark (the sprite) stops in mid air for no reason. What a bug this has turned out to be.



Neo-Toshi - The City That Never Sleeps

Share this post


Link to post
Share on other sites
well heres how I do it. Don''t know if it helps or not.
all tiles are 32x32 pixels.
Each tile has a blocking byte which is or''d to various constants I''ve defined.
so bit one is block up, bit two block east.
#define TILE_BLOCK_UP 1
#define TILE_BLOCK_RIGHT 2
#define TILE_BLOCK_BOTTOM 4
#define TILE_BLOCK_LEFT 8
#define TILE_BLOCK_ALL (TILE_BLOCK_UP | TILE_BLOCK_RIGHT TILE_BLOCK_BOTTOM | TILE_BLOCK_LEFT)

my character has a velocity x and a velocity y, in pixels.
To handle falling, _every_ frame we add gravity to the y velocity (see why later).
Characters have a width (in tiles) and a height(in tiles)
I the character''s position is tracked by the bottom left corner of it''s bounding rect.
I have a function to convert screen pixels into world coordinates.
A world coordinate is given by tilex, tiley, subtilex, subtiley;
The camera maintains a camera x, y and sub x, y to allow for smooth scrolling.
So I first calculate the world coordinates of the current tile I''m in.
I then calculate the world coordinates of the tile I''m travelling to. Based on the velocity of course.
I also calculate the world coordinates of all four bounding points of the character. East from the bottom left, I just add the character''s width and height.
Then depending on the direction of the velocity I do some checks.
example:
if(velocity.x < 0) //moving left
(
//check if the left edge has crossed a tile boundary
if(bottomleft.starttile.x != bottomleft.endtile.x)
{
if(World.GetTile(bottomleft.x,bottomleft.y)->GetBlocking()
&& TILE_BLOCK_RIGHT)
{
SetXVelocity(0) //stop moving in the x direction
SetXPosition(bottomleft.starttile, 0) //far left of start tile
}
else
{
//add x velocity to current x
}
}
)
else //moving right etc...

So that handles left and right motion pretty simply.
Y motion is pretty much the same
if(velocity.y < 0) // we''re falling. we should _always_ be falling
{
if(bottomleft.starttile.x != bottomleft.starttile.y)


}
























Share this post


Link to post
Share on other sites
Stand back from the problem now!!!

Get a piece of paper and look at the problem. As mentioned
you need to look ahead rather than where you are.

I am not going to give code. Code is the process of thinking
it through and no matter how many times you tweak the values
you are only putting off what you don''t understand.

Your sprite, from the looks of it , is getting stuck.

Let''s say your sprite just dropped out of the air onto that
platform. He had an original Y and a movement. So in essence
you have Y0 and Y1. Where Y1 was the target.

Now from Y0 through to Y1 you could have hit something. Now
you need to determine what Y0 through to Y1 would have hit.

Your map is regular and constrained within a 2D array. You
need to loop through X0,Y0 to X1,Y1 in incremental steps.

When you get a hit you snap your sprite (minus it''s height) to
the tile.

Now this is really robust because no matter how fast you move
your sprite will always have determined what it COULD have
gone through.

Example.

Sprite_X0 = 0

Sprite_X1 = Sprite_X0 + 64;

Let''s say your tiles width is 32. Your sprite now has passed
right through. You could argue that you restrict movemment to
less than the dimensions of a tile. But this restricts you big
time.

If you don''t want to be this robust then look at whether you
need to snap to the nearest tile.



Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!