File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "get ground postion" Watch "get ground postion" New topic
Author

get ground postion

sudde gameeef
Greenhorn

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
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

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
Greenhorn

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


getter



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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get ground postion