Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  java grid collsions detection  (Read 1851 times)
0 Members and 1 Guest are viewing this topic.
Offline Xenon

Senior Newbie





« Posted 2012-08-31 14:59:17 »

hey guys i have been trying to browse youtube and JGO for any tutorials on grid based collision detection but i can't seem to find any also i need to be able to build maps out of blocks so i need the grid for that aswell Tongue any help appreciated as its my first game ever and im struggling a bit Tongue
Offline aazimon
« Reply #1 - Posted 2012-08-31 16:12:34 »

When you say grid collision, is each entity contained only inside a grid cells?
If you store all your entities in an array [ ][ ], then you can check neighboring cells, with a range of entity's x-1 to entity's x+1 and entity's y-1 to entity's y+1. Or just check the cell the entity is moving into.
For storing you can use Entity[ x ][ y ] (or Entity[ x ][ y ][ z ] ).

Aazimon
Offline Xenon

Senior Newbie





« Reply #2 - Posted 2012-08-31 22:06:11 »

i really don't know lol, never worked with a grid before but i am going to check for collisions with objects in the cell yes.. but i havfe no idea of how to create "the grid" and so on xD
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2012-08-31 22:07:33 »

Don't worry about problems too much before you've even started.

And the way Aazimon said will work. Can't/shouldn't have 2 different things on the same tile/cell.
Offline Xenon

Senior Newbie





« Reply #4 - Posted 2012-08-31 22:12:11 »

yea i see Tongue but does anyone know of any tutorials or just something that explains the way to make it ?
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #5 - Posted 2012-08-31 22:14:20 »

You're probably using java 2D, but oh well...
http://cokeandcode.com/index.html?page=tutorials/tilemap1
made by kevglass (duke on this forum)
it's for Slick, I think, but explains the idea pretty well. There's also an A* pathfinding tutorial there.
Offline Xenon

Senior Newbie





« Reply #6 - Posted 2012-09-01 08:15:37 »

yea but it still does not explain how to make the grid, it just repeats everything i have read elsewhere Tongue and i understand all of that i just don't know how to create the grid
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #7 - Posted 2012-09-01 17:19:36 »

Well, creating the grid is just taking an array[][]. I really don't know how you are attempting to make the grid. Are you using images, Java2D, OpenGL, Slick?

Regardless, if you want to make a simple 10x10 grid and your "block" objects are 16x16. Here is a snippet that might help (assuming Java2D).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
//You can use an array to store images
Image[][] blockarray = new Image[10][10];

public void render(Graphics g)
{
     g.setColor(Color.BLUE);
     for(int i = 0; i < 10; i++){
           for(int j = 0; j < 10; j++){
                 g.fillRect(16*i, 16*j, i, j);//Normal grid with Blue rectangles
                g.drawImage(blockarray[i][j], i*16, j*16, <Component>);//Image grid
          }
     }
}

Offline aazimon
« Reply #8 - Posted 2012-09-02 14:49:46 »

Are you wanting to make the Grid lines?
This piece of code will draw grid lines for you.
1  
2  
3  
4  
5  
6  
7  
8  
9  
g2d.setColor(Color.BLACK);
// make the lines dotted lines.
g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[]{3.0f, 3.0f}, 0.0f));
for (int x = 0; x< totalWidth; x+= gridWidth) {
  g2d.drawLine(x, 0,x, totalHeight);
}
for (int y = 0; y< totalHeight; y+= gridHeight) {
   g2d.drawLine(0,y,totalWidth,y);
}
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 (23 views)
2014-08-19 09:29:53

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

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

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

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

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

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

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

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

BurntPizza (66 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!