This post is a portion of Part 11 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.
- Part 11.0 – Backgrounds
- Part 11.1 – Parallax Backgrounds
- Part 11.2 – Tile Backgrounds
- Part 11.3 – Tile Backgrounds with Mappy
In this video we move away from static backgrounds and look at dynamic, tile based backgrounds. We look at using a tile sheet and some math to make large backgrounds easy.
Full source can be found here.
Aren’t you forgetting to destroy your timer, or is that not necessary?
You are right. I must have accidentally deleted that line from my code template. You do need to destroy the timer. That is my mistake.
These tutorials have been amazing, im glad ive been able to discover them haha. So from this I tried to incorporate some collision detection and the start of gravity, also different images for the player sprite when the different keys are pressed. thanks for the tutorials. xD writing my first game off of this 😀
for(int i = 0; i (coord_y – 5) && bouncer_y < coord_y + 10/**/&& bouncer_x > coord_x && bouncer_x < coord_x + 256 )//down on an object tile
{
bouncer_y -= 10.0;
can_you_jump = true;
}
if(bouncer_y (coord_y + 220) /**/&& bouncer_x > coord_x && bouncer_x coord_y && bouncer_y coord_x – 8 && bouncer_x (coord_y + 10) && bouncer_y coord_x && bouncer_x (coord_y – 10))
{
gravity = false;
}
if(gravity = true)
{
//bouncer_y += .1; //lol buggy as hell right now, yawn
}
if(do_jump)
{
bouncer_y -= 1.0;
gravity = false;
}
//hehe lol hi
}
}
//keyboard input, player movement, animation, and map scrolling(which will not work soon anyways)
if(ev.type == ALLEGRO_EVENT_TIMER) {
//default no button press character
al_draw_bitmap_region(image, spriteTileSize * grid[1], 0, 128, 128,
bouncer_x, bouncer_y, 0);
if(key[KEY_UP]) {
if(bouncer_y = 400)
yOff -= 10.0;
else bouncer_y += 10.0;
al_draw_bitmap_region(image, spriteTileSize * grid[1], 0, 128, 128,
bouncer_x, bouncer_y, 0);
}
if(key[KEY_LEFT]) {
if(bouncer_x 600)
xOff -= 10.0;
else bouncer_x += 10.0;
al_draw_bitmap_region(image, spriteTileSize * grid[3], 0, 128, 128,
bouncer_x, bouncer_y, 0);
}
if(key[KEY_SPACE]) {
al_draw_text(font, al_map_rgb(255,0,255), 256, 48,ALLEGRO_ALIGN_CENTRE,”jump”);
do_jump = true;
}
redraw = true;
}
Enzo, try changing
if(gravity = true) to if(gravity == true)
else it will always be true.