• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collision Detection  RSS feed

 
Alaric Mustoe
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that you compare the x and y of said projectile to the x and y of the other object. Just don't know how to implement it. Could I get an example?
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you first show us what this 'said projectile' and 'the other object' are?
 
Alaric Mustoe
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the object is defined as
so then I have this and am working on an enemy class to also define seems more efficient than defining each one.
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see...

Well, some remarks could (and should) be made, but I have two questions first:

1) if I have an instance of this 'bullet' class, how should that instance behave? I.e. is it
supposed to fly around the screen in any direction, is its lifetime iimited, and so on.

2) and have you tested your class? If so, what were your findings?

About the collision:
suppose I give you two rectangles, each specified by the coordinates of the upper left
point, its width and height, can you come up with an algorithm that determines if
these two rectangles overlap?
 
Stephan van Hulst
Saloon Keeper
Posts: 7003
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that java.awt.Shape has intersects() methods.

If all of your geometric objects have rectangular shapes, you can use this method and you're done.

Otherwise, you can create a java.awt.geom.Area from a Shape, and intersect the areas of your two objects. If the intersection is empty, you know there is no collision.
 
Liutauras Vilda
Marshal
Posts: 3832
204
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is here? Please explain your intention.

Also why your fields are not private yet?

What 200 represents? dest? maybe destination? destination to target maybe (destinationToTarget)? Don't use magic number, use descriptive variable name.
Also, why you're not using conventional variables in the for loop as for example i and j ? "c" could make people to search the meaning of it as it is unusual choice.

[edit] And one more thing. Class names suppose to start with an Upper case according to the convention. Please get this habit and follow it.
 
Liutauras Vilda
Marshal
Posts: 3832
204
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where this 400 comes from and why 400?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!