Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1256 times)
0 Members and 1 Guest are viewing this topic.
Offline zainuluk

Senior Newbie




Java games rock!


« Posted 2003-01-15 19: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: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2003-01-15 19: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 09: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.

 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (73 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (44 views)
2014-09-07 01:13:42

Longarmx (27 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
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!