bool TouchScreenSlider::process(){
    unsigned int x, y, w, h;
    getDims(&x, &y, &w, &h);
    
    bool hit=false;
    bool wasChanged = false;
    //do{
        Point p = _controller->getTouchScreen()->getPoint();
        
        if (p.z > _controller->getTouchScreen()->pressureThreshhold) {
            p.x = map(p.x, TS_MINX, TS_MAXX, _controller->getScreenWidth(), 0);
            p.y = map(p.y, TS_MINY, TS_MAXY, _controller->getScreenHeight(), 0);
            hit = checkForHit(p.x , p.y);
            if(hit){
                wasChanged=true;
                if(_layout==HORIZONTAL){
                    unsigned int value = map(p.x, x, x+w-1, 0, 100);
                    setValue((float)value/100);
                    draw(true);
                }else if(_layout==VERTICAL){
                    unsigned int value = map(p.y, y+h-1, y, 0, 100);
                    setValue((float)value/100);
                    draw(true);
                }
            }
        }
    //}while(hit==true);
    return wasChanged;
}
예제 #2
0
/** Updates the position of the rubber band. It especially sets the
 *  end position of the rubber band, i.e. the side attached to the plunger,
 *  track, or kart hit.
 */
void RubberBand::updatePosition()
{
    const Vec3 &k = m_owner->getXYZ();

    // Get the position to which the band is attached
    // ----------------------------------------------
    switch(m_attached_state)
    {
    case RB_TO_KART:    m_end_position = m_hit_kart->getXYZ(); break;
    case RB_TO_TRACK:   m_end_position = m_hit_position;       break;
    case RB_TO_PLUNGER: m_end_position = m_plunger->getXYZ();
                        checkForHit(k, m_end_position);        break;
    }   // switch(m_attached_state);

    // Update the rubber band positions
    // --------------------------------
    // Todo: make height dependent on length (i.e. rubber band gets
    // thinner). And call explosion if the band is too long.
    const float hh=.1f;  // half height of the band
    const Vec3 &p=m_end_position;  // for shorter typing
    irr::video::S3DVertex* v=(video::S3DVertex*)m_buffer->getVertices();
    v[0].Pos.X = p.getX()-hh; v[0].Pos.Y=p.getY(); v[0].Pos.Z = p.getZ()-hh;
    v[1].Pos.X = p.getX()+hh; v[1].Pos.Y=p.getY(); v[1].Pos.Z = p.getZ()+hh;
    v[2].Pos.X = k.getX()+hh; v[2].Pos.Y=k.getY(); v[2].Pos.Z = k.getZ()+hh;
    v[3].Pos.X = k.getX()-hh; v[3].Pos.Y=k.getY(); v[3].Pos.Z = k.getZ()-hh;
    m_buffer->recalculateBoundingBox();
    m_mesh->setBoundingBox(m_buffer->getBoundingBox());
}   // updatePosition
예제 #3
0
void Projectile::update() {
	Unit* target = checkForHit();
	if (target == NULL) {
		if (this->isActionsFinished())
			remove();
		return;
	}

	onHit(target);
	remove();
}
TouchScreenMenuItem *TouchScreenMenu::process(bool waitForItem){
    TouchScreenMenuItem *item = 0;
    do{
        Point p = _controller->getTouchScreen()->getPoint();
    
        if (p.z > _controller->getTouchScreen()->pressureThreshhold) {
            p.x = map(p.x, TS_MINX, TS_MAXX, _controller->getScreenWidth(), 0);
            p.y = map(p.y, TS_MINY, TS_MAXY, _controller->getScreenHeight(), 0);
            item = checkForHit(p.x , p.y);
        }
    }while(item==NULL && waitForItem);
    
    return item;
}
예제 #5
0
void executeRound(PLAYER* plr1, PLAYER* plr2)
{
	COORDINATE target;
	bool plr1hits;
	bool plr2hits;


	printGrid(plr2->view);
	printf("Player 1: Enter target! ");
	inputCoord(&target);
	plr1hits = checkForHit(&target, plr2);

	printGrid(plr1->view);
	printf("Player 2: Enter target! ");
	inputCoord(&target);
	plr2hits = checkForHit(&target, plr1);

	printf("\n\nSHELLS IN THE AIR!\n\n");

	printf("Player 1... ");
	if(plr1hits)
	{
		printf("hits!\n");
		printf("Player %d can take %d more hits.\n", 2, plr2->hits);		
	} else {
		printf("misses.\n");
	}

	printf("Player 2... ");
	if(plr2hits)
	{
		printf("hits!\n");
		printf("Player %d can take %d more hits.\n", 1, plr1->hits);
	} else {
		printf("misses.\n");
	}
}
예제 #6
0
파일: Game.cpp 프로젝트: poseidon4o/NN-aim
void Game::move()
{
	//this hack fix player fov and rotation
	for (int i = 0; i < 2; ++i)
		m_players[i]->move(0.f, m_plAreas[i]);

	//move all bulets too
	for (int i = 0; i < 2; ++i)
	{
		if (m_bullets[i].active)
		{
			m_bullets[i].pos += m_bullets[i].dir * bulletSpeed;
		}
	}
	remInactiveBullets();
	checkForHit();
	m_frameCnt++;
}
bool TouchScreenArea::process(bool waitForClick){
    bool hit=false;
    bool wasHit = false;
    do{
        Point p = _controller->getTouchScreen()->getPoint();
        
        if (p.z > _controller->getTouchScreen()->pressureThreshhold) {
            p.x = map(p.x, TS_MINX, TS_MAXX, _controller->getScreenWidth(), 0);
            p.y = map(p.y, TS_MINY, TS_MAXY, _controller->getScreenHeight(), 0);
            hit = checkForHit(p.x , p.y);
            if(hit){
                draw(true);
            }
        }
    }while(hit==false && waitForClick);
    if(hit)
        draw(false);
    return hit;
}
예제 #8
0
void WaveformAna3Tcell::analyze3TCellWaveform(bool &hit, float &stepSize, float &timeConstant, float &hitDetectionTime, float &offset, float &slope, float &chi2)
{
  if(!_wave)
    return;
  // filter data
  if (!_wave->isFiltered())
    _wave->applyLowPassFilter(_avgBufLen);
 
  // check for hit
  _hit = checkForHit(_cutSimpleThreshold);
  int hitStartTime = 0;
  if(_hit){
    hitStartTime = getHitStartTime(_cutTime, _cutTimeThreshold);
  
    if(!_hit && (hitStartTime == 0))
    { //no hit, go out!
      return;
    } 
    else
    {
  
    stepSize = 0;
    timeConstant = 0;
    
    // cout << "\tDetected " << hitCnt << " hits" << endl;
    stepSize = 0.04;
    timeConstant = hitStartTime;
    //showWaveform(_waveOrig);
    
    //Fit parameters:
    double par[5];
    par[0]= _wave->getAmpl()[hitStartTime];				  //Offset of linear w/o hit	--> Charge collected by leakage current
    par[1]= -0.000001;                              //(_wave->getAmpl()[_avgBufLen*10] - _wave->getAmpl()[hitStartTime])/(double)(_wave->getTime()[hitStartTime]-_wave->getTime()[_avgBufLen*10]);	//Slope	without hit		--> Leakage current
    par[2]= 100.0;																  //Time Constant of exp	--> Charge collection time
    par[3]= (double)_wave->getTime()[hitStartTime];	//Start time of step		--> Time of particle detection
    par[4]= abs(_wave->getAmpl()[_wave->getSize() - _avgBufLen*10] - _wave->getAmpl()[hitStartTime]);								//Step Amplitude 		--> Collected charge 
    //cout << "Parameters: " << par[0] << ", " << par[1] << ", " << par[2] << ", " << par[3] << ", " << par[4] << endl;

    //due to possible resets, fit range needs to be defined dynamically outside reset range
    double min = _wave->getTime()[_avgBufLen*10];
    double max = _wave->getTime()[_wave->getSize()-_avgBufLen*5];
    if (hitStartTime > _resetEnd){
      min = _wave->getTime()[_resetEnd];
      max = _wave->getTime()[_wave->getSize()-_avgBufLen*5];
    }
    else if ((hitStartTime < _resetStart) && (_resetStart > 0)){
      min = _wave->getTime()[_avgBufLen*10];
      max = _wave->getTime()[_resetStart];
    }

    //Initiate function
    TF1 *expStep = new TF1("expStep", this, &WaveformAna3Tcell::expstep, min, max, 5, "WaveformAna3Tcell", "expstep");

    expStep->SetParameter(0, par[0]);
    expStep->SetParameter(1, par[1]);
    expStep->SetParameter(2, par[2]);
    expStep->SetParameter(3, par[3]);
    expStep->SetParameter(4, par[4]);
    
    //showWaveform(_wave, expStep);
    TGraph *wavegraph = new TGraph(_wave->getSize(), _wave->getTime(), _wave->getAmpl());
    TFitResultPtr ptr = wavegraph->Fit("expStep", "SQ", "", min, max);

    
      
    if (_showPulse)
      showWaveform(_wave, expStep);
      
    //Check and assign invalid, if needed. Need to define invalid conditions
    if((ptr->Chi2() > _cutChi2) || (expStep->GetParameter(3) < _cutMinHitDetectionTime) || (expStep->GetParameter(3) > _cutMaxHitDetectionTime))
      _isInvalid = true;

    //fill the results into the given parameters
    offset = expStep->GetParameter(0);
    slope = expStep->GetParameter(1);
    timeConstant = expStep->GetParameter(2);
    hitDetectionTime = expStep->GetParameter(3);
    stepSize = expStep->GetParameter(4);
    chi2 = ptr->Chi2();
    hit = _hit;
    
    //For online histogram of amplitude
    _stepAmplitude = expStep->GetParameter(4);
    
    if(expStep) delete expStep;
    if(wavegraph) delete wavegraph;
  }
  }
}
예제 #9
0
/******************************************************
* PONG
* DESCRIPTION: JConsole2 Portable implementation of pong
* Created: 8/28/2013
******************************************************/
void Pong(char autoAi)
{
   char hit = 0;
   char pong_ball_start = 0;
   unsigned int userScore = 0;
   unsigned int compScore = 0;
   unsigned int highScore = EEProm_Read_16(pongHighScore);
   unsigned int ballSpeed = PONG_INITIALBALLSPEED;
   struct Paddle playerPaddle;
   struct Paddle aiPaddle;
   struct Solid ball;
   LcdClear();

   //Construct game objects
   constructPaddle2(&aiPaddle, 74, 1, 10);
   constructPaddle2(&playerPaddle, 7, 1, 10);
   displayPaddle(&playerPaddle, 0);
   displayPaddle(&aiPaddle, 0);
   displayPongScore(&userScore, &compScore);
   reset(&ball, 15, 1, 3, 3, 1);

   //Start timers
   StartTimer(0, PONG_PLAYERMOVETIME);  //Move player timer
   StartTimer(1, ballSpeed);  //Move player timer

   for (;;)
   {
	  if (CheckTimer(0))
	  {
		  if (GetDown())
		  {
		     paddle_moveDown(&playerPaddle);
		  }
		  else if (GetUp())
		  {
			  paddle_moveUp(&playerPaddle);
		  }
		  else if (GetEnterButton()) //Pause
		  {
			 if (Pause(showPongScore, userScore,  compScore, highScore) == 1)
			 {
			     return;
			 }
			 displayPaddle(&playerPaddle, 0);
			 displayPaddle(&aiPaddle, 0);
			 displaySolid(&ball, 0);
			 displayPongScore(&userScore, &compScore);
		  }
		  StartTimer(0, PONG_PLAYERMOVETIME);  //Move player timer
	  }
      if (CheckTimer(1))
      {
         //If ball moves and hits a wall, make a sound
         if (autoMoveSolid(&ball) > 1)
         {
        	 SendData(SOUND_BLOCK_DESTROYED);
         }
         aiMove(&aiPaddle, &ball); //Move computer players paddle
         if (autoAi == 1)
         {
            aiMove(&playerPaddle, &ball);
         }
         hit = checkForHit(&aiPaddle, &ball) + checkForHit(&playerPaddle, &ball);   //Check to see if ball hit either paddle
         if (hit != 0)
         {
        	 SendData(SOUND_BLOCK_DESTROYED);
        	displayPongScore(&userScore, &compScore);
        	if (ballSpeed > 10)
        	{
        	   ballSpeed = ballSpeed - 1;
        	}
         }
         //Ball hit on players side
         if (ball.xLocation == 1)
         {
            compScore++;
            displayPongScore(&userScore, &compScore);
            displayPaddle(&playerPaddle, 0);
            displayPaddle(&aiPaddle, 0);
            randomBallStart(&ball, &pong_ball_start);
         }
         //Ball hit on computers side
         else if (ball.xLocation == 76)
         {
            userScore++;
            displayPongScore(&userScore, &compScore);
            displayPaddle(&playerPaddle, 0);
            displayPaddle(&aiPaddle, 0);
            randomBallStart(&ball, &pong_ball_start);
            if (userScore > highScore)
            {
               highScore = userScore;
               EEProm_Write_16(highScore, pongHighScore);
            }
         }
         StartTimer(1, ballSpeed);  //Move player timer
      }
   }

}