private void correctPosition() { if (checkXYPosition(xyPosition, 1, 1)) { return; } XY_Position[] searchers = new XY_Position[4]; for (int i = 0; i < 4; i++) { searchers[i] = new XY_Position(xyPosition.x, xyPosition.y); } while (true) { searchers[0] = searchers[0] + new XY_Position(1, 0); searchers[1] = searchers[1] + new XY_Position(0, 1); searchers[2] = searchers[2] + new XY_Position(-1, 0); searchers[3] = searchers[3] + new XY_Position(0, -1); foreach (XY_Position searcher in searchers) { if (checkXYPosition(searcher, 1, 1)) { xyPosition = searcher; return; } } } }
public bool checkXYPosition(XY_Position xyPos, uint width, uint height) { double halfWidth = width * 0.5; double halfHeight = height * 0.5; if ( Program.WORLD_MAP[(uint)(xyPos.x + halfWidth), (uint)(xyPos.y + halfHeight)].objectType != OBJECT_TYPE.BLOCK && Program.WORLD_MAP[(uint)(xyPos.x - halfWidth), (uint)(xyPos.y + halfHeight)].objectType != OBJECT_TYPE.BLOCK && Program.WORLD_MAP[(uint)(xyPos.x - halfWidth), (uint)(xyPos.y - halfHeight)].objectType != OBJECT_TYPE.BLOCK && Program.WORLD_MAP[(uint)(xyPos.x + halfWidth), (uint)(xyPos.y - halfHeight)].objectType != OBJECT_TYPE.BLOCK ) { return(true); } else { return(false); } }
public override void move(DIRECTION direction) { Program.WORLD_MAP[(uint)xyPosition.x, (uint)xyPosition.y] = new MAP_CELL(OBJECT_TYPE.AIR, 0); XY_Position aim = OPERATION[(uint)direction] + xyPosition; if (checkXYPosition(aim, 1, 1)) { xyPosition = aim; Program.WORLD_MAP[(uint)xyPosition.x, (uint)xyPosition.y] = new MAP_CELL(OBJECT_TYPE.PEOPLE, 0); sendMessage( new MessageToClient( id, xyPosition, xyPosition, xyPosition, Program.WORLD_MAP[(uint)xyPosition.x, (uint)xyPosition.y] ) ); } Console.WriteLine("player {0} 's position : {1}", id.ToString(), xyPosition.ToString()); }