1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/* modPill.cc
A "pill" which gives the player mods when taken
Copyright (C) 2000 Mathias Broxvall
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "modPill.h"
#include "debris.h"
#include "game.h"
#include "mainMode.h"
#include "map.h"
#include "player.h"
#include "sign.h"
#include "sound.h"
int isGoodPill[NUM_MODS] = {1, 1, 1, 0, 0, 0, 1, 1};
ModPill::ModPill(Real x, Real y, int kind, int time, int resurrecting)
: Ball(Role_OtherAnimated), kind(kind), resurrecting(resurrecting), time(time) {
no_physics = true;
realRadius = 0.2;
radius = realRadius;
is_on = true;
/* Change our color to red */
primaryColor = Color(1., 0.2, 0.2, 1.0);
/* set bogus velocity for the rendering of speed mods */
if (kind == MOD_SPEED) {
velocity[0] = 0.0;
velocity[1] = -1.2;
} else {
velocity = Coord3d();
}
modTimeLeft[kind] = -1.0;
clock = 0.0;
if (kind == MOD_EXTRA_LIFE) {
realRadius = 0.3;
radius = realRadius;
primaryColor = Color(1., 0.9, 0.2, 1.);
specularColor = Color(1., 0.9, 0.2, 1.);
}
position[0] = x;
position[1] = y;
position[2] = Game::current->map->getHeight(position[0], position[1]) + radius;
timeLeft = 0.;
}
ModPill::~ModPill() { this->Animated::~Animated(); }
void ModPill::tick(Real t) {
Animated::tick(t);
Player *player = Game::current->player1;
if (!is_on) {
timeLeft -= t;
if (resurrecting > 0.0 && timeLeft < 0) is_on = true;
}
clock += t;
if (kind == MOD_LARGE) {
realRadius = 0.2 * (1.0 + fmod(clock, 2.0) / 2.0);
radius = realRadius;
} else if (kind == MOD_SMALL) {
realRadius = 0.2 / (1.0 + fmod(clock, 2.0) / 2.0);
radius = realRadius;
}
if (is_on && kind == MOD_NITRO) Ball::generateNitroDebris(t);
if (is_on) {
position[2] = Game::current->map->getHeight(position[0], position[1]) + radius;
Coord3d v = player->position - position;
double dist = length(v);
if (dist < radius + player->radius) {
Coord3d signPos = position;
signPos[2] += 1.0;
/* Explanations of modpills shown after taking them. Note that only bad
ones have an exclamation mark after them */
const char *modExplanations[NUM_MODS] = {
_("Speed ball"), _("Extra jump"), _("Spikes"), _("Glass ball"),
_("Dizzy!"), _("Freeze!"), _("Floating"), _("Extra life"),
_("Small ball"), _("Large ball"), _("Nitro")};
Game::current->add(new Sign(modExplanations[kind], 6.0, 1.0, 60.0, signPos));
if (kind == MOD_EXTRA_LIFE) {
player->lives = std::min(4, player->lives + 1);
} else {
if (time >= 0.0)
player->modTimeLeft[kind] += time;
else
player->modTimeLeft[kind] = -1.0;
}
if (kind == MOD_FROZEN) MainMode::mainMode->flash = 2.0;
if (kind == MOD_EXTRA_LIFE)
playEffect(SFX_GOT_LIFE);
else if (isGoodPill[kind])
playEffect(SFX_GOT_GOODPILL);
else
playEffect(SFX_GOT_BADPILL);
is_on = false;
if (!resurrecting) remove();
timeLeft = (Real)resurrecting;
}
}
}
void ModPill::die(int /*how*/) {
is_on = false;
if (!resurrecting) remove();
}
|