| Author |
Game problem
|
Alec Porter
Greenhorn
Joined: Sep 05, 2010
Posts: 29
|
|
|
I'm having a problem with my game. I have two classes the problem is the the enemy class needs to know where the play is so it can follow it and the player class needs to know the enemy class to know possible enemys on the screen that it can intersect with. So for example A( B b) B( A a). I'm not sure how to solve this.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Sounds like the Enemy objects need a reference to an array/Collection of Players and Player objects need a reference to an array/Collection of enemies. Try something and if you can't solve it, shows us what you build and why tell us it failed. Then it will be easier to help you.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
James Elsey
Ranch Hand
Joined: Dec 21, 2007
Posts: 228
|
|
Like Wouter says, post up some of your code
We can have a look and offer suggestions
|
Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
|
 |
Sarah Becker
Greenhorn
Joined: Nov 14, 2010
Posts: 5
|
|
You could make a grid/tile layout for your game and then just check if an enemy and the player are in the same tile.
Or you can calculate rectangles (using java's Rectangle class) from the sprite images and see if they collide.
You can use these ways to detect collision with any game objects.
Cheers,
Sarah
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3050
|
|
Sarah Becker wrote:You could make a grid/tile layout for your game and then just check if an enemy and the player are in the same tile.
Interestingly, this is how pac-man is able to 'sneak past' the ghosts.
|
 |
Sarah Becker
Greenhorn
Joined: Nov 14, 2010
Posts: 5
|
|
Stephan van Hulst wrote:
Sarah Becker wrote:You could make a grid/tile layout for your game and then just check if an enemy and the player are in the same tile.
Interestingly, this is how pac-man is able to 'sneak past' the ghosts.
And all the surrounding tiles of all moving sprites. Sorry about that.
|
 |
 |
|
|
subject: Game problem
|
|
|