• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How can i check color collision ?

E

Emre Kapukaya

Guest
I try to make a game. I have a square and every corner diffirent color. Colorful balls falling from the sky. So how can i check red ball collision with red corner ? Please i need help :D
 

CloseRange

Member
have 4 different objects, 1 for each color, have them next to each other as to make 1 big square. Then check the collision with the individual color objects.
 

DesArts

Member
Upon collision you can check the angle between the balls and the square, for example anywhere between 0 and 90 when checked from the square centre to the ball centre would be the top right corner of the square.

In square's collision event with ball
Code:
//get angle to ball
var angle = point_direction(x, y, other.x, other.y);
var side = floor(angle/90); //will be 0, 1, 2 or 3 going anti clockwise starting at top right corner.

switch (side)
{
    case 0:
        //top right
    break;
    case 1:
        //top left
    break;
    case 2:
        //bottom left
    break;
    case 3:
        //bottom right
    break;
}
If the square rotates, all you need to do is subtract the square's angle from the point_direction angle and the code will still work. Not tested this though.
 

DesArts

Member
Ah so it's not the corners it's the sides.

This seems simpler, because when you touch a ball, all you need to check is which way round the square is to know if it's the same colour. Are you using image_angle or direction or rotate the square, or perhaps different image_index's?
 
E

Emre Kapukaya

Guest
i create a step image_angle=direction;
and im checking press space direction +=90;
 

TheouAegis

Member
Make an array in the Create Event for each color.

sides[0] = c_blue;
sides[1] = c_red;
sides[2] = c_yellow;
sides[3] = c_purple;

When a ball hits the box, get the box's color and compare it to the ball's.

Ball's Code:
if y-yprevious<other.bbox_top && other.sides[other.image_angle div 90]==image_blend
score++;
 

TheouAegis

Member
Yes the array is inside the square. Make sure the colors match up, though. Side 0 would be the color at the top of the square when its image_angle is 0. Side 1 would be the color to the right, side 2 would be the color on the bottom, and side 3 would be the color to the left.

I'm not sure how you're handling your balls, but when a ball is created, set its image_blend to the color it's supposed to be, matching the constants in the array. Or if you don't want to use image_blend, just set some other variable. The whole thing is pretty flexible and you could manipulate it however you want. In my example, I used image_blend to define the color of the ball and the array holds matching color constants. Or you could just use four sprites of different colors and the array can hold the sprite_indexes that would correspond to each side of the square as I described in the above paragraph.
 
E

Emre Kapukaya

Guest
That's my sprites and objects. Avlayici is my player ( square). But i didn't understand your codes. Can you explain a little bit please ?
 

Attachments

TheouAegis

Member
So replace each of the colors in the array with the object_indexes. Then replace image_blend with object_index.
 
E

Emre Kapukaya

Guest
i didnt understand ball cods. This not working like this.
 
Top