⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 special_power.cpp

📁 蕃茄炸弹超人[ACT]I ve no Tomatoes 开放原始码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Potato man power stuff
////////////////////////////////////////////////////////

// Initialize
void SP_POTATOMAN::init() {
	// Potato man doesn't pause the game
	special_power_pause = false;

	// If the potato man is already there, cancel
	if(potatoman.alive) {
		using_special_power = 0;
		return;
	}

	// Create the potato man
	create_potatoman();


	// Reduce the power amount
	icon_menu.count[GREEN_POWER_POTATOMAN]--;
	using_special_power = 0;

	// Play the potato man sound
	play_sound(SND_POTATOMAN, false);
}


// Update
void SP_POTATOMAN::update() {

}

// Draw
void SP_POTATOMAN::draw() {

}


// Flower power stuff
////////////////////////////////////////////////////////

// Initialize
void SP_FLOWERPOWER::init() {
	// Check that player isn't reloading and hasn't trown too much bombs
	if(using_special_power == 1 && (p1.reload != 0 || p1.num_flower_bombs >= 3)) {
		// Cancel
		using_special_power = 0;
		special_power_pause = false;
		return;
	}
	else if(using_special_power == 2 && (p2.reload != 0 || p2.num_flower_bombs >= 3)) {
		// Cancel
		using_special_power = 0;
		special_power_pause = false;
		return;
	}

	// Plant the flower bomb
	if(using_special_power == 1) {
		p1.reload = 30;

		add_bomb(p1.x, p1.y, BTYP_FLOWER, 1);
		p1.num_bombs++;
		p1.num_flower_bombs++;
	}
	else if(using_special_power == 2) {
		p2.reload = 30;

		add_bomb(p2.x, p2.y, BTYP_FLOWER, 2);
		p2.num_bombs++;
		p2.num_flower_bombs++;
	}

	// Play the sound
	play_sound(SND_BOMB, false);

	// Reduce the power amount
	icon_menu.count[GREEN_POWER_FLOWERPOWER]--;

	using_special_power = 0;
	special_power_pause = false;
}


// Update
void SP_FLOWERPOWER::update() {

}


// Draw
void SP_FLOWERPOWER::draw() {

}


// Teleport power stuff
////////////////////////////////////////////////////////

// Helper function which gets a random position block to which the player can
// teleport
bool block_teleport(int tx, int ty) {
	if(!map[tx][ty][1])
		return false;

	int count = 0;
	if(!map_solid(tx-1, ty))
		count++;
	if(!map_solid(tx+1, ty))
		count++;
	if(!map_solid(tx, ty-1))
		count++;
	if(!map_solid(tx, ty+1))
		count++;

	if(count)
		return true;
	else
		return false;
}


// Initialize
void SP_TELEPORT::init() {
	who = using_special_power;
	teleport_dir = DIR_UP;
	teleport_pos = 0.0f;

	// Choose the target position
	tx = RAND(0, MAP_W-1);
	ty = RAND(0, MAP_H-1);
	while(!block_teleport(tx, ty)) {
	//while(!can_teleport(tx, ty, true)) {
		tx = RAND(0, MAP_W-1);
		ty = RAND(0, MAP_H-1);
	}

	// Reduce the power amount
	icon_menu.count[BLUE_POWER_TELEPORT]--;

	// Play the teleport sound
	play_sound(SND_TELEPORT, false);
}


// Update
void SP_TELEPORT::update() {
	PLAYER &p = (who == 1) ? p1 : p2;

	// Update the teleport position
	if(teleport_dir == DIR_UP) {
		// Going up
		teleport_pos += 0.015f;

		// If we're on the top
		if(teleport_pos >= 1.0f) {
			teleport_pos = 1.0f;
			teleport_dir = DIR_DOWN;
			p.x = tx;
			p.y = ty;
			p.tx = tx;
			p.ty = ty;
			p.offset = 0;
			p.walking = false;
			p.anim = 0;
		}
	}
	else if(teleport_dir == DIR_DOWN) {
		// Going down
		teleport_pos -= 0.015f;

		// If we're landed
		if(teleport_pos <= 0.0f) {
			teleport_pos = 0.0f;
			using_special_power = 0;
			special_power_pause = false;
		}
	}


	// Create some particles
	VECT pos(p.get_real_x(), 0.25f, p.get_real_y());
	pos.y += TELEPORT_POWER_HEIGHT * teleport_pos;

	VECT dir;
	for(int f=0; f<5; f++) {
		VECT ppos = pos + VECT(RANDF(-0.5f,0.5f),RANDF(-0.5f,0.5f),RANDF(-0.5f,0.5f));
		dir.x = dir.y = dir.z = 0.0f;
		float c1[4] = { 0.3f, 0.3f, 1, 1 };
		float c2[4] = { 0.3f, 1, 1, 0.1f };

		if(ppos.y < TILE_H)
			ppos.y = TILE_H;

		add_particle(ppos, dir, RAND(10,30), 0.3f, 0.1f, c1, c2, part_star);
	}
}


// Draw
void SP_TELEPORT::draw() {

}


// Turn power stuff
////////////////////////////////////////////////////////

