Friday, April 16, 2021

【GAMEMAKER】Hints and Tips Flash or popup message

 Information about object: obj_player

Sprite: spr_idle_down
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
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;
can_show_message=true;   //allows message to be shown
Alarm Event for alarm 0:
execute code:

can_show_message=true;
Step Event:
execute code:


///keypress code
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:
        y -= 4;
        break;

        case player_state.down:
        y += 4;
        break;

        case player_state.left:
        x -= 4;
        break;
   
        case player_state.right:
        x += 4;
        break;
    }
}




execute code:

///collision with object for message
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;
    }
}

Collision Event with object obj_message_item:
execute code:

if can_show_message
{
    can_show_message=false;
    scr_message(other.message);
    alarm[0]=room_speed*3;
}

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

global.message=ds_list_create();//create a ds list to hold messages
can_show=true;//set that a message can show
to_draw="";//set text to draw to ""
show_text="";
count=0;

Alarm Event for alarm 0:
execute code:

///alarm0 set alarm1
alarm[1]=room_speed*1;//create a short pause
to_draw="";//remove text to show
show_text="";
count=0;
Alarm Event for alarm 1:
execute code:

///set as able to show
can_show=true;
Step Event:
execute code:

///check if message waiting
var check=ds_list_size(global.message);//get no of messages waiting
if check>0 && can_show//do this if more than one message and can show
{
    to_draw=ds_list_find_value(global.message,0);//get message from top of ds list
    ds_list_delete(global.message,0);//delete this message
    can_show=false;//prevent showing
    alarm[0]=room_speed*4;//create a pause
}
if(string_length(show_text) < string_length(to_draw))
{
show_text = string_copy(to_draw,1,count);
alarm[0] = room_speed*5;
count +=1;
}
Other Event: Game End:
execute code:

ds_list_destroy(global.message); 
Draw GUI Event:
execute code:

///draw message

if to_draw!=""//do if there is a message waiting
{
    //set up
    var xx=350;
    var yy=600;
    var padding=10;
    var border_size=2;
    var width =string_width(to_draw) + padding * 2; // width of message
    var height = string_height(to_draw) + padding * 2; 
    //draw border
    draw_set_colour(c_blue);
    draw_roundrect(xx-(width/2)-border_size,
    yy-(height/2)-border_size,xx+(width/2)+border_size,yy+(height/2)+border_size,false);
    //draw main message background
    draw_set_colour(c_aqua);
    draw_roundrect(xx-(width/2),
    yy-(height/2),xx+(width/2),yy+(height/2),false);
    //draw a message
    draw_set_font(font_message);
    draw_set_halign(fa_center);
    draw_set_valign(fa_middle);
    draw_set_colour(c_red);
    draw_text(xx+1,yy+1,show_text);
    draw_set_colour(c_black);
    draw_text(xx,yy,show_text);
}

Information about object: obj_message_item
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children
obj_door
obj_banana
obj_rum
obj_chest
Mask:
No Physics Object

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

message="You Need A Key To Open This";

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

message="Press P To Pick Up Banana";

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

message="Press M To Drink The Rum";

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

message="Press K To Use The Key";

No comments:

Post a Comment