Weapon fixes.

This commit is contained in:
Steve 2018-02-04 09:50:07 +00:00
parent 827a825c2d
commit 9841418d20
11 changed files with 57 additions and 17 deletions

View File

@ -29,7 +29,7 @@ static void explode(void);
void initGrenade(Bullet *b) void initGrenade(Bullet *b)
{ {
b->flags |= EF_BOUNCES | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_FRICTIONLESS | EF_NO_TELEPORT; b->flags = EF_BOUNCES | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_FRICTIONLESS | EF_NO_TELEPORT;
superBounce = b->bounce; superBounce = b->bounce;

View File

@ -25,7 +25,7 @@ static void touch(Entity *other);
void initLaser(Bullet *b) void initLaser(Bullet *b)
{ {
b->flags |= EF_WEIGHTLESS | EF_BOUNCES | EF_FRICTIONLESS | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_NO_TELEPORT; b->flags = EF_WEIGHTLESS | EF_BOUNCES | EF_FRICTIONLESS | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_NO_TELEPORT;
b->tick = tick; b->tick = tick;
b->touch = touch; b->touch = touch;

View File

@ -25,7 +25,7 @@ static void touch(Entity *other);
void initMissile(Bullet *b) void initMissile(Bullet *b)
{ {
b->flags |= EF_WEIGHTLESS | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_NO_TELEPORT; b->flags = EF_WEIGHTLESS | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS | EF_KILL_OFFSCREEN | EF_NO_TELEPORT;
b->tick = tick; b->tick = tick;
b->touch = touch; b->touch = touch;

View File

@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "weapons.h" #include "weapons.h"
Bullet *createBaseBullet(Unit *owner); Bullet *createBaseBullet(Unit *owner);
static void tick(void);
static void touch(Entity *other);
static Sprite *bulletSprite[2]; static Sprite *bulletSprite[2];
static Sprite *plasmaSprite[2]; static Sprite *plasmaSprite[2];
@ -33,8 +35,7 @@ static Sprite *alienGrenadeSprite;
static Sprite *shotgunPelletSprite; static Sprite *shotgunPelletSprite;
static Sprite *missileSprite[2]; static Sprite *missileSprite[2];
static void tick(void); static char *weaponName[WPN_ANY];
static void touch(Entity *other);
void initWeapons(void) void initWeapons(void)
{ {
@ -59,6 +60,12 @@ void initWeapons(void)
missileSprite[0] = getSprite("MissileRight"); missileSprite[0] = getSprite("MissileRight");
missileSprite[1] = getSprite("MissileLeft"); missileSprite[1] = getSprite("MissileLeft");
weaponName[WPN_PISTOL] = _("Pistol");
weaponName[WPN_PLASMA] = _("Plasma Rifle");
weaponName[WPN_SPREAD] = _("Spread Gun");
weaponName[WPN_LASER] = _("Laser Cannon");
weaponName[WPN_GRENADES] = _("Grenades");
} }
/* only used by Bob */ /* only used by Bob */
@ -242,8 +249,6 @@ Bullet *createBaseBullet(Unit *owner)
bullet = malloc(sizeof(Bullet)); bullet = malloc(sizeof(Bullet));
memset(bullet, 0, sizeof(Bullet)); memset(bullet, 0, sizeof(Bullet));
world.entityTail->next = (Entity*)bullet;
world.entityTail = (Entity*)bullet;
initEntity((Entity*)bullet); initEntity((Entity*)bullet);
@ -345,3 +350,8 @@ int getRandomPlayerWeapon(int excludeGrenades)
return rand() % WPN_ANY; return rand() % WPN_ANY;
} }
const char *getWeaponName(int i)
{
return weaponName[i];
}

View File

@ -53,7 +53,7 @@ void initEntity(Entity *e)
e->thinkTime = 0; e->thinkTime = 0;
e->spriteFrame = -1; e->spriteFrame = 0;
e->spriteTime = 0; e->spriteTime = 0;
e->init = init; e->init = init;

View File

@ -24,14 +24,6 @@ static void (*itemTick)(void);
static void tick(void); static void tick(void);
static void touch(Entity *other); static void touch(Entity *other);
static char *description[WPN_ANY] = {
"Pistol",
"Plasma Rifle",
"Spread Gun",
"Laser Cannon",
"Grenades"
};
void initWeaponPickup(Entity *e) void initWeaponPickup(Entity *e)
{ {
Item *i; Item *i;
@ -88,7 +80,7 @@ static void touch(Entity *other)
break; break;
default: default:
setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), _(description[i->weaponType])); setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), getWeaponName(i->weaponType));
break; break;
} }

