Information about object: obj_player
Sprite: spr_idle_down
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
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;
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:
///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_mushroomSprite: spr_mushroom
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask: No Physics ObjectCreate Event:execute code: ///Set Up Mushroom Object is_touching=false;//used to check whether colliding with player text="";//initial message state show_text="";//start the typewriter text as "" count=0;//location in show_text border_size=2; padding=10; //add text to ARRAY mushroom_text[0]="Hmm, mushroom..."; mushroom_text[1]="I'm not touching it#-#it might be poisonous!"; mushroom_text[2]="If only I had some chicken,#I could make soup."; mushroom_text[3]="It's a mushroom or a toad-stall,#how should I know?"; mushroom_text[4]="This mushroom smells of cheese,#is that normal?"; mushroom_text[5]="Reminds me of my favourite food,#mushrooms on toast."; mushroom_text[6]="It's just a boring old mushroom."; mushroom_text[7]="Mushrooms, mushrooms, mushrooms, mushrooms.#Mushrooms, mushrooms, mushrooms, mushrooms."; mushroom_text[8]="A mushroom! I've never seen a mushroom before!";Alarm Event for alarm 0:execute code: is_touching=false; text=""; show_text=""; count=0;Collision Event with object obj_player:execute code: if !is_touching { var message=irandom(8); show_debug_message(message); is_touching=true; alarm[0]=room_speed*5; text=mushroom_text[message]; switch (message) { case 0:break; case 1:break; case 2:break; case 3:break; case 4:break; case 5:break; case 6:break; case 7:break; case 8:break; } }Draw Event:execute code: ///drawing stuff depth=5; draw_self();//draw self depth=-5; ///set text to draw if(string_length(show_text) < string_length(text)) { show_text = string_copy(text,1,count); alarm[0] = room_speed*4; count +=1; } if show_text!=""///draw bubble if text present { padding=10; //set variables var width =string_width(text) + padding * 2; // width of message, capped at max_width var height = string_height(text) + padding * 2; //draw bits below first to create a border //round rectangle first draw_set_colour(c_blue); draw_roundrect(x-(width/2)-border_size, y-90-(height/2)-border_size,x+(width/2)+border_size,y-90+(height/2)+border_size,false); //triangle outline for triangle draw_line_width(x-(width/4)+border_size,y-90+(height/2)-border_size,x+border_size,y-25,border_size); draw_line_width(x,y-25,x-(width/2),y-90+(height/2),border_size); //draw a the box draw_set_colour(c_white); draw_roundrect(x-(width/2),y-90-(height/2),x+(width/2),y-90+(height/2),false); //draw_triangle to make it look like speech bubble draw_triangle( x-(width/2)+2,y-90+(height/2), x-(width/4),y-90+(height/2), x,y-25, false); //draw a message draw_set_font(font_message); draw_set_halign(fa_center); draw_set_valign(fa_middle); draw_set_colour(c_black); draw_text(x,y-90,show_text); }
No comments:
Post a Comment