Hi i am trying to make a jump and run game in Visual C++ using SDL

I have been following a tutorial(http://jnrdev.72dpiarmy.com/) which was very good but finished before everything was covered.
In a game lik mario, the players will navigate over jumps and onto ledges ect. I am using tilebased collsion and was hoping someone would be able to help me figure out how to create the map inwhich the players navigate. does anyone know how this works?

Dani AI

Generated

— the tutorial stops where the tricky bits begin. ’s one-word reply didn’t help, and was right to ask for details. Below is a compact, practical approach you can apply in SDL/C++ to build maps and handle tile-based collisions for a platformer.

Keep the map simple: store a 2D array (or a 1D array with width*height) of tile IDs. Give each tile type a small property bitfield (SOLID, ONE_WAY, SLOPE, etc.). Pick a sensible tileSize (16 or 32 px). At runtime convert world coords to tile indices with tileX = floor(x / tileSize). Only test tiles overlapping the player’s axis-aligned bounding box (AABB) — that keeps checks cheap.

Use separate-axis movement + resolution: move X, fix horizontal collisions, then move Y, fix vertical collisions. That order makes “grounded” detection simple. Example pseudocode (trimmed to the essentials):

// TS = tileSize, isSolid(tx,ty) checks map
void movePlayer(Player &p, float dx, float dy) {
    // horizontal
    p.rect.x += dx;
    for (int ty = floor(p.rect.y/TS); ty <= floor((p.rect.y+p.rect.h-1)/TS); ++ty)
      for (int tx = floor(p.rect.x/TS); tx <= floor((p.rect.x+p.rect.w-1)/TS); ++tx)
        if (isSolid(tx,ty)) {
          if (dx > 0) p.rect.x = tx*TS - p.rect.w;
          else p.rect.x = (tx+1)*TS;
          p.vx = 0;
        }

    // vertical
    p.rect.y += dy;
    for (int ty = floor(p.rect.y/TS); ty <= floor((p.rect.y+p.rect.h-1)/TS); ++ty)
      for (int tx = floor(p.rect.x/TS); tx <= floor((p.rect.x+p.rect.w-1)/TS); ++tx)
        if (isSolid(tx,ty)) {
          if (dy > 0) { p.rect.y = ty*TS - p.rect.h; p.onGround = true; }
          else { p.rect.y = (ty+1)*TS; }
          p.vy = 0;
        }
}

Handle special cases: one-way platforms collide only when falling and the player’s feet cross into tile; slopes can be implemented with per-tile height functions or small polygons; ledge grabs use raycasts or extra checks on the tile edge. Troubleshooting tips: draw AABBs and tile bounds while debugging, clamp velocities or use substeps to avoid tunneling, and keep the collision box slightly smaller than the sprite to prevent snagging on corners.

Recommended Answers

All 2 Replies

Member Avatar for Member #46692

does anyone know how this works?

Yes

Well that was helpful, Thanks.
Any chance you will share your knowledge? or else i don't see any reason for you to have posted on my thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.