java - Tile based map and collision; getting stuck -


i'm trying make character move around tile map collisions. works fine except 1 thing. show picture problem:

http://i.imgur.com/bcyz5.jpg is, when reach tile above can not move anywhere. if come left, can not move either or down. if reach bottom, can move left not right. , when reach right can move in direction.

honestly have no idea may failing. think has if (...), because if change order, addresses can move change :/

here leave code:

boolean collision = false;  if(keyboard.iskeydown(keyboard.key_up)) {     for(int = 0; < map.getnumlayers(); i++) {         if(uptile(map, i) > 128) {             collision = true;         }     }      if(!collision) addpos(0.0f, -vel); } if(keyboard.iskeydown(keyboard.key_left)) {     for(int = 0; < map.getnumlayers(); i++) {         if(lefttile(map, i) > 128) {             collision = true;         }     }      if(!collision) addpos(-vel, 0.0f); } if(keyboard.iskeydown(keyboard.key_down)) {     for(int = 0; < map.getnumlayers(); i++) {         if(downtile(map, i) > 128) {             collision = true;         }     }      if(!collision) addpos(0.0f, vel); } if(keyboard.iskeydown(keyboard.key_right)) {     for(int = 0; < map.getnumlayers(); i++) {         if(righttile(map, i) > 128) {             collision = true;         }     }      if(!collision) addpos(vel, 0.0f); } 

this easier of separate game's model view shown above. example shows 1 approach, while more elaborate example models related grid based game.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -