Questions about different pieces of a game

Started by
10 comments, last by NoodleCandy 10 years, 5 months ago

Hello there,

I'm looking to make a small game (more of a tech demo, really). I have some experience programming in C++ and am even currently playing around with OpenFrameworks. With OF, I've learned to draw shapes, move them, and even do very simple collision detection between them. I'm very inexperienced with making games through object oriented programming though so I'm hoping you people could guide me in the right direction.

Currently in the middle of learning vectors and storing instances of an object within it and my end goal is to create a top-down 2D game where shapes will be spawned by an EnemySpawner class. These shapes will fly at the player character which will be controlled via mouse and said shapes are erased once off-screen. I have an idea of how I'll structure the classes but I'm unsure if there are tools I can learn to make some tasks easier.

For example, if there were 20 shapes on-screen at once, I could run a loop that will check any intersection between those shapes and the player or the edges of the screen. Is a loop really the way to go about this or could some sort of game framework abstract this away somehow? I'm talking out my ass due to inexperience but these are the kind of issues I'm wondering about.

Advertisement

If this is a learning exercise, skip the framework, this is exactly the kind of stuff you want to learn from trial and error.

You have a perfect opportunity ahead of you. You know a way to solve something ( brute force loop to check for collisions ) but have a feeling there is a better way to do it. Instead of using a framework, implement the loop then try to improve it. At the end of the day, that really is more or less how you check for collisions, loop through the entities and see if they hit any other entities, there are certainly grounds for improvement. For example, if you have A, B and C, once A checked against C, when it comes to C's turn, you don't need to check against A. So then you can implement it as a list, and pop once an entity has been tested against all others, remove it from the list. This is a simple optimization you can make after the fact. Next you can start looking in to occlusion. Where instead of going through all entities you go through only the entities within a certain distance for example. Then if you find yourself with too many entities, you can start looking at alternative storage structures that support partitioning, like a b-tree.

So, to put that simply... looping through all the entities checking for collisions will work. It's not ideal, but it is what you should start with. From there, you can optimize and improve and learn a hell of a lot more about why one way is better than another in a given situation. Finding a framework or being told a better way to do it will be doing you a disservice.

Thanks for the reply! I'm also now bookmarking your signature's tutorials ph34r.png

I agree with what you've said, in that I should start with baby steps. It's just I look at my brute force loop code and can't help but be disgusted. I see your point in:


Finding a framework or being told a better way to do it will be doing you a disservice.

However, that's the problem I'm facing at the minute. I'm not entirely sure how to find more efficient ways myself, though I'm about to look up tutorials on the things you've mentioned like occlusion. I suppose I was asking to skip too much when I asked about game engines, it's just that I wasn't sure if I should be using them to speed up learning. Perhaps what I should have asked for is tutorials?

I agree about trial and error. However I'd like to add that using resources is also a good thing. There are books about how to make engine components, like Logging, Resource Management, Rendering ect...

If you are doing 2d I would suggest reading the new SFML2 book in my signature. They build a large framework in it.

Also there are a few books about 3d engines that go in depth into the components of an engine. Some good ones are the links below.

I read this one, its good for learning about each engine component seperately.

http://www.amazon.com/Game-Engine-Design-And-Implementation/dp/0763784516/ref=sr_1_3?ie=UTF8&qid=1383156729&sr=8-3&keywords=game+engine

I read this one too, its good for learning how to write an entire 3d engine from scratch

http://www.amazon.com/Game-Coding-Complete-Fourth-Edition/dp/1133776574/ref=sr_1_4?ie=UTF8&qid=1383156774&sr=8-4&keywords=game+engine

I haven't read this one but people seem to like it

http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135/ref=sr_1_1?ie=UTF8&qid=1383156774&sr=8-1&keywords=game+engine

If this post or signature was helpful and/or constructive please give rep.

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

// Easy to learn 2D Game Library c++

SFML2.2 Download http://www.sfml-dev.org/download.php

SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/

// Excellent 2d physics library Box2D

http://box2d.org/about/

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

Thanks for the reply! I'm also now bookmarking your signature's tutorials ph34r.png

I agree with what you've said, in that I should start with baby steps. It's just I look at my brute force loop code and can't help but be disgusted. I see your point in:


Finding a framework or being told a better way to do it will be doing you a disservice.

However, that's the problem I'm facing at the minute. I'm not entirely sure how to find more efficient ways myself, though I'm about to look up tutorials on the things you've mentioned like occlusion. I suppose I was asking to skip too much when I asked about game engines, it's just that I wasn't sure if I should be using them to speed up learning. Perhaps what I should have asked for is tutorials?

Again hands on is the best way to do it. There arent actually a ton of tutorials or books about optimization, especially not aimed at the beginner level. You can get things like Game Programming Gems, but those books are aimed more towards experienced game developers.

My suggestion to you, implement it however you can, clean your code up until you are happy with it, then create a thread here or somewhere else asking for recommendations on how to improve it. This really is one of those things experience will teach you.


If you are doing 2d I would suggest reading the new SFML2 book in my signature. They build a large framework in it.

I'll be having a look at those for sure, since 2D is definitely the direction I'll be going for now until I feel comfortable.


Also there are a few books about 3d engines that go in depth into the components of an engine. Some good ones are the links below.

Those books seem very interesting and I notice that the Game Engine Architecture book has a segment about good C++ coding practices. Hopefully these books will answer the question I originally had which was:"What the hell does a game engine even do?"


My suggestion to you, implement it however you can, clean your code up until you are happy with it, then create a thread here or somewhere else asking for recommendations on how to improve it.

Great! I'll be experimenting using your C++ with SFML and 2D Gamedev math tutorials so I hope you'll keep imparting wisdom on such things.

One thing; as I mentioned in my original post- I've been toying around with OpenFrameworks. The reason for it is that, to my understanding, it wraps a whole bunch of libraries into one which seems to be similar to what SFML does. Graphics, audio, windows, events, some math, etc. Would you have any idea if SFML does anything special that OpenFrameworks can't do? At the moment, OF provides a very easy interface to FMOD which I need for Fast Fourier Transforms. I'm hoping I could keep a portion of my code using OF.

To be honest I have zero experience with open frameworks, sorry.

I’ve written a tutorial on a very fast quadtree structure that can be used to speed up collision tests with each other, the player, edges of the screen, etc.

Efficient Instant-Insertion Quadtrees

It performs extremely well even on low-end devices, but it is not a good starting point if you want to learn about quadtrees in detail, although I doubt it is too advanced to figure out if you put your mind to it.

A quadtree of any kind (mine or your own) would be the next step up in looking at how to get performance out of collision detection and there is plenty of material online about their concepts.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


Efficient Instant-Insertion Quadtrees

Thank you for the reply but my eyes melted a little. I think I understand the premise but the implementation is something that will probably take a while to wrap my head around.

Will you be using physics in your game? If you are, libraries like Box2D will do the collision detection for you and you just handle it in the callback functions it gives.

This topic is closed to new replies.

Advertisement