Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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 thought and is it possible?  (Read 928 times)
0 Members and 1 Guest are viewing this topic.
Offline subless

Junior Newbie





« Posted 2012-09-06 11:57:48 »

I was thinking, since I am a visual learner I want to visually put my maps together from the image tiles, and save them as one big picture(similar to a spreadsheet I guess). Lets say that my tiles are going to be 40 x 40 pixles.

Instead of checking a map tile against the player's position for collision detection, would it be possible to check an array of the exact same size of the tilled map isself?

Let me explain...

I'd like to have an invisible grid laid on-top of the map. Each grid cell will be exactly the same size as each tile 40 x 40 pixles. Each cell will either have a value of 1 for true or 0 for false.

Would it be possible to check the array/grid for all the true values and let the player be-able to walk in those cells?

Sorry for my horrible explaining skills. Look at the photo below to get an idea. The bottom line is instead of checking the map for player collision, I'd rather just allow the player's character to walk in the cells that have a true(1) value. Since the array will be the exact size as the map, it will look as if the player is actually walking on the map, when the player is actually walking threw the array/grid cells.

The brown blocks are walls that the player shouldn't be able to walk through. Therefore the brown blocks would hold a 0(false) value. The gray is the walk-able area which holds the 1(true) value, letting the methods of character movement know that the player is allowed to move in those areas. The green dot is the player.

It just seems it would be easier and processer friendly to check a boolean value vs checking a players position, then having to check the tiles position and then having to compare the two for collision detection.



If this is indeed possible it would make map creation and checking for collision detection much easier! Even though if it is indeed possible there wouldn't be any need for collision detection since the player wouldn't be allowed to walk anywhere with a false value set in the array in the first playce Smiley

Thanks in advance for any ideas or replys.
Offline Sammyster

Senior Newbie


Medals: 1



« Reply #1 - Posted 2012-09-06 13:09:20 »

Hello subless!

I belive there is an excellent tutorial for this over at cokeandcode.com if you havent checked that out yet!

A bit rough but all you should need to do is to declare an array wich holds the values you want, would be BLOCKED (0) and CLEAR(1) in this case.
Then you simply compare the players position to find out whether the tile you try to move too is clear or not.

something like this:
1  
2  
3  
4  
 public boolean moveable(int playerX, int playerY) {
        //return true if this happen- coords from player move
       return blockedData[ playerX ][ playerY ] == CLEAR;
    }


Sorry for a terrible explanation, but take a look here http://www.cokeandcode.com/index.html?page=tutorials  should cover something like this in greater details:)
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (128 views)
2013-05-17 21:29:12

alaslipknot (135 views)
2013-05-16 21:24:48

gouessej (166 views)
2013-05-16 00:53:38

gouessej (158 views)
2013-05-16 00:17:58

theagentd (170 views)
2013-05-15 15:01:13

theagentd (155 views)
2013-05-15 15:00:54

StreetDoggy (199 views)
2013-05-14 15:56:26

kutucuk (223 views)
2013-05-12 17:10:36

kutucuk (222 views)
2013-05-12 15:36:09

UnluckyDevil (226 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.079 seconds with 20 queries.