Esempio n. 1
0
void move_Tanks(TANK_MANAGER* t_m, BULLET_MANAGER* b_m)
{
	TANK *tank = t_m->nextTank;
    srand((unsigned int)time(NULL) );
	while(NULL != tank)
	{
		if( 1 == tank->id ){
            operateTankWithInput( tank, b_m );
		} else {
            operateTankWithAI(tank, b_m);
            if( 0 >= tank->live){
                TANK* temp = tank->nextTank;

                addBoom(tank->x, tank->y, tank->color, t_m);    // tank boom^
                delTank(t_m, tank);
                tank = temp;
                //continue;
                return;
            }
		}

		moveTank(tank);
		operate_TankHitTank(tank, t_m);
		checkBounds(tank, WIDTH, HEIGHT);
		drawTank(tank);
		cleanTank(tank);
		tank = tank->nextTank;
	}
}
Esempio n. 2
0
void Tank::drawTank(QPainter &p)
{
    if(!live)
    {
        tk->tank1.removeOne(this);
        return ;
    }
    if(dir!=STOP)
        point_dir=dir;
    switch(point_dir)
    {
        case U: p.drawImage(x,y,tankImg[0]);break;
        case D: p.drawImage(x,y,tankImg[1]);break;
        case L: p.drawImage(x,y,tankImg[2]);break;
        case R: p.drawImage(x,y,tankImg[3]);break;

        case LU: p.drawImage(x,y,tankImg[4]);break;
        case LD: p.drawImage(x,y,tankImg[5]);break;
        case RU: p.drawImage(x,y,tankImg[6]);break;
        case RD: p.drawImage(x,y,tankImg[7]);break;
        default:break;
    }
    p.setPen(Qt::yellow);
    p.setBrush(Qt::red);

    p.setBrush(Qt::red);
    p.drawRect(x,y,life/3,5);

    moveTank();
}
Esempio n. 3
0
void set_UserTank(int* angle, int* velocity, psController ps, tank* user, tank* enemy, terrain tr)
{
	char done_Charging = 0;
	char hasxBeenPressed = 0;

	//Draw background of power bar
	alt_up_pixel_buffer_dma_draw_box(pixel_buffer, x0_chargeBar, y0_chargeBar, (MAX_VELOCITY) + x0_chargeBar, chargeBar_Width +  y0_chargeBar, 0x7BEF, 0);
	alt_up_pixel_buffer_dma_draw_box(pixel_buffer, x0_chargeBar, y0_chargeBar, (MAX_VELOCITY) + x0_chargeBar, chargeBar_Width +  y0_chargeBar, 0x7BEF, 1);
	//loop continues until x is pressed and released, a collision occurs, or velocity maxed out
	while(done_Charging == 0)
	{
		update_Controller_Keys(&ps);
		set_Angle( angle, ps);
		done_Charging = set_Velocity( velocity, ps);

		if(ps.b.x == 1)
			hasxBeenPressed = 1;

		//X has been released
		if(ps.b.x == 0 && hasxBeenPressed == 1)
			done_Charging = 1;

		if(ps.b.right == 1)
		{
			moveTank(user, 2, 1); //go right
			drawTank(user, tr);
			drawTank(enemy, tr);
			updateVGA();
		}
		else if(ps.b.left)
		{
			moveTank(user, 1, 1); // go left
			drawTank(user, tr);
			drawTank(enemy, tr);
			updateVGA();
		}
		display_Input(*angle, *velocity);
		delay();
	}


}
Esempio n. 4
0
int main()
{
	arr = (unsigned int**)malloc(4377 * sizeof(unsigned int));
	psController ps;
	int velocity = 0;
	int angle = 0;
	long ii = 0;
	int** collisionMatrix;
	int ee;
	int numfiles;
	char * filenames[MAXFILES];

	//init_VGA_Pixel();
	initVGA(); //pixel
	init_VGA_Char();
	av_config_setup();
	numfiles = init_sd(filenames);
	init_wav(arr);
	printf("timing audio\n");
	//time_of_sound = time_audio(arr);
	printf("looping audio\n");

	audio_isr_k = 0;
	alt_irq_register(AUDIO_IRQ, NULL, &audio_isr);
	alt_up_audio_enable_write_interrupt(audio);


	//====INITIALIZE AND DRAW TERRAIN USING BMP ===========================//
		short int fd;

		terrain background;
		fd = alt_up_sd_card_fopen("bg.bmp", false);
		initTerrain(fd, &background);
		drawBackground(background);
		alt_up_sd_card_fclose(fd);


		terrain terrain;
		fd = alt_up_sd_card_fopen("tr.bmp", false);
		initTerrain(fd, &terrain);
		drawTerrain(terrain);
		alt_up_sd_card_fclose(fd);

	//====INITIALIZE AND DRAW USER TANK USING BMP ===========================//
		fd = alt_up_sd_card_fopen("tank.bmp", false);
		tank user;
		initUserTank(&user, fd);
		drawTank(&user, background);
		alt_up_sd_card_fclose(fd);
	//====INITIALIZE AND DRAW ENEMY TANK USING BMP ===========================//
		tank enemy;
		fd = alt_up_sd_card_fopen("tk.bmp", false);
		initEnemyTank1(&enemy, fd);
		drawTank(&enemy,background);
		alt_up_sd_card_fclose(fd);
	//====SWAP BUFFERS =======================================================//
		updateVGA();
		drawBackground(background);
		drawTerrain(terrain);
		drawTank(&enemy, background);
		for(ee=0;ee < 20;ee++)
		{
			moveTank(&user, RIGHT, 1);
			drawTank(&user,background);
			updateVGA();
			drawTank(&user,background);
			//delay();
		}
	//for(ii = 0; ii < 300000; ii++);

	collisionMatrix = init_CollisionMatrix(XMAXSCREEN_RESOLUTION + 1, XMAXSCREEN_RESOLUTION + 1);

	//alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 120, 340, 240, 0x7E0 , 0); //draw terrain

	set_CollisionAtRectArea(collisionMatrix, 0 , 0, 340, 240, EMPTY);
	set_CollisionAtRectArea(collisionMatrix, 0 , 161, 340, 240, TERRAIN_COLOR);//set the rectangular area drawn by terrain to filled with terrain
	while(1){
		//angle = 0;
		velocity = 0;
		set_UserTank(&angle, &velocity, ps, &user, &enemy, background); //reads controller to set angle, power, and shoot
		shoot_Missile(angle, velocity,( user.x + user.t_VGA.width) - 1 , (240 - user.y + user.t_VGA.height) - 7, collisionMatrix, background);

	}
	clean_audio(arr);
	return 0;
}