【GAMEMAKER】Party Mechanics Changing Character

 Information about object: obj_player_parent

Sprite: spr_idle_down
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children
obj_player_1
obj_player_2
obj_player_3
Mask:
No Physics Object
Create Event:
execute code:

///set up
enum player_state {
    idle,
    up,
    down,
    left,
    right
    }
dir=player_state.down;
is_moving=false;
image_speed=0.5;
global.move_speed=4;

Step Event:
execute code:

///keypress code
is_moving=false;
if global.selected!=my_id exit;

if (keyboard_check(vk_left))
{
    dir=player_state.left;
    is_moving=true;
}
else
if (keyboard_check(vk_right))
{
    dir=player_state.right;
    is_moving=true;
}
else
if (keyboard_check(vk_up))
{
    dir=player_state.up;
    is_moving=true;
}
else
if (keyboard_check(vk_down))
{
    dir=player_state.down;
    is_moving=true;
}
else
{
    is_moving=false;
}
execute code:

///movement
if is_moving
{
    switch (dir)
    {
        case player_state.up:
        if !position_meeting(x,y-global.move_speed,obj_solid_base) y -= global.move_speed;
        break;

        case player_state.down:
        if !position_meeting(x,y+global.move_speed,obj_solid_base) y += global.move_speed;
        break;

        case player_state.left:
        if !position_meeting(x-global.move_speed,y,obj_solid_base) x -= global.move_speed;
        break;
   
        case player_state.right:
        if !position_meeting(x+global.move_speed,y,obj_solid_base) x += global.move_speed;
        break;
    }
}
depth=-y;
execute code:


///animation
if is_moving
{
    switch (dir)
    {
        case player_state.up:
        sprite_index=spr_walk_up;
        break;

        case player_state.down:
        sprite_index=spr_walk_down;
        break;

        case player_state.left:
        sprite_index=spr_walk_left;
        break;
   
        case player_state.right:
        sprite_index=spr_walk_right;
        break;
    }
}
else
{
    switch (dir)
    {
        case player_state.up:
        sprite_index=spr_idle_up;
        break;

        case player_state.down:
        sprite_index=spr_idle_down;
        break;

        case player_state.left:
        sprite_index=spr_idle_left;
        break;
   
        case player_state.right:
        sprite_index=spr_idle_right;
        break;
    }
}


Information about object: obj_cactus
Sprite: spr_cactus
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_elements_parent
Children:
Mask:
No Physics Object

Information about object: obj_flag
Sprite: spr_flag
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_elements_parent
Children:
Mask:
No Physics Object

Information about object: obj_mushroom
Sprite: spr_mushroom
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_elements_parent
Children:
Mask:
No Physics Object

Information about object: obj_elements_parent
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children
obj_cactus
obj_flag
obj_mushroom
Mask:
No Physics Object
Create Event:
execute code:

instance_create(x,y,obj_solid_base);
depth=-y;

Information about object: obj_solid_base
Sprite: spr_solid_base
Solid: false
Visible: false
Depth: 0
Persistent: false
Parent:
Children
obj_tree
Mask:
No Physics Object

Information about object: obj_selected_control
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///set up initial selection
global.selected=1;
view_object[0] = obj_player_1;
Step Event:
execute code:

///Key Press For Change Selection
if keyboard_check_released(ord('1'))
{
    global.selected=1;
    global.move_speed=4;
    view_object[0] = obj_player_1;
}   
if keyboard_check_released(ord('2'))
{
    global.selected=2;
    global.move_speed=6;
    view_object[0] = obj_player_2;
}   
if keyboard_check_released(ord('3'))
{
    global.selected=3;
    global.move_speed=4;
    view_object[0] = obj_player_3;
}   
Draw GUI Event:
execute code:

draw_text(50,50,"Keys 1 2 3 To Select - Selected Character="+string(global.selected));

Information about object: obj_tree
Sprite: spr_tree
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_solid_base
Children:
Mask:
No Physics Object

Information about object: obj_player_1
Sprite: spr_walk_down
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_player_parent
Children:
Mask:
No Physics Object
Create Event:
execute code:

my_id=1;
event_inherited();

Information about object: obj_player_2
Sprite: spr_walk_down
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_player_parent
Children:
Mask:
No Physics Object
Create Event:
execute code:

my_id=2;
event_inherited();

Information about object: obj_player_3
Sprite: spr_idle_down
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_player_parent
Children:
Mask:
No Physics Object
Create Event:
execute code:

my_id=3;
event_inherited();
Collision Event with object obj_tree:
execute code:

///destroy tree
with (other) instance_destroy();

No comments:

Top 3 UX Design Articles of 2024 to Remember

Based on most subscriptions ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­...

Contact Form

Name

Email *

Message *