コード例 #1
0
ファイル: Balls.cpp プロジェクト: good-mark/winapi
void Balls::killNeighbours( int i, int j ) {
	color c = balls[i][j].c;
	if ( i > 0 ) 
		if ( balls[i - 1][j].isExist && balls[i - 1][j].c == c && !balls[i - 1][j].dfs ) {
			deleteBall( i - 1, j );
		}
	if ( j > 0 ) 
		if ( balls[i][j - 1].isExist && balls[i][j - 1].c == c && !balls[i][j - 1].dfs ) {
			deleteBall( i, j - 1 );
		}
	if ( i < WIDTH - 1 )  
		if ( balls[i + 1][j].isExist && balls[i + 1][j].c == c && !balls[i + 1][j].dfs ) {
			deleteBall( i + 1, j );
		}
	if ( j < HEIGHT - 1 )
		if ( balls[i][j + 1].isExist && balls[i][j + 1].c == c && !balls[i][j + 1].dfs ) {
			deleteBall( i, j + 1 );
		}
}
コード例 #2
0
ファイル: world.cpp プロジェクト: jw16057/angleball_3.0
void World::newFrame() // Call this to advance the world one tick
{
	if(deleteKeyPressed)
		deleteBall(currentMousePos);

	int x = balls.size()-1;
	Collision * returnedValue;
	if(tempOnTop)
			x--;
	while(x >= 0)
	{
		returnedValue = balls[x].tick(screenWidth, screenHeight, gravityDirection, gravityStrength, speedControl.getTime());
		
		if(returnedValue != NULL)
			collisions.push_back(returnedValue);

		x--;
	}
	speedControl.reset();
	speedControl.start();

	frameNum++;
}
コード例 #3
0
ファイル: lab3.c プロジェクト: erichuangr/ece4760
// === Animation Thread =============================================
static PT_THREAD (protothread_anim_balls(struct pt *pt))
{
    PT_BEGIN(pt); 
    while(1) {    
        PT_YIELD_TIME_msec(20);
        iterator = initial_ball;
        while(iterator != NULL) {       
            iterator2 = iterator->next;
            tft_fillCircle(fix2int16(iterator->xc), fix2int16(iterator->yc), RADIUS, ILI9340_BLACK);
            (iterator->xc) = (iterator->xc) + multfix16((iterator->vxc), drag);
            (iterator->yc) = (iterator->yc) + multfix16((iterator->vyc), drag);
            tft_fillCircle(fix2int16(iterator->xc), fix2int16(iterator->yc), RADIUS, ILI9340_WHITE);
            while(iterator2 != NULL)    {
                if (balls_collide(iterator, iterator2) && (iterator->hit_counter <= 0) && (iterator2->hit_counter <= 0))
                    computeVelocityChange(iterator, iterator2);
                else if (balls_collide(iterator, iterator2))
                {
                    iterator->hit_counter = COUNTER;
                    iterator2->hit_counter = COUNTER;
                }
                else{
                    iterator->hit_counter--;
					iterator2->hit_counter--;
                }
                iterator2 = iterator2->next;
            }
            // If the ball hits the paddle
            if ((myPaddle->xc+DIAMETER >= fix2int16(iterator->xc)) && (myPaddle->yc <= fix2int16(iterator->yc)) 
                    && ((myPaddle->yc+PADDLE_LEN) >= fix2int16(iterator->yc))){
                iterator->vxc = -(iterator->vxc);
                iterator->vyc = iterator->vyc + multfix16(int2fix16(myPaddle->vyc),pdrag);
                //DmaChnSetTxfer(dmaChn, sine_table2, (void*)&CVRCON, sizeof(sine_table2), 1, 1);
                //DmaChnEnable(dmaChn);
                //PT_YIELD_TIME_msec(2);
                //DmaChnDisable(dmaChn);  
            }
            // Else the ball went off the right edge
            else if (myPaddle->xc+DIAMETER >= fix2int16(iterator->xc))                                                    
            { 
                DmaChnSetTxfer(dmaChn, ball_scored, (void*)&CVRCON, sizeof(ball_scored), 1, 1);
                DmaChnEnable(dmaChn);
                PT_YIELD_TIME_msec(2);
                DmaChnDisable(dmaChn);  
                deleteBall(iterator); 
                score--;
            }
            // Calculate top bin
            else if ((iterator->xc) <= int2fix16(250+2) && iterator->xc >= int2fix16(175-2) && iterator->yc <= int2fix16(25+9))    
                { deleteBall(iterator); score++;}   
            // Calculate bottom bin
            else if ((iterator->xc) <= int2fix16(250+2) && iterator->xc >= int2fix16(175-2) && iterator->yc >= int2fix16(233-2))   
                { deleteBall(iterator); score++;}
            // Bounce off right wall
            else if ((iterator->xc) >= int2fix16(315))                                      
                (iterator->vxc) = -(iterator->vxc); 
            // Bounce off top or bottom wall
            else if ((iterator->yc) <= int2fix16(25) ||(iterator->yc) >= int2fix16(233))    
                (iterator->vyc) = -(iterator->vyc);         
            iterator = iterator->next;   
        }
    } // END WHILE(1)
    PT_END(pt);
} // animation thread