Subscribe to Stuck in an Infiniteloop        RSS Feed
-----

Easy Collision Detection

Icon 2 Comments
Or, how I love to not reinvent the wheel!

I was browsing this thread over in the Java forum and I wrote a quick diddy that has a square ping pong back and forth between two "walls", nothing fancy, but illustrates a concept we as programmers should take to heart: do not reinvent the wheel.


Sure, I could have written my own function to determine if two rectangles had intersection within the next "cycle", OR I could use java.awt.Rectangle's intersects() function. But...do I really need a homebrew solution for my rectangle? The answer is a resounding no, even if I was to make the movement more complex (angles, rather then straight horizontal motion), I still could utilize (or leverage if you're into buzzwords) the power of the standard Java library to meet my needs.


Here's a picture!

Posted Image


How awesome are pictures?


Source code can be found here.

2 Comments On This Entry

Page 1 of 1

NotarySojac Icon

17 December 2011 - 04:33 PM

Quote

How awesome are pictures?

Quite awesome.

Might you also have the liberty to share source code? I'm teaching a cousin Java and he might get a kick out of moving rectangles =)
0

KYA Icon

17 December 2011 - 06:02 PM
Source code can be found in this post. I'll add it to the post above as well.
1
Page 1 of 1

July 2014

S M T W T F S
  12345
6789101112
13141516171819
20212223 24 2526
2728293031  

Tags

    Recent Entries

    Recent Comments

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)