Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5339

Left mouse click+canvas

$
0
0

Hello.

I have been making this mini game where you have a black ball on a black canvas which moves according to the timer and gets brighter and brighter.

The user need to click on the ball (somewhere on it, it has a diameter of about 30) to stop the clock and end the game.

I've tried using GetRelativeMouseState to get the mouse coordinates and then comparing them to the x,y co of the ball.

Then checking if they match (or within the diameter) the ball and the timer should stop.

For some reason it doesn't work and I'm fairly new to using left mouse click and state.

here is the part of the code that I need help with:

 

int CVICALLBACK timerFunc (int panel, int control, int event, //circle game timer func (move ball)
void *callbackData, int eventData1, int eventData2)
{

    switch (event)
   {
   case EVENT_TIMER_TICK:
   circleCount=circleCount+0.01;
   colorCirc=MakeColor (r, g, b);
   SetCtrlAttribute (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, ATTR_PEN_COLOR, colorCirc);
   SetCtrlAttribute (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, ATTR_PEN_WIDTH, 100);
   CanvasStartBatchDraw (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC);
   CanvasClear (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, VAL_ENTIRE_OBJECT);
   x=x+vx;
   y=y+vy;
   CanvasDrawPoint (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, MakePoint(x,y));
   if(x>=canvasW-15)
      {
         vx=-(vx);
      }
   if(y>=canvasH-15)
      {
        vy=-(vy);
       }
    if(x<=15)
      {
       vx=-(vx);
      }
    if(y<=15)
     {
       vy=-(vy);
      }
 switch (event)
    {
       case EVENT_LEFT_CLICK:
      GetRelativeMouseState (panelHandle_circ, 0, &mousePosX, &mousePosY, NULL, NULL, NULL);
      if ((mousePosX<=x+15)&&(mousePosX>=x-15)&&(mousePosY<=y+15)&&(mousePosY>=y-15))
            {
                SetCtrlAttribute (panelHandle_circ, PANEL_CIRC_TIMER, ATTR_ENABLED, 0);
                MessagePopup ("All Done!", "Good job! Play Another Game!");
            }
    }
break;
}
return 0;
}


Viewing all articles
Browse latest Browse all 5339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>