Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Game problem

 
Alec Porter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Wouter says, post up some of your code

We can have a look and offer suggestions

 
Sarah Becker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5813
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic