From f4190a5ccd34130d6e7c4077eba8c28ff4231fce Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 13 Feb 2018 08:23:31 +0000 Subject: [PATCH] Show and hide radar arrows. Integrate radar access into game. --- common.mk | 2 +- src/system/transition.c | 46 +++++++++++ src/system/transition.h | 28 +++++++ src/test/atlasTest.c | 6 +- src/world/radar.c | 177 +++++++++++++++++++++++++++++++++------- src/world/radar.h | 9 ++ src/world/world.c | 28 +++++-- src/world/world.h | 3 + 8 files changed, 260 insertions(+), 39 deletions(-) create mode 100644 src/system/transition.c create mode 100644 src/system/transition.h diff --git a/common.mk b/common.mk index 522902f..0d3455c 100644 --- a/common.mk +++ b/common.mk @@ -48,7 +48,7 @@ _OBJS += particles.o player.o plasmaBlob.o plasmaDroid.o pistolBlob.o pistolDroi _OBJS += quadtree.o _OBJS += radar.o _OBJS += shotgunBlob.o shotgunDroid.o sound.o spreadGunBlob.o spreadGunDroid.o sprites.o structures.o -_OBJS += tankCommander.o tankTrack.o teeka.o teleporter.o text.o textures.o title.o triggers.o +_OBJS += tankCommander.o tankTrack.o teeka.o teleporter.o text.o textures.o title.o transition.o triggers.o _OBJS += unit.o util.o _OBJS += weapons.o weaponPickup.o widgets.o world.o worldLoader.o worldSaver.o diff --git a/src/system/transition.c b/src/system/transition.c new file mode 100644 index 0000000..362e61a --- /dev/null +++ b/src/system/transition.c @@ -0,0 +1,46 @@ +/* +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 "transition.h" + +static long transitionStartTime; + +void startSectionTransition(void) +{ + transitionStartTime = SDL_GetTicks(); + + prepareScene(); + + clearInput(); + + presentScene(); + + expireTexts(1); +} + +void endSectionTransition(void) +{ + long elasped = 250 - (SDL_GetTicks() - transitionStartTime); + + if (elasped > 0) + { + SDL_Delay(elasped); + } +} diff --git a/src/system/transition.h b/src/system/transition.h new file mode 100644 index 0000000..0512851 --- /dev/null +++ b/src/system/transition.h @@ -0,0 +1,28 @@ +/* +Copyright (C) 2015-2017 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 prepareScene(void); +extern void presentScene(void); +extern void clearInput(void); +extern void expireTexts(int all); + +extern App app; diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index 0dd72ef..2e8e744 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -24,7 +24,7 @@ void initAtlasTest(void) { dev.cheatStatic = 0; dev.cheatBlind = 0; - dev.cheatNoEnemies = 1; + dev.cheatNoEnemies = 0; dev.cheatKeys = 1; dev.cheatPower = 1; dev.cheatHealth = 1; @@ -33,13 +33,11 @@ void initAtlasTest(void) initHub(); - loadWorld("beachFront1"); + loadWorld("greenlands1"); initWorld(); initMap(); initEntities(); - - initRadar(); } diff --git a/src/world/radar.c b/src/world/radar.c index 8ddaee8..cfa040c 100644 --- a/src/world/radar.c +++ b/src/world/radar.c @@ -29,18 +29,26 @@ static int isValidBlip(Entity *e); static void getBlipColor(Entity *e, SDL_Color *c); static void drawMarkers(void); static void initMarker(int i, int x, int y, int angle, int type); +static void initBlips(void); +static void enableMarker(int type, int i); static SDL_Rect viewRect; static Texture *atlasTexture; static Atlas *background; static Atlas *arrow; static int blinkTimer; -static Marker marker[M_MAX * 4]; +static Marker marker[MAX_MARKERS]; +static Entity *blips[MAX_BLIPS]; void initRadar(void) { SDL_Rect limits; + startSectionTransition(); + + memset(blips, 0, sizeof(Entity*) * MAX_BLIPS); + memset(marker, 0, sizeof(Marker) * MAX_MARKERS); + app.delegate.logic = logic; app.delegate.draw = draw; @@ -51,8 +59,8 @@ void initRadar(void) limits.x = world.map.bounds.x / MAP_TILE_SIZE; limits.y = world.map.bounds.y / MAP_TILE_SIZE; - limits.w = (world.map.bounds.w / MAP_TILE_SIZE) - MAP_RENDER_WIDTH; - limits.h = (world.map.bounds.h / MAP_TILE_SIZE) - MAP_RENDER_HEIGHT; + limits.w = (world.map.bounds.w / MAP_TILE_SIZE) - (VIEW_SIZE_X - MAP_RENDER_WIDTH) - 1; + limits.h = (world.map.bounds.h / MAP_TILE_SIZE) - (VIEW_SIZE_Y - MAP_RENDER_HEIGHT); viewRect.x = limit(viewRect.x, limits.x, limits.w); viewRect.y = limit(viewRect.y, limits.y, limits.h); @@ -83,6 +91,10 @@ void initRadar(void) initMarker(9, SCREEN_WIDTH / 2 + 450, SCREEN_HEIGHT / 2 - 200, 90, M_MIA); initMarker(10, SCREEN_WIDTH / 2 + 450, SCREEN_HEIGHT / 2, 90, M_ITEM); initMarker(11, SCREEN_WIDTH / 2 + 450, SCREEN_HEIGHT / 2 + 200, 90, M_ENEMY); + + initBlips(); + + endSectionTransition(); } static void initMarker(int i, int x, int y, int angle, int type) @@ -93,10 +105,107 @@ static void initMarker(int i, int x, int y, int angle, int type) marker[i].type = type; } +static void initBlips(void) +{ + Entity *e; + int i, x, y; + + i = 0; + + for (e = world.entityHead.next ; e != NULL ; e = e->next) + { + if (isValidBlip(e)) + { + x = (e->x / MAP_TILE_SIZE); + y = (e->y / MAP_TILE_SIZE); + + if (y < viewRect.y) + { + enableMarker(e->type, M_MIA); + } + else if (y > viewRect.y + viewRect.h) + { + enableMarker(e->type, M_MIA + (M_MAX)); + } + else if (x < viewRect.x) + { + enableMarker(e->type, M_MIA + (M_MAX * 2)); + } + else if (x > viewRect.x + viewRect.w) + { + enableMarker(e->type, M_MIA + (M_MAX * 3)); + } + else if (i < MAX_BLIPS) + { + blips[i++] = e; + } + } + } +} + +static void enableMarker(int type, int i) +{ + switch (type) + { + case ET_BOB: + case ET_MIA: + case ET_TEEKA: + marker[i].visible = 1; + break; + + case ET_HEART_CELL: + case ET_KEY: + case ET_ITEM: + case ET_DESTRUCTABLE: + marker[i + 1].visible = 1; + break; + + case ET_ENEMY: + case ET_BOSS: + marker[i + 2].visible = 1; + break; + + default: + break; + } +} + static void logic(void) { + int i; + Marker *m; + blinkTimer++; blinkTimer %= 60; + + for (i = 0 ; i < MAX_MARKERS ; i++) + { + m = &marker[i]; + + if (i / 3 % 2 == 0) + { + m->value += 0.1; + } + else + { + m->value -= 0.1; + } + + if (i < 6) + { + m->y += (float) sin(m->value); + } + else + { + m->x += (float) sin(m->value); + } + } + + if (isControl(CONTROL_MAP)) + { + clearControl(CONTROL_MAP); + exitRadar(); + } } static void draw(void) @@ -108,6 +217,15 @@ static void draw(void) drawEntities(); drawMarkers(); + + drawRect((SCREEN_WIDTH / 2) - 230, SCREEN_HEIGHT - 58, 14, 14, 255, 255, 0, 255); + drawText((SCREEN_WIDTH / 2) - 200, SCREEN_HEIGHT - 65, 20, TA_LEFT, colors.yellow, "MIAs"); + + drawRect((SCREEN_WIDTH / 2) - 30, SCREEN_HEIGHT - 58, 14, 14, 0, 255, 255, 255); + drawText((SCREEN_WIDTH / 2), SCREEN_HEIGHT - 65, 20, TA_LEFT, colors.cyan, "Items"); + + drawRect((SCREEN_WIDTH / 2) + 170, SCREEN_HEIGHT - 58, 14, 14, 255, 0, 0, 255); + drawText((SCREEN_WIDTH / 2) + 200, SCREEN_HEIGHT - 65, 20, TA_LEFT, colors.red, "Targets"); } static void drawMap(void) @@ -173,15 +291,14 @@ static void getMapTileColor(int i, SDL_Color *c) static void drawEntities(void) { Entity *e; - Entity **candidates; int i, x, y; SDL_Color c; - - candidates = getAllEntsWithin(viewRect.x * MAP_TILE_SIZE, viewRect.y * MAP_TILE_SIZE, viewRect.w * MAP_TILE_SIZE, viewRect.h * MAP_TILE_SIZE, NULL); - for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) + for (i = 0 ; i < MAX_BLIPS ; i++) { - if (isValidBlip(e)) + e = blips[i]; + + if (e != NULL) { x = (e->x / MAP_TILE_SIZE); y = (e->y / MAP_TILE_SIZE); @@ -193,7 +310,10 @@ static void drawEntities(void) getBlipColor(e, &c); - drawRect(OFFSET_X + (x * RADAR_TILE_SIZE), OFFSET_Y + (y * RADAR_TILE_SIZE), RADAR_TILE_SIZE - 1, RADAR_TILE_SIZE - 1, c.r, c.g, c.b, 255); + if (blinkTimer < 30) + { + drawRect(OFFSET_X + (x * RADAR_TILE_SIZE), OFFSET_Y + (y * RADAR_TILE_SIZE), RADAR_TILE_SIZE - 1, RADAR_TILE_SIZE - 1, c.r, c.g, c.b, 255); + } } } } @@ -206,17 +326,15 @@ static int isValidBlip(Entity *e) case ET_BOB: case ET_MIA: case ET_TEEKA: - return blinkTimer < 30; + return 1; case ET_ENEMY: case ET_BOSS: case ET_HEART_CELL: case ET_KEY: - return e->isMissionTarget ? blinkTimer < 30 : 1; - case ET_ITEM: case ET_DESTRUCTABLE: - return e->isMissionTarget && blinkTimer < 30; + return e->isMissionTarget; default: return 0; @@ -266,24 +384,27 @@ static void drawMarkers(void) { int i; - for (i = 0 ; i < M_MAX * 4 ; i++) + for (i = 0 ; i < MAX_MARKERS ; i++) { - switch (i % M_MAX) + if (marker[i].visible) { - case M_MIA: - SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 0); - break; - - case M_ITEM: - SDL_SetTextureColorMod(atlasTexture->texture, 0, 192, 255); - break; - - case M_ENEMY: - SDL_SetTextureColorMod(atlasTexture->texture, 255, 0, 0); - break; + switch (i % M_MAX) + { + case M_MIA: + SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 0); + break; + + case M_ITEM: + SDL_SetTextureColorMod(atlasTexture->texture, 0, 192, 255); + break; + + case M_ENEMY: + SDL_SetTextureColorMod(atlasTexture->texture, 255, 0, 0); + break; + } + + blitRectRotated(atlasTexture->texture, marker[i].x, marker[i].y, &arrow->rect, marker[i].angle); } - - blitRectRotated(atlasTexture->texture, marker[i].x, marker[i].y, &arrow->rect, marker[i].angle); } SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 255); diff --git a/src/world/radar.h b/src/world/radar.h index 93a464a..0014614 100644 --- a/src/world/radar.h +++ b/src/world/radar.h @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define VIEW_SIZE_Y 30 #define OFFSET_X ((SCREEN_WIDTH - (RADAR_TILE_SIZE * VIEW_SIZE_X)) / 2) #define OFFSET_Y ((SCREEN_HEIGHT - (RADAR_TILE_SIZE * VIEW_SIZE_Y)) / 2) +#define MAX_MARKERS 12 +#define MAX_BLIPS 32 enum { @@ -43,6 +45,13 @@ extern Atlas *getImageFromAtlas(char *filename); extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center); extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a); extern void blitRectRotated(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, float angle); +extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); +extern void exitRadar(void); +extern int isControl(int type); +extern void clearControl(int type); +extern void startSectionTransition(void); +extern void endSectionTransition(void); extern App app; +extern Colors colors; extern World world; diff --git a/src/world/world.c b/src/world/world.c index 60ea2f7..8d0deda 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -238,12 +238,6 @@ static void doWorldInProgress(void) doCommon(); doLocationTriggers(); - - if (isControl(CONTROL_PAUSE)) - { - world.state = WS_PAUSED; - clearControl(CONTROL_PAUSE); - } if (world.allObjectivesComplete && world.state != WS_COMPLETE) { @@ -262,6 +256,18 @@ static void doWorldInProgress(void) stopMusic(); } + + if (isControl(CONTROL_PAUSE)) + { + world.state = WS_PAUSED; + clearControl(CONTROL_PAUSE); + } + + if (isControl(CONTROL_MAP)) + { + initRadar(); + clearControl(CONTROL_MAP); + } } if (world.observationTimer > 0) @@ -572,3 +578,13 @@ void observeActivation(Entity *e) exit(1); } } + +void exitRadar(void) +{ + startSectionTransition(); + + app.delegate.logic = logic; + app.delegate.draw = draw; + + endSectionTransition(); +} diff --git a/src/world/world.h b/src/world/world.h index e9a6d33..2bcd121 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -69,6 +69,9 @@ extern void clearControls(void); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern void loadMusic(char *filename); extern void playMusic(int loop); +extern void initRadar(void); +extern void startSectionTransition(void); +extern void endSectionTransition(void); extern App app; extern Colors colors;