Ejemplo n.º 1
0
//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(0, 0, 0);
    
    moveBall();
    ofPoint* target = reach(segments[0], ball->x, ball->y);
    for(int i=1; i<numSegments; i++){
        Segment* segment = segments[i];
        target = reach(segment, target->x, target->y);
    }
    
    for(int i=numSegments - 1; i>0; i--){
        Segment* segmentA = segments[i];
        Segment* segmentB = segments[i - 1];
        position(segmentB, segmentA);
    }
    
    checkHit();
    ofNoFill();
    ofSetColor(0, 255, 0);
    for(int i=0; i<numSegments; i++){
        segments[i]->update();
    }
    
    ofFill();
    ball->update();
}
Ejemplo n.º 2
0
bool JKTetrisPiece::init(const JKTetrisPiece &other)
{
    this->x=other.x;
    this->y=other.y;
    this->type=other.type;
    this->rotation=other.rotation;
    return !checkHit();
}
Ejemplo n.º 3
0
bool JKTetrisPiece::moveRight()
{
    int oldx=x;
    x++;
    if (!checkHit()) {
        return true;
    } else {
        x=oldx;
        return false;
    }
}
Ejemplo n.º 4
0
bool JKTetrisPiece::rotateLeft()
{
    int oldrot=rotation;
    rotation=rotation-1;
    if (rotation<0) rotation=3;
    if (!checkHit()) {
        return true;
    } else {
        rotation=oldrot;
        return false;
    }
}
Ejemplo n.º 5
0
bool JKTetrisPiece::rotateRight()
{
    int oldrot=rotation;
    rotation=rotation+1;
    if (rotation>3) rotation=0;
    if (!checkHit()) {
        return true;
    } else {
        rotation=oldrot;
        return false;
    }
}
Ejemplo n.º 6
0
bool JKTetrisPiece::moveDown()
{
    if (y>=boardHeight) return false;
    int oldy=y;
    y++;
    if (!checkHit()) {
        return true;
    } else {
        y=oldy;
        return false;
    }
}
Ejemplo n.º 7
0
bool JKTetrisPiece::initTop(int type)
{
    this->x=boardWidth/2-JKTetrisPiece::PieceSize/2;//qrand()%boardWidth;
    this->y=0;
    rotation=0;
    this->type=type;
    if (type<0) {
        this->type=qrand()%JKTetrisPiece::PieceCount;
    }

    /*while (checkHit()) {
        x=qrand()%boardWidth;
    }*/
    return !checkHit();
}
Ejemplo n.º 8
0
void HelloWorld::onTouchEnded(Touch *touch, Event *unused_event)
{
	cocos2d::Point gap = touch->getLocation() - _oldP;
	float dx = abs(gap.x);
	float dy = abs(gap.y);
	if (dx <= TOUCH_GAP && dy <= TOUCH_GAP)
	{
		//
		CCLOG("click catch");
		if (!checkHit(touch->getLocation()))
		{
			addPoint(touch->getLocation());
			operationGeometryView();
		}
	}
}
Ejemplo n.º 9
0
/*
 *----------------------------------------------------------
 *	winPassive
 *	Handles passive house movements
 *	x, y - mouse position
 *----------------------------------------------------------
 */
