Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Checking collision between a Shap and a Rectangle  (Read 2131 times)
0 Members and 1 Guest are viewing this topic.
Offline Fiskpotatis

Junior Newbie

« Posted 2013-05-18 12:33:06 »

In my game the player uses a Rectangle for his bounding box, he can do this because I only need to rotate the player image and not the acctual rectangle but for a eletric beam that one of the bosses have I need to use a Shape because I need to rotate the acctual bounding box and not only the image. The problem is that because I have one Rectangle and one Shape I can't use rectangle.intersect(shape) nor rectangle.intersect((Rectangle)shape), I also can't use the Shapes getBounds() method because that woud defeat the purpose of using a Shape so how would I be able to check the collision between the rectangle and the shape? or is there a way that I can rotate a rectangle on instead of a shape (I use the createTransformedShape instance of an AffineTransform to rotate the shape )?
Offline relminator
« Reply #1 - Posted 2013-05-18 14:07:35 »


Also, because your shapes are just rotated boxes, you can optimize it further by projecting 1/2 of the edges.
Offline Opiop
« Reply #2 - Posted 2013-05-18 14:13:59 »

Fix the link?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline relminator
« Reply #3 - Posted 2013-05-18 14:31:21 »

Fix the link?

Sorry using phone right now.
Offline Opiop
« Reply #4 - Posted 2013-05-18 14:32:47 »

No problem, I got it
Offline Andre Lopes
« Reply #5 - Posted 2013-05-19 01:54:39 »

Seems a little complicated. I will print and study that because, well, it seems fun.

Thought, i wonder if theres an easier way without much precision. Tongue
Offline DrZoidberg

JGO Coder

Medals: 21

« Reply #6 - Posted 2013-05-19 11:40:03 »

Sure, you can use java.awt.geom.Area
To test if 2 arbitrary shapes intersect you just have to do this
Area area = new Area(shape1);
area.intersect(new Area(shape2));
boolean isIntersecting = !area.isEmpty();

You can even test how much they intersect with area.getBounds2D().
Pages: [1]
  ignore  |  Print  

hadezbladez (330 views)
2018-11-16 13:46:03

hadezbladez (169 views)
2018-11-16 13:41:33

hadezbladez (328 views)
2018-11-16 13:35:35

hadezbladez (78 views)
2018-11-16 13:32:03

EgonOlsen (2168 views)
2018-06-10 19:43:48

EgonOlsen (2195 views)
2018-06-10 19:43:44

EgonOlsen (1372 views)
2018-06-10 19:43:20

DesertCoockie (1998 views)
2018-05-13 18:23:11

nelsongames (1641 views)
2018-04-24 18:15:36

nelsongames (2291 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!