Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (530)
games submitted by our members
Games in WIP (512)
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  
  Detecting a particular tile in a tile map HELP!!!  (Read 1195 times)
0 Members and 1 Guest are viewing this topic.
Offline moonknightskye

Senior Newbie




^_~! love is in the air


« Posted 2004-10-29 03:49:46 »

Wink hi. im currently developing a bomberman type of game  . The character is fixed at the center of the screen... the floor does the movement.

THE PROBLEM:
I have a boulder in the game (which is obviously , the player can't pass though). My question is how can i detect that my player is on a tile that is a boulder so that i can have a condition that the player can't advance more? i am talking about tiledLayer here... im planning to use sprites instead but my game is already flooded by sprites and i want to retain the tiledLayer.

I have already read a topic here which has the same problem but i didnt got it coz im a newbee here... i just started 2 weeks ago for my OJT. please, if you can give me the simplest and detailed code that a newbee can understand... PLEASE I BEG YOU... HELP me. thanks in advance! Cheesy


PS:
this is the code i used

player.collidesWith(backgroundTiledImage,true)
                System.out.println("you collided to the tiled image");

but i want to detect only the collision between a particular tile in the tiledLayer(eg. wall,boulder) Wink

At the dark MOON, a KNIGHT will appear to clear the SKYE.

MABUHAY ANG PILIPINAS!
Offline Serethos

Junior Member




Java games rock!


« Reply #1 - Posted 2004-10-30 10:50:40 »

oehm, as far as im am informed even a tiledlayer uses indexes for the tiles. far the simplest solution would be to have a formula for whicht tile is a boulder.
e.g. all tiles after index 30 or whatever ..

btw:
i dont understand you code snippet. there should be a sourrounding if-clause, right ?
also, for which reason do you pass the boolean 'true' value in the collide-method ?
Offline davidaprice

Junior Member





« Reply #2 - Posted 2004-10-31 08:53:21 »

The problem is that there isn't a method like:

 mySprite.collidesWith(myTiledLayer, boulderIndex, true);

i.e., you can check whether the sprite overlaps a non-transparent part of the tiled layer, but you can't check whether it overlaps a tile with a particular index.

Sprite and TiledLayer provide no solution to this. However, you must have created the tiled layer from some array of index data; just keep this array around, and check against it using your own code.

For example code, download Forum Nokia's example 'MIDP 2.0: Introduction to the Game API v1.0' (in the Documents->Java section). See the method containsImpassableArea in the class Field: it does exactly what you're asking for.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline moonknightskye

Senior Newbie




^_~! love is in the air


« Reply #3 - Posted 2004-11-02 07:50:12 »

HI GUYS! thanks for the ones who read and replied... I finally got how to detect a particular tile in the tiledLayer. you must hard code it.

e.g.

you initialise the tiledLayer; assuming the tiles is 25x25
. it means that tile[0][0] is from 0 to 24 pixels in X and Y axis.
tileX = new int {0,25,50,75,10};
tileY= new int {0,25,50,75,10};
map = new int[][] ={
{0,0,1,1},
{0,0,1,1},
{0,0,1,1},
{0,0,1,1}
};

the method to determine a particular tile is...
for(i =0,i<4,i++){
if((sprite.getX() >= tileX)&&(sprite.getX() <  tileX[i+1])
         tileIndexX = i;
if((sprite.getY() >= tileY)&&(sprite.getY() <  tileY[i+1])
         tileIndexY= i;
}
tiledLayer.getCell(tileIndexX,tileIndexY);

try to move your sprite and  make a code to print what kind of tile is underneath your sprite. try it to your application... it may help too. but if you have a better code for detecting a particular tile... pls POET IT HERE! thanks a lot! and i hope this code may help others.

At the dark MOON, a KNIGHT will appear to clear the SKYE.

MABUHAY ANG PILIPINAS!
Offline davidaprice

Junior Member





« Reply #4 - Posted 2004-11-02 12:40:51 »

How about:

 tileIndexX = sprite.getX() / 25;
 tileIndexY = sprite.getY() / 25;

By the way, notice that  in your line:
  tileX = new int {0,25,50,75,10};
that last number should be 100. I assume that's just a typo. Smiley

But, notice that your solution assumes that the sprite is just a point, i.e. 1x1 pixels.  In reality, your sprite has width and height. This means that it could easily be overlapping several cells at the same time. Do go and check out that Forum Nokia example: it contains example code for exactly this problem. No point reinventing the wheel!
Offline moonknightskye

Senior Newbie




^_~! love is in the air


« Reply #5 - Posted 2004-11-02 12:58:47 »

tileIndexX = sprite.getX() / 25;
 tileIndexY = sprite.getY() / 25;

y did you dvided it  into 25? the program is supposed to get the value of i in the for loop to reference it to the current x&y position of a cell in tiledLayer...

uhh...

anyway... thanks again DAVID for your help. I'm gonna check that article you told me and see for myself how it can help me. again thanks and regards! and yeah... nice observation david on the size of the sprite (1x1) pixel.. you are right but i just tweaked my code to make it bigger to the actual size of my sprite... and now... im gonna check the article and compare which is better. THANKS!

At the dark MOON, a KNIGHT will appear to clear the SKYE.

MABUHAY ANG PILIPINAS!
Offline davidaprice

Junior Member





« Reply #6 - Posted 2004-11-04 12:15:20 »

Sorry it wasn't clear; those two lines replace your whole for loop. And you don't need tileX or tileY either.

Let's say your sprite is at (x=60,y=30). So tileIndexX = 60/25 = 2 (remember it's integer division) and tileIndexY = 30/25 = 1.  That's the same result your for loop would have produced, isn't it?
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.

xsi3rr4x (72 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (79 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (80 views)
2014-04-14 15:48:38

tom_mai78101 (104 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!