Start of items.
This commit is contained in:
parent
5b37609404
commit
fd57743511
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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"
|
14
src/defs.h
14
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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
Loading…
Reference in New Issue