Grace Michelle
Grace Michelle

Reputation: 223

Game Maker - Check Collision With Subimages

I have an obj_roulette, which contains 4 subimages, with value 2-5 and image_number 0-3. The value result from roulette stored as var global.roulette.

Then, I make many obj_meteorite, which contains 4 subimages too, spawn from above with random x value and random image_number. Player can shoot them with left-mouse click.

This is what I want:

If image_number obj_roulette is 0, and player shoot obj_meteorite with image_number 0, score +10. If image_number obj_roulette is 0, and player shoot obj_meteorite with image_number 1, score -10.

I don't know how to check collision between mouse_x/mouse_y and object image_number, and how to match obj_roulette image_number and obj_meteorite image_number.

Is it using collision checking? If it yes, then maybe the examples in these links can help: link 1 link 2

Please explain your answer. Thanks.

Upvotes: 0

Views: 166

Answers (1)

Kake_Fisk
Kake_Fisk

Reputation: 1165

I assume this is the kind of game where you click with your mouse and hit exactly where the mouse was clicked. And as I understand it from your question. If the mouse is clicked and obj_roulette's image_index is the same as obj_meteorite, you want to add 10 to the score. If not, you want to subtract 10 from the score. And you need help converting your pseudo-code into gml.

// Check if obj_meteorite was clicked
if (mouse_check_button_released(mb_left) && position_meeting(mouse_x, mouse_y, obj_meteorite))
{
    // Check wheter or not obj_meteorite's and obj_roulette's image_index is the same
    if (obj_meteorite.image_index == obj_roulette.image_index)
    {
        // Add 10 to the score
        score += 10;
    }
    else
    {
        // Subtract 10 from the score
        score -= 10;
    }
}

If this is not what you want, I suggest editing your question to make it more clear. Preferably explain shortly what your game is actually about.

Upvotes: 0

Related Questions