• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Crusable77

Game Design

6 posts in this topic

Hello, I just finished my first pong game and decided that my next project will be a space invaders clone. I am having a bit of trouble figuring out how to structure the project though. The way I see it is that I would have a Game class which basically runs the program. Then I have an entity class which is the base for all the game objects, Branching off that I have the player class, enemy and any other entity I might have. Then I would have an Image handler to handle the image loading and blitting. Now This is where I am stuck(assuming that the design I wrote down is not complete crap), would I need a separate class for audio and events? and what about the collision/physics system? on my pong game I had what little physics I needed in the entity classes them self and then a separate class that tested for collision on everything, every frame; however I heard that this is not the best way to do it. Thank you in advance for any help.

0

Share this post


Link to post
Share on other sites

Entity systems are very complicated by themselves (no matter how much people state otherwise). There are plenty of discussions supporting this statement.

The main problem with having an Entity class is more or less than having a common base class for everything in a typical programming language. What does an Entity do? Historically, those systems are typically driven by inheritance and are said to be complicated, you might have heard about those "components" supposed to fix that issue.

Entity systems are also proven to work.

Personally I had issues with pure entity systems, mainly regarding code reuse. My issues were compounded by the fact I didn't had a design to follow and so I couldn't focus on what an Entity was supposed to do. Hopefully you won't have that issue. I think your choice is appropriate.

 

Yes, of course you need a system for audio. Audio is, for first, based on a different API and there's no reason to do a big code mess. At worse, you can always merge the two classes toghether in a derived class.

Events are... different. Again, use another class and eventually merge the various systems in a single class using inheritance.

 

Physics. What you're looking for is collision and rigid body dynamics. For your game, plenty of people is going to suggest you to "do your own physics" and maybe they are not completely off-track. Personally I think it is never a bad idea to consider a physics library. What they do however is exactly the same thing as you do, they check collisions every frame. Except they are better at this.

0

Share this post


Link to post
Share on other sites
I think many of the resource handling and logic can be done with plain functions, but defining classes for entities is fine. Just keep things simple..

Use classes for things you need multiple instances of, such as entities, 2d vectors, rectangles, etc. Even the game class you described can be a few variables in the function scope, if you don't need more than one instance of the game running in one process.
0

Share this post


Link to post
Share on other sites

In this situation, I always recommend to use the Model-View-Controller design pattern. You divide your source code into three sections:

 

1. The Model manages the physical behavior of objects in the game.

2. The View request state information and events from the Model, and presents it to the player. This also includes sound.

3. The Controller manages all input (keyboard, mouse, timers and other OS events), and tells the Model or View to act accordingly.

 

0

Share this post


Link to post
Share on other sites

I think you're design thus far is fine.  Assuming your "Entity" class has all the similar properties of a physical object that can be displayed: Location, Velocity, Size, and Image/Animations.

 

This way you can use this Entity for all on screen objects: Player, Enemies, Bullets, Shields (in the classic space invaders), etc.

 

For Audio, I'm not sure you need a specific "system" for it.  As long as you have an Audio Manager (similar to imageManager) that can handle  loading and playing the Audio, that should be enough.  I would think  the Audio needed would be for:

#1, firing bullets (could be part of the specific bullet class, played on creation)

#2, taking a hit (would be called from player or enemy class, when collision happens)

#3, dying

#4, finishing a level

#5, Game Over

#6 Winning

 

For Events, I'm not sure which events you would need outside of Input events without things getting complicated. And, I would handle them inside the player class.  In fact, I'd probably structure it like this:

 
TPlayer Player;
std::vector<TEnemy> Enemies;
std::vector<TBullet> Bullets;
 
// Setup Player and Enemies for the level
 
while(IsRunning) {
 
  // Check level progress: see if all enemies are dead or player dead
  CheckLevelProgress();
 
  // Check for input, set velocity based on input, and fire bullets (if refire rate has lapsed since last shot)
  Player->Update();
 
  // Loop through all the enemies and set velocities, and fire bullets if time
  UpdateEnemies();
 
  // Update (do they do anything special besides just move) all the Bullets
  UpdateBullets();
 
  // This performs all the physics, moves the player, bullets, and enemies, and checks for collisions
  // If you had a physics library, it could be done here
  PerformPhysics();
}
 
...
 
// parts of what physics should do
void PerformPhysics()
{
  Player->Move();
 
  // Loop through enemies moving them
  for (i = 0; i < Enemies.size(); i++) {
    Enemies[i].Move();
  }
 
  for (i = 0; i < Bullets.size(); i++) {
    if (Bullets[i].IsEnemy()) {
      if (IsCollision(Player, Bullets[i]) {
        Player->HandleCollision(Bullets[i]);
        // Mark Bullet for deletion
      }
      else {
        // Check Bullet hits any enemies
      }
    }
  }
}

 

That's a simplistic method, and it should give an idea of what should be done.

0

Share this post


Link to post
Share on other sites

Thank you for the responses. Making a separate audio manager class with SDL_mixer to play and load music I had thought to be redundant since I could do it all in a constructor and call it when needed (unlike the image manager which would make no sense to re-code the function that loads the images in every class that needs it). Also, when the player dies I was thinking I would call delete (assuming that I dynamically allocated it). Is this the best way? is there a better way? 

0

Share this post


Link to post
Share on other sites

Thank you for the responses. Making a separate audio manager class with SDL_mixer to play and load music I had thought to be redundant since I could do it all in a constructor and call it when needed (unlike the image manager which would make no sense to re-code the function that loads the images in every class that needs it). Also, when the player dies I was thinking I would call delete (assuming that I dynamically allocated it). Is this the best way? is there a better way? 

Dpends how SDL_Mixer handles loading sounds.  My assumption is you should only load a sound once, but be able to play it many times, similarly to how you only want to load an image once, but display it many times.  That's what I mean by an Audio manager.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0