Wednesday, 24 March 2021

【GAMEMAKER】sokoban pushable object

 Information about object: obj_pushable

Sprite:
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children
obj_block
obj_player
Mask:
No Physics Object

Information about object: obj_block
Sprite: spr_block
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent: obj_pushable
Children:
Mask:
No Physics Object
Begin Step Event:
execute code:

global.collisions=0;
End Step Event:
execute code:

if position_meeting(x,y,obj_hole)
{
global.collisions++;
}
Information about object: obj_hole
Sprite: spr_hole
Solid: false
Visible: true
Depth: 3
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Information about object: obj_player
Sprite: spr_player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_pushable
Children:
Mask:
No Physics Object
Create Event:
execute code:

move_dx = 0;
move_dy = 0;
move_amt = 0;
global.collisions=0;//set up

Step Event:
execute code:

if (move_amt > 0)
{
// moving towards destination
if (soko_move(move_dx, move_dy))
{
move_amt -= 1;
}
else move_amt = 0; // if hit a wall, stop moving
}
else
{
var spd = 4; // movement speed (grid size should divide by it w/o remainder)
move_amt = 32 div spd; // calculate number of steps for movement
move_dx = 0;
move_dy = 0;
if (keyboard_check(vk_left)) && !((position_meeting(x-18,y,obj_block) && (position_meeting(x-50,y,obj_block))))
{
move_dx = -spd;
}
else if (keyboard_check(vk_right))&& !((position_meeting(x+18,y,obj_block) && (position_meeting(x+50,y,obj_block))))
{
move_dx = spd;
}
else if (keyboard_check(vk_up)) && !((position_meeting(x,y-18,obj_block) && (position_meeting(x,y-50,obj_block))))
{
move_dy = -spd;
}
else if (keyboard_check(vk_down))&& !((position_meeting(x,y+18,obj_block) && (position_meeting(x,y+50,obj_block))))
{
move_dy = spd;
}
else move_amt = 0; // don't move if no buttons are pressed
}
End Step Event:
execute code:

if global.collisions==instance_number(obj_hole) && move_amt <= 0//check if all crates in place and stopped movi
{
show_message("You Win");
room_goto_next();//goto next room

}
Draw Event:
execute code:

draw_self();
draw_text(20,20,"Done="+string(global.collisions)+" of "+string(instance_number(obj_hole)));
Information about object: obj_wall
Sprite: spr_wall
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Information about object: obj_restart
Sprite: spr_restart
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Released:
execute code:

room_restart();
Information about object: obj_game_end
Sprite: sprite6
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Released:
execute code:

game_restart();

No comments:

Post a Comment

BREAKING: North Carolina automotive group acquires 7 Upstate dealerships

Breaking news from GSA Business Report Click here to view this message in a browser window. ...