This commit is contained in:
Steve 2018-01-27 08:03:26 +00:00
parent e7d4c02834
commit 8e7f53ea54
7 changed files with 237 additions and 10 deletions

View File

@ -13,6 +13,7 @@ SEARCHPATH += src/world
SEARCHPATH += src/world/entities
SEARCHPATH += src/world/entities/blobs
SEARCHPATH += src/world/entities/boss
SEARCHPATH += src/world/entities/cannons
SEARCHPATH += src/world/entities/items
vpath %.c $(SEARCHPATH)
@ -22,7 +23,7 @@ DEPS += defs.h structs.h
OBJS += atlas.o
OBJS += battery.o blaze.o bob.o boss.o blobBoss.o
OBJS += camera.o cell.o cherry.o combat.o consumable.o
OBJS += camera.o cannon.o cell.o cherry.o combat.o consumable.o
OBJS += draw.o
OBJS += effects.o entities.o explosions.o eyeDroidCommander.o
OBJS += frost.o

View File

@ -192,6 +192,11 @@ enum
MS_COMPLETE
};
enum
{
WS_IN_PROGRESS
};
enum
{
PLANE_BACKGROUND,

View File

@ -113,6 +113,7 @@ struct Entity {
int damage;
int weaponType;
int shotsToFire;
int maxShotsToFire;
int isSolid;
int environment;
int isStatic;
@ -147,6 +148,7 @@ struct Entity {
void (*touch)(Entity *other);
void (*tick)(void);
void (*die)(void);
int (*canFire)(Entity *target);
void (*reset)(void);
void (*activate)(int active);
void (*changeEnvironment)(void);
@ -331,6 +333,7 @@ struct Particle {
typedef struct {
char id[MAX_NAME_LENGTH];
int state;
Entity *bob, *boss;
Map map;
Entity entityHead, *entityTail;

View File

@ -0,0 +1,191 @@
/*
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 "cannon.h"
static void applyDamage(int damage);
static void walk(void);
static void die(void);
static void animate(void);
static SDL_Rect getBounds(void);
static int canFire(Entity *target);
static void preFire(void);
void initCannon(Entity *e)
{
initUnit(e);
e->sprite[FACING_LEFT] = getSpriteIndex("CannonLeft");
e->sprite[FACING_RIGHT] = getSpriteIndex("CannonRight");
e->sprite[FACING_DIE] = getSpriteIndex("CannonLeft");
e->weaponType = WPN_MISSILE;
e->maxShotsToFire = 4;
e->reload = 0;
e->canCarryItem = 1;
e->health = e->healthMax = 50;
e->flags |= EF_EXPLODES;
e->animate = animate;
e->applyDamage = applyDamage;
e->walk = walk;
e->die = die;
e->getBounds= getBounds;
e->canFire = canFire;
}
static void applyDamage(int damage)
{
if (self->health > 0)
{
self->health -= damage;
self->facing = self->x < world.bob->x ? FACING_RIGHT : FACING_LEFT;
self->thinkTime = 0;
}
}
static void die(void)
{
int mx, my;
self->health--;
if (self->health % 3 == 0)
{
mx = (int) ((self->x + (self->w / 2)) / MAP_TILE_SIZE);
my = (int) ((self->y + self->h) / MAP_TILE_SIZE);
addScorchDecal(mx, my);
addExplosion(self->x, self->y, 50, self);
}
if (self->health <= -50)
{
updateObjective(self->name);
updateObjective("ENEMY");
fireTriggers(self->name);
dropCarriedItem();
self->alive = ALIVE_DEAD;
}
}
static void patrol(void)
{
self->facing = rand() % 2 ? FACING_LEFT : FACING_RIGHT;
self->thinkTime = rrnd(FPS / 2, FPS);
}
static void lookForPlayer(void)
{
int r;
self->thinkTime = rrnd(FPS / 2, FPS);
if (world.state != WS_IN_PROGRESS || dev.cheatBlind)
{
patrol();
return;
}
if ((self->facing == FACING_LEFT && world.bob->x > self->x) || (self->facing == FACING_RIGHT && world.bob->x < self->x))
{
patrol();
return;
}
if (getDistance(world.bob->x, world.bob->y, self->x, self->y) > 650)
{
patrol();
return;
}
if (!enemyCanSeePlayer(self))
{
patrol();
return;
}
r = rand() % 100;
if (self->isMissionTarget)
{
r = rand() % 20;
}
if (r < 15)
{
self->shotsToFire = rrnd(1, self->maxShotsToFire);
self->action = preFire;
}
}
static void preFire(void)
{
self->facing = (world.bob->x < self->x) ? FACING_LEFT : FACING_RIGHT;
if (self->reload > 0)
{
return;
}
self->attack();
self->shotsToFire--;
if (self->shotsToFire == 0)
{
self->walk();
}
}
static void walk(void)
{
self->action = lookForPlayer;
}
static void animate(void)
{
}
static SDL_Rect getBounds(void)
{
self->bounds.x = self->x + 36;
self->bounds.y = self->y;
self->bounds.w = 36;
self->bounds.h = self->h;
return self->bounds;
}
static int canFire(Entity *target)
{
return abs(target->y - self->y) <= MAP_TILE_SIZE;
}

View File

@ -0,0 +1,36 @@
/*
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 "../../../common.h"
extern void initUnit(Entity *e);
extern void addExplosion(float x, float y, int radius, Entity *owner);
extern int rrnd(int low, int high);
extern int getSpriteIndex(char *name);
extern int getDistance(int x1, int y1, int x2, int y2);
extern int enemyCanSeePlayer(Entity *e);
extern void updateObjective(char *targetName);
extern void fireTriggers(char *targetName);
extern void dropCarriedItem(void);
extern void addScorchDecal(int x, int y);
extern Dev dev;
extern Entity *self;
extern World world;

View File

@ -20,14 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../../../common.h"
extern void playSound(int snd, int ch);
extern void setGameplayMessage(int type, char *format, ...);
extern void initItem(Entity *e);
extern int getSpriteIndex(char *name);
extern void updateObjective(char *targetName);
extern int rrnd(int low, int high);
extern void teekaExitMission(void);
extern Entity *self;
extern Game game;
extern World world;

View File

@ -24,13 +24,9 @@ extern void playSound(int snd, int ch);
extern void setGameplayMessage(int type, char *format, ...);
extern void initConsumable(Entity *e);
extern int getSpriteIndex(char *name);
extern void updateObjective(char *targetName);
extern int rrnd(int low, int high);
extern void pickupItem(void);
extern void teekaExitMission(void);
extern void setEntitySize(Entity *e);
extern int touchedPlayer(Entity *e);
extern Entity *self;
extern Game game;
extern World world;