aspose file tools*
The moose likes Beginning Java and the fly likes get ground postion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "get ground postion" Watch "get ground postion" New topic

get ground postion

sudde gameeef

Joined: Mar 21, 2013
Posts: 19
how to get ground postion, no matter where your player is standing.

2d array: (0=sky, 1=ground, 2=player)

so to get ground position i do this.

problem with above code is that it will only get me the last row postion and thats the ground postion. it wont take in count the ground above it.

so i did this in a loop. i am not sure what to do in if statment so it will give me ground postion, no matter where is player is standing.

Greg Charles

Joined: Oct 01, 2001
Posts: 2854

I would search for the player first. Once you find her, you might just have to subtract 1 from her height. Of course, that assumes that she's a well-grounded player.

I don't really understand either of your code snippets. "a" represents the array I guess. What's tile_size?
sudde gameeef

Joined: Mar 21, 2013
Posts: 19

i just change some of the stuff.

tile_size = 32;

this code justt making a rectange where there is ground and storeing in arraylist


this code loop though arraylist and see is player is touching the rectanges in arraylist.

this code will find the ground no matter where is the player. bc i getting player y postion.

but the problem is that 1st player will be touch the ground(1) so it will get player y postion + height and thats the ground postion. if he moves right than there is another ground block on top. so he touchs that and moves the ground up. and so on...

now notic if player moves left than he is no ground under him and he is not touching any ground blocks. so he should fall down untill he touch another block. but this doesnt happed. he just stays there and no ground block under him.

i tried this but didnt worked i dont know why.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 39436
sudde gameeef wrote: . . .

2d array: . . .
No, it isn’t. There is no such thing as a 2D array in Java. What you have is an array of arrays.

I have had to go back and correct some of the formatting errors in your post, because you have lines too long. I didn’t correct the inconsistent indentation, nor the use of tabs and spaces together, nor the identifier names which do not follow the conventions for this language.
subject: get ground postion