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 (406)
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  
  COLLISIONS???? HELP ME PLEASE!!!!!!!  (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
Offline zainuluk

Senior Newbie




Java games rock!


« Posted 2003-01-15 20:02:40 »

Ok here is all the collsion part of my game...hope someone can help.

Ok this is the main class where everything is controlled
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
class MyGame{
...
marioCharacter = new MainCharacter(.....some parameters...);
....
//here the background is controlled
bk_level_1 = new Scene(...some parameters...);

...
//test for collision between main character and a particular tile
public void collisionCheck(Scene _level,MainCharacter _char){
      if(_level.collisionTest(_char,173)){
            collision = true;
      }
      else {collision = false;}
}

....

}


This next class is one one for the maincharacter....I will just show how the bounding box is set up every cycle.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
class MainCharacter{
...
public void updateBounds(){

      boundX = current_pos.x()+20;
      boundY = current_pos.y()+10;
      boundWidth = tileWidth-28;
      boundHeight = tileHeight-18;
      character_bounds.setRect(boundX,boundY,boundWidth,boundHeight);
}
...
}


The next class two classes are the Scene class and the tile class. The Tile class simple is each tile . here a bounding box is created round the tile.
1  
2  
3  
4  
5  
6  
7  
8  
class Tile{
...
public void updateBound(int x, int y){
         tile_bound.setRect(x,y,_width,_height);
}
...

}


1  
2  
3  
4  
5  
6  
7  
class Scene{
...
public boolean collisionTest(MainCharacter _character,int tileNum){
      return _character.getCharacterBounds().intersects(bkCollection[tileNum].getBound());
}
...
}


ok most of it should be obvious, but it only detects some tiles.
can anyone help. thanks.
If you need anyother info then just ask.

Offline Orangy Tang

JGO Kernel


Medals: 48
Projects: 11


Monkey for a head


« Reply #1 - Posted 2003-01-15 20:30:00 »

Firstly, loose the caps  Shocked

'Only detects some tiles' is pretty vauge. Try and narrow it down to something more specific. Your first test should probably be to draw all of your bounding boxes to test if they really are where you think they are.

The test between 2 bounding, axis aligned boxes should be trivial but theres plenty of references on the 'net if you look. More likely is MyGame::collisionCheck() method being the culprit. Are you just checking for a single hard-coded other object, or is there multiple ones in your level? If multiple, then make sure you're checking all the tiles you're overlapping with, not just the one you're actually on. If theres just the single then definatly investigate your intersects() method in detail...

(oh, and whats with the _variables prefix? Looks like the old C style of labling member variables  Angry, but i've never seen anyone use it for Java before..)

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline zainuluk

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-01-16 10:33:42 »

yes, there are multiply tiles of the same tile used. However I detect collisions on some tiles but not on other....for example.......if the level consists of a black background with several clouds each made up of two tiles, say 12, and 13. The when my character movesover a tile it wll detect some number '12' tiles but some number '12' tiles will be undetected.
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 (76 views)
2013-05-17 21:29:12

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

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

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

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

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

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

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

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

UnluckyDevil (185 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.143 seconds with 20 queries.