Archived

This topic is now archived and is closed to further replies.

nmoogn

Beyond the (extremely) basics

Recommended Posts

Hi, I am just trying to get my head around object-oriented programming, and game programming and I have gotten a bit stuck. I got off to a good start, and made a simple sideways shoot''em-up style game. It was all going good - you move around the screen, shoot the baddies, you get points, if you hit a baddie *BOOM* you''re dead, start again. (I was just doing this in DHML with javascript - I am not interested in the code at the moment, just good design practises - I kept getting bogged down in directX!. anyways, the start was: www10.brinkster.com/nmoog/game/spacey.html) I was feeling confident then... Ok lets see, a new baddie... and an attack wave a-la-galaga... hmm... so far in my demo I create a "baddie controller" with 5 or so baddies in it. every frame I give a baddieController.move() which moves each baddie, and when one gets of the screen it gets put back on the other side... every frame also calls baddieController.checkForCollision(bulletController) which check each bullet the player has fired. If it gets shot and killed, every frame it has a one in 20 chance of bieng re-born. Every frame also does a Player.checkForCollision(baddieController). For some more baddies should I do a player.CheckForCollision(AnotherBaddieController) Oh, its starting to look a bit messy an inefficient now. And its really boring shooting the same 5 baddies. I need to make some kind of level... But how should I make a GROUP of creatures? How do I make a level of groups of creatures? If I had a bunch of classes like... class bullet extends ammunition (this.power=5) class kingkong extends creature (this.move{jumpUpAndDown()}) class anaconda extends creature (this.move{slideAround()}) class aliG extends creature (this.move{popNlock()}) class powerUp extends gameObject class superGun extends gameObject ...how do I make a level so that after starting at pixel(0,0) and moving right for 100 pixels a few random anacondas slide by, then after 150 pixels a powerUp appears, then after 200 pixels a wave of 10 kingkongs appear in a v-shaped pattern, then after 300 pixels the a superGun and the end-of-level-baddie aliG appears at location (300,50), and moves in a circle breakdancing? How can I elegantly do collision detection between each player bullet, and each creature? How about each creature and the player? Do I put the collision detection in the player class, or the ammunition class or the creature class or all or what?!! Aaargghh! ANY help would be appreciated!

Share this post


Link to post
Share on other sites
When I did something similar:

I put enemy-bullet collision detection (CD) in the bullet class. It looped through each bullet which checked if it collided with any enemy.

I made the player class do CD with each enemy.

All enemy, player and bullet classes were sub-classes of the big "cObjects" class. This controled pointers to its sub classes.



- Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda

Share this post


Link to post
Share on other sites
Oh, so all object derive from one parent class? How did you store the overall structure of each level? How did the objects know it was their cue to enter stage left?!

Share this post


Link to post
Share on other sites