diff --git a/common.mk b/common.mk index c2c6c4b..29c000a 100644 --- a/common.mk +++ b/common.mk @@ -13,7 +13,7 @@ OBJS += draw.o OBJS += effects.o entities.o explosions.o OBJS += game.o OBJS += hud.o -OBJS += init.o input.o io.o +OBJS += init.o input.o io.o items.o OBJS += lookup.o OBJS += main.o map.o maths.o OBJS += objectives.o @@ -22,7 +22,7 @@ OBJS += quadtree.o OBJS += sound.o sprites.o OBJS += text.o textures.o title.o triggers.o OBJS += util.o -OBJS += widgets.o +OBJS += weapons.o widgets.o # top-level rule to create the program. all: $(PROG) $(LOCALE_MO) diff --git a/src/combat/weapons.c b/src/combat/weapons.c new file mode 100644 index 0000000..4b65bb1 --- /dev/null +++ b/src/combat/weapons.c @@ -0,0 +1,31 @@ +/* +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 "weapons.h" + +int getRandomPlayerWeapon(int excludeGrenades) +{ + if (excludeGrenades) + { + return rand() % WPN_GRENADES; + } + + return rand() % WPN_ANY; +} diff --git a/src/combat/weapons.h b/src/combat/weapons.h new file mode 100644 index 0000000..8ad0dc9 --- /dev/null +++ b/src/combat/weapons.h @@ -0,0 +1,21 @@ +/* +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" diff --git a/src/defs.h b/src/defs.h index 7ff15e6..22151fc 100644 --- a/src/defs.h +++ b/src/defs.h @@ -95,6 +95,20 @@ enum FACING_LEFT }; +enum +{ + WPN_PISTOL, + WPN_PLASMA, + WPN_SPREAD, + WPN_LASER, + WPN_GRENADES, + WPN_ANY, + WPN_AIMED_PISTOL, + WPN_MACHINE_GUN, + WPN_SHOTGUN, + WPN_MISSILE +}; + enum { ALIVE_ALIVE diff --git a/src/structs.h b/src/structs.h index b099842..8f6949c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -93,8 +93,11 @@ struct Entity { long flags; SDL_Rect bounds; int sprite[3]; + int spriteTime; + int spriteFrame; void (*walk)(void); void (*attack)(void); + void (*touch)(Entity *other); Entity *next; }; @@ -187,6 +190,7 @@ typedef struct { Entity entityHead, *entityTail; int allObjectivesComplete; int currentStatus; + int isBossMission; Quadtree quadtree; Objective objectiveHead, *objectiveTail; Trigger triggerHead, *triggerTail; diff --git a/src/world/items.c b/src/world/items.c new file mode 100644 index 0000000..3fdb70a --- /dev/null +++ b/src/world/items.c @@ -0,0 +1,94 @@ +/* +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 "items.h" + +static void throwItem(Entity *e); +static int getRandomPlayerWeaponAt(int x, int y); + +static int wpnIconSprite; +static int cherrySprite[3]; +static int batterySprite; + +void initItems(void) +{ + wpnIconSprite = getSpriteIndex("Weapon"); + batterySprite = getSpriteIndex("Battery"); + + cherrySprite[0] = getSpriteIndex("Cherry"); + cherrySprite[1] = getSpriteIndex("DualCherry"); + cherrySprite[2] = getSpriteIndex("CherryBunch"); +} + +void addRandomWeapon(double x, double y) +{ + Entity *wpn; + int type; + + wpn = malloc(sizeof(Entity)); + memset(wpn, 0, sizeof(Entity)); + world.entityTail->next = wpn; + world.entityTail = wpn; + + wpn->x = x; + wpn->y = y; + + type = getRandomPlayerWeaponAt(wpn->x, wpn->y); + + switch (type) + { + case 0: + wpn->touch = NULL; + break; + + default: + break; + } + + wpn->sprite[0] = wpn->sprite[1] = wpn->sprite[2] = wpnIconSprite; + wpn->spriteFrame = type; + wpn->spriteTime = -1; + + throwItem(wpn); +} + +static int getRandomPlayerWeaponAt(int x, int y) +{ + int type; + + type = getRandomPlayerWeapon(world.isBossMission); + + if (world.map.data[(x / MAP_TILE_SIZE)][(y / MAP_TILE_SIZE)] == MAP_TILE_WATER) + { + type = WPN_PISTOL; + } + else if (type == WPN_PISTOL && rand() < 0.25) + { + type = getRandomPlayerWeapon(world.isBossMission); + } + + return type; +} + +static void throwItem(Entity *e) +{ + e->dx = rrnd(-3, 3); + e->dy = rrnd(-7, -5); +} diff --git a/src/world/items.h b/src/world/items.h new file mode 100644 index 0000000..c4b62e7 --- /dev/null +++ b/src/world/items.h @@ -0,0 +1,27 @@ +/* +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 int rrnd(int low, int high); +extern int getRandomPlayerWeapon(int excludeGrenades); +extern int getSpriteIndex(char *name); + +extern World world;