2018-01-26 08:56:12 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2018 Parallel Realities
|
|
|
|
|
|
|
|
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 "blobBoss.h"
|
|
|
|
|
|
|
|
static void activate(int activate);
|
2018-01-26 09:51:07 +01:00
|
|
|
static void walk(void);
|
2018-01-26 08:56:12 +01:00
|
|
|
static void tick(void);
|
|
|
|
static void changeEnvironment(void);
|
2018-01-30 00:00:14 +01:00
|
|
|
static Sprite *getCurrentSprite(void);
|
2018-01-26 08:56:12 +01:00
|
|
|
static void animate(void);
|
|
|
|
static void applyDamage(int amount);
|
|
|
|
static void moveTowardsPlayer(void);
|
|
|
|
static void preFire(void);
|
|
|
|
static void teleport(void);
|
|
|
|
static void attack(void);
|
|
|
|
static void die1(void);
|
|
|
|
static void die2(void);
|
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
static Sprite *aimedSprite;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
|
|
|
void initBlobBoss(Entity *e)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
2018-01-26 08:56:12 +01:00
|
|
|
initBoss(e);
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b = (Boss*)e;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->flags |= EF_HALT_AT_EDGE;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->health = b->healthMax = 250;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->teleportTimer = FPS * rrnd(4, 6);
|
|
|
|
|
|
|
|
b->activate = activate;
|
|
|
|
b->walk = walk;
|
|
|
|
b->tick = tick;
|
|
|
|
b->changeEnvironment = changeEnvironment;
|
|
|
|
b->getCurrentSprite = getCurrentSprite;
|
|
|
|
b->animate = animate;
|
|
|
|
b->applyDamage = applyDamage;
|
|
|
|
b->die = die1;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
aimedSprite = getSprite("AimedShot");
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void activate(int activate)
|
|
|
|
{
|
|
|
|
self->flags &= ~EF_GONE;
|
|
|
|
|
|
|
|
world.isBossActive = 1;
|
|
|
|
|
|
|
|
addTeleportStars(self);
|
|
|
|
|
|
|
|
if (!isPlayingMusic())
|
|
|
|
{
|
|
|
|
playMusic("", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tick(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (b->health > 0)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->stunTimer = MAX(b->stunTimer - 1, 0);
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->environment == b->weakAgainst)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->health -= 2;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
world.boss = b;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->stunTimer == 0)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->facing = (world.bob->x < b->x) ? FACING_LEFT : FACING_RIGHT;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->reload = limit(--b->reload, 0, FPS);
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->teleportTimer = limit(b->teleportTimer - 1, 0, 9999);
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->isOnGround)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->flags |= EF_HALT_AT_EDGE;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->flags &= ~EF_HALT_AT_EDGE;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void changeEnvironment()
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (b->environment == b->weakAgainst)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->teleportTimer = 0;
|
|
|
|
b->stunTimer = 90;
|
|
|
|
b->spriteFrame = b->spriteTime = 0;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->teleportTimer = 0;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void die1(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
b->flags |= EF_BOUNCES;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->thinkTime = 0;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->spriteTime = 0;
|
|
|
|
b->spriteFrame = 0;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->environment == ENV_AIR)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->dy = -9;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->dx = (randF() - randF()) * 5;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->flags &= ~EF_HALT_AT_EDGE;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
|
|
|
switch (rand() % 3)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
playSound(SND_DEATH_1, CH_DEATH);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
playSound(SND_DEATH_2, CH_DEATH);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
playSound(SND_DEATH_3, CH_DEATH);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->action = die2;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
static Sprite *getCurrentSprite(void)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (b->stunTimer > 0 || b->health <= 0)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
return b->sprite[FACING_DIE];
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
return b->sprite[b->facing];
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void animate(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (b->dx != 0 || b->health <= 0 || b->stunTimer > 0)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
|
|
|
animateEntity(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lookForPlayer(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
b->thinkTime = rrnd(0, FPS / 2);
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (getDistance(world.bob->x, world.bob->y, b->x, b->y) > 650)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
|
|
|
moveTowardsPlayer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!enemyCanSeePlayer(self))
|
|
|
|
{
|
|
|
|
moveTowardsPlayer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rand() % 100 < 15)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->shotsToFire = rrnd(1, 12);
|
|
|
|
b->action = preFire;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
moveTowardsPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void moveTowardsPlayer(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
b->dx = 0;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
|
|
|
if (rand() % 100 < 20)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
if (world.bob->x < b->x)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->dx = -3.5;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (world.bob->x > b->x)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->dx = 3.5;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (world.bob->y <= b->y && rand() % 2 == 0 && b->isOnGround)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->dy = JUMP_POWER;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->stunTimer == 0 && b->teleportTimer == 0)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
|
|
|
teleport();
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->teleportTimer = FPS * rrnd(4, 6);
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void preFire(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (b->reload > 0)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
attack();
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->shotsToFire--;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->shotsToFire == 0)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->walk();
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void attack(void)
|
|
|
|
{
|
2018-01-27 09:13:50 +01:00
|
|
|
Bullet *bullet;
|
2018-01-26 08:56:12 +01:00
|
|
|
float dx, dy;
|
|
|
|
int bx, by;
|
|
|
|
|
|
|
|
bx = (int) (world.bob->x + rrnd(-8, 24));
|
|
|
|
by = (int) (world.bob->y + rrnd(-8, 24));
|
|
|
|
|
|
|
|
getSlope(bx, by, self->x, self->y, &dx, &dy);
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
bullet = createBaseBullet((Unit*)self);
|
2018-01-26 08:56:12 +01:00
|
|
|
bullet->x = self->x;
|
|
|
|
bullet->y = (self->y + self->h / 2) - 3;
|
|
|
|
bullet->facing = self->facing;
|
|
|
|
bullet->damage = 1;
|
|
|
|
bullet->owner = self;
|
|
|
|
bullet->health = FPS * 3;
|
|
|
|
bullet->weaponType = WPN_AIMED_PISTOL;
|
|
|
|
bullet->dx = dx * 12;
|
|
|
|
bullet->dy = dy * 12;
|
|
|
|
bullet->sprite[0] = bullet->sprite[1] = aimedSprite;
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
((Boss*)self)->reload = 4;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
|
|
|
playSound(SND_MACHINE_GUN, CH_WEAPON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void walk(void)
|
|
|
|
{
|
|
|
|
self->action = (self->health > 0) ? lookForPlayer : die2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reappear(void)
|
|
|
|
{
|
|
|
|
int valid, r;
|
|
|
|
|
|
|
|
valid = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
r = (int) (rand() % MAX_CHECKPOINTS);
|
|
|
|
self->x = world.checkpoints[r].x;
|
|
|
|
self->y = world.checkpoints[r].y;
|
|
|
|
valid = (self->x != 0 && self->y != 0);
|
|
|
|
}
|
|
|
|
while (!valid);
|
|
|
|
|
|
|
|
self->y -= (self->h + 10);
|
|
|
|
|
|
|
|
walk();
|
|
|
|
|
|
|
|
self->flags &= ~EF_GONE;
|
|
|
|
|
|
|
|
addTeleportStars(self);
|
|
|
|
|
|
|
|
playSound(SND_APPEAR, CH_ANY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void applyDamage(int amount)
|
|
|
|
{
|
|
|
|
self->health -= amount;
|
|
|
|
|
|
|
|
self->thinkTime = 0;
|
|
|
|
|
|
|
|
if (rand() % 10 == 0)
|
|
|
|
{
|
|
|
|
teleport();
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
world.boss = (Boss*)self;
|
2018-01-26 08:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void teleport(void)
|
|
|
|
{
|
|
|
|
self->action = reappear;
|
|
|
|
self->flags |= EF_GONE;
|
|
|
|
self->thinkTime = FPS * rrnd(3, 6);
|
|
|
|
addTeleportStars(self);
|
|
|
|
playSound(SND_APPEAR, CH_ANY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void die2(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
b->health--;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->health <= -FPS)
|
2018-01-26 08:56:12 +01:00
|
|
|
{
|
|
|
|
addTeleportStars(self);
|
|
|
|
|
|
|
|
playSound(SND_APPEAR, CH_ANY);
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->alive = ALIVE_DEAD;
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
updateObjective(b->name);
|
2018-01-26 08:56:12 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
addDefeatedTarget(b->name);
|
2018-01-26 08:56:12 +01:00
|
|
|
|
|
|
|
game.enemiesKilled++;
|
|
|
|
}
|
|
|
|
}
|