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

	float xdiff;
	Drawable *bar = &drawed[drawed.size() - 2];
	Drawable *ball = &drawed[drawed.size() - 1];
	if(g_input == KEY_LEFT){
		if(bar->d_start_col > bar_speed){
			erase_object(*bar);
			bar->d_start_col -= bar_speed;
			bar->d_end_col -= bar_speed;
			draw_object(*bar);
			if(!is_ball_moving){
				erase_object(*ball);
				ball->d_start_col -= bar_speed;
				ball->d_end_col -= bar_speed;
				draw_object(*ball);
			}
		} else {
			if(bar->d_start_col > 1){
				erase_object(*bar);
				bar->d_start_col --;
				bar->d_end_col --;
				draw_object(*bar);
				if(!is_ball_moving){
					erase_object(*ball);
					ball->d_start_col --;
					ball->d_end_col --;
					draw_object(*ball);
				}
			}
		}
	} else if(g_input == KEY_RIGHT){
		
		if(bar->d_end_col < default_max_col - bar_speed - 2){
			erase_object(*bar);
			bar->d_start_col += bar_speed;
			bar->d_end_col += bar_speed;
			draw_object(*bar);
			if(!is_ball_moving){
				erase_object(*ball);
				ball->d_start_col += bar_speed;
				ball->d_end_col += bar_speed;
				draw_object(*ball);
			}
		} else {
			if(bar->d_end_col < default_max_col - 2){
				erase_object(*bar);
				bar->d_start_col ++;
				bar->d_end_col ++;
				draw_object(*bar);
				if(!is_ball_moving){
					erase_object(*ball);
					ball->d_start_col ++;
					ball->d_end_col ++;
					draw_object(*ball);
				}
			}
		}
	}
}
static int erase(struct exfat_dev* dev)
{
	const struct fs_object** pp;
	off64_t position = 0;
	const size_t block_size = 1024 * 1024;
	void* block = malloc(block_size);

	if (block == NULL)
	{
		exfat_error("failed to allocate erase block of %zu bytes", block_size);
		return 1;
	}
	memset(block, 0, block_size);

	for (pp = objects; *pp; pp++)
	{
		position = ROUND_UP(position, (*pp)->get_alignment());
		if (erase_object(dev, block, block_size, position,
				(*pp)->get_size()) != 0)
		{
			free(block);
			return 1;
		}
		position += (*pp)->get_size();
	}

	free(block);
	return 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
文件: 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;
}