示例#1
0
void Game::createBullet(bool ifPlayer) {
	for (int i = 0; i < AMOUNTOFVECTORS; i++) {
		bullet bullet1;
		/*bullet1.r = rand() % 255;
		bullet1.g = rand() % 255;
		bullet1.b = rand() % 255;*/

		bullet1.frameExposure = 0;
		bullet1.frame = 0;

		if (ifPlayer) {
			bullet1.x = playerShip.x;
			bullet1.y = playerShip.y;
			findRotation(bullet1.x, bullet1.y, mouse.GetMouseX(), mouse.GetMouseY(), bullet1.rotation);

			bullet1.vx = cos(bullet1.rotation) * PLAYERBULLETSPEED;
			bullet1.vy = sin(bullet1.rotation) * PLAYERBULLETSPEED;

			arrayOfVectors[i].push_back(bullet1);
			//plasmaShot.Play();
		}

		else {
			int k = rand() % enemyShipFleet.size();
			bullet1.x = enemyShipFleet[k].x;
			bullet1.y = enemyShipFleet[k].y;
			findRotation(bullet1.x, bullet1.y, playerShip.x, playerShip.y, bullet1.rotation);

			bullet1.vx = cos(bullet1.rotation) * ENEMYBULLETSPEED;
			bullet1.vy = sin(bullet1.rotation) * ENEMYBULLETSPEED;

			enemyBulletVector.push_back(bullet1);
		}	
	}
}
int main()
{
  char a[] = "abcd";
  char b[] = "cdab";
  printf("%d \n", findRotation(a, b));

}
示例#3
0
void Game::fireMissile(bool ifPlayer) {
	if (ifPlayer && missileAmmoVector.back().target != NULL) {
		missileAmmoVector.back().x = playerShip.x;
		missileAmmoVector.back().y = playerShip.y;
		missileAmmoVector.back().frame = 0;

		findRotation(missileAmmoVector.back().x, missileAmmoVector.back().y, missileAmmoVector.back().target->x, missileAmmoVector.back().target->y, missileAmmoVector.back().rotation);
		missileAmmoVector.back().vx = cos(missileAmmoVector.back().rotation) * PLAYERMSSILESPEED;
		missileAmmoVector.back().vy = sin(missileAmmoVector.back().rotation) * PLAYERMSSILESPEED;

		missileVector.push_back(missileAmmoVector.back());
		missileAmmoVector.erase(missileAmmoVector.begin() + missileAmmoVector.size() - 1);
		playerShip.missileAmmunition--;
	}

	else {
	}
}
示例#4
0
void Game::bulletLogic() {
	if (kbd.EnterIsPressed() && weaponChoice == BULLET && !keysPressedLastFrame){
		weaponChoice = MISSILE;
		keysPressedLastFrame = true;
	}

	else if (kbd.EnterIsPressed() && weaponChoice == MISSILE && !keysPressedLastFrame){
		weaponChoice = BULLET;
		keysPressedLastFrame = true;
	}

	if (mouse.LeftIsPressed() && weaponChoice == BULLET/*&& !keysPressedLastFrame*/) {
		if (frameCount % 8 == 0) //perfect for slowing bullets down
		createBullet(true);
		keysPressedLastFrame = true;
	}

	else if (weaponChoice == MISSILE/*&& !keysPressedLastFrame*/) {
		allLocking();
	}

	
	//if (!(mouse.LeftIsPressed())) keysPressedLastFrame = false;
	//if (!(kbd.EnterIsPressed())) keysPressedLastFrame = false;

	//movement and boundaries of bullets and animation
	for (int i = 0; i < AMOUNTOFVECTORS; i++) {
		for (int j = 0; j < arrayOfVectors[i].size(); j++) {
			arrayOfVectors[i].at(j).x += arrayOfVectors[i].at(j).vx;
			arrayOfVectors[i].at(j).y += arrayOfVectors[i].at(j).vy;
			arrayOfVectors[i].at(j).frameExposure++;
			if (arrayOfVectors[i].at(j).frameExposure > 4) {
				arrayOfVectors[i].at(j).frame++;
				if (arrayOfVectors[i].at(j).frame > 4) arrayOfVectors[i].at(j).frame = 0;
				arrayOfVectors[i].at(j).frameExposure = 0;
			}

			if (arrayOfVectors[i].at(j).y > LOWERBOUNDARY || arrayOfVectors[i].at(j).y < UPPERBOUNDARY || arrayOfVectors[i].at(j).x > RIGHTBOUNDARY || arrayOfVectors[i].at(j).x < LEFTBOUNDARY) {
				//FOR A MOTHERFUCKIN CLUSTERFUCK
				//arrayOfVectors[i].at(j).vx = arrayOfVectors[i].at(j).vx * - 1;
				//arrayOfVectors[i].at(j).vy = arrayOfVectors[i].at(j).vy * - 1;
				arrayOfVectors[i].erase(arrayOfVectors[i].begin() + j);
			}
		}
	}

	for (int a = 0; a < enemyBulletVector.size(); a++) {
		enemyBulletVector[a].x += enemyBulletVector[a].vx;
		enemyBulletVector[a].y += enemyBulletVector[a].vy;

		enemyBulletVector[a].frameExposure++;
		if (enemyBulletVector[a].frameExposure > 4) {
			enemyBulletVector[a].frame++;
			if (enemyBulletVector[a].frame > 4) enemyBulletVector[a].frame = 0;
			enemyBulletVector[a].frameExposure = 0;
		}

		if (enemyBulletVector[a].y > LOWERBOUNDARY || enemyBulletVector[a].y < UPPERBOUNDARY || enemyBulletVector[a].x > RIGHTBOUNDARY || enemyBulletVector[a].x < LEFTBOUNDARY)
		{
			enemyBulletVector.erase(enemyBulletVector.begin() + a);
		}
	}

	for (int j = 0; j < missileVector.size(); j++) {
		if (missileVector[j].target) findRotation(missileVector[j].x, missileVector[j].y, missileVector[j].target->x, missileVector[j].target->y, missileVector[j].rotation);
		else missileVector[j].target = NULL;
		//not needed should be done elsewhere instead of all the time
		missileVector[j].vx = cos(missileVector[j].rotation) * PLAYERMSSILESPEED;
		missileVector[j].vy = sin(missileVector[j].rotation) * PLAYERMSSILESPEED;

		missileVector[j].x += missileVector[j].vx;
		missileVector[j].y += missileVector[j].vy;

		if (missileVector[j].y > LOWERBOUNDARY || missileVector[j].y < UPPERBOUNDARY || missileVector[j].x > RIGHTBOUNDARY || missileVector[j].x < LEFTBOUNDARY) {
			missileVector[j].target = NULL;
			missileVector.erase(missileVector.begin() + j);
		}
	}
}
示例#5
0
void Game::updateInsects() {
	//insect kamikaze ship rotation, movement, boundaries, bullet and ship collision
	for (int i = 0; i < insectKamikazeFleet.size(); i++) {
		findRotation(insectKamikazeFleet[i].x, insectKamikazeFleet[i].y, playerShip.x, playerShip.y, insectKamikazeFleet[i].rotation);
		insectKamikazeFleet[i].vx = cos(insectKamikazeFleet[i].rotation) * insectKamikazeFleet[i].speed;
		insectKamikazeFleet[i].vy = sin(insectKamikazeFleet[i].rotation) * insectKamikazeFleet[i].speed;
		insectKamikazeFleet[i].x += insectKamikazeFleet[i].vx;
		insectKamikazeFleet[i].y += insectKamikazeFleet[i].vy;
		insectKamikazeFleet[i].frameExposure++;
		if (insectKamikazeFleet[i].frameExposure > 4) {
			insectKamikazeFleet[i].frame++;
			insectKamikazeFleet[i].frameExposure = 0;
			if (insectKamikazeFleet[i].frame > 14) insectKamikazeFleet[i].frame = 0;
		}

		if (insectKamikazeFleet[i].x + (ENEMYDIMENSION * INSECTSCALE) / 2 > RIGHTBOUNDARY) insectKamikazeFleet[i].x = RIGHTBOUNDARY - (ENEMYDIMENSION * INSECTSCALE) / 2;
		else if (insectKamikazeFleet[i].x - (ENEMYDIMENSION * INSECTSCALE) / 2 < LEFTBOUNDARY) insectKamikazeFleet[i].x = LEFTBOUNDARY + 5;
		if (insectKamikazeFleet[i].y + (ENEMYDIMENSION * INSECTSCALE) / 2 > LOWERBOUNDARY) insectKamikazeFleet[i].y = LOWERBOUNDARY - (ENEMYDIMENSION * INSECTSCALE) / 2;
		else if (insectKamikazeFleet[i].y - (ENEMYDIMENSION * INSECTSCALE) / 2 < UPPERBOUNDARY) insectKamikazeFleet[i].y = UPPERBOUNDARY + 5;

		if (insectKamikazeFleet[i].ifHit) {
			insectKamikazeFleet[i].framesSinceHit++;
			if (insectKamikazeFleet[i].framesSinceHit > FRAMESPERFLASH) {
				insectKamikazeFleet[i].framesSinceHit = 0;
				insectKamikazeFleet[i].ifHit = false;
			}
		}
	}

	for (int k = 0; k < insectKamikazeFleet.size(); k++) {
		for (int i = 0; i < AMOUNTOFVECTORS; i++) {
			for (int j = 0; j < arrayOfVectors[i].size(); j++) {
				if (arrayOfVectors[i].at(j).x > insectKamikazeFleet[k].x - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
					arrayOfVectors[i].at(j).x < insectKamikazeFleet[k].x + (ENEMYDIMENSION * INSECTSCALE) / 2 &&
					arrayOfVectors[i].at(j).y > insectKamikazeFleet[k].y - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
					arrayOfVectors[i].at(j).y < insectKamikazeFleet[k].y + (ENEMYDIMENSION * INSECTSCALE) / 2) {
					arrayOfVectors[i].erase(arrayOfVectors[i].begin() + j);
					insectKamikazeFleet[k].lives -= BULLETDAMAGE;	
					if (insectKamikazeFleet[k].lives <= 0) {
						createExplosion(explosion(), insectKamikazeFleet[k].x, insectKamikazeFleet[k].y, insectKamikazeFleet[k].rotation, 0.55f, 0, 255, 0);
						insectKamikazeFleet.erase(insectKamikazeFleet.begin() + k);
						totalInsectKillsLevel++;
						break;
					}
					else {
						insectKamikazeFleet[k].ifHit = true;
						insectKamikazeFleet[k].framesSinceHit = 0;
					}
				}
			}
		}
	}

	/*




	Make function that takes in x,y of bullet/weapon and ship, full width and height of both bullet and ship, What type of ship,
	will make much easier to change other stuff then.







	*/


	for (int k = 0; k < insectKamikazeFleet.size(); k++) {
		for (int i = 0; i < missileVector.size(); i++) {
			if (missileVector[i].x > insectKamikazeFleet[k].x - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
				missileVector[i].x < insectKamikazeFleet[k].x + (ENEMYDIMENSION * INSECTSCALE) / 2 &&
				missileVector[i].y > insectKamikazeFleet[k].y - (ENEMYDIMENSION * INSECTSCALE) / 2 &&
				missileVector[i].y < insectKamikazeFleet[k].y + (ENEMYDIMENSION * INSECTSCALE) / 2) {
				missileVector.erase(missileVector.begin() + i);
				insectKamikazeFleet[k].lives -= MISSILEDAMAGE;
				if (insectKamikazeFleet[k].lives <= 0) {		
					createExplosion(explosion(), insectKamikazeFleet[k].x, insectKamikazeFleet[k].y, insectKamikazeFleet[k].rotation, 0.55f, 0, 255, 0);
					insectKamikazeFleet.erase(insectKamikazeFleet.begin() + k);
					totalInsectKillsLevel++;
					break;
				}
				else {
					insectKamikazeFleet[k].ifHit = true;
					insectKamikazeFleet[k].framesSinceHit = 0;
				}
			}
		}
	}
}
示例#6
0
void Game::updateEnemyShip1s() {
	//rotation, movement, boundaries, bullet and ship collision
	for (int i = 0; i < enemyShipFleet.size(); i++) {
		findRotation(enemyShipFleet[i].x, enemyShipFleet[i].y, playerShip.x, playerShip.y, enemyShipFleet[i].rotation);
		enemyShipFleet[i].x += enemyShipFleet[i].vx;
		enemyShipFleet[i].y += enemyShipFleet[i].vy;

		/*
		**************************************************************************************************************

		changes to try(change direction somehow if boundary hit) Talking about enemyship1 (which he is called from now on to avoid ambiguity with the insect with just enemyship itself):
		1. Make his y = x * x
		2. y = x * x * x, log(x) sqrt(x), sin(x) etc
		3. his y = cos(rotation) and x = y * y
		4. find circle formula (based on centre maybe)
		5. semi circle
		6. form function which takes distance close to player and works dynamic circle  which changes every frame if player moves. Then try semi circle. Work it maybe with angles, or maybe just come circumference follower
		7. Finally work some way finally after doing all that to make him avoid his fellow teammates ships which will be hard.
		Function that takes in x and y of every teammate within 200-400 pixels and moves in a direction away from them but towards you if possible. Have them go slow so they can easily plan in a group mentality kinda way?
		Maybe have them eventually just go fast and slow. They slow down when clsoe to an enemy ship and eventually move away. They maybe never get too close to an enemy ship because they slow down same with yours.
		8. And separate point as to how it will look if you do eventually collide off an enemy ship. Maybe just bounce off and lose health so player avoids hitting them then.
		9. make them go in a parade kinda way. or a big s towards you and instead of avoiding you maybe enemyship1s also eventually crash into you but take their time about it.
		left all the way then small or mediumu turn towards right
		*/

		if (enemyShipFleet[i].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 > RIGHTBOUNDARY) enemyShipFleet[i].x = RIGHTBOUNDARY - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
		else if (enemyShipFleet[i].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 < LEFTBOUNDARY) enemyShipFleet[i].x = LEFTBOUNDARY + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
		if (enemyShipFleet[i].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 > LOWERBOUNDARY) {
			enemyShipFleet[i].y = LOWERBOUNDARY - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
			enemyShipFleet[i].vy *= -1;
		}
		else if (enemyShipFleet[i].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 < UPPERBOUNDARY) {
			enemyShipFleet[i].y = UPPERBOUNDARY + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2;
			enemyShipFleet[i].vy *= -1;
		}
		if (enemyShipFleet[i].ifHit) {
			enemyShipFleet[i].framesSinceHit++;
			if (enemyShipFleet[i].framesSinceHit > FRAMESPERFLASH) {
				enemyShipFleet[i].framesSinceHit = 0;
				enemyShipFleet[i].ifHit = false;
			}
		}
	}

	for (int k = 0; k < enemyShipFleet.size(); k++) {
		for (int i = 0; i < AMOUNTOFVECTORS; i++) {
			for (int j = 0; j < arrayOfVectors[i].size(); j++) {
				if (arrayOfVectors[i].at(j).x > enemyShipFleet[k].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).x < enemyShipFleet[k].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).y > enemyShipFleet[k].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
					arrayOfVectors[i].at(j).y < enemyShipFleet[k].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2) {
					arrayOfVectors[i].erase(arrayOfVectors[i].begin() + j);
					enemyShipFleet[k].lives -= BULLETDAMAGE;
					if (enemyShipFleet[k].lives <= 0) {
						createExplosion(explosion(), enemyShipFleet[k].x, enemyShipFleet[k].y, enemyShipFleet[k].rotation, 0.6f, rand() % 255, rand() % 255, rand() % 255);
						for (int a = 0; a < pShipTargets.size(); a++) {
							;//if (pShipTargets[a].ship == &enemyShipFleet[k]) pShipTargets.erase(pShipTargets.begin() + a);
						}			
						enemyShipFleet.erase(enemyShipFleet.begin() + k);
						totalEnemyShipKillsLevel++;
						break;
					}
					else {
						enemyShipFleet[k].ifHit = true;
						enemyShipFleet[k].framesSinceHit = 0;
					}
				}
			}
		}
	}

	for (int k = 0; k < enemyShipFleet.size(); k++) {
		for (int i = 0; i < missileVector.size(); i++) {
			if (missileVector[i].x > enemyShipFleet[k].x - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].x < enemyShipFleet[k].x + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].y > enemyShipFleet[k].y - (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2 &&
				missileVector[i].y < enemyShipFleet[k].y + (ENEMYDIMENSION * ENEMYSHIPSCALE) / 2) {
				missileVector[i].target = NULL;
				missileVector.erase(missileVector.begin() + i);
				enemyShipFleet[k].lives -= MISSILEDAMAGE;
				if (enemyShipFleet[k].lives <= 0) {
					createExplosion(explosion(), enemyShipFleet[k].x, enemyShipFleet[k].y, enemyShipFleet[k].rotation, 0.6f, 255, 255, 255);
					for (int a = 0; a < pShipTargets.size(); a++) {
						if (pShipTargets[a].ship == &enemyShipFleet[k]) {
							//pShipTargets[a].ship = NULL;
							//pShipTargets.erase(pShipTargets.begin() + a);
							noOfLockedOn--;
							break;
						}
					}
					//pShipTargets[k].ship = NULL;
					pShipTargets.erase(pShipTargets.begin() + k); //on the way to getting there. Fixes killing 1 guy and another green lock on showing hmm ///wont work with insects
					enemyShipFleet.erase(enemyShipFleet.begin() + k);
					for (int i = 0; i < pShipTargets.size(); i++) {
						pShipTargets[i].ship = &enemyShipFleet[i];
					}
					totalEnemyShipKillsLevel++;
					break;
				}
				else {
					enemyShipFleet[k].ifHit = true;
					enemyShipFleet[k].framesSinceHit = 0;
				}
			}
		}
	}

	if (frameCount % 60 == 0 && enemyShipFleet.size() > 0) createBullet(false);
}
示例#7
0
void Game::playerShipLogic() {
	if (kbd.RightIsPressed()) {
		playerShip.x = playerShip.x + speed;
	}

	if (kbd.LeftIsPressed()) {
		playerShip.x = playerShip.x - speed;
	}

	if (kbd.UpIsPressed()) {
		playerShip.y = playerShip.y - speed;
	}

	if (kbd.DownIsPressed()) {
		playerShip.y = playerShip.y + speed;
	}

	//boundary conditions for all
	if (playerShip.x + PLAYERDIMENSION * PLAYERSHIPSCALE > RIGHTBOUNDARY) playerShip.x = RIGHTBOUNDARY - PLAYERDIMENSION * PLAYERSHIPSCALE;
	else if (playerShip.x - PLAYERDIMENSION * PLAYERSHIPSCALE < LEFTBOUNDARY) playerShip.x = LEFTBOUNDARY + PLAYERDIMENSION * PLAYERSHIPSCALE;
	if (playerShip.y + PLAYERDIMENSION * PLAYERSHIPSCALE> LOWERBOUNDARY) playerShip.y = LOWERBOUNDARY - PLAYERDIMENSION * PLAYERSHIPSCALE;
	else if (playerShip.y - PLAYERDIMENSION * PLAYERSHIPSCALE < UPPERBOUNDARY) playerShip.y = UPPERBOUNDARY + PLAYERDIMENSION * PLAYERSHIPSCALE;

	findRotation(playerShip.x, playerShip.y, mouse.GetMouseX(), mouse.GetMouseY(), playerShip.rotation);

	if (playerShip.ifHit) {
		playerShip.framesSinceHit++;
		if (playerShip.framesSinceHit > FRAMESPERFLASH){
			playerShip.framesSinceHit = 0;
			playerShip.ifHit = false;
		}
	}

	//collision with enemy bullets
	if (!invincible) {
		for (int a = 0; a < enemyBulletVector.size(); a++) {
			if (enemyBulletVector[a].x > playerShip.x - (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2 &&
				enemyBulletVector[a].x < playerShip.x + (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2 &&
				enemyBulletVector[a].y > playerShip.y - (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2 &&
				enemyBulletVector[a].y < playerShip.y + (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2)
			{
				enemyBulletVector.erase(enemyBulletVector.begin() + a);
				if (playerShip.lives > 1) {
					playerShip.lives--;
					playerShip.ifHit = true;
					playerShip.framesSinceHit = 0;
				}
				else {
					playerShip.lives--;
					gameOver = true;
				}
			}
		}
	}

	//collision with insects
	if (!invincible) {
		for (int i = 0; i < insectKamikazeFleet.size(); i++) {
			if (insectKamikazeFleet[i].x - (ENEMYDIMENSION * INSECTSCALE) / 2 > playerShip.x - (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2 &&
				insectKamikazeFleet[i].x + (ENEMYDIMENSION * INSECTSCALE) / 2 < playerShip.x + (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2 &&
				insectKamikazeFleet[i].y - (ENEMYDIMENSION * INSECTSCALE) / 2 > playerShip.y - (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2 &&
				insectKamikazeFleet[i].y + (ENEMYDIMENSION * INSECTSCALE) / 2 < playerShip.y + (PLAYERDIMENSION * PLAYERSHIPSCALE) / 2)
			{
				insectKamikazeFleet.erase(insectKamikazeFleet.begin() + i);
				if (playerShip.lives > 1) {
					playerShip.lives--;
					playerShip.ifHit = true;
					playerShip.framesSinceHit = 0;
				}
				else {
					playerShip.lives--;
					gameOver = true;
				}
			}
		}
	}
}