// Helper function which creates a new path for the enemy
void create_new_path(ENEMY *e) {
	// Trace in straight line to the opposite direction and create a path to there
	int dir = e->dir + 2;
	if(dir > DIR_W)
		dir -= 4;


	// Movement deltas for each direction
	const int dx[4] = {  0, 1, 0, -1 };
	const int dy[4] = { -1, 0, 1,  0 };

	// Sweep in a straigth line and check for the walls
	int px, py;
	int pos;
	for(pos=0; pos < MAP_W; pos++) {
		px = e->x + dx[dir] * pos;
		py = e->y + dy[dir] * pos;

		// Check for solid tile
		if(map_solid(px, py)) {
			px -= dx[dir];
			py -= dy[dir];
			break;
		}
	}

	// Calculate a new path to (px,py)
	if(e->pf.find_path(e->x, e->y, px, py) == PATH_FAILED) {
		e->path_pos = -1;
		return;
	}

	// Now we've got a nice path for us!
	e->path_pos = 0;
	e->offset = 0.0f;
	e->tx = e->pf.path[0].x;
	e->ty = e->pf.path[0].y;

}


// Initialize
void SP_TURN::init() {
	// Turn doesn't pause the game
	special_power_pause = false;

	if(enemylist.size() == 0) {
		// No enemies, cancel
		using_special_power = 0;
		return;
	}
	else {
		// Begin turning the enemies
		list<ENEMY>::iterator e;
		for(e = enemylist.begin(); e != enemylist.end(); ++e) {
			if(!(*e).dying && !(*e).turning && !(*e).burning) {
				(*e).x = (int)(*e).get_real_x();
				(*e).y = (int)(*e).get_real_y();
				(*e).turning = 1;
				(*e).offset = 0.0f;
				(*e).nextdir = (*e).dir + 1;
				if((*e).nextdir > DIR_W)
					(*e).nextdir = DIR_N;
				(*e).turning_counter = 0;
				(*e).turning_raise = 0.0f;
				(*e).speed = 0.05f;
				(*e).chase = 0;

				create_new_path(&(*e));
			}
		}
	}

	// Reduce the power amount
	icon_menu.count[BLUE_POWER_TURN]--;

	// Play the turn sound
	play_sound(SND_TURN, false);
}


// Update
void SP_TURN::update() {
	// Stop the power after a second
	if(special_power_count > 60) {
		using_special_power = 0;
	}
}


// Draw
void SP_TURN::draw() {

}


// Lightning power stuff
////////////////////////////////////////////////////////

// Initialize
void SP_LIGHTNING::init() {
	// Clear the targets
	for(int f=0; f<ENEMY_AMOUNT; f++) {
		targets[f] = NULL;
		noise[f] = RANDF(0,359);
	}

	// Choose 1 - ENEMY_AMOUNT targets
	num_targets = RAND(1,ENEMY_AMOUNT);
	if(num_targets > (signed)enemylist.size())
		num_targets = enemylist.size();

	list<ENEMY>::iterator e = enemylist.begin();
	int i;
	for(i=0; i<num_targets; i++) {
		targets[i] = &(*e);				// Pointer to the enemy in the list
		if(targets[i]->dying)
			targets[i] = NULL;
		e++;
	}

	// Count the number of the actual targets
	int num = 0;
	for(i=0; i<ENEMY_AMOUNT; i++) {
		if(targets[i])
			num++;
	}

	// If there isn't any, cancel the special power
	if(num == 0) {
		using_special_power = 0;
		special_power_pause = false;
	}
	else {
		// There is valid target(s), reduce the power amount
		icon_menu.count[BLUE_POWER_LIGHTNING]--;

		// Play the lightning sound
		play_sound(SND_LIGHTNING, false);
	}
}


// Update
void SP_LIGHTNING::update() {
	// Animate the noise using sine wave
	for(int f=0; f<ENEMY_AMOUNT; f++) {
		noise[f] = add_angle(noise[f], 5.0f);

		// Create some particles emerging from the targets
		if(RAND(0,100) > 50 && targets[f] && !targets[f]->dying) {
			VECT pos(targets[f]->get_real_x(), 0.5f, targets[f]->get_real_y());
			VECT dir;
			pos.x += RANDF(-0.5f, 0.5f);
			pos.y += RANDF(-0.5f, 0.5f);
			pos.z += RANDF(-0.5f, 0.5f);

			dir.x = RANDF(-0.025f, 0.025f);
			dir.y = RANDF(0.025f, 0.025f);
			dir.z = RANDF(-0.025f, 0.025f);
			float c1[4] = { .2f, .8f, 1, 1 };
			float c2[4] = { 0, 0, 1, 0 };
			add_particle(pos, dir, RAND(10,60), 0.5f, 0.3f, c1, c2, part_glow);
		}
	}

	if(special_power_count > 120) {
		// Kill the targets
		for(int f=0; f<ENEMY_AMOUNT; f++) {
			if(targets[f] && !targets[f]->dying) {
				targets[f]->die();
				targets[f] = NULL;
			}
		}

		using_special_power = 0;
		special_power_pause = false;
	}
}


// Draw
void SP_LIGHTNING::draw() {
	// Draw the lightning bolts to the targets
	int f;
	for(f=0; f<ENEMY_AMOUNT; f++) {
		if(targets[f] && !targets[f]->dying) {
			VECT pos1(targets[f]->get_real_x(), 0.5f, targets[f]->get_real_y());
			VECT pos2 = pos1;
			pos2.y += 14.0f;

			// Compute the noise levels using a sine wave
			float noise1 = 0.35f + (SIN(noise[f]) * 0.2f);
			float noise2 = 0.2f + (COS(noise[f]) * 0.1f);
			draw_lightning(pos1, pos2, noise1, noise2);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -