示例#1
0
文件: game.cpp 项目: WareX97/aPlus
void arkanoid::Game::init_game_settings(){

	nodelay(stdscr, TRUE);
	getmaxyx(stdscr, actual_max_row, actual_max_col);
	stop = false;
	dr_counter = 0;
	is_ball_moving = false;
	ticks = 0;
	if(level_nr < 50)
		level_nr++;
		
	bar_speed = 4;
	if(rand() % 2 == 0)
		col_mod = -1;
	else
		col_mod = 1;

	row_mod = -1;
	draw_border();
	load_level();
	draw_object(bar);
	draw_object(ball1);
	draw_health();
	draw_level_nr();

}
示例#2
0
	void draw(BITMAP * buffer) {
		blit(bg, buffer, 0, 0, 0, 0, SCREEN_X, SCREEN_Y);
		draw_sprite(buffer, bld, 0, 0);
		for (int i = 0; i < (int)shots.size(); ++i)
			shots[i].draw(buffer);
		for (int i = 0; i < (int)tanks.size(); ++i)
			tanks[i].draw(buffer);
		for (int i = 0; i < (int)explosions.size(); ++i) {
			explosions[i].draw(buffer);
			explosions[i].destroy(bld);
			explosions[i].destroy(bld_collision);
		}
		for (int i = 0; i < (int)enemies.size(); ++i)
			enemies[i].draw(buffer);
		
		draw_health(buffer, tanks[0].health_int(), Vector(10, 10));
		
		circle(buffer, mouse_x, mouse_y, 6, makecol(255, 0, 0));
		circle(buffer, mouse_x, mouse_y, 12, makecol(255, 0, 0));
		line  (buffer, mouse_x - 16, mouse_y, mouse_x + 16, mouse_y, makecol(255, 0, 0));
		line  (buffer, mouse_x, mouse_y - 16, mouse_x, mouse_y + 16, makecol(255, 0, 0));
	}