View File

@ -26,6 +26,7 @@ extern void initConsumable(Entity *e);
extern Sprite *getSprite(char *name); extern Sprite *getSprite(char *name);
extern void pickupItem(void); extern void pickupItem(void);
extern int touchedPlayer(Entity *e); extern int touchedPlayer(Entity *e);
extern const char *getWeaponName(int i);
extern Entity *self; extern Entity *self;
extern World world; extern World world;

View File

@ -51,6 +51,8 @@ void drawHud(void)
{ {
int x, y; int x, y;
drawText(SCREEN_WIDTH - 5, 5, 16, TA_RIGHT, colors.white, "Weapon: %s", getWeaponName(world.bob->weaponType));
if (messageTime > 0) if (messageTime > 0)
{ {
drawRect(0, SCREEN_HEIGHT - 32, SCREEN_WIDTH, 32, 0, 0, 0, 200); drawRect(0, SCREEN_HEIGHT - 32, SCREEN_WIDTH, 32, 0, 0, 0, 200);

View File

@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern void showWidgetGroup(char *groupName); extern void showWidgetGroup(char *groupName);
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a); extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
const char *getWeaponName(int i);
extern Dev dev; extern Dev dev;
extern Camera camera; extern Camera camera;

View File

@ -41,9 +41,13 @@ void initWorld(void)
{ {
background = getTexture(world.background); background = getTexture(world.background);
initQuadtree(&world.quadtree);
initObjectives(); initObjectives();
initHud(); initHud();
initWeapons();
world.enemySpawnTimer = (FPS * rrnd(world.minEnemySpawnTime, world.maxEnemySpawnTime)); world.enemySpawnTimer = (FPS * rrnd(world.minEnemySpawnTime, world.maxEnemySpawnTime));
@ -68,8 +72,10 @@ void initWorld(void)
startMission(); startMission();
/*
world.bob->x = 166 * MAP_TILE_SIZE; world.bob->x = 166 * MAP_TILE_SIZE;
world.bob->y = 98 * MAP_TILE_SIZE; world.bob->y = 98 * MAP_TILE_SIZE;
*/
} }
static void logic(void) static void logic(void)
@ -175,6 +181,7 @@ static void doWorldInProgress(void)
game.config.control[CONTROL_UP] = app.keyboard[SDL_SCANCODE_W]; game.config.control[CONTROL_UP] = app.keyboard[SDL_SCANCODE_W];
game.config.control[CONTROL_DOWN] = app.keyboard[SDL_SCANCODE_S]; game.config.control[CONTROL_DOWN] = app.keyboard[SDL_SCANCODE_S];
game.config.control[CONTROL_JUMP] = app.keyboard[SDL_SCANCODE_I]; game.config.control[CONTROL_JUMP] = app.keyboard[SDL_SCANCODE_I];
game.config.control[CONTROL_FIRE] = app.keyboard[SDL_SCANCODE_J];
if (app.keyboard[SDL_SCANCODE_SPACE]) if (app.keyboard[SDL_SCANCODE_SPACE])
{ {
@ -183,6 +190,31 @@ static void doWorldInProgress(void)
app.keyboard[SDL_SCANCODE_SPACE] = 0; app.keyboard[SDL_SCANCODE_SPACE] = 0;
} }
if (app.keyboard[SDL_SCANCODE_1])
{
world.bob->weaponType = WPN_PISTOL;
}
if (app.keyboard[SDL_SCANCODE_2])
{
world.bob->weaponType = WPN_PLASMA;
}
if (app.keyboard[SDL_SCANCODE_3])
{
world.bob->weaponType = WPN_SPREAD;
}
if (app.keyboard[SDL_SCANCODE_4])
{
world.bob->weaponType = WPN_LASER;
}
if (app.keyboard[SDL_SCANCODE_5])
{
world.bob->weaponType = WPN_GRENADES;
}
if (!world.showingInfoMessage) if (!world.showingInfoMessage)
{ {
doBob(); doBob();

View File

@ -53,6 +53,8 @@ extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h, int cen
extern void clearScreen(void); extern void clearScreen(void);
extern void drawHud(void); extern void drawHud(void);
extern void initHud(void); extern void initHud(void);
extern void initWeapons(void);
extern void initQuadtree(Quadtree *root);
extern App app; extern App app;
extern Dev dev; extern Dev dev;