📄 special_power.cpp
字号:
/*************************************************************************
"I Have No Tomatoes"
Copyright (c) 2004, Mika Halttunen
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Mika Halttunen <lsoft@mbnet.fi>
*************************************************************************/
#include <stdio.h>
#include "SDL.h"
#include "SDL_opengl.h"
#include "SDL_image.h"
#include "special_power.h"
#include "enemy.h"
#include "mymath.h"
#include "effects.h"
#include "particle.h"
#include "texture.h"
#include "tilemap.h"
#include "bomb.h"
#include "game.h"
#include "trap.h"
#include "helpers.h"
#include "soundmusic.h"
#include "select_special.h"
// Special power in progress? (0 == not using, 1 == p1 using, 2 == p2)
int using_special_power = 0;
// Which special power
int which_special_power = 0;
// Special power timer
int special_power_count = 0;
// Does the special power pause the game?
bool special_power_pause;
// Teleport particle from teleport.cpp
extern GLuint part_teleport;
// The power instances
SP_TRAP sp_trap;
SP_WILDFIRE sp_wildfire;
SP_NAPALM sp_napalm;
SP_WISP sp_wisp;
SP_POTATOMAN sp_potatoman;
SP_FLOWERPOWER sp_flowerpower;
SP_TELEPORT sp_teleport;
SP_TURN sp_turn;
SP_LIGHTNING sp_lightning;
// Invoke a special power
void invoke_special_power(int who, int what) {
// if(using_special_power)
// return;
using_special_power = who;
which_special_power = what;
special_power_count = 0;
special_power_pause = true;
// Initialize the correct special power instance
switch(which_special_power) {
default:
case RED_POWER_TRAP:
sp_trap.init(); break;
case RED_POWER_WILDFIRE:
sp_wildfire.init(); break;
case RED_POWER_NAPALM:
sp_napalm.init(); break;
case GREEN_POWER_WISP:
sp_wisp.init(); break;
case GREEN_POWER_POTATOMAN:
sp_potatoman.init(); break;
case GREEN_POWER_FLOWERPOWER:
sp_flowerpower.init(); break;
case BLUE_POWER_TELEPORT:
sp_teleport.init(); break;
case BLUE_POWER_TURN:
sp_turn.init(); break;
case BLUE_POWER_LIGHTNING:
sp_lightning.init(); break;
}
}
// Draw the special power
void draw_special_power() {
if(!using_special_power)
return;
// Draw the correct special power instance
switch(which_special_power) {
default:
case RED_POWER_TRAP:
sp_trap.draw(); break;
case RED_POWER_WILDFIRE:
sp_wildfire.draw(); break;
case RED_POWER_NAPALM:
sp_napalm.draw(); break;
case GREEN_POWER_WISP:
sp_wisp.draw(); break;
case GREEN_POWER_POTATOMAN:
sp_potatoman.draw(); break;
case GREEN_POWER_FLOWERPOWER:
sp_flowerpower.draw(); break;
case BLUE_POWER_TELEPORT:
sp_teleport.draw(); break;
case BLUE_POWER_TURN:
sp_turn.draw(); break;
case BLUE_POWER_LIGHTNING:
sp_lightning.draw(); break;
}
}
// Update the special power
void update_special_power() {
if(!using_special_power)
return;
special_power_count++;
// Handle the different special powers
switch(which_special_power) {
default:
case RED_POWER_TRAP:
sp_trap.update(); break;
case RED_POWER_WILDFIRE:
sp_wildfire.update(); break;
case RED_POWER_NAPALM:
sp_napalm.update(); break;
case GREEN_POWER_WISP:
sp_wisp.update(); break;
case GREEN_POWER_POTATOMAN:
sp_potatoman.update(); break;
case GREEN_POWER_FLOWERPOWER:
sp_flowerpower.update(); break;
case BLUE_POWER_TELEPORT:
sp_teleport.update(); break;
case BLUE_POWER_TURN:
sp_turn.update(); break;
case BLUE_POWER_LIGHTNING:
sp_lightning.update(); break;
}
}
// Trap power stuff
////////////////////////////////////////////////////////
// Initialize
void SP_TRAP::init() {
// Add a trap
if(using_special_power == 1)
add_trap((int)p1.get_real_x(), (int)p1.get_real_y(), 1);
else if(using_special_power == 2)
add_trap((int)p2.get_real_x(), (int)p2.get_real_y(), 2);
using_special_power = 0;
special_power_pause = false;
// Reduce the power amount
icon_menu.count[RED_POWER_TRAP]--;
// Play the trap laying sound
play_sound(SND_TRAP, false);
}
// Update
void SP_TRAP::update() {
}
// Draw
void SP_TRAP::draw() {
}
// Wildfire power stuff
////////////////////////////////////////////////////////
// From enemy.cpp
extern int enemy_burn_time;
// Initialize
void SP_WILDFIRE::init() {
// Wildfire doesn't pause the game
special_power_pause = false;
if(enemylist.size() == 0) {
// No enemies, cancel
using_special_power = 0;
return;
}
else {
// Choose the first non-burning enemy in the list as the first victim
bool burnt = false;
list<ENEMY>::iterator e;
for(e = enemylist.begin(); e != enemylist.end(); ++e) {
if(!(*e).burning && !(*e).dying) {
(*e).burning = true;
(*e).burn_time = enemy_burn_time;
(*e).speed += 0.06f;
burnt = true;
break;
}
}
// Check that we actually burnt somebody
if(!burnt) {
// Cancel
using_special_power = 0;
return;
}
}
// Reduce the power amount
icon_menu.count[RED_POWER_WILDFIRE]--;
using_special_power = 0;
// Play the burning sound
play_sound(SND_WILDFIRE, false);
}
// Update
void SP_WILDFIRE::update() {
}
// Draw
void SP_WILDFIRE::draw() {
}
// Napalm power stuff
////////////////////////////////////////////////////////
// Helper function from player.cpp
void get_random_block_at(int x, int y, int &bx, int &by);
// Initialize
void SP_NAPALM::init() {
// Save the old player positions before jumping
oldx[0] = (int)p1.get_real_x();
oldy[0] = (int)p1.get_real_y();
oldx[1] = (int)p2.get_real_x();
oldy[1] = (int)p2.get_real_y();
// Make the player jump to safety, but don't jump if we're already on a block
if(!map_solid(oldx[0], oldy[0])) {
int jtx = 0, jty = 0;
get_random_block_at(oldx[0], oldy[0], jtx, jty);
p1.jump(jtx, jty, 2.0f, 0.05f);
// Play the jump sound
play_sound(SND_JUMP, false);
}
if(!map_solid(oldx[1], oldy[1]) && two_players) {
int jtx = 0, jty = 0;
get_random_block_at(oldx[1], oldy[1], jtx, jty);
p2.jump(jtx, jty, 2.0f, 0.05f);
// Play the jump sound
play_sound(SND_JUMP, false);
}
// Reduce the power amount
icon_menu.count[RED_POWER_NAPALM]--;
// Initialize the bombing raid! :)
cur_x = 1;
cur_y = 0;
explo_delay = 30;
}
// Update
void SP_NAPALM::update() {
// Reduce the explosion delay
if(explo_delay > 0)
explo_delay--;
// If it's time to create a new explosion, do it
if(explo_delay == 0) {
// Create an explosion
if(!map_solid(cur_x, cur_y)) {
create_explosion(cur_x, cur_y, EXP_NAPALM);
explo_delay = 1;
// Check for enemies here and kill them
list<ENEMY>::iterator e;
for(e = enemylist.begin(); e != enemylist.end(); ++e) {
if((int)((*e).get_real_x()) == cur_x && (int)((*e).get_real_y()) == cur_y && !(*e).dying)
(*e).die();
}
}
// Move
cur_x+=2;
if(cur_x > MAP_W-1) {
cur_x = (cur_y % 2) ? 1 : 0;
cur_y++;
if(cur_y > MAP_H-1) {
// Jump the players back to where they were
if(!map_solid(oldx[0], oldy[0])) {
p1.jump(oldx[0], oldy[0], 2.0f, 0.05f);
// Play the jump sound
play_sound(SND_JUMP, false);
}
if(two_players && !map_solid(oldx[1], oldy[1])) {
p2.jump(oldx[1], oldy[1], 2.0f, 0.05f);
// Play the jump sound
play_sound(SND_JUMP, false);
}
// ..and we're done!
using_special_power = 0;
special_power_pause = false;
}
// Play the explosion sound
play_sound(SND_EXPLO, true);
}
}
}
// Draw
void SP_NAPALM::draw() {
}
// Wisp power stuff
////////////////////////////////////////////////////////
// Initialize
void SP_WISP::init() {
// Wisp doesn't pause the game
special_power_pause = false;
// If the wisp is already there, cancel
if(wisp.alive) {
using_special_power = 0;
return;
}
// Create the wisp
create_wisp();
// Reduce the power amount
icon_menu.count[GREEN_POWER_WISP]--;
using_special_power = 0;
// Play the wisp sound
play_sound(SND_WISP, false);
}
// Update
void SP_WISP::update() {
}
// Draw
void SP_WISP::draw() {
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -