I am trying to create a game inspired by terraria, And Out starbound. But i only just started java coding, And i'm just making basics then after i learn all i need to learn on the basics i will re-code all i've done again and... Then thats where my game comes in. Now, What i'm trying to do is make collisions with My so called "craft" And that is the player, This is meant to be a player and the reason its called that is because its from a tutorial :P Anyway, So how would i get my craft(or player) To have collisions? And the same with blocks, Because like all games blocks and players have collisions, Forgive me if i'm sounding very newby... I'm new to all this java stuff. Anyway... Yeah so.. Too narrow down the question, All i need to know is how to create collisions for my player and blocks. Thank you!
Asked
Active
Viewed 684 times
0
-
2You should google for collision detection, there's a lot of information around the Internet. For starters, see [collision detection on Wikipedia](http://en.wikipedia.org/wiki/Collision_detection). – Dariusz May 14 '14 at 12:32
-
1Check http://www.jbox2d.org/ – mrak May 14 '14 at 12:33
-
In 2D detecting collisions isn't too difficult; its all about overlaps. What you then do once you've detected the collisions is where it gets complicated (but really there are physics libraries out there) – Richard Tingle May 14 '14 at 12:33
-
Here is a slightly related question giving an in-depth answer to handling object overlapping - http://stackoverflow.com/questions/21190553/circle-rectangle-collision-side-detection-in-libgdx – Mitch Connor May 14 '14 at 12:53
-
Sorry, havent check back in a while. Back, But I did some research before and it was all too confusing. I'll look at what you guys sent me though. – Luka ash May 17 '14 at 22:50
1 Answers
0
If you are doing this without any 3rd party libraries, you pretty much have to calculate it out for every object that you want to block movement. You take the x and y of your hero and then at every refresh, you see if it has hit some object. If so, you will block further movement to that side.
If you are using something like Slick tough, which is a nice library for making simple games, you can just use programs like Tiled, to make a tile map for your game, and your Java application can then just make a collision map from the objects from that map and then also on the fly, you will check if the hero has hit an object that belongs to the collision group.

Veske
- 547
- 1
- 4
- 15
-
I'll try it out in the morning. Currently it's almost 1 am. And i'm real tried. If it works i'll be sure to click the check on your answer. – Luka ash May 17 '14 at 22:54