Пример #1
0
Virus::Virus(SDL_Renderer *renderer, string filePath, string audioPath, float x, float y)
{
	active = true;

	fire = Mix_LoadWAV((audioPath + "fire.wav").c_str());
	splat = Mix_LoadWAV((audioPath + "splat.mp3").c_str());

	string basePath = filePath + "vBase2.png";

	vBase = IMG_LoadTexture(renderer, basePath.c_str());

	string barrelPath = filePath + "vTurret2.png";

	vBarrel = IMG_LoadTexture(renderer, barrelPath.c_str());

	// base
	baseRect.x = x;
	baseRect.y = y;

	int w, h;
	SDL_QueryTexture(vBase, NULL, NULL, &w, &h);
	baseRect.w = w;
	baseRect.h = h;

	// barrel
	barrelRect.x = x;
	barrelRect.y = y;

	SDL_QueryTexture(vBarrel, NULL, NULL, &w, &h);
	barrelRect.w = w;
	barrelRect.h = h;

	center.x = w/2;
	center.y = h/2;

	string bulletPath = filePath + "virusBullet.png";

	for (int i = 0; i < 10; i++)
	{
		VirusBullet tmpBullet(renderer, bulletPath, 1500, 1500);
		bulletList.push_back(tmpBullet);
	}

	srand(time(NULL));

	// update the float values for movement
	posB_X = baseRect.x;
	posB_Y = baseRect.y;

	posT_X = barrelRect.x;
	posT_Y = barrelRect.y;

	health = 10;


}
Пример #2
0
Turret::Turret(SDL_Renderer *renderer, string filePath, string audioPath, float x, float y){
	active = true;

	fire = Mix_LoadWAV((audioPath+"fire.wav").c_str());

	string basePath = filePath + "turretBase.png";

	tBase = IMG_LoadTexture(renderer, basePath.c_str());

	string barrelPath = filePath + "turretBarrel.png";

	tBarrel = IMG_LoadTexture(renderer, barrelPath.c_str());

	baseRect.x=x;
	baseRect.y=y;

	int w,h;

	SDL_QueryTexture(tBase,NULL,NULL,&w,&h);

	baseRect.w=w;
	baseRect.h=h;

	barrelRect.x=x+20;
	barrelRect.y=y+0;

	SDL_QueryTexture(tBarrel,NULL,NULL,&w,&h);
	barrelRect.w=w;
	barrelRect.h=h;

	center.x=10;
	center.y=35;

	string bulletPath = filePath + "tBullet.png";

	for(int i = 0; i < 10; i++)
	{
		TurretBullet tmpBullet(renderer,bulletPath, 500,500);

		bulletList.push_back(tmpBullet);
	}
	srand(time(NULL));

	//update the float values for movement
	posB_X = baseRect.x;
	posB_Y = baseRect.y;

	posT_X = barrelRect.x;
	posT_Y = barrelRect.y;
}
Пример #3
0
// Tank creation Method
Tank::Tank(SDL_Renderer *renderer, int pNum, string filePath, string audioPath, float x, float y)
{
	// activate the player
	active = true;

	// set the player number 0 or 1
	playerNum = pNum;

	// set float for player speed
	speed = 200.0f;

	fire = Mix_LoadWAV((audioPath + "fire.wav").c_str());

	// see if this is player 1, or player 2, and create the correct file path
	if(playerNum == 0){
		//Create the red Tank texture
		playerPath = filePath + "redTank.png";
	}else{
		//Create the blue Tank texture
		playerPath = filePath + "blueTank.png";
	}

	// load the surface into the texture
	texture = IMG_LoadTexture(renderer, playerPath.c_str());

	// set the SDL_Rect X and Y for the player
	posRect.x = x;
	posRect.y = y;

	// Use SDL_QueryTexture to get the W and H of the player's texture
	int w, h;
	SDL_QueryTexture(texture, NULL, NULL, &w, &h);
	posRect.w = w;
	posRect.h = h;

	// Set the movement floats to the players original X and Y
	pos_X = x;
	pos_Y = y;

	// set the xDir and yDir for the joysticks
	xDir = 0;
	yDir = 0;

	// set initial values so the tank can shoot
	xDirOld = 1;
	yDirOld = 0;

	// find the center of the texture
	center.x = posRect.w/2;
	center.y = posRect.h/2;

	// String to create the path to the player's bullet image
	string bulletPath;

	// see if this is player 1, or player 2, and create the correct file path
	if(playerNum == 0){
		//Create the bullet 1 texture
		bulletPath = filePath + "redBullet.png";
	}else{
		//Create the bullet 2 texture
		bulletPath = filePath + "blueBullet.png";
	}

	//Create the player's bullet pool
	for (int i = 0; i < 10; i++)
	{
		// create the bullet and move offscreen, out of the game play area
		TankBullet tmpBullet(renderer, bulletPath, -1000, -1000, 0, 0);

		// add to bulletlist
		bulletList.push_back(tmpBullet);
	}
}
Пример #4
0
Player::Player(SDL_Renderer *renderer,int pNum,string filePath,string audioPath,float x,float y)
{
	active = true;

	playerNum = pNum;

	speed=500.0f;

	laser = Mix_LoadWAV((audioPath + "/lazer.wav").c_str());

	//init for score and lives var
	oldScore=0;
	playerScore=0;
	oldLives=0;
	playerLives=3;

	TTF_Init();

	font = TTF_OpenFont((audioPath + "/Comic.ttf").c_str(), 40);

	if(playerNum==0){
		scorePos.x=scorePos.y=10;
		livesPos.x=10;
		livesPos.y=40;
	}else{
		scorePos.x=650;
		scorePos.y=10;
		livesPos.x=650;
		livesPos.y=40;
	}

	//update score method
	UpdateScore(renderer);

	UpdateLives(renderer);

	if(playerNum==0){
		playerpath = filePath + "/Player1.png";
	}else{
		playerpath = filePath + "/Player2.png";
	}
	surface = IMG_Load(playerpath.c_str());

	texture = SDL_CreateTextureFromSurface(renderer,surface);

	SDL_FreeSurface(surface);

	posRect.x=x;

	posRect.y=y;

	int w,h;

	SDL_QueryTexture(texture,NULL,NULL,&w,&h);

	posRect.w=w;

	posRect.h=h;

	pos_X=x;
	pos_Y=y;

	xDir=0;
	yDir=0;

	string bulletPath;

	if (playerNum == 0) {

		bulletPath = filePath + "/bullet.png";
	}
	else {
		bulletPath = filePath + "/bullet2.png";
	}

	for (int i = 0; i < 10; i++)
	{
		Bullet tmpBullet(renderer, bulletPath, -1000, -1000);

		bulletList.push_back(tmpBullet);
	}

}
Пример #5
0
// tank creation
Tank::Tank(SDL_Renderer *renderer, int pNum, string filePath, string audioPath, float x, float y)
{
	// load the health GUI
	back = IMG_LoadTexture(renderer, (filePath + "health_1.png").c_str());
	mid = IMG_LoadTexture(renderer, (filePath + "health_2.png").c_str());
	front = IMG_LoadTexture(renderer, (filePath + "health_3.png").c_str());

	empty = IMG_LoadTexture(renderer, (filePath + "emptyKeyGUI.png").c_str());
	one = IMG_LoadTexture(renderer, (filePath + "oneKeyGUI.png").c_str());
	two = IMG_LoadTexture(renderer, (filePath + "twoKeyGUI.png").c_str());

	none = IMG_LoadTexture(renderer, (filePath + "tLegNoneGUI.png").c_str());
	One = IMG_LoadTexture(renderer, (filePath + "tLegOneGUI.png").c_str());
	Two = IMG_LoadTexture(renderer, (filePath + "tLegTwoGUI.png").c_str());
	Three = IMG_LoadTexture(renderer, (filePath + "tLegThreeGUI.png").c_str());

	// bring in the rock landing sound
	// sound effect for the rock hit
	//rockLand = Mix_LoadWAV((audioPath + "rockClatter.wav").c_str());

	// set win condition to false
	win1 = false;
	win2 = false;

	key = 0;

	emptyR.x = oneR.x = twoR.x = 10;
	emptyR.y = oneR.y = twoR.y = 10;
	emptyR.w = oneR.w = twoR.w = 100;
	emptyR.h = oneR.h = twoR.h = 100;

	noneR.x = OneR.x = TwoR.x = ThreeR.x = 800;
	noneR.y = OneR.y = TwoR.y = ThreeR.y = 10;
	noneR.w = OneR.w = TwoR.w = ThreeR.w = 200;
	noneR.h = OneR.h = TwoR.h = ThreeR.h = 100;
	
	backR.x = midR.x = frontR.x = 350;
	backR.y = midR.y = frontR.y = 10;
	backR.w = midR.w = frontR.w = 300;
	backR.h = midR.h = frontR.h = 60;

	// player health
	playerHealth = 100.0f;
	maxHealth = 100.0f;

	active = true;

	playerNum = pNum;

	speed = 100.0f;

	// number of rocks Bibble starts with
	rocks = 3;

	// tank firing sound
	//fire = Mix_LoadWAV((audioPath + "fire.wav").c_str());

	playerPath = filePath + "Bibble.png";

	texture = IMG_LoadTexture(renderer, playerPath.c_str());

	if(texture == NULL)
	{
		printf("Could not get image: %s\n", SDL_GetError());
	}

	posRect.x = x;
	posRect.y = y;
	int w, h;
	SDL_QueryTexture(texture, NULL, NULL, &w, &h);
	posRect.w = w;
	posRect.h = h;

	pos_X = x;
	pos_Y = y;

	xDir = 0;
	yDir = 0;

	xDirOld = 1;
	yDirOld = 0;

	center.x = posRect.w/2;
	center.y = posRect.h/2;

	string bulletPath;

	if(playerNum == 0)
	{
		bulletPath = filePath + "rockItem.png";
	} 

	//create the player's bullet pool
	for (int i = 0; i < 10; i++)
	{
		//create the bullet and move offscreen, out of the gameplayer area
		Rocks tmpBullet(renderer, bulletPath, -1000, -1000, 0, 0);

		//add to bulletList
		bulletList.push_back(tmpBullet);
	}

	lockX = false;
	lockY = false;

	// create a pool of explosions - 10
	for (int i = 0; i < 10; i++) {
		// create the enemy
		RockHit tmpExplode(renderer, filePath, -1000, -1000, 0);

		// add to the enemyList
		rockHitList.push_back(tmpExplode);
	}

	// create the rects for the rock ammo indicators
	oneRock.w = twoRock.w = threeRock.w = 80;
	oneRock.h = twoRock.h = threeRock.h = 80;

	oneRock.x = 10;
	twoRock.x = 90;
	threeRock.x = 170;

	oneRock.y = twoRock.y = threeRock.y = 700;

}
Пример #6
0
//Player creation method
Player::Player(SDL_Renderer *renderer, int pNum, string filePath, string audioPath, float x, float y)
{

	//activate the player
	active = true;

	//set the player number 0 or 1
	playerNum = pNum;

	//set float for player speed
	speed = 500.0f;

	laser = Mix_LoadWAV((audioPath + "bullet.wav").c_str());

	// init score and lives vars
	oldScore = 0;
	playerScore = 0;
	oldLives = 0;
	playerLives = 3;

	//init the font system
	TTF_Init();

	//load the font
	font = TTF_OpenFont((audioPath + "Amperzand.ttf").c_str(), 40);

	//see if this is player 1 or player 2, and create the correct X and Y locations
	if (playerNum == 0)
	{
		//Create the score texture X and Y position
		scorePos.x = scorePos.y = 10;
		livesPos.x = 10;
		livesPos.y = 50;
	}
	else
	{
		scorePos.x = 650;
		scorePos.y = 10;
		livesPos.x = 650;
		livesPos.y = 50;
	}

	// update score method
	UpdateScore(renderer);

	//Update lives method
	UpdateLives(renderer);

	//see if this is player 1, or player 2, and create the correct file path
	if(playerNum == 0)
	{//Create the player 1 texture
		playerPath = filePath + "player.png";
	}else
	{//Create the player 2 texture
		playerPath = filePath + "player2.png";
	}
	//load the surface
	surface = IMG_Load(playerPath.c_str());

	//load the surface into the texture
	texture = SDL_CreateTextureFromSurface(renderer, surface);

	//free the surface for later use
	SDL_FreeSurface(surface);

	//set the SDL_Rect X and Y for the player
	posRect.x = x;
	posRect.y = y;

	//Use SDL_QueryTexture to get the kW and H of the player's texture
	int w, h;

	SDL_QueryTexture(texture, NULL, NULL, &w, &h);

	posRect.w = w;

	posRect.h = h;

	//Set the movement floats to the players original X and Y
	pos_X = x;
	pos_Y = y;

	//set the xDir and yDir for the joysticks
	xDir = 0;
	yDir = 0;

	//String to create the path to the player's bullet image
	string bulletPath;

	//see if this is player 1, or player 2, and create the correct file path
	if(playerNum == 0){
		//Create the bullet 1 texture
		bulletPath = filePath + "bullet.png";
	}else{
		//Create the bullet 2 texture
		bulletPath = filePath + "bullet2.png";
	}

	//Create the player's bullet pool
	for(int i = 0; i < 10; i++)
	{
		//create the bullet and move offscreen, out of the game play area
		Bullet tmpBullet(renderer, bulletPath, -1000, -1000);

		//add to bulletlist
		bulletList.push_back(tmpBullet);

	}


}
Пример #7
0
Turret::Turret(SDL_Renderer *renderer, string filePath, string audioPath, float x, float y)
{

	//activate
	active = true;
	e1K = false;

	

	tHealth = 10;

	powderDropped = false;

	fire = Mix_LoadWAV((audioPath + "fire.wav").c_str());

	hitP = Mix_LoadWAV((audioPath + "hit.wav").c_str());

	string basePath = filePath + "tBase.png";

	tBase = IMG_LoadTexture(renderer, basePath.c_str());

	string barrelPath = filePath + "tHead.png";

	tBarrel = IMG_LoadTexture(renderer, barrelPath.c_str());

	string powderPath = filePath + "Bag.png";

	powder = IMG_LoadTexture(renderer, powderPath.c_str());

	powderRect.x = x;
	powderRect.y = y;

	int w, h;
	SDL_QueryTexture(powder, NULL, NULL, &w, &h);
	powderRect.w = w;
	powderRect.h = h;

	baseRect.x = x;
	baseRect.y = y;


	SDL_QueryTexture(tBase, NULL, NULL, &w, &h);
	baseRect.w = w;
	baseRect.h = h;

	barrelRect.x = x +46;
	barrelRect.y = y +46;

	SDL_QueryTexture(tBarrel, NULL, NULL, &w, &h);
	barrelRect.w = w;
	barrelRect.h = h;

	center.x = 12;
	center.y = 12;

	string bulletPath = filePath + "tbullet.png";

	for (int i = 0; i < 10; i++)
	{
		TurretBullet tmpBullet(renderer, bulletPath, 1500, 1500);

		bulletList.push_back(tmpBullet);
	}

	srand(time(NULL));

	//update the float
	posB_X = baseRect.x;
	posB_Y = baseRect.y;

	posT_X = baseRect.x;
	posT_Y = baseRect.x;


}