• Post Reply Bookmark Topic Watch Topic
  • New Topic

Space Invaders Collision detection

 
Alaric Mustoe
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have some code all of it works but I can't figure this one out.

Along with the objects




Can you help me out it is urgent
 
Alaric Mustoe
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if the bullet hits the saucer or the enemies for it to repaint without it there
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is far too much code for us to read. I can see a few things, however.
I can see a class which appears to encapsulate game logic and implement listener interfaces. It is also much bigger than the others, which makes me suspect it is a God class. That is a well‑known “anti‑pattern” and should be changed.
 
Les Morgan
Rancher
Posts: 717
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alaric Mustoe wrote:So if the bullet hits the saucer or the enemies for it to repaint without it there


Alaric, here is a link to a question that was asked yesterday on collision detection: Point Subtraction The theory on collision detection is explained there and you will be able to see how to detect collisions.

As far as movement and removing the object from the screen when the collision happens here comes some stern words: you basically need to go back and do what I suggested when this all started. You need to make each object responsible for it's own actions. Each of your ships, bullets, and barricades needs to be added to a screen objects' collection and take activation from the timer event and check if they hit something or if they move. If they hit something they need to be removed from the screen objects' collection so they no longer receive activation from the timer event.

You are not doing this.

When you started this project, I gave you a basic animation/game loop, container, that you could experiment with and offered help for what ever you may need. You didn't like learning enough Java to actually progress down the path of making the classes for your screen objects properly, so you have been begging code from the community ever since. You have reached the point now where you need to man up, and go back and fix your object design. That means you have to actually start learning Java, then study 2D animation and how that applies to object oriented programming in Java. I suggest you take this opportunity to go back and learn Java, then do some more simple animations and put emphasis on making objects to interact in your game container--your animation/game loop.

If I would have known you were not going to experiment with objects while learning Java, but just jump in over your head and try to get a game up and running, I would have never given you the container to use. It's time to go back and learn enough Java, so you can at least know what people are talking about when they offer you help.

Les

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!