Added debug keys.

This commit is contained in:
Steve 2015-12-18 10:12:37 +00:00
parent 7325bbe506
commit b5dfab1bd5
15 changed files with 164 additions and 9 deletions

View File

@ -1,6 +1,6 @@
VERSION = 0.5
REVISION = $(shell date +"%y%m%d")
DEBUG = 0
DEBUG = $(shell stat dev 1>/dev/null 2>&1 && echo 1 || echo 0)
SEARCHPATH += src/ src/battle src/draw src/game src/galaxy src/json src/system src/test
vpath %.c $(SEARCHPATH)
@ -11,7 +11,7 @@ DEPS += defs.h structs.h
OBJS += ai.o
OBJS += battle.o bullets.o
OBJS += capitalShips.o challenges.o cJSON.o
OBJS += debris.o draw.o
OBJS += debris.o dev.o draw.o
OBJS += effects.o entities.o extractionPoint.o
OBJS += fighters.o
OBJS += galacticMap.o game.o grid.o

View File

@ -410,11 +410,17 @@ static void preAttack(void)
if (self->guns[0].type && (self->missiles == 0 || rand() % 50 > 0))
{
fireGuns(self);
if (!dev.noAIWeapons)
{
fireGuns(self);
}
}
else if (self->missiles && getDistance(self->x, self->y, self->target->x, self->target->y) >= 350)
{
fireMissile(self);
if (!dev.noAIWeapons)
{
fireMissile(self);
}
self->action = doAI;
}

View File

@ -40,5 +40,6 @@ extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern Battle battle;
extern Colors colors;
extern Dev dev;
extern Entity *self;
extern Entity *player;

View File

@ -406,6 +406,8 @@ static void loadComponents(Entity *parent, cJSON *components)
parent->health++;
}
}
parent->maxHealth = parent->health;
}
static void loadGuns(Entity *parent, cJSON *guns)

View File

@ -72,8 +72,20 @@ void doEntities(void)
}
}
if (dev.playerImmortal)
{
player->health = player->maxHealth;
player->shield = player->maxShield;
}
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{
if (dev.allImmortal)
{
e->health = e->maxHealth;
e->shield = e->maxShield;
}
if (e->active)
{
self = e;
@ -120,6 +132,11 @@ void doEntities(void)
{
if (e->action != NULL)
{
if (dev.noEntityActions)
{
e->thinkTime = 2;
}
if (--e->thinkTime <= 0)
{
e->thinkTime = 0;

View File

@ -34,5 +34,6 @@ extern void destroyGrid(void);
extern App app;
extern Battle battle;
extern Dev dev;
extern Entity *self;
extern Entity *player;

View File

@ -121,6 +121,11 @@ void doPlayer(void)
{
selectMissionTarget();
}
if (dev.playerUnlimitedMissiles)
{
player->missiles = 999;
}
}
if (battle.boostTimer == (int)BOOST_FINISHED_TIME)

View File

@ -40,6 +40,7 @@ extern void addECMEffect(Entity *ent);
extern App app;
extern Battle battle;
extern Colors colors;
extern Dev dev;
extern Entity *player;
extern Entity *self;
extern Game game;

View File

@ -47,7 +47,11 @@ void prepareScene(void)
void presentScene(void)
{
#if DEBUG
drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "FPS: %d", app.fps);
drawText(5, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "DEBUG MODE");
if (dev.showFPS)
{
drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "FPS: %d", dev.fps);
}
#endif
drawMouse();

View File

@ -25,3 +25,4 @@ extern void drawMouse(void);
extern App app;
extern Colors colors;
extern Dev dev;

View File

@ -28,6 +28,7 @@ int main(int argc, char *argv[])
SDL_Event event;
memset(&app, 0, sizeof(App));
memset(&dev, 0, sizeof(Dev));
atexit(cleanup);
@ -48,7 +49,7 @@ int main(int argc, char *argv[])
initTitle();
}
app.fps = frames = td = 0;
dev.fps = frames = td = 0;
then = SDL_GetTicks();
lastFrameTime = SDL_GetTicks() + 1000;
@ -104,15 +105,20 @@ int main(int argc, char *argv[])
app.delegate.draw();
doDevKeys();
frames++;
if (SDL_GetTicks() > lastFrameTime)
{
app.fps = frames;
dev.fps = frames;
frames = 0;
lastFrameTime = SDL_GetTicks() + 1000;
/*saveScreenshot();*/
if (dev.takeScreenshots)
{
saveScreenshot();
}
}
SDL_Delay(1);

View File

@ -34,10 +34,12 @@ extern void saveScreenshot(void);
extern void doMouseDown(SDL_MouseButtonEvent *event);
extern void doMouseUp(SDL_MouseButtonEvent *event);
extern void doMouseWheel(SDL_MouseWheelEvent *event);
extern void doDevKeys(void);
App app;
Colors colors;
Battle battle;
Dev dev;
Entity *self;
Entity *player;
Game game;

View File

@ -36,6 +36,17 @@ typedef struct MessageBox MessageBox;
typedef struct GridCell GridCell;
typedef struct ScriptRunner ScriptRunner;
typedef struct {
int takeScreenshots;
int noAIWeapons;
int showFPS;
int playerImmortal;
int playerUnlimitedMissiles;
int noEntityActions;
int allImmortal;
int fps;
} Dev;
typedef struct {
float x;
float y;
@ -334,7 +345,6 @@ typedef struct {
int musicVolume;
int soundVolume;
int vSync;
int fps;
Mouse mouse;
int keyboard[MAX_KEYBOARD_KEYS];
SDL_Texture *backBuffer;

75
src/system/dev.c Normal file
View File

@ -0,0 +1,75 @@
/*
Copyright (C) 2015 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 "dev.h"
void doDevKeys(void)
{
#if DEBUG
if (app.keyboard[SDL_SCANCODE_1])
{
dev.playerImmortal = !dev.playerImmortal;
app.keyboard[SDL_SCANCODE_1] = 0;
printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal);
}
if (app.keyboard[SDL_SCANCODE_2])
{
dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles;
app.keyboard[SDL_SCANCODE_2] = 0;
printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles);
}
if (app.keyboard[SDL_SCANCODE_3])
{
dev.noAIWeapons = !dev.noAIWeapons;
app.keyboard[SDL_SCANCODE_3] = 0;
printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons);
}
if (app.keyboard[SDL_SCANCODE_4])
{
dev.noEntityActions = !dev.noEntityActions;
app.keyboard[SDL_SCANCODE_4] = 0;
printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions);
}
if (app.keyboard[SDL_SCANCODE_5])
{
dev.allImmortal = !dev.allImmortal;
app.keyboard[SDL_SCANCODE_5] = 0;
printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal);
}
if (app.keyboard[SDL_SCANCODE_9])
{
dev.showFPS = !dev.showFPS;
app.keyboard[SDL_SCANCODE_9] = 0;
printf("DEBUG: dev.showFPS=%d\n", dev.showFPS);
}
if (app.keyboard[SDL_SCANCODE_0])
{
dev.takeScreenshots = !dev.takeScreenshots;
app.keyboard[SDL_SCANCODE_0] = 0;
printf("DEBUG: dev.takeScreenshots=%d\n", dev.takeScreenshots);
}
#endif
}

24
src/system/dev.h Normal file
View File

@ -0,0 +1,24 @@
/*
Copyright (C) 2015 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 App app;
extern Dev dev;