ID:140028
 
Code:
mob
{
proc
{
pixel_movement()
{
if(src.moving) {return} src.moving = !src.moving;
while(1)
{
for(var/v in src.directions)
{
var/turf/t = get_step(src, v);
if(t && t.density && ((v == NORTH && src.pixel_y >= 28) || \
(v == EAST && src.pixel_x >= -4) || (v == SOUTH && src.pixel_y <= 4) || \
(v == WEST && src.pixel_x <= 4))) {src.moving = !src.moving; return;}
}
if(NORTH in src.directions)
{
if(src.y == world.maxy) {src.moving = !src.moving; return;}
else if(src.pixel_y >= 28) {src.pixel_y = 4; src.y++;}
else {src.pixel_y += 4;}
}
if(SOUTH in src.directions)
{
if(src.y == 1 && !src.pixel_y) {src.moving = !src.moving; return;}
else if(!src.pixel_y) {src.y--; src.pixel_y = 28;}
else {src.pixel_y -= 4;}
}
if(EAST in src.directions)
{
if(src.x == world.maxx) {src.moving = !src.moving; return;}
else if(src.pixel_x == 32) {src.x++; src.pixel_x = 4;}
else {src.pixel_x += 4;}
}
if(WEST in src.directions)
{
if(src.x == 1 && !src.pixel_x) {src.moving = !src.moving; return;}
else if(!src.pixel_x) {src.x--; src.pixel_x = 28;}
else {src.pixel_x -= 4;}
}
if(!src.directions.len) {src.moving = !src.moving; return;}
sleep(0.1);
}
}
}
}


Problem description:
Well the movement seems to work great and all the problem I am having is getting it to bump dense turfs. Now it bumps them, but if you go East then move North and there is a dense object you can go through about the first half of it. Now if you just go East and try to go through a dense object you can get about 4 pixels in. So, if I can get some help on when I should be updating the location on the East movement it would be appreciated.

Here is a demo for it, to show what I'm talking about.

http://www.mediafire.com/?itijigv2eoy

I suck at math and numbers so I couldn't give you a good answer. However I'm slightly better at debugging. So why not set the pixel movement to increase by 1 pixel instead of 4. Then output the player's pixel_x every step to see when you should be updating the location.
I didn't read much of it, but from what it seems is density is not being checked until pixel 28, when your trying to move it up. You will need to fix this with each direction, and that should solve your problem.

As a suggestion, instead of setting pixel_x or y to 0, i would -32. Then it gets changed as necessary if you decide to mess with the rate at a later time.

P.S. Did you set your icon size to 28? If not, then you should be setting pixel_x/y to 0 when you move them not 4.
In response to Pirion (#2)
Pirion wrote:
I didn't read much of it, but from what it seems is density is not being checked until pixel 28, when your trying to move it up. You will need to fix this with each direction, and that should solve your problem.

It's not being checked until pixel 28 only when moving North, because that's the effect I want and has nothing to do with the problem at all. The problem is when they are moving East or West their location isn't being updated at the correct time. This causes them to be able to walk through the very ends of walls, because it's location is actually one more over than the wall, it just doesn't look like it.

As a suggestion, instead of setting pixel_x or y to 0, i would -32. Then it gets changed as necessary if you decide to mess with the rate at a later time.

I'm not setting any pixels in here to 0, so I don't know what you mean. Setting it to -32 however would make it appear as if the mobs were moving backwards every time I was to update their location.

P.S. Did you set your icon size to 28? If not, then you should be setting pixel_x/y to 0 when you move them not 4.

No, because once they hit pixel 32 or 0 it updates their location. If I were to set their pixel to 0 or 32 when the location was updated there would be an obvious small pause, especially when they are moving diagonally. i.e. Player's pixel is 32 location gets updated on next step, since this is another step their pixel needs to be updated four more pixels. 32 - 32 + 4 = 4, 0 + 32 - 4 = 28
In response to Ulterior Motives (#1)
I'll try this and see if I can figure out the correct update pixel.
In response to Librarian (#3)
...This causes them to be able to walk through the very ends of walls, because it's location is actually one more over than the wall, it just doesn't look like it...



Well, I should have read better sorry.

Example for heading west and to the south.

With this you would want to make 2 checks, 1st is to check if the turf below the mob is dense. If it is not, you would want to check if the turf southeast is dense until you reach pixel_x =0. If either return true then fail the movement.

You need to make 2 checks rather than just updating the location as this icon will be in 2 turfs at the same time, trying to move into 2 more turfs.

Hope that is what you are looking for.

Edit...for some turfs that you want to allow this for when they get to a pixel range, you will want to store that in the turf and check that also.