Ejemplo n.º 1
0
bool ElasticItem::checkCollision(MoveableItem *item)
{
	if (opacity() == 0)
		return false;

	QPoint ballCenter = item->centerPoint();
	QPoint mappedCenter = mapFromItem(item->parentItem(), ballCenter).toPoint();
	ballCenter = mappedCenter;

	if (topSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedY(-fabs(item->speedY()));
		return true;
	}
	if (bottomSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedY(fabs(item->speedY()));
		return true;
	}
	if (leftSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedX(-fabs(item->speedX()));
		return true;
	}
	if (rightSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedX(fabs(item->speedX()));
		return true;
	}

	if (topLeftSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedX(-fabs(item->speedX()));
		item->setSpeedY(-fabs(item->speedY()));
		return true;
	}
	if (topRightSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedX(fabs(item->speedX()));
		item->setSpeedY(-fabs(item->speedY()));
		return true;
	}

	if (bottomLeftSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedX(-fabs(item->speedX()));
		item->setSpeedY(fabs(item->speedY()));
		return true;
	}
	if (bottomRightSensor(item->width()/2).contains(ballCenter, true)) {
		item->setSpeedX(fabs(item->speedX()));
		item->setSpeedY(fabs(item->speedY()));
		return true;
	}

	return false;
}
Ejemplo n.º 2
0
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                			 // Stop WDT

  ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IE;		 // ADC10ON, interrupt enabled
  ADC10CTL1 = ADC10DIV_7;
  ADC10CTL1 |= ADC10SSEL1|ADC10SSEL0;  				// Select SMCLK

  P1DIR |= BIT0; 									// Set P1.0 to output direction
  P1DIR |= BIT6;

  for (;;){

    leftSensor();
    if (ADC10MEM < 0x180)
      P1OUT &= BIT0;   						// Clear P1.0 LED off
    else
      P1OUT |= BIT0;  						// Set P1.0 LED on

    _delay_cycles(1000);
    rightSensor();
    if (ADC10MEM < 0x180)
    	P1OUT &= BIT6;
    else
    	P1OUT |= BIT6;

    _delay_cycles(1000);
    centerSensor();
    if (ADC10MEM < 0x150)
       	P1OUT &= BIT0;
    else
       	P1OUT |= BIT0;
  }

    return 0;
}
Ejemplo n.º 3
0
/*
 * main.c
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    BCSCTL1 = CALBC1_8MHZ;									// 8MHz clock
    DCOCTL = CALDCO_8MHZ;

    P2DIR |= BIT2;							// P2.2 is associated with TACCTL1
    P2SEL |= BIT2;

    P2DIR |= BIT4;							// P2.4 is associated with TACCTL2
    P2SEL |= BIT4;

    TA1CTL = ID_3 | TASSEL_2 | MC_1;		//set duty cycle and MCLK
    TA1CCR0 = 100;

    TA1CCR1 = 50;
    TA1CCTL1 = OUTMOD_7;					// set TACCTL1 to Reset / Set mode

    TA1CCR2 = 50;						// set TACCTL2 to Set / Reset mode
    TA1CCTL2 = OUTMOD_3;


     ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IE;		 // ADC10ON, interrupt enabled
     ADC10CTL1 = ADC10DIV_7;
     ADC10CTL1 |= ADC10SSEL1|ADC10SSEL0;  				// Select SMCLK


     for (;;){
    	 stopMovement();
    	 _delay_cycles(110000);

    	 if(leftSensor() < 0x190)					// two if statements to stay close to left wall
    	 {
    		 	turnLeftLittle();
    			_delay_cycles(9000);
    			stopMovement();
    			_delay_cycles(100000);
    	 }
    	 if(leftSensor() >= 0x170)
    	 {
    		 turnRightLittle();
    		 _delay_cycles(9000);
    		  stopMovement();
   			_delay_cycles(100000);
    	 }
    	 if (centerSensor() >=0x170 && leftSensor() >= 0x165)		// statement to turn right if both left and center sensors triggered
    	 {
    		 turnRightBig();
    		 _delay_cycles(7500);
    		stopMovement();
    		_delay_cycles(100000);
    	 }
    	 if (centerSensor() < 0x170 && leftSensor() >= 0x170)		// has robot move forward when neither sensors are triggered
    	    {
    	      moveForward();
    	      _delay_cycles(100000);
    	    }

    	 else if (centerSensor() < 0x190)
    	 {
    		 moveForward();
    		 _delay_cycles(100000);
    	 }

     }
   return 0;
}