Allegro.cc Forums » Game Design & Concepts » platformer tutorial/guide in c

 platformer tutorial/guide in c
 _jagged Member #17,124 September 2019 Hello everyone, I'm interested in making a simple tile based 2d platformer in the style of ghouls n ghosts. But i'm having trouble finding information on how to begin. I've found tutorials on youtube that use c++ but nothing using plain c. I know I could probably adapt the info from one of these c++ tutorials into c, but they all tend to go straight into classes and inheritance and all the garbage of c++ that i'm not interested in.Does anybody know of a tutorial or guide that could at least point me in the right direction? I know enough allegro and c to make simple shmups that constantly scroll, with parallax backgrounds and animations but I have no idea how to set up a tile based map, make tiles solid etc...Cheers!
 MikiZX Member #17,092 June 2019 Possibly these pages can help you a little (please note I've never used these and they are mostly Allegro5 related):
 DanielH Member #934 January 2001 Try yourself*This is a basic example, from memory*#SelectExpand 1//1. determine how many tiles will fit on your display at one time 2#define GRID_WIDTH 40 3#define GRID_HEIGHT 30 4 5//2. determine cell size 6#define CELL_WIDTH 32 7#define CELL_HEIGHT 32 8 9//3. determine how big the overall map is 10//will it scroll horizontally or vertically or both 11#define MAP_WIDTH 400 12#define MAP_HEIGHT 30 // same as grid height if not scrolling vertically 13 14int camera_x = 0 15int camera_y = 0 16int map[MAP_WIDTH * MAP_HEIGHT]; 17 18// for this example I'm using an array of bitmaps for tile 19// ALLEGRO *tile[]; 20void draw_map 21{ 22 int i, j, x, y, sx, sy, c; 23 24 x = camera_x / CELL_WIDTH; 25 y = camera_y / CELL_HEIGHT; 26 sx = camera_x - (x * CELL_WIDTH); 27 sy = camera_y - (y * CELL_HEIGHT); 28 c = map[x + (y * MAP_HEIGHT)]; 29 30 // draw grid height + 1 31 for (j = 0; j <= GRID_HEIGHT; ++j) 32 { 33 // draw grid width + 1 34 for (i = 0; i <= GRID_WIDTH; ++i) 35 { 36 // draw tile at pos 37 al_draw_bitmap(tile[c], 0, 0, (i * CELL_WIDTH) - sx, (j * CELL_HEIGHT) - sy); 38 } 39 } 40} All you have to do is adjust camera_x and camera_y. You can adjust by pixel amount or whole tile size;What I do is put player in the middle. If the player crosses an imaginary boundary then adjust the camera to counter movement;example: The map above is for a 640x480 grid. You can put boundary at 80 and 560;```if (player_x < 80) { camera_x -= (80 = player_x); if (camera_x < 0) camera_x = 0; // keep in check player_x = 80; } if (player_x >= 560) { camera_x += (player_x - 560); if (camera_x >= (MAP_WIDTH - (GRID_WIDTH * CELL_WIDTH))) camera_x = (MAP_WIDTH - (GRID_WIDTH * CELL_WIDTH))); player_x = 559; } ```
 RmBeer2 Member #16,660 April 2017 It has no secret, it's just about printing a mesh of images based on a double index vector. πππ π BlackRook WebSite π C/C++ π GNU/Linux π IceCream/Cornet π πππRm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023!
 _jagged Member #17,124 September 2019 Thank you all for your replies, I think there's enough here to get started. I'm now realising I actually know less about game design than programming. It's just the map that's moving.. damn. So, does the player just float a certain tile height? as in there's no coding of solid/ethereal for the ground? If the ground is two tiles deep then the player's y position (at feet) is window height - 2* tile height?