Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
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 715 times)
0 Members and 1 Guest are viewing this topic.
Offline scanevaro
« Posted 2013-07-30 22:16:35 »

Hello guys.

I been working on a prototipe for a game like Mr.Driller and this is what i got so far:
<a href="http://www.youtube.com/v/qGc0TqfxUdA?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/qGc0TqfxUdA?version=3&amp;hl=en_US&amp;start=</a>
As you can see, its not perfect, there some things in need of improvement, but sence its a prototipe, its k.

So question is:
How to make blocks drop when theres no block below?
i have worked with some code but cant seem to make it work.

p.s.: prototipe is for Android and uses Opengl ES

Thanks!
Offline Herjan
« Reply #1 - Posted 2013-07-30 22:22:26 »

I think you have a grid like this:
grid[20][100];

ok so grid[15][90] = air;
1  
2  
3  
4  
5  
6  
7  
for(int i = 91; i <= grid[0].lenght; i++){
  if(grid[15][i] != air){
    grid[15][i-1] = grid[15][i];
    grid[15][i] = air;
  }else
    break;
}

This should work Wink

Offline scanevaro
« Reply #2 - Posted 2013-07-30 22:29:32 »

I think you have a grid like this:
grid[20][100];

ok so grid[15][90] = air;
for(int i = 91; i <= grid[0].lenght; i++){
if(grid[15] != air){
grid[15] [i-1] = grid[15];
grid[15] = air;
}
}

This should work Wink

BTW, super weird bug [iii] doesnt get displayed

So... wait... first: im not a very experienced programmer, i just drawed the blocks on those positions.
your saying i first should draw the blocks with this grid?

Please help, i kinda know what you mean, but i have the blocks just drawed there
every block has a model a view and a controler too
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herjan
« Reply #3 - Posted 2013-07-30 22:39:13 »

Ok, what I should do is this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
int[][] grid = new int[width][height];
Image[] image = new Image[3];
image[0] = xImage;
image[1] = yImage;
image[2] = zImage;

for(int x = 0; x < grid.length; x++){
  for(int y = 0; y < grid[0].length; y++){
    grid[x][y] = (int) (Math.random() *3); //random generated 'world'
 }
}

public void render(){
  for(int x = 0; x < grid.length; x++){
    for(int y = 0; y < grid[0].length; y++){
      if(grid[x][y] != air)
        draw( image[ grid[x][y] ]); //draw our random generated 'world'
   }
  }
}

public void deleteBlock(int x, int y){
  grid[x][y] = air;
  for(int i = y+1; i <= grid[0].lenght; i++){
    if(grid[x][i] != air){
      grid[x][i-1] = grid[15];
      grid[x][i] = air;
  }
}
}


Code is most of the time easier to understand then words Smiley

Offline scanevaro
« Reply #4 - Posted 2013-07-30 22:51:01 »

Ok, what I should do is this:

1  
...


Code is most of the time easier to understand then words Smiley

You Sir, are amazing.
Thank you a LOT.
Offline ReBirth
« Reply #5 - Posted 2013-07-31 04:24:30 »

Some little fix
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void deleteBlock(int x, int y){
    grid[x][y] = air;
    for(int i = y+1; i < grid[0].length; i++){
        if(grid[x][i] != air){
            int _i = i - 1;
            while (grid[x][_i] != air && _i >= 0) {
                _i--;
            }
            if (_i >= 0) {
                grid[x][_i] = grid[x][i];
                grid[x][i] = air;
            }
        }
    }
}

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.

pw (15 views)
2014-07-24 01:59:36

Riven (14 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (15 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!