//CollisionWithGroup(object, spriteWidth, spriteHeight);

object = argument0;
width = argument1;
height = argument2;


//Horizontal check
horizontalCheck = false;
for (i = abs(object.h_spd); i > 0; i -= 1;)
{
    move_check = sign(object.h_spd) * i;
    
    if (place_free(object.x + move_check, object.y) && object.x + move_check >= width/2 && object.x + move_check <= room_width - width/2)
    {
        object.x += move_check; 
        horizontalCheck = true;
        break;
    }
    
    if (place_free(object.x + move_check, object.y - i) && object.y - i >= height/2 && object.y - i <= room_height - height/2)
    {
        object.y -= (i / 2);
    }
    
    if (place_free(object.x + move_check, object.y + i) && object.y - i >= height/2 && object.y - i <= room_height - height/2)
    {
        object.y += (i / 2); 
    }
}

//Vertical check
verticalCheck = false;
for (i = abs(object.v_spd); i > 0; i -= 1;)
{
    move_check = sign(object.v_spd) * i;
    
    if (place_free(object.x , object.y + move_check) && object.y + move_check >= height/2 && object.y + move_check <= room_height - height/2)
    {
        object.y += move_check; 
        verticalCheck = true;
        break;
    }
    
    if (place_free(object.x - i, object.y + move_check) && object.x - i >= width/2 && object.x - i <= room_width - width/2)
    {
        object.x -= (i / 2);
    }
    
    if (place_free(object.x + i, object.y + move_check) && object.x - i >= width/2 && object.x - i <= room_width - width/2)
    {
        object.x += (i / 2);
    }
}


if( (!verticalCheck && abs(object.v_spd) > object.spd*0.90) || (!horizontalCheck && abs(object.h_spd) > object.spd*0.90) )
{
    soundIndex = floor(random(array_length_1d(object.soundTalkImpact)));
    audio_play_sound(object.soundTalkImpact[soundIndex], 10, false);
    
    //audio_play_sound(object.soundTalkImpact[0], 10, false);
    audio_play_sound(SfxCollision, 10, false);
    object.animatedCollision = true;
}

if(!horizontalCheck)
{
    object.h_spd = 0;
}

if(!verticalCheck)
{
    object.v_spd = 0;
}



