2D Game Dev – Part 8.0: Structured Sprites

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

Structure

So far we have been using independent variables to control a single entity on the screen. The next logical step is to allow for multiple entities to appear on the screen at the same time. With the way we have been doing things, that is easier said than done. If you will recall, so far we have been using basic x and y variables to keep track of our entity’s location. Similarly, we have been using generic variables for velocity, animation, and dimensions. If we wanted more entities, we could create variables like x2 and y2, or we could add a structure for self contained variables.

The Code

Not a whole lot is going to be different in this part. As you will see, we will be adding the Sprite Struct (normally it is a Sprite Class, but we are keeping it simple) and adding a few helper functions. After that I have a few neat examples for you. You will see that having an “object” allows for a great deal of code reuse as we begin to treat our entities generically. In the next part, we will be taking what we have learned and using it to super charge our shooter game from Part 5.

Posted in 2D Game Dev, Allegro, C++, Code, Game Dev, Part 8, Tutorial

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 6 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. 2 days ago