Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
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  
  Collision Detection  (Read 1725 times)
0 Members and 1 Guest are viewing this topic.
Offline Raildex

Senior Newbie

« Posted 2013-07-23 10:07:32 »

Hey there.
I'm currently thinking of an algorithm for a collision detection.
I want to implement various tile-collisions...
  public static final byte COLL_THROUGH = 0;
  public static final byte COLL_SOLID = 1;
  public static final byte COLL_SLOPE_R = 2;
  public static final byte COLL_SLOPE_L = 3;
  public static final byte COLL_12SLOPE_R = 4;
  public static final byte COLL_22SLOPE_R = 5;
  public static final byte COLL_12SLOPE_L = 6;
  public static final byte COLL_22SLOPE_L = 7;
  public static final byte COLL_14SLOPE_R = 8;
  public static final byte COLL_24SLOPE_R = 9;
  public static final byte COLL_34SLOPE_R = 10;
  public static final byte COLL_44SLOPE_R = 11;
  public static final byte COLL_14SLOPE_L = 12;
  public static final byte COLL_24SLOPE_L = 13;
  public static final byte COLL_34SLOPE_L = 14;
  public static final byte COLL_44SLOPE_L = 15;
  public static final byte COLL_STAIR_R = 16;
  public static final byte COLL_STAIR_L = 17;
  public static final byte COLL_14 = 18;
  public static final byte COLL_24 = 19;
  public static final byte COLL_34 = 20;
  public static final byte COLL_WATER_SURFACE = 21;
  public static final byte COLL_UNDERWATER = 22;

Here for a graphical visualisation:

Does someone have an Idea how I should start with this?
I've never done something like that before...
Offline trollwarrior1
« Reply #1 - Posted 2013-07-23 10:28:41 »

You need to figure a way to detect collision in a triangle. Since all shapes are made up of triangles, you can then detect collision in any shape. I don't know how to detect collision in triangle, sorry. But it's a start Cheesy
Offline jonjava
« Reply #2 - Posted 2013-07-23 13:15:27 »

I'd not go with the triangle shape, these are pixel perfect in my opinion. Simply save the height at each pixel on the x-plane and do pixel perfect collision after you've culled the obvious collisions (those that don't even fit inside a full rectangle).

You can easily get the height if, for instance, your images are fully transparent on places you don't want covered (or any other color you decide is your "background color" or whatever) by looping through the image and checking the height of each pixel that is part of the shape and if it's higher than the one stored already then overwrite it etc.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Chili

Senior Newbie

Projects: 1

« Reply #3 - Posted 2013-07-23 19:56:44 »

Make polygons, and use ShapeIntersect for collisions. If you ask me.
Offline 666DemonThe

Senior Newbie

« Reply #4 - Posted 2013-07-24 13:25:37 »

make more then one rects for one image and detect for all of them togeter i think it will work try it out then msg me Cheesy
Offline jonjava
« Reply #5 - Posted 2013-07-24 14:14:14 »

If they are tiles like you've shown and they're pixel perfect you really need pixel perfect collision or it's going to look weird with polygons or shapes as collision masks.

Since all of the tiles you've shown are filled bottoms up you can simply store the height of each pixel on the tile and use that information when testing collisions with objects on the tile.

However, if your levels are made up of a lot of big polygons (like e.g.) then obviously this tile based pixel perfect method is a complete waste of time.

Offline UprightPath
« Reply #6 - Posted 2013-07-24 14:17:34 »

Look at my project (Perils of Alchemy, it's somewhere in the forum and I'm being lazy). Also, you can look at: which has a lot of information about doing tile based collisions.

Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

nelsongames (2629 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!