Radar map updates.

This commit is contained in:
Steve 2018-02-12 22:40:15 +00:00
parent c47a15b88a
commit 5f150901e1
8 changed files with 169 additions and 34 deletions

View File

@ -61,6 +61,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MAP_WIDTH 200 #define MAP_WIDTH 200
#define MAP_HEIGHT 200 #define MAP_HEIGHT 200
#define MAP_RENDER_WIDTH ((SCREEN_WIDTH / MAP_TILE_SIZE) + 1)
#define MAP_RENDER_HEIGHT ((SCREEN_HEIGHT / MAP_TILE_SIZE) + 1)
#define MAP_TILE_SIZE 64 #define MAP_TILE_SIZE 64
#define MAP_TILE_AIR 0 #define MAP_TILE_AIR 0
#define MAP_TILE_WATER 1 #define MAP_TILE_WATER 1

View File

@ -316,6 +316,8 @@ typedef struct {
int musicVolume; int musicVolume;
int keyControls[CONTROL_MAX]; int keyControls[CONTROL_MAX];
int joypadControls[CONTROL_MAX]; int joypadControls[CONTROL_MAX];
int hudInventory;
int blood;
} Config; } Config;
typedef struct { typedef struct {
@ -367,8 +369,11 @@ typedef struct {
struct Marker { struct Marker {
Sprite *sprite; Sprite *sprite;
float x, y;
float value; float value;
float y; int angle;
int visible;
int type;
Marker *next; Marker *next;
}; };

View File

@ -104,6 +104,21 @@ void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center)
SDL_RenderCopy(app.renderer, texture, srcRect, &dstRect); SDL_RenderCopy(app.renderer, texture, srcRect, &dstRect);
} }
void blitRectRotated(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, float angle)
{
SDL_Rect dstRect;
dstRect.x = x;
dstRect.y = y;
dstRect.w = srcRect->w;
dstRect.h = srcRect->h;
dstRect.x -= (srcRect->w / 2);
dstRect.y -= (srcRect->h / 2);
SDL_RenderCopyEx(app.renderer, texture, srcRect, &dstRect, angle, NULL, SDL_FLIP_NONE);
}
void blitScaled(SDL_Texture *texture, int x, int y, int w, int h, int center) void blitScaled(SDL_Texture *texture, int x, int y, int w, int h, int center)
{ {
SDL_Rect dstRect; SDL_Rect dstRect;

View File

@ -24,7 +24,7 @@ void initAtlasTest(void)
{ {
dev.cheatStatic = 0; dev.cheatStatic = 0;
dev.cheatBlind = 0; dev.cheatBlind = 0;
dev.cheatNoEnemies = 0; dev.cheatNoEnemies = 1;
dev.cheatKeys = 1; dev.cheatKeys = 1;
dev.cheatPower = 1; dev.cheatPower = 1;
dev.cheatHealth = 1; dev.cheatHealth = 1;
@ -33,7 +33,7 @@ void initAtlasTest(void)
initHub(); initHub();
loadWorld("beachApproach"); loadWorld("beachFront1");
initWorld(); initWorld();

View File

@ -57,11 +57,11 @@ void drawMap(void)
mx = camera.x / MAP_TILE_SIZE; mx = camera.x / MAP_TILE_SIZE;
x1 = (camera.x % MAP_TILE_SIZE) * -1; x1 = (camera.x % MAP_TILE_SIZE) * -1;
x2 = x1 + RENDER_WIDTH * MAP_TILE_SIZE + (x1 == 0 ? 0 : MAP_TILE_SIZE); x2 = x1 + MAP_RENDER_WIDTH * MAP_TILE_SIZE + (x1 == 0 ? 0 : MAP_TILE_SIZE);
my = camera.y / MAP_TILE_SIZE; my = camera.y / MAP_TILE_SIZE;
y1 = (camera.y % MAP_TILE_SIZE) * -1; y1 = (camera.y % MAP_TILE_SIZE) * -1;
y2 = y1 + RENDER_HEIGHT * MAP_TILE_SIZE + (y1 == 0 ? 0 : MAP_TILE_SIZE); y2 = y1 + MAP_RENDER_HEIGHT * MAP_TILE_SIZE + (y1 == 0 ? 0 : MAP_TILE_SIZE);
tile = 0; tile = 0;
decal = 0; decal = 0;
@ -201,13 +201,13 @@ static void calculateMapBounds(void)
} }
} }
if (world.map.bounds.h - RENDER_HEIGHT < world.map.bounds.y) if (world.map.bounds.h - MAP_RENDER_HEIGHT < world.map.bounds.y)
{ {
world.map.bounds.y = 0; world.map.bounds.y = 0;
} }
world.map.bounds.x = (int) limit(world.map.bounds.x, 0, MAP_WIDTH - RENDER_WIDTH); world.map.bounds.x = (int) limit(world.map.bounds.x, 0, MAP_WIDTH - MAP_RENDER_WIDTH);
world.map.bounds.y = (int) limit(world.map.bounds.y, 0, MAP_HEIGHT - RENDER_HEIGHT); world.map.bounds.y = (int) limit(world.map.bounds.y, 0, MAP_HEIGHT - MAP_RENDER_HEIGHT);
world.map.bounds.x *= MAP_TILE_SIZE; world.map.bounds.x *= MAP_TILE_SIZE;
world.map.bounds.y *= MAP_TILE_SIZE; world.map.bounds.y *= MAP_TILE_SIZE;

