Example #1
0
int Bonus::move_bonus(double distance, Platform plat) {
	this->cir.center.y+=distance;
	point P=intersects(this->cir,plat.return_rectangle());
	if(cir.center.y>640+cir.r) return -1;
	else {
		if(P.x!=INF&&P.y!=INF) return this->type;
		else return 0;
	}
}
Example #2
0
//co zwraca opisane jest w Ball.h
int Ball::move(vbl &blocks, vbo &borders, vbn &bonuses, Platform plat, int blocksuntouched[]) {
	bool col = false;
	bool usun = false;

	rectangle rr;
	point w;

	int cc = 0;

	//zderzenie z obramowaniem
	for (vbo::iterator it = borders.begin(); it != borders.end()/* && !col*/ && !usun; it++) {
		rr = (*it).return_rectangle();
		w = collision(rr);
		if (w.x != INF) {			
			if (!(*it).isMurderous()) {
				col = true;
				cc++;
				reflect(w);
				this->moze_odbic_sie_od_platformy = true;
			}
			else {
				usun = true;
				break;
			}
			change_vec(0.0, 0.0);
		}
	}

	bool chanceforbonus=false; //zmienna spamiętująca czy usunięto klocek
	point bonuscords;


	//zderzenie z blokiem
	for (vbl::iterator it = blocks.begin(); it != blocks.end()/* && !col*/ && !usun; it++) {
		rr = (*it).return_rectangle();
		w = collision(rr);
		if (w.x != INF) {
			col = true;
			cc++;
			reflect(w);
			if ((*it).get_lives()==(*it).get_maxlives()) blocksuntouched[(*it).get_type()]--;
			if ((*it).hit(1)) { // uderzenie z siłą 1 - do zmiany !!!
				
				chanceforbonus=true;
				bonuscords.x=((*it).return_rectangle().bottomright.x+(*it).return_rectangle().upperleft.x)/2;
				bonuscords.y=(*it).return_rectangle().bottomright.y;

				blocks.erase(it);
				
				
			}
			
			//tworzenie bonusu

			srand(time(0));
			int bonustype=rand()%3+1;
			if(bonustype%2==0&&chanceforbonus) chanceforbonus=true;
			else chanceforbonus=false;

			if(chanceforbonus) {
				circle cir;
				cir.r=16;
				cir.center=bonuscords;
				Bonus bonus(cir, bonustype); 
				bonuses.push_back(bonus);
			}
			this->moze_odbic_sie_od_platformy = true;
			break;
		}
	}

	
	
	

	

	bool plat_col = false;
	//zderzenie z platformą będzie tu ↓
//	if (this->moze_odbic_sie_od_platformy == true) {
		rr = plat.return_rectangle();
		w = collision(rr);
		if (w.x != INF) {
			plat_col = true;
			cc++;
			if (this->moze_odbic_sie_od_platformy) {
				double dist = (w.x-(rr.upperleft.x + (rr.bottomright.x-rr.upperleft.x)/2));
				reflect(w);
				change_vec(plat.getSpeed(), dist); //sprawdź czy nie krawędź
			}
			this->moze_odbic_sie_od_platformy = false;
		}
//	}
	
	//if (cc > 1) cout<<"errrrr\n";
	if (cc > 1 && plat_col) usun = true;
	
	(this->cir).center.x += speed*mv.x;
	(this->cir).center.y += speed*mv.y;	

	if (usun && !plat_col) return 1;
	else if (usun && plat_col) return 2;
	else if (plat_col) return 3;
	else return 4;
}
Example #3
0
//co zwraca opisane jest w Ball.h
int Ball::move(vbl &blocks, vbo &borders, vbn &bonuses, Platform &plat, int blocksuntouched[], int &blocks_left) {
    lBR_tmp.clear();
    lBoR_tmp.clear();
    bool col = false;
    bool usun = false;
    bool usun_zolte = false;

    rectangle rr;
    point w;

    int cc = 0;

    //zderzenie z obramowaniem
    for (vbo::iterator it = borders.begin(); it != borders.end()/* && !col*/ && !usun; it++) {
        rr = (*it).return_rectangle();
        w = collision(rr);
        if (w.x != INF && !find(*it)/*lastBorderReflection != it*/) {
            if (!(*it).isMurderous()) {
                col = true;
                cc++;
                reflect(w);
                this->moze_odbic_sie_od_platformy = true;
            }
            else {
                usun = true;
                break;
            }
            change_vec(0.0, 0.0);
            lBoR_tmp.push_back(*it);
//			lastBorderReflection = it;
//			lastBlockReflection = blocks.end();
        }
        else if (w.x != INF && find(*it)) {
            puts("err 2*lBoR");
            lBoR_tmp.push_back(*it);
        }
    }

    bool chanceforbonus=false; //zmienna spamiętująca czy usunięto klocek
    point bonuscords;


    //zderzenie z blokiem
    for (vbl::iterator it = blocks.begin(); it != blocks.end()/* && !col*/ && !usun; it++) {
        rr = (*it).return_rectangle();
        w = collision(rr);
        if (w.x != INF && !find(*it)/*lastBlockReflection != it*/) {
            lBR_tmp.push_back(*it);
//			lastBlockReflection = it;
//			lastBorderReflection = borders.end();
            col = true;
            cc++;
            reflect(w);
            if ((*it).get_lives()==(*it).get_maxlives()) {
                blocksuntouched[(*it).get_type()]--;
                int yellowblock=3;

                if(blocksuntouched[yellowblock]==0) {
                    usun_zolte = true;

                    blocksuntouched[yellowblock]=-1;
//					lastBlockReflection = blocks.end();
//					lBR_tmp.clear();
                }
            }
            if ((*it).hit(1)) { // uderzenie z siłą 1 - do zmiany !!!

                chanceforbonus=true;
                bonuscords.x=((*it).return_rectangle().bottomright.x+(*it).return_rectangle().upperleft.x)/2;
                bonuscords.y=(*it).return_rectangle().bottomright.y;

                it--;
                blocks.erase(it+1);
                blocks_left--;
//				lastBlockReflection = blocks.end();
            }
            //printf("bloki: %d\n", blocks_left);
            //lastBlockReflection = blocks.end();

            //tworzenie bonusu

            int bonustype=rand()%5;
            bonustype++;
//			bonustype=5;
            if(rand()%3==0&&chanceforbonus) chanceforbonus=true;
            else chanceforbonus=false;

            if(chanceforbonus) {
                circle cir;
                //cir.r=16;
                cir.center=bonuscords;
                Bonus bonus(cir, bonustype);
                bonuses.push_back(bonus);
            }
            this->moze_odbic_sie_od_platformy = true;
            break;
        }
        else if (w.x != INF && find(*it)/*lastBlockReflection == it*/) {
            puts("err 2*lBR");
            lBR_tmp.push_back(*it);
        }
    }

    if (usun_zolte) {
        int yellowblock = 3;
        for (vbl::iterator it2 = blocks.begin(); it2 != blocks.end(); it2++) {	//to nie powinno być w części rysowania!
            if((*it2).get_type()==yellowblock) {
                it2--;
                blocks.erase(it2+1);
                blocks_left--;
            }
        }
    }


    bool plat_col = false;
    //zderzenie z platformą będzie tu ↓
//	if (this->moze_odbic_sie_od_platformy == true) {
    rr = plat.return_rectangle();
    w = collision(rr);
    if (w.x != INF) {
        plat_col = true;
        cc++;
        if (this->moze_odbic_sie_od_platformy) {
            double dist = (w.x-(rr.upperleft.x + (rr.bottomright.x-rr.upperleft.x)/2));
            reflect(w);
            change_vec(plat.getSpeed(), dist); //sprawdź czy nie krawędź
//				lastBorderReflection = borders.end();
//				lastBlockReflection = blocks.end();
        }
        this->moze_odbic_sie_od_platformy = false;
    }
//	}


    if (!plat_col && blocksuntouched[0]) {
        w=collision(bon_bl);
        if (w.x != INF) {
            cc++;
            reflect(w);
//			lastBorderReflection = borders.end();
//			lastBlockReflection = blocks.end();
            this->moze_odbic_sie_od_platformy = false;
            change_vec(0.0, 0.0);
            blocksuntouched[0]=0;
        }
    }

    lBR.clear();
    for (vbl::iterator it = lBR_tmp.begin(); it != lBR_tmp.end(); it++) {
        lBR.push_back(*it);
//		(*it).print();
    }

    lBoR.clear();
    for (vbo::iterator it = lBoR_tmp.begin(); it != lBoR_tmp.end(); it++) {
        lBoR.push_back(*it);
//		(*it).print();
    }

    if (cc > 1) puts("errrrr");
    if (cc > 1 && plat_col) usun = true;

    (this->cir).center.x += speed*mv.x;
    (this->cir).center.y += speed*mv.y;

    if (usun && !plat_col) return 1;
    else if (usun && plat_col) return 2;
    else if (plat_col) return 3;
    else return 4;
}
Example #4
0
//co zwraca opisane jest w Ball.h
int Ball::move(vbl &blocks, vbo &borders, vbn &bonuses, Platform &plat, int blocksuntouched[], int &blocks_left, int &new_points) {
	lBR_tmp.clear();
	lBoR_tmp.clear();
	bool col = false;
	bool usun = false;
	bool usun_zolte = false;
	
	new_points = 0;

	rectangle rr;
	point w;

	int cc = 0;

	//zderzenie z obramowaniem
	for (vbo::iterator it = borders.begin(); it != borders.end()/* && !col*/ && !usun; it++) {
		rr = (*it).return_rectangle();
		w = collision(rr);
		if (w.x != INF && !find(*it)/*lastBorderReflection != it*/) {		
			if (!(*it).isMurderous()) {
				//col = true;
				cc++;
				reflect(w);
				this->moze_odbic_sie_od_platformy = true;
			}
			else {
				usun = true;
				break;
			}
			change_vec(0.0, 0.0);
			lBoR_tmp.push_back(*it);
//			lastBorderReflection = it;
//			lastBlockReflection = blocks.end();
		}
		else if (w.x != INF && find(*it)) {
			puts("err 2*lBoR");
			lBoR_tmp.push_back(*it);
		}
	}

	bool chanceforbonus=false; //zmienna spamiętująca czy usunięto klocek
	point bonuscords;

	//zderzenie z blokiem
	for (vbl::iterator it = blocks.begin(); it != blocks.end() && !usun; it++) {
		rr = (*it).return_rectangle();
		w = collision(rr);
		if (w.x != INF && !find(*it)) {
			lBR_tmp.push_back(*it);

			col = true;
			cc++;
			reflect(w);
			if ((*it).get_lives()==(*it).get_maxlives()) {
				blocksuntouched[(*it).get_type()]--;
				int yellowblock=3;
	
				if(blocksuntouched[yellowblock]==0) {
					usun_zolte = true;
					
					blocksuntouched[yellowblock]=-1;
				}
			}
			if ((*it).hit(1)) { // uderzenie z siłą 1 - do zmiany !!!
				
				chanceforbonus=true;
				bonuscords.x=((*it).return_rectangle().bottomright.x+(*it).return_rectangle().upperleft.x)/2;
				bonuscords.y=(*it).return_rectangle().bottomright.y;

				new_points += (*it).get_type();

				it--;
				blocks.erase(it+1);
				blocks_left--;					
			}			
			
			//tworzenie bonusu
			int bonustype;
			if (chanceforbonus) {
				double random_no = (double)rand() / RAND_MAX;
				if (random_no < 0.850) chanceforbonus = false;
				else if (chanceforbonus && random_no < 0.870) bonustype = 1;
				else if (chanceforbonus && random_no < 0.905) bonustype = 2;
				else if (chanceforbonus && random_no < 0.945) bonustype = 3;
				else if (chanceforbonus && random_no < 0.980) bonustype = 4;
				else if (chanceforbonus && random_no <= 1.0) bonustype = 5;			
				/*
					1 - zmniejsz platformę
					2 - zwiększ platformę
					3 - dodaj border na dole
					4 - dodaj 2 nowe piłki
					5 - dodaj życie
				*/
				//bonustype=2;
			}

			if(chanceforbonus) {
				circle cir;
				//cir.r=16;
				cir.center=bonuscords;
				Bonus bonus(cir, bonustype); 
				bonuses.push_back(bonus);
			}
			this->moze_odbic_sie_od_platformy = true;
			break;
		}
		else if (w.x != INF && find(*it)) {
			puts("err 2*lBR");
			lBR_tmp.push_back(*it);
		}
	}
	
	if (usun_zolte) {
		int yellowblock = 3;
		for (vbl::iterator it2 = blocks.begin(); it2 != blocks.end(); it2++) {	//to nie powinno być w części rysowania!
			if((*it2).get_type()==yellowblock) {
				new_points += (*it2).get_type();
				it2--;
				blocks.erase(it2+1);
				blocks_left--;
			}
		}
	}
	

	//zderzenie z platformą
	bool plat_col = false;	
	rr = plat.return_rectangle();
	w = collision(rr);
	if (w.x != INF) {
		plat_col = true;
		cc++;
		if (this->moze_odbic_sie_od_platformy) {
			double dist = (w.x-(rr.upperleft.x + (rr.bottomright.x-rr.upperleft.x)/2));
			reflect(w);
			change_vec(plat.getSpeed(), dist); //sprawdź czy nie krawędź
		}
		this->moze_odbic_sie_od_platformy = false;
	}


	if (!plat_col && blocksuntouched[0]) {
		w=collision(bon_bl);
		if (w.x != INF) {
			cc++;
			reflect(w);
			this->moze_odbic_sie_od_platformy = false;
			change_vec(0.0, 0.0);
			blocksuntouched[0] = 0;
		}
	}
	/*else if (plat_col && blocksuntouched[0]) {
		blocksuntouched[0] = 0;
	}*/
	
	lBR.clear();
	for (vbl::iterator it = lBR_tmp.begin(); it != lBR_tmp.end(); it++) {
		lBR.push_back(*it);
	}
	
	lBoR.clear();
	for (vbo::iterator it = lBoR_tmp.begin(); it != lBoR_tmp.end(); it++) {
		lBoR.push_back(*it);
	}
	
	if (cc > 1) puts("errrrr");
	if (cc > 1 && plat_col) {
		mv.x = 0;
		mv.y = 10;
		if ((this->cir).center.y < 595) mv.y *= -1;
		if ((this->cir).center.x > 480) (this->cir).center.x -= 0.1;
		else (this->cir).center.x += 0.1;
		//usun = true;
	}
	
	(this->cir).center.x += speed*mv.x;
	(this->cir).center.y += speed*mv.y;	

	if (usun && !plat_col) return 1;
	else if (usun && plat_col) return 2;
	else if (plat_col) return 3;
	else return 4;
}
Example #5
0
//co zwraca opisane jest w Ball.h
int Ball::move(vbl &blocks, vbo &borders, Platform plat) {
	bool col = false;
	bool usun = false;

	rectangle rr;
	point w;

	//zderzenie z obramowaniem
	for (vbo::iterator it = borders.begin(); it != borders.end() && !col && !usun; it++) {
		rr = (*it).return_rectangle();
		w = collision(rr);
		if (w.x != INF) {
			if (!(*it).isMurderous()) {
				col = true;
				reflect(w);
				this->moze_odbic_sie_od_platformy = true;
			}
			else {
				usun = true;
				break;
			}
		}
	}


	//zderzenie z blokiem
	for (vbl::iterator it = blocks.begin(); it != blocks.end() && !col && !usun; it++) {
		rr = (*it).return_rectangle();
		w = collision(rr);
		if (w.x != INF) {
			col = true;
			reflect(w);
			if ((*it).hit(1)) { // uderzenie z siłą 1 - do zmiany !!!
				cout<<"usuwam...\n";
				blocks.erase(it);
			}
			this->moze_odbic_sie_od_platformy = true;
			break;
		}
	}

	bool plat_col = false;
	//zderzenie z platformą będzie tu ↓
//	if (this->moze_odbic_sie_od_platformy == true) {
		rr = plat.return_rectangle();
		w = collision(rr);
		if (w.x != INF) {
			plat_col = true;
			if (this->moze_odbic_sie_od_platformy) {
				change_vec(plat.getSpeed());
				reflect(w);
			}
			this->moze_odbic_sie_od_platformy = false;
		}
//	}
	
	(this->cir).center.x += speed*mv.x;
	(this->cir).center.y += speed*mv.y;	

	if (usun && !plat_col) return 1;
	else if (usun && plat_col) return 2;
	else if (plat_col) return 3;
	else return 4;
}