function check_hitstop()
{
	if global.hitstop > 0
		return true;
	else
		return false;
}
/// @desc 优雅地检测该实例的sprite当前动画是否到达最后一帧
function animation_end()
{
	if animation_spd == 0
		return false;
    return (image_index + animation_spd >= image_number);
}
/// @desc 优雅地将该实例的sprite替换为给定值，并将sprite_index归零
/// @param {Asset.GMSprite} _sprite 将要替换为的sprite
function set_sprite(_sprite)
{
	if sprite_index != _sprite
	{
        sprite_index = _sprite;
        image_index = 0;
    }
}

function camera_snap(_target_x = global.player.x, _target_y = global.player.y)
{
    var _cam = global.camera;
    _cam.x = clamp(_target_x, _cam.bound_left + _cam.cam_width / 2, _cam.bound_right - _cam.cam_width / 2);
    _cam.y = clamp(_target_y, _cam.bound_top + _cam.cam_height / 2, _cam.bound_bottom - _cam.cam_height / 2);
}

/// @desc 触发屏幕震动
/// @param {Real} _magnitude 以像素计算的震动强度
function screen_shake(_magnitude)
{
    with(global.camera)
	{
        if _magnitude > shake_magnitude
            shake_magnitude = _magnitude;
    }
}

function player_add_INK(_amount)
{
	if global.playerINK + _amount >
	global.save_data.player.maxINK
	
		global.playerINK = global.save_data.player.maxINK;
	
	else
		global.playerINK += _amount;
		
	oUI.flash_timer = 10;
	oUI.flash_duration = 10;
}
function player_add_HP(_amount)
{
	if global.playerHP + _amount >
	global.save_data.player.maxHP
	
		global.playerHP = global.save_data.player.maxHP;
	
	else
		global.playerHP += _amount;
}

function to_gui(_wx, _wy)
{
    var _cam    = view_camera[0];
    var _cam_x  = camera_get_view_x(_cam);
    var _cam_y  = camera_get_view_y(_cam);
    var _cam_w  = camera_get_view_width(_cam);
    var _cam_h  = camera_get_view_height(_cam);
    var _gui_w  = display_get_gui_width();
    var _gui_h  = display_get_gui_height();
    
    return
	{
        x: (_wx - _cam_x) / _cam_w * _gui_w,
        y: (_wy - _cam_y) / _cam_h * _gui_h
    };
}

//use together
function lock_player()
{
	if !instance_exists(global.player)
		return;
	global.player.state = state_locked;
	global.player.locked_timer = infinity;
	global.player.x_spd = 0;
	global.player.y_spd = 0;
}
function unlock_player()
{
	if !instance_exists(global.player)
		return;
    global.player.locked_timer = 0;
}

function lock_door()
{
	with(oDoorLocker)
	{
		icd(oDoorLocked, x, y, 0, {unlock : unlock});
		instance_destroy();
	}
}
function unlock_door()
{
	with(oDoorLocked)
	{
		if unlock
			animation_spd = -0.25;
	}
}

function camera_set_bounds(_l, _r, _t, _b)
{
    oCamera.bound_left   = _l;
    oCamera.bound_right  = _r;
    oCamera.bound_top    = _t;
    oCamera.bound_bottom = _b;
}