Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (578)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / J2ME / Re: tile collission in MIDP 2.0 and scrolling? on: 2004-12-02 09:56:14
Is there nobody who has written a vertical scrolling game and knows how to make the spaceship collide with a tile?

Please help..... anyone who has the code or knows where to get it / other forums?

/Arnold
2  Java Game APIs & Engines / J2ME / tile collission in MIDP 2.0 and scrolling? on: 2004-11-30 07:28:57
Hi all!

I have the following problem - I want my airplane to be able to collide with a tile.

this are the methods I'm now using but they doesn't seem to work as I want them to...

In the GameCanvas class:

/*method to check for collission*/

boolean containsImpassableArea(int x, int y, int widths, int heights) {
int rowMin = y / tHeight;
int rowMax = (y + heights - 1) / tHeight;
int columnMin = x / tWidth;
int columnMax = (x + widths - 1) / tWidth;

for (int row = rowMin; row <= rowMax; ++row) {
for (int column = columnMin; column <= columnMax; ++column) {
int cell = tBakgrund.getCell(column, row);
if (cell == STOP_TILE) {
return true;
}
}
}
return false;
}

/*method to check for keystates and invokes containsImpassableArea */

private void checkKeys() throws Exception {

int keyStates = getKeyStates();

if ((keyStates & LEFT_PRESSED) != 0) {
if (sprit.getX() > 0
&& !containsImpassableArea(sprit.getX() - 4, sprit.getY(),
sprit.getWidth(), sprit.getHeight())) {
sprit.move(-4, 0);
sprit.setFrame(Cool;
} else {
sprit.setFrame(9);
}
}
/*the same on RIGHT_PRESSED, UP and DOWN*/


/* if no key is pressed */
if ((keyStates == 0)) {
sprit.setFrame(9);

if(containsImpassableArea(sprit.getX(), sprit.getY() - 4,
sprit.getWidth(), sprit.getHeight())) { scrolling = false; }
else{
scrolling = true;
}

}

/* the method that handles the scolling */

if (terrainScroll < 0 && scrolling == true ) {
terrainScroll += 2;
tBackground.setPosition(0,terrainScroll);
}

}//end of method checkkeys...

my tiles are defined in a two-dimentional array/matrice

ok.... why doesn't it work ...is it some kind of layerproblem (sprite and tiles not in the same layers)?

Perhaps someone has any code samples?

Thanks in advance!

/arnold
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

DarkCart (14 views)
2014-10-31 21:44:48

DarkCart (17 views)
2014-10-31 21:43:57

TehJavaDev (40 views)
2014-10-27 03:28:38

TehJavaDev (30 views)
2014-10-27 03:27:51

DarkCart (44 views)
2014-10-26 19:37:11

Luminem (26 views)
2014-10-26 10:17:50

Luminem (30 views)
2014-10-26 10:14:04

theagentd (36 views)
2014-10-25 15:46:29

Longarmx (64 views)
2014-10-17 03:59:02

Norakomi (62 views)
2014-10-16 15:22:06
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!