Information about object: pawn_object
Sprite: sprite0
Solid: true
Visible: true
Depth: -100
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
///Pawn piece Variables
image_speed = 0;
is_selected = false;
spaces_moved = 0;
spaces_created = path_get_number(pawn_move_path);;
Step Event:
execute code:
///spaces to move in once a direction has been set, after selecting this piece
if(is_selected)
{
image_speed = 0.1;
//direction of movement to set the piece to when it starts moving
if( keyboard_check_pressed(vk_right) ){direction = 0;}
if( keyboard_check_pressed(vk_left ) ){direction = 180;}
if( keyboard_check_pressed(vk_down ) ){direction = 270;}
if( keyboard_check_pressed(vk_up ) ){direction = 90;}
//Movement input
if(keyboard_check_pressed( ord("0") ) ){spaces_moved = 0;}
if(keyboard_check_pressed( ord("1") ) ){spaces_moved = 1;}
if(keyboard_check_pressed( ord("2") ) ){spaces_moved = 2;}
if(keyboard_check_pressed( ord("3") ) ){spaces_moved = 3;}
if(keyboard_check_pressed( ord("4") ) ){spaces_moved = 4;}
spaces_created = path_get_number(pawn_move_path);
switch(spaces_moved)
{
//Number of spaces
case 0 : spaces_moved = 0; break;
case 1 : spaces_moved = 1; break;
case 2 : spaces_moved = 2; break;
case 3 : spaces_moved = 3; break;
case 4 : spaces_moved = 4; break;
default : show_message("Pawns can only move 4 spaces at a time"); break;
}
//-------------------------------------------------------------------------------------------------
if(path_position == 1)
{
path_delete_point(pawn_move_path, spaces_created - 1);
path_position = 0;//"The new position your on in-path is now seen as 0, not 1 for when the new path starts."
}
}else{ image_speed = 0; image_index = 0; }
Mouse Event for Left Button:
execute code:
///click on the piece you wish to move
move_piece = show_question("Move this piece");
if(!move_piece){exit;}else
{ show_message("Hold UP, DOWN, LEFT or RIGHT to choose a direction,
then input the number of spaces you'd like to move this piece. (Max = 4)");
is_selected = true;//This piece can move with the inputs given now
}
Draw Event:
execute code:
draw_self();
draw_set_font(font0);
draw_text(view_xview, view_yview, "Path Points = " +string(spaces_created) );
draw_text(view_xview, view_yview+50, "Movement = " +string(spaces_moved) );
draw_text(view_xview, view_yview+100, "Path Angle = " +string(direction) );
draw_text(view_xview, view_yview+150, "Path Position = " +string(path_position) );
draw_path(pawn_move_path, x, y, true);
Key Release Event for <Space> Key:
execute code:
///Move the piece after deciding on a direction and number
if(is_selected)
{
{
switch(direction)
{
case 90 :
path_add_point(pawn_move_path, x, y -64 *spaces_moved, 10);
path_start(pawn_move_path, 10, path_action_stop, false);
break;
//---------------------------------------------------------------------------------------------------
case 270 :
path_add_point(pawn_move_path, x, y +64 *spaces_moved, 10);
path_start(pawn_move_path, 10, path_action_stop, false);
break;
//-----------------------------------------------------------------------------------------------------
case 180 :
path_add_point(pawn_move_path, x -64 *spaces_moved, y, 10);
path_start(pawn_move_path, 10, path_action_stop, false);
break;
//-----------------------------------------------------------------------------------------------------
case 0 :
path_add_point(pawn_move_path, x +64 *spaces_moved, y, 10);
path_start(pawn_move_path, 10, path_action_stop, false);
break;
}
}
}