41 // TODO: Is thir the right way to do this? |
41 // TODO: Is thir the right way to do this? |
42 world.addObject(this); |
42 world.addObject(this); |
43 } |
43 } |
44 |
44 |
45 Vector PhysicsObject::walk (bool right) { |
45 Vector PhysicsObject::walk (bool right) { |
46 Vector cursor = right ? this->position + Vector(1,0) : |
46 Vector cursor = this->position + shape[2] + (right ? Vector(1,0) : Vector(-1,0)); |
47 this->position + Vector(-1,0); |
|
48 Vector reached = this->position; |
47 Vector reached = this->position; |
49 |
48 |
50 //for(int steps = 0; steps < 3; steps++) { |
49 //for(int steps = 0; steps < 3; steps++) { |
51 |
50 |
52 // Go up but not if the wall is over two pixels |
51 // Go up but not if the wall is over two pixels |
53 if(world.getType(cursor) != EMPTY) { |
52 if(world.getType(cursor) != EMPTY) { |
54 for(int height = 0, max = 3; height < max+42; height++) { |
53 for(int height = 0, max = 2; height < max+42; height++) { |
55 |
54 |
56 if(height >= max) |
55 if(height >= max) |
57 return reached; |
56 return reached; |
58 |
57 |
59 cursor.y--; |
58 cursor.y--; |
60 if(world.getType(cursor) == EMPTY) { |
59 if(world.getType(cursor) == EMPTY) { |
61 // Check that the other parts of the worm don't collide with anything |
60 // Check that the other parts of the worm don't collide with anything |
62 if(possibleLocation(cursor)) { |
61 if(possibleLocation(cursor)) { |
63 reached = cursor; |
62 reached = cursor - shape[2]; |
64 continue; |
63 continue; |
65 } else { |
64 } else { |
66 // Can't get any further |
65 // Can't get any further |
67 return reached; |
66 return reached; |
68 } |
67 } |
69 } |
68 } |
70 } |
69 } |
71 } else { |
70 } else { |
72 if(possibleLocation(cursor)) { |
71 if(possibleLocation(cursor)) { |
73 reached = cursor; |
72 reached = cursor - shape[2]; |
74 } |
73 } |
75 // Start checking if the lower squares are empty |
74 // Start checking if the lower squares are empty |
76 |
75 |
77 for(int depth = 0, max = 3; depth < max+42; depth++) { |
76 for(int depth = 0, max = 3; depth < max+42; depth++) { |
78 |
77 |