Oooh thank you. Okay now he is moving really fast...
EDIT: Kay he's going normal speed now, except when the game starts, the character just walks upwards directly off screen...
I changed the "y-=32" parts to their corresponding direction example: y-=32 is direction=90.
Here is the object information:
Information about object: obj_joel
Sprite: spr_joel_right
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
execute code:
image_speed = 0.7
global.grid = ds_grid_create(room_width / 20, room_height / 20);
ds_grid_clear(grid, 1);
/* CREATE event */
visitedX = ds_stack_create();
visitedY = ds_stack_create();
Alarm Event for alarm 0:
execute code:
//Old method of movement
directory_create[3]:=place_free(x,y+30);
dir[2]:=place_free(x-30,y);
dir[1]:=place_free(x,y-30);
dir[0]:=place_free(x+30,y);
move:=0;
direc:=direction;
for(i:=0; i<360; i+=90)
{
if i!=(direction+180)mod(360) and dir[i/90] then
{
if floor(random(move+1))=0 then
{
direc:=i;
}
move+=1;
}
}
direction:=direc;
if move=0 then
{
direction:=(direction+180)mod(360);
}
alarm[0]:=8;
speed:=4;
Step Event:
execute code:
/* STEP event */
/* See if we can win */
if ((y==ENDING_Y && (x-20==ENDING_X || x+20==ENDING_X)) || (x==ENDING_X && (y-20==ENDING_Y || y+20==ENDING_Y))) {
/* You've won. Do whatever. */
}
/* Check up */
if (ds_grid_get(grid, x div 20, (y div 20)-1)==1 && ((x div 20)!=ds_stack_top(visitedX) || (y div 20)-1!=ds_stack_top(visitedY))) { /* Make sure there's no wall and this is not the previous space */
ds_stack_pop(visitedX);
ds_stack_pop(visitedY); /* Pop the previous value off the stack. */
ds_stack_push(visitedX, x div 20); /* Add current x to the stack. */
ds_stack_push(visitedY, y div 20); /* Add current y to the stack. */
direction=90; speed = 4 /* Move up 1 space */
}
/* Check left */
else if (ds_grid_get(grid, (x div 20)-1, y div 20)==1 && ((x div 20)-1!=ds_stack_top(visitedX) || (y div 20)!=ds_stack_top(visitedY))) { /* Make sure there's no wall and this is not the previous space */
ds_stack_pop(visitedX);
ds_stack_pop(visitedY); /* Pop the previous value off the stack. */
ds_stack_push(visitedX, x div 20); /* Add current x to the stack. */
ds_stack_push(visitedY, y div 20); /* Add current y to the stack. */
direction=180; speed = 4; /* Move left 1 space */
}
/* Check down */
else if (ds_grid_get(grid, x div 20, (y div 20)+1)==1 && ((x div 20)!=ds_stack_top(visitedX) || (y div 20)+1!=ds_stack_top(visitedY))) { /* Make sure there's no wall and this is not the previous space */
ds_stack_pop(visitedX);
ds_stack_pop(visitedY); /* Pop the previous value off the stack. */
ds_stack_push(visitedX, x div 20); /* Add current x to the stack. */
ds_stack_push(visitedY, y div 20); /* Add current y to the stack. */
direction=270; speed = 4; /* Move down 1 space */
}
/* Check right */
else if (ds_grid_get(grid, (x div 20)+1, y div 20)==1 && ((x div 20)+1!=ds_stack_top(visitedX) || (y div 20)!=ds_stack_top(visitedY))) { /* Make sure there's no wall and this is not the previous space */
ds_stack_pop(visitedX);
ds_stack_pop(visitedY); /* Pop the previous value off the stack. */
ds_stack_push(visitedX, x div 20); /* Add current x to the stack. */
ds_stack_push(visitedY, y div 20); /* Add current y to the stack. */
direction=0; speed = 4; /* Move left 1 space */
}
set variable depth to -y
Begin Step Event:
execute code:
if direction = 0
{
sprite_index = spr_joel_right
image_speed = 0.7
}
if direction = 90
{
sprite_index = spr_joel_up
image_speed = 0.7
}
if direction = 180
{
sprite_index = spr_joel_left
image_speed = 0.7
}
if direction = 270
{
sprite_index = spr_joel_down
image_speed = 0.7
}
else
exit
Edited by xx Zeeke, 11 April 2011 - 07:02 AM.