Leandro Saccoletto
Member
Hi guys,
I was problem to development one feature used in the Bomberman game:Edge Sliding.
If player is on the edge of a block and tries to go down, but the tile down is blocked and if tile next to this block is walkable, the player will gently slide onto it.
I tried too many and still could figuring out. The objects are 16x16 and with orgin point point at. I'll post the important code of this problem.
obj_player's create event:
vx=0;//horizontal speed
vy=0;//vertical speed
vxmax=2;//absolute max horizontal speed
vymax=vxmax;//absolute max vertical speed
acc=vxmax;//accelaration to the motion. set to vxmax or vymax value if you want skip the smooth transition
fric=vxmax;//friction to the motion. set to vxmax or vymax value if you want skip the smooth transition
//For sub-pixel motion
cx=0;
cy=0;
state=pstate.idle;//Player state
prevstate=state;//previous Player state
facing=270;//Facing direction : 0 Right 90 UP 180 Left 270 Down
pfacing=270;
obj_player's step event:
// Input //////////////////////////////////////////////////////////////////////
var kLeft, kRight, kUp, kDown, kBomb;
kLeft = left_held_input();
kRight = right_held_input();
kDown = down_held_input();
kUp = up_held_input();
kBomb = bomb_pressed_input();
////////////////////////////////////////////
////////////////////////////////////////// Left movement
if (kLeft and not kRight) {
vx=Approach(vx,-vxmax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =180;
}
////////////////////////////////////////// Right movement
else if (kRight and not kLeft) {
vx=Approach(vx, vxmax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =0;
}
////////////////////////////////////////// Stops Action
else if (not kRight and not kLeft){
vx=Approach(vx,0,fric);
if(state==pstate.walk) state=pstate.idle;
}
////////////////////////////////////////// Left movement
if (kUp and not kDown) {
vy=Approach(vy,-vymax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =90;
}
////////////////////////////////////////// Right movement
else if (kDown and not kUp) {
vy=Approach(vy, vymax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =270;
}
////////////////////////////////////////// Stops Action
else if (not kUp and not kDown){
vy=Approach(vy,0,fric);
if(state==pstate.walk) state=pstate.idle;
}
scr_player_hmotion();
scr_player_vmotion();
scr_player_hmotion()
var vxNew,yy;
cx += vx;
vxNew = round(cx);
cx -= vxNew;
// Horizontal
repeat(abs(vxNew)) {
yy=y+7;
yy=round(yy/grid_size)*grid_size;
if(not place_meeting(x+sign(vxNew),yy,obj_block))
y+=sign(yy-y);
if(not place_meeting(x+sign(vxNew),y,obj_block))
x+=sign(vxNew);
else {
vx= 0;
break;
}
}
scr_player_vmotion()
var vyNew,xx;
cy += vy;
vyNew = round(cy);
cy -= vyNew;
// Vertical
repeat(abs(vyNew)) {
xx=x+7;
xx=round(xx/grid_size)*grid_size;
if(not place_meeting(xx,y+sign(vyNew),obj_block))
x+=sign(xx-x);
if (not place_meeting(x, y + sign(vyNew),obj_block))
y+=sign(vyNew);
else {
vy= 0;
break;
}
}
The motion is based of using repeat loop method that I saw in the ZackBellBlog. If some one can give a idea of how implementing the edge sliding, I'll appreciate.
I was problem to development one feature used in the Bomberman game:Edge Sliding.
If player is on the edge of a block and tries to go down, but the tile down is blocked and if tile next to this block is walkable, the player will gently slide onto it.
I tried too many and still could figuring out. The objects are 16x16 and with orgin point point at. I'll post the important code of this problem.
obj_player's create event:
vx=0;//horizontal speed
vy=0;//vertical speed
vxmax=2;//absolute max horizontal speed
vymax=vxmax;//absolute max vertical speed
acc=vxmax;//accelaration to the motion. set to vxmax or vymax value if you want skip the smooth transition
fric=vxmax;//friction to the motion. set to vxmax or vymax value if you want skip the smooth transition
//For sub-pixel motion
cx=0;
cy=0;
state=pstate.idle;//Player state
prevstate=state;//previous Player state
facing=270;//Facing direction : 0 Right 90 UP 180 Left 270 Down
pfacing=270;
obj_player's step event:
// Input //////////////////////////////////////////////////////////////////////
var kLeft, kRight, kUp, kDown, kBomb;
kLeft = left_held_input();
kRight = right_held_input();
kDown = down_held_input();
kUp = up_held_input();
kBomb = bomb_pressed_input();
////////////////////////////////////////////
////////////////////////////////////////// Left movement
if (kLeft and not kRight) {
vx=Approach(vx,-vxmax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =180;
}
////////////////////////////////////////// Right movement
else if (kRight and not kLeft) {
vx=Approach(vx, vxmax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =0;
}
////////////////////////////////////////// Stops Action
else if (not kRight and not kLeft){
vx=Approach(vx,0,fric);
if(state==pstate.walk) state=pstate.idle;
}
////////////////////////////////////////// Left movement
if (kUp and not kDown) {
vy=Approach(vy,-vymax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =90;
}
////////////////////////////////////////// Right movement
else if (kDown and not kUp) {
vy=Approach(vy, vymax,acc);
if(state==pstate.idle)state=pstate.walk;
facing =270;
}
////////////////////////////////////////// Stops Action
else if (not kUp and not kDown){
vy=Approach(vy,0,fric);
if(state==pstate.walk) state=pstate.idle;
}
scr_player_hmotion();
scr_player_vmotion();
scr_player_hmotion()
var vxNew,yy;
cx += vx;
vxNew = round(cx);
cx -= vxNew;
// Horizontal
repeat(abs(vxNew)) {
yy=y+7;
yy=round(yy/grid_size)*grid_size;
if(not place_meeting(x+sign(vxNew),yy,obj_block))
y+=sign(yy-y);
if(not place_meeting(x+sign(vxNew),y,obj_block))
x+=sign(vxNew);
else {
vx= 0;
break;
}
}
scr_player_vmotion()
var vyNew,xx;
cy += vy;
vyNew = round(cy);
cy -= vyNew;
// Vertical
repeat(abs(vyNew)) {
xx=x+7;
xx=round(xx/grid_size)*grid_size;
if(not place_meeting(xx,y+sign(vyNew),obj_block))
x+=sign(xx-x);
if (not place_meeting(x, y + sign(vyNew),obj_block))
y+=sign(vyNew);
else {
vy= 0;
break;
}
}
The motion is based of using repeat loop method that I saw in the ZackBellBlog. If some one can give a idea of how implementing the edge sliding, I'll appreciate.