【GAMEMAKER】Quest (mini map, timer)

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;
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:
        if !position_meeting(x,y-4,obj_wall) y -= 4;
        break;

        case player_state.down:
        if !position_meeting(x,y+4,obj_wall) y += 4;
        break;

        case player_state.left:
        if !position_meeting(x-4,y,obj_wall) x -= 4;
        break;
   
        case player_state.right:
        if !position_meeting(x+4,y,obj_wall) x += 4;
        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_wall

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

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

///Draw Outline
draw_set_alpha(0.2);
draw_circle(75,600,75,0);
draw_set_alpha(1);
draw_set_colour(c_green);
draw_circle(75,600,75,1);
draw_circle(75,600,10,1);

//set up variables
var d,a,radarX,radarY;
radarX = obj_player.x;
radarY = obj_player.y;

//draw the wall instance that are in range
with(obj_wall)
{
    //how far
    d = point_distance(radarX,radarY,x,y);
    if(d <= 600)  // This is the distance to check for
    {
        d = d/600*75;
        a = point_direction(radarX,radarY,x,y)
        draw_sprite(spr_map_wall, 0, 75 + lengthdir_x(d,a), 600 + lengthdir_y(d,a));
    }
}

//draw the chest on the mini map
with(obj_chest)
{
    //how far
    d = point_distance(radarX,radarY,x,y);
    //in range
    if( d > 600)  //for detecting long range chest instances
    { 
        //convert range to draw
        d = 75; 
        //angle to target
        a = point_direction(radarX,radarY,x,y)
        //draw relative to center of radar using simplified lengthdir function
        draw_sprite(spr_map_chest, 0, 75 + lengthdir_x(d,a), 600 + lengthdir_y(d,a));
    }
    else if(d <= 600)  // This is the standard distance to check for
    {
        d = d/600*75;
        a = point_direction(radarX,radarY,x,y)
        draw_sprite(spr_map_chest, 0, 75 + lengthdir_x(d,a), 600 + lengthdir_y(d,a));
    }
}

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

///Set Up
image_speed=0;
image_index=0;
has_opened=false;
Alarm Event for alarm 0:
execute code:

instance_destroy();
Collision Event with object obj_player:
execute code:

///Open the chest, change image and set alarm
if !has_opened
{
    has_opened=true;
    image_index=1;
    alarm[0]=room_speed*4; //to destroy
}

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

///set time and alarm
clock_time=360;
alarm[0]=room_speed;
Alarm Event for alarm 0:
execute code:

///reset alarm and change time
alarm[0]=room_speed;
clock_time--;
Step Event:
execute code:

///Check if out of time or quest completed
if clock_time==0
{
    show_message("Out Of Time");
    game_restart();
}
if instance_number(obj_chest)==0
{
    show_message("Quest Complete");
    game_end();
}
Draw Event:
execute code:

///comment to prevent default drawing

Draw GUI Event:
execute code:

draw_self();
draw_sprite_ext(spr_clock_hand,0,x,y,1,1,clock_time,0,1);

No comments:

Top 3 UX Design Articles of 2024 to Remember

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

Contact Form

Name

Email *

Message *