Sprite Logic

Nibbie
Posts: 1
Joined: 2009.05
Post: #1
Hi People,
I am a complete newbie to the forum so please be gentle Smile
I am in the process of learning to develop in obj-c, and all is going well for me, so i am taking on the challenge of writing a 2D game for my own learning.
I am currently in the position where I would like my "baddies" to have a little bit of intelligence, and wonder if you would be able to guide me a little.
I am torn with how to create the bad guy logic as far as:

- Do I create one method for my bad guys (there will be about 10 initially, and then as they die this will decrease obviously) and use something like a random number generator to select which one will do the chasing first, second, etc. like:

-(void)baddieLogic {

// pick a random number between 0 and 9
// depending on that number pick that baddies and go after the goodie.
// start this again.

}

- Do I have a separate methods for each bad guy and randomly choose which one I want to call and have him / them enter play through my main game loop, like :

-(void)BaddieOne {
// go after the goodie
}

-(void)BaddieTwo {
//go after the goodie
}

etc etc

- Am I totally missing the point of this fundamental question, and should I run away and read up more on "Baddy Logic" somewhere.

- Is one method more efficient that the other, as this is such a fascinating challenge, and hopefully if i can get all of this working, i would create some sort of a tutorial as I have learnt so much from this already, yet there seems so much more to learn.

Thank you in advance, and I look forward to your advice.
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2009.05
Post: #2
(First post, woot!)

This is a perfect example of object-oriented programming. Your "baddies" and "goodies" should be objects. From your syntax I'm assuming objective c so the basic idea is:
1. Create a class for each type of thing you need to represent, for example a class Goodie and a class Baddie.
2. Create a manager class that represents the current game state, like GameManager.
3. GameManager will have member variables for instances of the above 2 classes, and use them as required to implement the game logic.
4. Since Baddies need to chase Goodies, Baddie might have a method
- chase(Goodie*)
which performs whatever logic is required.
5. When you need to do the actual chasing in the game, you might select a Baddie from a list at random, and call that method. You don't need a separate method for each Baddie, because that would be impossible to maintain if the number got high or you needed to change them all at once.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Have Hierarchical Sprite Tree, Need To Transform Screen X,Y To Determine Which Sprite kalimba 5 6,005 Mar 16, 2009 06:31 PM
Last Post: AnotherJake
  Mouse Picking (My Math/Logic) hangt5 5 4,727 Apr 20, 2005 01:53 PM
Last Post: hangt5