blobwarsAttrition/src/entities/blobs/teeka.c

184 lines
3.3 KiB
C
Raw Normal View History

2018-01-25 09:11:45 +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 "teeka.h"
2018-02-01 08:50:37 +01:00
static void (*superTick)(void);
2018-01-25 09:11:45 +01:00
static void tick(void);
static void lookForEnemies(void);
static void preFire(void);
static void attack(void);
static Entity *target;
2018-01-30 00:00:14 +01:00
static Sprite *aimedSprite;
2018-01-25 09:11:45 +01:00
static int exitMission;
Entity *initTeeka(void)
2018-01-25 09:11:45 +01:00
{
Unit *u;
2018-01-29 23:12:18 +01:00
u = createUnit();
u->type = ET_TEEKA;
2018-01-25 09:11:45 +01:00
u->flags |= EF_IMMUNE;
2018-01-25 09:11:45 +01:00
u->action = lookForEnemies;
2018-01-25 09:11:45 +01:00
u->weaponType = WPN_AIMED_PISTOL;
2018-01-25 09:11:45 +01:00
2018-01-30 00:00:14 +01:00
u->sprite[FACING_LEFT] = getSprite("TeekaLeft");
u->sprite[FACING_RIGHT] = getSprite("TeekaRight");
u->sprite[FACING_DIE] = getSprite("TeekaLeft");
2018-01-25 09:11:45 +01:00
2018-01-29 23:12:18 +01:00
u->health = u->healthMax = 9999;
2018-01-25 09:11:45 +01:00
2018-02-01 08:50:37 +01:00
superTick = u->tick;
u->tick = tick;
2018-03-17 17:57:11 +01:00
exitMission = 0;
2018-01-30 00:00:14 +01:00
aimedSprite = getSprite("AimedShot");
return (Entity*)u;
2018-01-25 09:11:45 +01:00
}
static void tick(void)
{
self->health = self->healthMax = 9999;
if (target != NULL)
{
self->facing = (target->x < self->x) ? FACING_LEFT : FACING_RIGHT;
if (target->alive == ALIVE_DEAD)
{
target = NULL;
self->action = lookForEnemies;
2018-01-25 09:11:45 +01:00
}
}
2018-02-01 08:50:37 +01:00
superTick();
2018-01-25 09:11:45 +01:00
}
static void lookForEnemies(void)
{
Entity *e;
float distance, range;
Unit *u;
u = (Unit*)self;
2018-01-25 09:11:45 +01:00
u->thinkTime = rrnd(FPS / 2, FPS);
2018-01-25 09:11:45 +01:00
target = NULL;
distance = 800;
for (e = world.entityHead.next ; e != NULL ; e = e->next)
{
if (e->type == ET_ENEMY)
{
range = getDistance(u->x, u->y, e->x, e->y);
2018-01-25 09:11:45 +01:00
if (range < distance)
{
if (hasLineOfSight(self, e))
{
target = e;
distance = range;
}
}
}
}
if (target != NULL)
{
u->shotsToFire = rrnd(3, 5);
2018-01-25 09:11:45 +01:00
u->action = preFire;
2018-01-25 09:11:45 +01:00
}
else if (exitMission)
{
addTeleportStars(self);
u->alive = ALIVE_DEAD;
2018-02-26 19:56:13 +01:00
playBattleSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS, u->x, u->y);
2018-01-25 09:11:45 +01:00
}
else
{
u->facing = rand() % 2 == 0 ? FACING_LEFT : FACING_RIGHT;
2018-01-25 09:11:45 +01:00
}
}
static void preFire(void)
{
Unit *u;
u = (Unit*)self;
if (u->reload > 0)
2018-01-25 09:11:45 +01:00
{
return;
}
if (target->y < u->y && u->isOnGround && rand() % 10 == 0)
2018-01-25 09:11:45 +01:00
{
u->dy = JUMP_POWER;
2018-01-25 09:11:45 +01:00
}
attack();
if (--u->shotsToFire <= 0)
2018-01-25 09:11:45 +01:00
{
u->thinkTime = FPS;
u->action = lookForEnemies;
2018-01-25 09:11:45 +01:00
}
}
static void attack(void)
{
2018-01-27 09:13:50 +01:00
Bullet *bullet;
2018-01-25 09:11:45 +01:00
float dx, dy;
getSlope(target->x, target->y, self->x, self->y, &dx, &dy);
2018-04-24 20:04:08 +02:00
bullet = createBaseBullet((Unit*)self, aimedSprite->w);
2018-01-25 09:11:45 +01:00
bullet->facing = self->facing;
bullet->damage = 1;
bullet->owner = self;
bullet->health = FPS * 3;
bullet->weaponType = WPN_AIMED_PISTOL;
bullet->dx = dx * 9;
bullet->dy = dy * 9;
bullet->sprite[0] = bullet->sprite[1] = aimedSprite;
bullet->health *= 2;
2018-02-11 15:10:15 +01:00
((Unit*)self)->reload = 8;
2018-02-26 19:56:13 +01:00
playBattleSound(SND_PISTOL, self->uniqueId % MAX_SND_CHANNELS, self->x, self->y);
2018-01-25 09:11:45 +01:00
}
2018-01-26 23:29:08 +01:00
void teekaExitMission(void)
{
exitMission = 1;
}