2D Game Dev – Part 11.2: Tile Backgrounds

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.

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.

Posted in 2D Game Dev, Allegro, C++, Code, Game Dev, Part 11, Tutorial
3 Comments » for 2D Game Dev – Part 11.2: Tile Backgrounds
  1. Xsitsu says:

    Aren’t you forgetting to destroy your timer, or is that not necessary?

    • Mike says:

      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.

  2. enzoMatrix says:

    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 :D
    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;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Skrilles better watch out. New dubstep group laying it down: http://t.co/tMzmjs0F 5 hours ago
  • Everyday I'm kerfuffle-ing. 1 day ago
  • Who's got two thumbs and finished his research paper? This guy! #ayyyyyyy #fonz 1 day ago
  • App Idea- tag cloud favorite book and allow user to assemble sentences. Algorithmically assign tones. User can hear favorite lines from book 1 day ago
  • I just wrote 2 sentences of this research paper and I feel exhausted. 1 day ago