示例#3
0
文件: game.cpp 项目: WareX97/aPlus
unsigned arkanoid::Game::update_scene(){

	if(is_scrsize_changed()){
		delete_border();
		for(unsigned i = 0; i < drawed.size(); i++){
			erase_object(drawed[i]);
		}

		getmaxyx(stdscr, actual_max_row, actual_max_col);
		
		draw_border();

		for(unsigned i = 0; i < drawed.size(); i++){
			draw_object(drawed[i]);
		}
		draw_health();
		draw_level_nr();
	}

	update_bar_position();

	return update_ball_position();
}
示例#4
0
int main(void) {
	/* Related object data */
	system_t* system;
	player_t* player1;
	player_t* player2;

	alt_timestamp_start();
	int start_time = alt_timestamp();
	int wind;
	int restart = 0;
	/* initialize all hardware dev */
	system = system_init(VIDEO_PIXEL_BUFFER_DMA_NAME,
			"/dev/video_character_buffer_with_dma_0",
			ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME, PS2_0_NAME);
	if (!alt_up_sd_card_is_Present()) {
		printf("SD card not present\n");
		return -2;
	} else {
		printf("SD card detected.\n");
	}
	if (!alt_up_sd_card_is_FAT16()) {
		printf("SD card is not FAT16.\n");
		return -3;
	} else {
		printf("SD card is FAT 16.\n");
	}
	fireSound = initSoundbank("shotgun.wav");
	explosionSound = initSoundbank("big_bomb.wav");
	printf("Done Initializing\n");
	int end_time = alt_timestamp();
	srand(end_time - start_time);
	clearScreen(system);
	printf("Press enter to start game");
	restartGame(system);
	while (restart == 1) {
	/* initialize required objects */
	player1 = makePlayer(1, "Lomash");
	player2 = makePlayer(2, "TJ");

	/*
	 * Draw the screen for the first time.
	 */
	store_background_data();
	draw_background(system);
	drawPlayers(system);
	draw_ground(system);
	draw_windbox(system);
	draw_player1GUI(system);
	draw_player2GUI(system);
	update_wind(system, wind);
	draw_health(player1, system);
	draw_health(player2, system);
	update_power(player1, system);
	update_power(player2, system);
	usleep(2000000); // sleep to wait for video buffer to load
	while (TRUE) {

	printf(
	 "\n\n\n\n===========================================================\n");
	 printf("Player 1 Health = %d \t\t Player 2 Health = %d\n",
	 player1->health, player2->health);
	 wind = rand() % 11 - 5;
	 draw_windbox(system);
	 update_wind(system, wind);


//	 Player 1's turn

	 player_1_jump(system);
	 player_1_jump(system);
	 printf("Getting Player 1 Power.\n");
	 getKeyboardInput(1, player1, system); // Power
	 skipOneEnter(system);
	 printf("Getting Player 1 Angle.\n");
	 getKeyboardInput(2, player1, system); // Angle

//	 Player 1 Animation
	 printf("Starting animation\n");
	 clear_angle_drawer(system);
	 animate_cannon1(system);
	 playSound(fireSound, system->audio);
	 switch (animateShooting(system, player1, wind)) { // different value for result
	 case 1: {
	 update_health(player2, system, -DAMAGE);
	 printf(
	 "Player 1 hit player 2.\n Remaining Health for Player 2: %d\n",
	 player2->health);
	 break;
	 }
	 case 2: {
	 update_health(player1, system, -DAMAGE);
	 printf(
	 "Player 1 hit player 1.\n Remaining Health for Player 1: %d\n",
	 player1->health);
	 break;
	 }
	 default: {
	 break;
	 }
	 }
	 printf("Ended animation\n");

//	 Post-animation Calculation
	 if (player1->health <= 0 || player2->health <= 0) {
	 break;
	 }


//	 Player 2's turn


	 wind = rand() % 11 - 5;
	 draw_windbox(system);
	 update_wind(system, wind);
	 player_2_jump(system);
	 player_2_jump(system);
	 printf("Getting Player 2 Velocity.\n");
	 getKeyboardInput(1, player2, system);
//	 Player 2 Angle-Selection
	 skipOneEnter(system);
	 printf("Getting Player 2 Angle.\n");
	 getKeyboardInput(2, player2, system);

//	 Player 2 Animation
	 printf("Starting animation\n");
	 clear_angle_drawer(system);
	 animate_cannon2(system);
	 playSound(fireSound, system->audio);
//	 Post-animation Calculation
	 switch (animateShooting(system, player2, wind)) { // different value for result
	 case 1: {
	 update_health(player1, system, -DAMAGE);
	 printf(
	 "Player 2 hit player 1.\n Remaining Health for Player 1: %d\n",
	 player1->health);
	 break;
	 }
	 case 2: {
	 update_health(player2, system, -DAMAGE);
	 printf(
	 "Player 2 hit player 2.\n Remaining Health for Player 2: %d\n",
	 player2->health);
	 break;
	 }
	 default: {
	 break;
	 }
	 }

	 if (player1->health <= 0 || player2->health <= 0) {
	 break;
	 }
	};
	/*
	 * Find out who won.
	 */
		if (player1->health <= 0) {
			printf("Player 2 Wins!!! \n");
			draw_P2WIN(system);
		} else if (player2->health <= 0) {
			printf("Player 1 Wins!!!\n");
			draw_P1WIN(system);
		} else {
			printf("we shouldn't be here.\n");
		}
		restart = restartGame(system);
	}
	return 0; // FIN
}
示例#5
0
文件: main.cpp 项目: strykejern/jumpy
int main() {
	const int spd = 16;
	for (int x=0;x<41;++x) {
		angles_y[x] = (spd*cos(PI/180*(x-20+90)));
		angles_x[x] = (spd*sin(PI/180*(x-20+90)));
	}
	
    allegro_init();
    install_keyboard();
    install_timer();
   
    LOCK_VARIABLE(speed_counter);
    LOCK_FUNCTION(increment_speed_counter);
    install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
   
    const int width = 1024;
    const int height = 768;
   
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, width, height, 0, 0);
    set_alpha_blender();
	
    BITMAP* buffer = create_bitmap(width, height);
    
    //BITMAP* image3 = load_bitmap("./sprites/chopper3.tga", 0);
    BITMAP* image2 = load_bitmap("./sprites/chopper.tga", 0);
    BITMAP* image = load_bitmap("./sprites/chopper2.tga", 0);
    
    BITMAP* background = load_bitmap("./sprites/background.bmp", 0);
    
    BITMAP* image_sphere = load_bitmap("./sprites/sphere1.tga", 0);
    BITMAP* image_sphere2 = load_bitmap("./sprites/sphere2.tga", 0);
    
    BITMAP* image_shot = load_bitmap("./sprites/shot.tga", 0);
    
    BITMAP* image_explosion[17];
    
    image_explosion[0] = load_bitmap("./sprites/exp_frame_0.tga", 0);
    image_explosion[1] = load_bitmap("./sprites/exp_frame_1.tga", 0);
    image_explosion[2] = load_bitmap("./sprites/exp_frame_2.tga", 0);
    image_explosion[3] = load_bitmap("./sprites/exp_frame_3.tga", 0);
    image_explosion[4] = load_bitmap("./sprites/exp_frame_4.tga", 0);
    image_explosion[5] = load_bitmap("./sprites/exp_frame_5.tga", 0);
    image_explosion[6] = load_bitmap("./sprites/exp_frame_6.tga", 0);
    image_explosion[7] = load_bitmap("./sprites/exp_frame_7.tga", 0);
    image_explosion[8] = load_bitmap("./sprites/exp_frame_8.tga", 0);
    image_explosion[9] = load_bitmap("./sprites/exp_frame_9.tga", 0);
    image_explosion[10] = load_bitmap("./sprites/exp_frame_10.tga", 0);
    image_explosion[11] = load_bitmap("./sprites/exp_frame_11.tga", 0);
    image_explosion[12] = load_bitmap("./sprites/exp_frame_12.tga", 0);
    image_explosion[13] = load_bitmap("./sprites/exp_frame_13.tga", 0);
    image_explosion[14] = load_bitmap("./sprites/exp_frame_14.tga", 0);
    image_explosion[15] = load_bitmap("./sprites/exp_frame_15.tga", 0);
    image_explosion[16] = load_bitmap("./sprites/exp_frame_16.tga", 0);
	
	std::vector<helicopter> heli;
    heli.push_back(helicopter(image_explosion, 17,image->w,  image->h,  40,  40, 0, 0,   0, gravity / 2, 0.8, 0.5));
    heli.push_back(helicopter(image_explosion, 17,image2->w, image2->h, 720, 40, 0, 0,   0, gravity / 2, 0.8, 0.5));
    //heli.push_back(helicopter(image_explosion, 17,image3->w, image3->h, 350, 200, 0, 100, 0, gravity / 2, 0.8, 0.5));
    heli[0].flip = !heli[0].flip;
    
    srand(time(NULL));
    
    std::vector<ball> spheres;
	for (int x=0;x<10;++x) 
		spheres.push_back(
			ball(
				image_sphere->w,
				image_sphere->h,
				(double)((int)rand()%(SCREEN_W-image_sphere->w)),
				(double)((int)rand()%(SCREEN_H-image_sphere->h)),
				(double)((int)rand()%60),
				(double)((int)rand()%60),
				0.0,
				gravity * 2,
				0.95,
				0.95));
	
	std::vector<explosion> explosions;
	
    while (!key[KEY_ESC]) {
        while (speed_counter > 0) {
        	heli[1].get_input(key[KEY_UP], key[KEY_DOWN], key[KEY_LEFT], key[KEY_RIGHT], true);
        	heli[0].get_input(key[KEY_W], key[KEY_S], key[KEY_A], key[KEY_D], true);
        	//heli[2].get_input(key[KEY_Y], key[KEY_H], key[KEY_G], key[KEY_J], true);
        	
        	for (unsigned int x=0;x<heli.size();++x) {
            	if (!(heli[x].health>0))explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y, rand()%(heli[x].size_x*2), rand()%(heli[x].size_y*2)));
        		heli[x].update_phys();
        	}
            
            for (unsigned int x=0;x<spheres.size();++x) {
            	spheres[x].update_phys();
            }
            	
            for (unsigned int x=0;x<explosions.size();++x)
            	if (explosions[x].alive)
            		explosions[x].update_frame();
            	else
            		explosions.erase(explosions.begin()+x);
            
            for (unsigned int x=0;x<heli.size();++x)
				for (unsigned int y=0;y<spheres.size();++y)
					if (check_collision(spheres[y], heli[x])) {
						heli[x].explode((heli[x].pos_x - spheres[y].pos_x)+heli[x].speed_x, (heli[x].pos_y - spheres[y].pos_y)+heli[x].speed_y, 1);
						spheres[y].explode((spheres[y].pos_x - heli[x].pos_x)+spheres[y].speed_x, (spheres[y].pos_y - heli[x].pos_y)+spheres[y].speed_y);
						if (heli[x].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y, heli[x].size_x, heli[x].size_y));
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[y].pos_x, (int)spheres[y].pos_y));
					}
            
            for (unsigned int x=0;x<spheres.size();++x)
            	for (unsigned int y=x+1;y<spheres.size();++y)
					if (check_collision(spheres[x], spheres[y])) {
						spheres[x].explode((spheres[x].pos_x - spheres[y].pos_x)+spheres[x].speed_x, (spheres[x].pos_y - spheres[y].pos_y)+spheres[x].speed_y);
						spheres[y].explode((spheres[y].pos_x - spheres[x].pos_x)+spheres[y].speed_x, (spheres[y].pos_y - spheres[x].pos_y)+spheres[y].speed_y);
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[x].pos_x, (int)spheres[x].pos_y));
						explosions.push_back(explosion(image_explosion, 17, (int)spheres[y].pos_x, (int)spheres[y].pos_y));
					}
            
            if (check_collision(heli[0], heli[1])) {
            	heli[0].explode((heli[0].pos_x - heli[1].pos_x)+heli[0].speed_x, (heli[0].pos_y - heli[1].pos_y)+heli[0].speed_y, 5);
            	heli[1].explode((heli[1].pos_x - heli[0].pos_x)+heli[1].speed_x, (heli[1].pos_y - heli[0].pos_y)+heli[1].speed_y, 5);
            	if (heli[0].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[0].pos_x, (int)heli[0].pos_y, heli[0].size_x, heli[0].size_y));
            	if (heli[1].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[1].pos_x, (int)heli[1].pos_y, heli[1].size_x, heli[1].size_y));
            }
            
            for (unsigned int x=0;x<heli.size();++x) {
            	for (unsigned int y=0;y<heli[x].shots.size();++y) {
            		for (unsigned int z=0;z<heli.size();++z)
            			if (z!=x)
            				if (check_collision(heli[x].shots[y], heli[z])) {
            					heli[z].explode((heli[z].pos_x - heli[x].shots[y].pos_x)+heli[z].speed_x, (heli[z].pos_y - heli[x].shots[y].pos_y)+heli[z].speed_y,10);
            					if (heli[z].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[z].pos_x, (int)heli[z].pos_y));
            				}
            		for (unsigned int z=0;z<spheres.size();++z)
            			if (check_collision(heli[x].shots[y], spheres[z])) {
							spheres[z].explode((spheres[z].pos_x - heli[x].shots[y].pos_x)+spheres[z].speed_x, (spheres[z].pos_y - heli[x].shots[y].pos_y)+spheres[z].speed_y);
							explosions.push_back(explosion(image_explosion, 17, (int)spheres[z].pos_x, (int)spheres[z].pos_y));
							if (z==0) {
								spheres.erase(spheres.begin());
								spheres.push_back(ball(image_sphere->w,image_sphere->h,(double)((int)rand()%(SCREEN_W-image_sphere->w)),(double)((int)rand()%(SCREEN_H-image_sphere->h)),(double)((int)rand()%60),(double)((int)rand()%60),0.0,gravity * 2,0.95,0.95));
								heli[x].health += 50;
							}
						}
            	}
            	for (unsigned int y=x+1;y<heli.size();++y)
            		if (check_collision(heli[x], heli[y])) {
            			heli[x].explode((heli[x].pos_x - heli[y].pos_x)+heli[x].speed_x, (heli[x].pos_y - heli[y].pos_y)+heli[x].speed_y,10);
            			if (heli[x].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[x].pos_x, (int)heli[x].pos_y));
            			heli[y].explode((heli[y].pos_x - heli[x].pos_x)+heli[y].speed_x, (heli[y].pos_y - heli[x].pos_y)+heli[y].speed_y,10);
            			if (heli[y].health>0) explosions.push_back(explosion(image_explosion, 17, (int)heli[y].pos_x, (int)heli[y].pos_y));
            		}
            }
            
            speed_counter--;
        }
        
		blit(background, buffer, 0, 0, 0, 0, width, height);
		
		for (unsigned int x=0;x<spheres.size();++x) {
			if (x==0)
				spheres[x].draw(buffer, image_sphere2);
			else
				spheres[x].draw(buffer, image_sphere);
		}
			
        heli[0].draw(buffer, image, image_shot);
        heli[1].draw(buffer, image2, image_shot);
        //heli[2].draw(buffer, image3, image_shot);
        
        draw_health(buffer, 10, 10, heli[0].health);
        draw_health(buffer, SCREEN_W-110, 10, heli[1].health);
        //draw_health(buffer, SCREEN_W/2, 10, heli[2].health);
        
        for (unsigned int x=0;x<explosions.size();++x)
        	explosions[x].draw(buffer);
		
        blit(buffer, screen, 0, 0, 0, 0, width, height);
        clear_bitmap(buffer);
    }
   
    destroy_bitmap(buffer);
    
   
    return 0;
}
示例#6
0
文件: game.cpp 项目: WareX97/aPlus
unsigned arkanoid::Game::update_ball_position(){

	if(!is_ball_moving && g_input == ' '){

		is_ball_moving = true;

	}

	int ob_id;
	bool anglex = false, angley = false;

	if(is_ball_moving){
		if(ticks % (200000 - (level_nr * 2500)) == 0){
			Drawable *bar = &drawed[drawed.size() - 2];
			Drawable *ball = &drawed[drawed.size() - 1];

			ball_px = ball->d_start_col;
			ball_py = ball->d_start_row;
			erase_object(*ball);
			ball->d_start_col += col_mod;
			ball->d_end_col += col_mod;
			ball->d_start_row += row_mod;
			ball->d_end_row += row_mod;
			if(alevel->M[ball->d_start_row][ball->d_start_col] == 0){
				if((ball->d_start_row >= bar->d_start_row) && (ball->d_start_col >= bar->d_start_col) && (ball->d_start_col <= bar->d_end_col)){
					row_mod = -row_mod;
					ball->d_start_col += col_mod;
					ball->d_end_col += col_mod;
					ball->d_start_row += row_mod;
					ball->d_end_row += row_mod;
					draw_object(*ball);

				} else if((ball->d_start_row >= bar->d_start_row) && !((ball->d_start_col >= bar->d_start_col) && (ball->d_start_col <= bar->d_end_col))){
					if(health > 1){
						is_ball_moving = false;
						ball->d_start_col = (bar->d_end_col + bar->d_start_col) / 2;
						ball->d_end_col = (bar->d_end_col + bar->d_start_col) / 2;
						ball->d_start_row = 21;
						ball->d_end_row = 21;
						draw_object(*ball);
						if(rand() % 2 == 0)
							col_mod = -1;
						else
							col_mod = 1;
						row_mod = -1;
						health--;
						draw_health();
						
					} else {
						return 1;
					}
				} else {
					draw_object(*ball);
				}
			} else {
				ob_id = alevel->M[ball->d_start_row][ball->d_start_col];
				if(alevel->M[ball_py + row_mod][ball_px] != 0){
					row_mod = -row_mod;
				} else {
					angley = true;
				}

				if(alevel->M[ball_py][ball_px + col_mod] != 0){
					col_mod = -col_mod;
				} else {
					anglex = true;
				}

				if(anglex && angley){
					row_mod = -row_mod;
					col_mod = -col_mod;
				}

				if(ob_id != -1){
					erase_object(drawed[ob_id - 1]);
					drawed[ob_id - 1].not_visible();
					alevel->mark_element(drawed[ob_id - 1].d_start_row, drawed[ob_id - 1].d_start_col, 0);
					if(ob_id == 1){
						return 2;
					}
				}
				
				ball->d_start_col += col_mod;
				ball->d_end_col += col_mod;
				ball->d_start_row += row_mod;
				ball->d_end_row += row_mod;

				if(alevel->M[ball->d_start_row][ball->d_start_col] != -1){
					if((ball->d_start_row == bar->d_start_row) && (ball->d_start_col >= bar->d_start_col) && (ball->d_start_col <= bar->d_end_col)){
						if(anglex){
							col_mod = -col_mod;
							ball->d_start_col += col_mod;
							ball->d_end_col += col_mod;
							ball->d_start_row += row_mod;
							ball->d_end_row += row_mod;
							draw_object(*ball);
						} else if(angley){
							row_mod = -row_mod;
							ball->d_start_col += col_mod;
							ball->d_end_col += col_mod;
							ball->d_start_row += row_mod;
							ball->d_end_row += row_mod;
							draw_object(*ball);
						}
					} else if((ball->d_start_row > bar->d_start_row) && (ball->d_start_col >= bar->d_start_col) && (ball->d_start_col <= bar->d_end_col)){
						if(angley)
							row_mod = -row_mod;
						else if(anglex)
							col_mod = -col_mod;
							
						ball->d_start_col = ball_px + col_mod;
						ball->d_end_col = ball_px + col_mod;
						ball->d_start_row = ball_py + row_mod;
						ball->d_end_row = ball_py + row_mod;
					} else if((ball->d_start_row >= bar->d_start_row) && !((ball->d_start_col >= bar->d_start_col) && (ball->d_start_col <= bar->d_end_col))){
						is_ball_moving = false;
						ball->d_start_col = (bar->d_end_col + bar->d_start_col) / 2;
						ball->d_end_col = (bar->d_end_col + bar->d_start_col) / 2;
						ball->d_start_row = 21;
						ball->d_end_row = 21;
						draw_object(*ball);
						if(rand() % 2 == 0)
							col_mod = -1;
						else
							col_mod = 1;
						row_mod = -1;
						health--;
						draw_health();
					} else {
						draw_object(*ball);
					}
				} else {
					if(anglex){
						col_mod = -col_mod;
						ball->d_start_col += col_mod;
						ball->d_end_col += col_mod;
						ball->d_start_row += row_mod;
						ball->d_end_row += row_mod;
						draw_object(*ball);
					} else if(angley){
						row_mod = -row_mod;
						ball->d_start_col += col_mod;
						ball->d_end_col += col_mod;
						ball->d_start_row += row_mod;
						ball->d_end_row += row_mod;
						draw_object(*ball);
					}

				}
				
			}
		}
	}
	return 0;
}