2D Game Dev – Part 4.2: Putting the Timing Together

This post is a portion of Part 4 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.

Concluding Part 4, this video goes over putting together what we have worked with up to this point. In Part 5, we will be taking Parts 1-4 and putting them together in our first game. Don’t miss it!

Source code can be found here.

Notice that the source code is slightly different from the video? Here is why.

Posted in 2D Game Dev, Allegro, C++, Code, Game Dev, Part 4, Tutorial
13 Comments » for 2D Game Dev – Part 4.2: Putting the Timing Together
  1. Graham says:

    Thank you – this was very informative. Please keep the tutorials coming asap! :)

  2. Sebas-Godman says:

    God bless you dude, hey im wondering why i can’t watch your videos now, yesterday i could, but i don’t know what’s happenning right now, do i need any addon?

    -Thank you, blessings-

  3. Nick says:

    These videos have been really helpful :)

    Cheers!

  4. James says:

    Working my way through the course. Really, can’t say thanks enough.

    Question on this video: it seems cutoff at the very end. Given your consistent pattern, it’s likely just a couple of words, but wanted to make sure I wasn’t missing anything.

  5. AJ says:

    Hey,
    First of all thanks for this it has been really helpful and hopefully I will learn how to make some games will I’m on winter break.

    Any who, it is saying that the video was taken down my the user :(

  6. Pedro says:

    hi! first thing: my apologies for my english.
    Your course is amazing!! all those collision detection methods, background styles, etc…, really awesome, thanks for your work!!.
    In the other hand, i’m spanish, and it’s a bit difficult to me understand you in the videos, (hehehe, i have to work my english), so, in this video, i can’t understand why the square is drawn without hit any key when you activates the timer. The drawing code is in the same line after all.

    • Mike says:

      I believe I understand your question. Basically, since the timer is now running (it runs automatically) we don’t need to hit a button to get things to draw. The events start firing off right away.

  7. lars says:

    great vid, thnx
    is there any way to make the square move at a constant speed: its now moving at 10 pixels/fps both x direction and y direction. but if you press like UP-key and LEFT-KEY its speed will increase to squareroot 200 pixels/fps witch is about 14 pixels/fps. is there anyway to also make it move diogonaly at 10 pixels/fps?

    • Mike says:

      Sure is. I cover angular velocity at some point. I think it is in the “gravity demo” in the sprite section. Keep watching.

  8. Nicki says:

    Hi Mike,
    I’m working on a game that is based off of your code and when I run the game, it uses over 100% of the CPU. I have to run ./a.out a random number of times in order for my game to run. I’m new to Allegro, but I would think this has something to do with the timing. Here is the timer related code that i have and then I destroy the timer at the end. I’m not sure if this is enough of my code for you to determine what is wrong or not.
    Thanks!
    Nicki

    // Syncing various events
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_keyboard_event_source());

    // Sets the background color
    al_clear_to_color(al_map_rgb(0,0,0));
    // Draws the start screen image
    // Arguments: image,dx,dy,flags
    al_draw_bitmap(imageStartScreen,0,0,0);
    // Rotates the two buffers
    al_flip_display();
    // Plays and loops the music until the window closes
    al_play_sample(music, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL);
    // Starts the game timer
    al_start_timer(timer);

    // Starts the game window and stops when it is closed
    while(!done)
    {

    int step = 4;

    // Create a new variable and then wait for an event to occur
    ALLEGRO_EVENT ev;
    al_wait_for_event(event_queue, &ev);

    // Counter to alternate “press start” every second
    pressSpace = fpsCounter(countStart, FPS);

    // Timer trigered event for the game logic
    if(ev.type == ALLEGRO_EVENT_TIMER)
    {
    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 1 hour ago
  • Everyday I'm kerfuffle-ing. 22 hours 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