Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: get ground postion

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default get ground postion

    how to get ground postion, no matter where your player is standing.

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

    0001
    2011
    1111

    so to get ground position i do this.

    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.

    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 * )
        }
          }
        }
     }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: get ground postion

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: get ground postion

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

    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
    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'.

    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

    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.

    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.

     on_ground = map_height - (tile_size * vaaa)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: get ground postion

    Can you post a small complete program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. drawing is in the same postion :(
    By kisokiso in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 20th, 2011, 08:02 AM