# get ground postion

Printable View

• March 26th, 2013, 05:44 PM
game06
get ground postion
how to get ground postion, no matter where your player is standing.

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

Code java:

```0001 2011 1111```

so to get ground position i do this.

Code java:

```int map_height = a.length * tile_size; int on_ground = map_height - tile_size;```

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.

Code java:

```for(int y = 0; y < a.length; y++) { for(int x = 0; x < a[y].length; x++) { if(a[y][x] == 1) { on_ground = map_height - (tile_size * ) } } } }```
• March 26th, 2013, 07:06 PM
Norm
Re: get ground postion
Quote:

how to get ground postion, no matter where your player is standing.
Can you describe the problem in programming terms? "ground position", "player", "is standing" don't mean anything for java programming.
• March 26th, 2013, 08:42 PM
game06
Re: get ground postion
Quote:

(0=sky, 1=ground, 2=player)
it is a tile map and each tile is 32 X 32 (tile_size)

Code :

```0001 2011 1111```

so to get the height of map(not the array). array height 4 but bc each values is 32 pix. so to get map height
Code :

`int map_height = a.length * tile_size;`

i now know the map_height so if i do minus tile_size. that will give me ground postion. ground postion is top of 1. so player is standing on top of '1'.

Code :

`int on_ground = map_height - tile_size;`

this code above will give me ground postion. but if u notic in a i have 1 on top on 1. so if player jump on top of another '1' than ground postion is

Code :

`int on_ground = map_height - tile_size - tile_size;`

-----------------
my problem is that the code above gets the ground postion but i hard code it. i want the method to know when to do one minus or two mius or three minus. etc...

i looped tho the map and where ever i see 1. i it if player(2) collisiont with ground(1) than i want player on top on ground.

Code :

```for(int y = 0; y < a.length; y++) { for(int x = 0; x < a[y].length; x++) { if(a[y][x] == 1)```

here i am changeing ground value. but i need to get the value of "vaaa". so if player is standing on one '1's than do vaaa = 1. if player is standing on two '1's than vaaa=2. etc...
than this will give me y postion of ground no matter where the player is.

Code :

` on_ground = map_height - (tile_size * vaaa)`
• March 26th, 2013, 08:47 PM
Norm
Re: get ground postion
Can you post a small complete program that compiles, executes and shows the problem?