Hey all,
I'm trying to make it so when you click on a ball, it disappears (pops). However the mouse input is not working as it should. I'm using Raylib and C++. I've posted the snippet of code I'm having trouble with. If needed I can post more code. Note that when clicking on the ball, nothing happens.
//Inside of an init() method
Yellow_Ball.X_Pos = (float)GetRandomValue(1, MAX_WIDTH);
Yellow_Ball.Y_Pos = (float)GetRandomValue(1, MAX_HEIGHT);
Yellow_Ball.X_Vel = 4.0f;
Yellow_Ball.Y_Vel = 4.0f;
Yellow_Ball.Pos.x = Yellow_Ball.X_Pos;
Yellow_Ball.Pos.y = Yellow_Ball.Y_Pos;
Yellow_Ball.Vel.x = Yellow_Ball.X_Vel;
Yellow_Ball.Vel.y = Yellow_Ball.Y_Vel;
Yellow_Ball.Radius = 20;
Yellow_Ball.Timer_Countdown = 200;
Yellow_Ball.Points = 5;
Yellow_Ball.Popped = false;
Yellow_Ball.Visible = true;
//Inside an update() method
Vector2 MousePos = GetMousePosition();
mx = (int)MousePos.x;
my = (int)MousePos.y;
//issue is here
if ( MousePos.x == Yellow_Ball.Pos.x && MousePos.y == Yellow_Ball.Pos.y && IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
Yellow_Ball.Popped = true;
Player.Score += Yellow_Ball.Points;
Player.Balls_Popped++;
Player.Yellow_Balls_Popped++;
}
if (Yellow_Ball.Popped == true)
{
Yellow_Ball.Vel.x = 0;
Yellow_Ball.Vel.y = 0;
Yellow_Ball.Timer_Countdown--;
if (Yellow_Ball.Timer_Countdown == 0)
{
Yellow_Ball.Popped = false;
Yellow_Ball.Vel.x += 4.0f;
Yellow_Ball.Vel.y += 4.0f;
Yellow_Ball.Timer_Countdown = 200;
}
}