View File

@ -20,9 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../common.h" #include "../common.h"
#define RENDER_WIDTH ((SCREEN_WIDTH / MAP_TILE_SIZE) + 1)
#define RENDER_HEIGHT ((SCREEN_HEIGHT / MAP_TILE_SIZE) + 1)
extern float limit(float i, float a, float b); extern float limit(float i, float a, float b);
extern int rrnd(int low, int high); extern int rrnd(int low, int high);
extern char *readCompressedFile(const char *filename); extern char *readCompressedFile(const char *filename);

View File

@ -27,35 +27,92 @@ static void drawMap(void);
static void drawEntities(void); static void drawEntities(void);
static int isValidBlip(Entity *e); static int isValidBlip(Entity *e);
static void getBlipColor(Entity *e, SDL_Color *c); 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 SDL_Rect viewRect; static SDL_Rect viewRect;
static Texture *atlasTexture;
static Atlas *background;
static Atlas *arrow;
static int blinkTimer;
static Marker marker[M_MAX * 4];
void initRadar(void) void initRadar(void)
{ {
SDL_Rect limits;
app.delegate.logic = logic; app.delegate.logic = logic;
app.delegate.draw = draw; app.delegate.draw = draw;
viewRect.x = (world.bob->x / MAP_TILE_SIZE) - (VIEW_SIZE / 2); viewRect.x = (world.bob->x / MAP_TILE_SIZE) - (VIEW_SIZE_X / 2);
viewRect.y = (world.bob->y / MAP_TILE_SIZE) - (VIEW_SIZE / 2); viewRect.y = (world.bob->y / MAP_TILE_SIZE) - (VIEW_SIZE_Y / 2);
viewRect.w = VIEW_SIZE; viewRect.w = VIEW_SIZE_X;
viewRect.h = VIEW_SIZE; viewRect.h = VIEW_SIZE_Y;
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;
viewRect.x = limit(viewRect.x, limits.x, limits.w);
viewRect.y = limit(viewRect.y, limits.y, limits.h);
blinkTimer = 0;
atlasTexture = getTexture("gfx/atlas/atlas.png");
background = getImageFromAtlas("gfx/radar/background.png");
arrow = getImageFromAtlas("gfx/radar/arrow.png");
/* top */
initMarker(0, SCREEN_WIDTH / 2 - 275, SCREEN_HEIGHT / 2 - 275, 0, M_MIA);
initMarker(1, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 275, 0, M_ITEM);
initMarker(2, SCREEN_WIDTH / 2 + 275, SCREEN_HEIGHT / 2 - 275, 0, M_ENEMY);
/* bottom */
initMarker(3, SCREEN_WIDTH / 2 - 275, SCREEN_HEIGHT / 2 + 275, 180, M_MIA);
initMarker(4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 275, 180, M_ITEM);
initMarker(5, SCREEN_WIDTH / 2 + 275, SCREEN_HEIGHT / 2 + 275, 180, M_ENEMY);
/* left */
initMarker(6, SCREEN_WIDTH / 2 - 450, SCREEN_HEIGHT / 2 - 200, 270, M_MIA);
initMarker(7, SCREEN_WIDTH / 2 - 450, SCREEN_HEIGHT / 2, 270, M_ITEM);
initMarker(8, SCREEN_WIDTH / 2 - 450, SCREEN_HEIGHT / 2 + 200, 270, M_ENEMY);
/* right */
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);
}
static void initMarker(int i, int x, int y, int angle, int type)
{
marker[i].x = x;
marker[i].y = y;
marker[i].angle = angle;
marker[i].type = type;
} }
static void logic(void) static void logic(void)
{ {
blinkTimer++;
blinkTimer %= 60;
} }
static void draw(void) static void draw(void)
{ {
blitRectScaled(atlasTexture->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, &background->rect, 0);
drawMap(); drawMap();
drawEntities(); drawEntities();
drawMarkers();
} }
static void drawMap(void) static void drawMap(void)
{ {
int x, y, mx, my; int x, y, mx, my, i;
SDL_Color c; SDL_Color c;
for (x = 0 ; x < viewRect.w ; x++) for (x = 0 ; x < viewRect.w ; x++)
@ -65,17 +122,23 @@ static void drawMap(void)
mx = viewRect.x + x; mx = viewRect.x + x;
my = viewRect.y + y; my = viewRect.y + y;
drawRect(OFFSET_X + (x * RADAR_TILE_SIZE), OFFSET_Y + (y * RADAR_TILE_SIZE), RADAR_TILE_SIZE - 1, RADAR_TILE_SIZE - 1, 0, 0, 0, 255);
if (isWithinMap(mx, my)) if (isWithinMap(mx, my))
{ {
if (world.map.data[mx][my] > MAP_TILE_AIR) i = world.map.data[mx][my];
if (i > MAP_TILE_AIR && i < MAP_TILE_NON_SOLID)
{ {
getMapTileColor(world.map.data[mx][my], &c); getMapTileColor(i, &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); 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);
} }
} }
} }
} }
drawOutlineRect(OFFSET_X, OFFSET_Y, viewRect.w * RADAR_TILE_SIZE, viewRect.h * RADAR_TILE_SIZE, 0, 128, 0, 255);
} }
static void getMapTileColor(int i, SDL_Color *c) static void getMapTileColor(int i, SDL_Color *c)
@ -85,17 +148,15 @@ static void getMapTileColor(int i, SDL_Color *c)
switch (i) switch (i)
{ {
case MAP_TILE_WATER: case MAP_TILE_WATER:
c->r = c->g = c->b = 128;
c->b = 255; c->b = 255;
break; break;
case MAP_TILE_SLIME: case MAP_TILE_SLIME:
c->r = c->g = c->b = 128;
c->g = 255; c->g = 255;
break; break;
case MAP_TILE_LAVA: case MAP_TILE_LAVA:
c->r = c->g = c->b = 128; c->g = 128;
c->r = 255; c->r = 255;
break; break;
@ -143,17 +204,19 @@ static int isValidBlip(Entity *e)
switch (e->type) switch (e->type)
{ {
case ET_BOB: case ET_BOB:
return 1; case ET_MIA:
case ET_TEEKA:
return blinkTimer < 30;
case ET_ENEMY: case ET_ENEMY:
case ET_TEEKA:
case ET_BOSS: case ET_BOSS:
case ET_HEART_CELL: case ET_HEART_CELL:
case ET_KEY: case ET_KEY:
return e->isMissionTarget ? blinkTimer < 30 : 1;
case ET_ITEM: case ET_ITEM:
case ET_MIA:
case ET_DESTRUCTABLE: case ET_DESTRUCTABLE:
return 1; return e->isMissionTarget && blinkTimer < 30;
default: default:
return 0; return 0;
@ -169,18 +232,27 @@ static void getBlipColor(Entity *e, SDL_Color *c)
switch (e->type) switch (e->type)
{ {
case ET_BOB: case ET_BOB:
c->r = c->g = c->b = 255;
break; break;
case ET_ENEMY: case ET_ENEMY:
case ET_BOSS:
c->r = 255; c->r = 255;
break; break;
case ET_TEEKA: case ET_TEEKA:
case ET_BOSS: case ET_MIA:
c->r = c->g = 255;
break;
case ET_HEART_CELL: case ET_HEART_CELL:
case ET_KEY: case ET_KEY:
case ET_ITEM: case ET_ITEM:
case ET_MIA: c->g = 168;
c->b = 255;
break;
case ET_DESTRUCTABLE: case ET_DESTRUCTABLE:
c->r = c->b = 255; c->r = c->b = 255;
break; break;
@ -189,3 +261,30 @@ static void getBlipColor(Entity *e, SDL_Color *c)
break; break;
} }
} }
static void drawMarkers(void)
{
int i;
for (i = 0 ; i < M_MAX * 4 ; i++)
{
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);
}
SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 255);
}

View File

@ -18,16 +18,32 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define RADAR_TILE_SIZE 16
#define VIEW_SIZE 40
#define OFFSET_X ((SCREEN_WIDTH - (RADAR_TILE_SIZE * VIEW_SIZE)) / 2)
#define OFFSET_Y ((SCREEN_HEIGHT - (RADAR_TILE_SIZE * VIEW_SIZE)) / 2)
#include "../common.h" #include "../common.h"
#define RADAR_TILE_SIZE 16
#define VIEW_SIZE_X 50
#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)
enum
{
M_MIA,
M_ITEM,
M_ENEMY,
M_MAX
};
extern int isWithinMap(int x, int y); extern int isWithinMap(int x, int y);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
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);
extern float limit(float i, float low, float high);
extern Texture *getTexture(const char *filename);
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 blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
extern void blitRectRotated(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, float angle);
extern App app; extern App app;
extern World world; extern World world;