static void winPassive (int x, int y)
{
    /*Verificar*/
    faces[OldFaceIndex].hit = FALSE;
    if (createVect)
    {
	    polygonPicking = TRUE;
	    checkHit(x,y);
	    polygonPicking = FALSE;
	    
	    capturePoints( x, y, &coords[0]);
	    faces[PointPicking].hit = TRUE;
	    OldFaceIndex = PointPicking;
    }
	
    oldMouseX = x;
    oldMouseY = y;
}
Ejemplo n.º 10
0
void PluginPong::moveBall() {
  boolean done = false;
  
  while (!done) {
    char newX, newY;

    switch (ball.angle) {
      case ANGLE_UP:  // Up
        newX = ball.x;
        newY = ball.y - ball.speed;
        break;
      case ANGLE_UP_RIGHT:  // Up and right
        newX = ball.x + ball.speed;
        newY = ball.y - ball.speed;
        break;
      case ANGLE_DOWN_RIGHT:  // Down and right
        newX = ball.x + ball.speed;
        newY = ball.y + ball.speed;
        break;
      case ANGLE_DOWN:  // Down
        newX = ball.x;
        newY = ball.y + ball.speed;
        break;
      case ANGLE_DOWN_LEFT:  // Down and left
        newY = ball.y + ball.speed;
        newX = ball.x - ball.speed;
        break;
      case ANGLE_UP_LEFT:  // Up and left
        newY = ball.y - ball.speed;
        newX = ball.x - ball.speed;
        break;
    }

    switch (checkHit(newX, newY)) {
      case NO_HIT:
        ball.x = newX;
        ball.y = newY;
        done = true;
        break;
      case HIT_UP:
      case HIT_UPPER_PADDLE:
        ball.angle = random(2, 5); // 2,3,4 = DOWN
        break;
      case HIT_DOWN:
      case HIT_LOWER_PADDLE:
        // Hack
        ball.angle = random(0, 3);
        if (ball.angle == 2)
          ball.angle = 5;
        break;
      case HIT_RIGHT:
        if (ball.angle == ANGLE_DOWN_RIGHT) {
          ball.angle = ANGLE_DOWN_LEFT;
        } else if (ball.angle == ANGLE_UP_RIGHT) {
          ball.angle = ANGLE_UP_LEFT;
        }
        break;
      case HIT_LEFT:
        if (ball.angle == ANGLE_DOWN_LEFT) {
          ball.angle = ANGLE_DOWN_RIGHT;
        } else if (ball.angle == ANGLE_UP_LEFT) {
          ball.angle = ANGLE_UP_RIGHT;
        }
        break;
    }
  }
}
void OperationCreatureHitTest::visit_Grass( StrangeGrass* target )
{
    checkHit( target, HitGrass );
}
void OperationCreatureHitTest::visit_Herbivore( StrangeHerbivore* target )
{
    checkHit( target, HitHerbivore );
}
void OperationCreatureHitTest::visit_Carnivore( StrangeCarnivore* target )
{
    checkHit( target, HitCarnivore );
}
Ejemplo n.º 14
0
void Enemy::checkDamage() {
    int ch;
    // Chech shots.
    for (int i = 0; i < shots->actor.size(); ++i) {
        if (!shots->actor[i]->isExist)
            continue;
        Vector sp =
            tr1::dynamic_pointer_cast<Shot>(shots->actor[i])->pos;
        ch = checkHit(sp, 0.7, 0);
        if (ch >= HIT) {
            manager->addParticle(sp, rand.nextSignedFloat(0.3), 0, Shot::SPEED / 4);
            manager->addParticle(sp, rand.nextSignedFloat(0.3), 0, Shot::SPEED / 4);
            manager->addParticle(sp, M_PI + rand.nextSignedFloat(0.3), 0, Shot::SPEED / 7);
            shots->actor[i]->isExist = false;
            if (ch == HIT)
                addDamage(SHOT_DAMAGE);
            else
                addDamageBattery(ch, SHOT_DAMAGE);
        }
    }
    if (manager->mode == P47GameManager::ROLL) {
        // Chech rolls.
        for (int i = 0; i < rolls->actor.size(); ++i) {
            if (!rolls->actor[i]->isExist)
                continue;
            tr1::shared_ptr<Roll> rl
                = tr1::dynamic_pointer_cast<Roll>(rolls->actor[i]);
            ch = checkHit(rl->pos[0], 1.0, 1.0);
            if (ch >= HIT) {
                for (int i = 0; i < 4; ++i)
                    manager->addParticle(rl->pos[0], rand.nextFloat(M_PI * 2), 0, Shot::SPEED / 10);
                float rd = ROLL_DAMAGE;
                if (rl->released) {
                    rd += rd;
                } else {
                    if (rl->cnt < Roll::NO_COLLISION_CNT)
                        continue;
                }
                if (ch == HIT)
                    addDamage(static_cast<int>(rd));
                else
                    addDamageBattery(ch, static_cast<int>(rd));
            }
        }
    } else if (type->type != EnemyType::SMALL) {
        //     Chech locks.
        for (int i = 0; i < locks->actor.size(); ++i) {
            if (!locks->actor[i]->isExist)
                continue;
            tr1::shared_ptr<Lock> lk = 
                tr1::dynamic_pointer_cast<Lock>(locks->actor[i]);
            if (lk->state == Lock::SEARCH || lk->state == Lock::SEARCHED) {
                ch = checkLocked(lk->pos[0], 2.5, lk);
                if (ch >= HIT) {
                    lk->state = Lock::SEARCHED;
//                    lk->lockedEnemy = this;
                    lk->lockedEnemy = returnSharedThis();
                    lk->lockedPart = ch;
                }
                return;
//            } else if (lk->state == Lock::FIRED && lk->lockedEnemy == this) {
            } else if (lk->state == Lock::FIRED && lk->lockedEnemy == returnSharedThis()) {
                ch = checkHit(lk->pos[0], 1.5, 1.5);
                if (ch >= HIT && ch == lk->lockedPart) {
                    for (int i = 0; i < 4; ++i)
                        manager->addParticle(lk->pos[0], rand.nextFloat(M_PI * 2), 0, Shot::SPEED / 10);
                    if (ch == HIT)
                        addDamage(LOCK_DAMAGE);
                    else
                        addDamageBattery(ch, LOCK_DAMAGE);
                    lk->hit();
                }
            }
        }
    }
}
Ejemplo n.º 15
0
/*Modified by Fabiane Queiroz at 29/01/2009*/
static void winMouse( int button, int state, int x, int y )
{ 
	
	if( !polygonPicking && !cellPicking )
	{
		leftPickFlag = FALSE;
		middlePickFlag = FALSE;
		
		if (button == GLUT_MIDDLE_BUTTON) 
		{
			if (state == GLUT_DOWN)
			{
				/*Start*/
				
				/*comented by fabiane Queiroz
				 For many triangles, it has a "bus error" in McloneViewer*/
				//faces[PointPicking].hit = FALSE;
				
				
				createVect = TRUE;
				
				polygonPicking = TRUE;
				
				checkHit(x,y);
				
				polygonPicking = FALSE;
				createVect = FALSE;
				
				
				if (IndexAnterior < PointPicking)
				{
					IndiceGeodesicPath = ((	IndexAnterior * NumberFaces) - ((IndexAnterior * (IndexAnterior + 1))/2));
					OffSetIndiceGeodesicPath = ((PointPicking - IndexAnterior)-1);
					
				}
				else {
					IndiceGeodesicPath = ((PointPicking * NumberFaces) - ((PointPicking * (PointPicking+1))/2));
					OffSetIndiceGeodesicPath = ((IndexAnterior - PointPicking)-1);
					
				}
				
				/*fprintf( stderr, "\nIndex = %d [%d][%d] = %f (%d, %d)\n", PointPicking, IndexAnterior, PointPicking, ArrayGeodesicPath[(IndiceGeodesicPath 							+ OffSetIndiceGeodesicPath)].Distance, ArrayGeodesicPath[(IndiceGeodesicPath + OffSetIndiceGeodesicPath)].Path1, 							ArrayGeodesicPath			[(IndiceGeodesicPath + OffSetIndiceGeodesicPath)].Path2);*/
				IndexAnterior = PointPicking;
				faces[PointPicking].hit = TRUE;
				/*End*/
				oldMouseX = x;
				oldMouseY = y;
				if (rotateflag == TRUE)
				{
					zoomflag = TRUE;
					rotateflag = FALSE;
				}
				else panflag = TRUE;
			}
			else if (state == GLUT_UP)
			{
				if (zoomflag == TRUE)
				{
					zoomflag = FALSE;
					rotateflag = TRUE;
				}
				else panflag = FALSE;
			}
		}
		else if (button == GLUT_LEFT_BUTTON)
			
		{
			if (state == GLUT_DOWN)
			{
				if( createVect == TRUE )
				{	
					storePointVector( x, y );
					glutPostRedisplay();
				}
				
				if(removevect){
					printf("removendo vetor: %d \n", PointPicking);
					removeVect(PointPicking);
				}
				
				oldMouseX = x;
				oldMouseY = y;
				if (panflag == TRUE)
				{
					zoomflag = TRUE;
					panflag = FALSE;
				}
				else rotateflag = TRUE;
			}
			
			else if (state == GLUT_UP)
			{				
				if (zoomflag == TRUE)
				{
					zoomflag = FALSE;
					panflag = TRUE;
				}
				else rotateflag = FALSE;
			}	
		}
		
	}
	/* picking is in effect */
	else
	{		
		if (state == GLUT_DOWN)
		{
			switch( button ) 
			{
				case GLUT_LEFT_BUTTON:
					leftPickFlag = TRUE;
					middlePickFlag = FALSE;
					/* Added by Thompson at 11/12/2003 */
					//fprintf(stderr, "\n\tThank you!\n");
					checkHit(x,y);
					//printf("Left Button -> X = %d | Y = %d \n", x, y);
					break;	
				case GLUT_MIDDLE_BUTTON:
					leftPickFlag = FALSE;
					middlePickFlag = TRUE;
					/* Added by Thompson at 11/12/2003 */
					//fprintf(stderr, "\n\tThank you!\n");
					checkHit(x,y);
					//printf("Middle Button -> X = %d | Y = %d \n", x, y);
					break;
				default:
					break;
			}
		}
	}
}	
Ejemplo n.º 16
0
 float checkHit(Ray ray) {
     return checkHit(ray.eye, ray.direction);
 }