Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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 434 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...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
  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...
Online 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 soldat.pl 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: http://info.sonicretro.org/SPG:Solid_Tiles which has a lot of information about doing tile based collisions.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!