diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Makefile | 4 | ||||
| -rw-r--r-- | src/client/game.c | 1 | ||||
| -rw-r--r-- | src/client/radar.c | 117 | ||||
| -rw-r--r-- | src/client/radar.h | 24 |
4 files changed, 145 insertions, 1 deletions
diff --git a/src/client/Makefile b/src/client/Makefile index c5637ea..f8fee47 100644 --- a/src/client/Makefile +++ b/src/client/Makefile @@ -1,6 +1,6 @@ -all: client.o configFile.o font.o game.o image.o interface.o keytable.o language.o layer.o panel.o screen.o term.o +all: client.o configFile.o font.o game.o image.o interface.o keytable.o language.o layer.o panel.o radar.o screen.o term.o client.o: client.c client.h $(CC) $(CFLAGS) -o client.o -c client.c @@ -26,6 +26,8 @@ layer.o: layer.c layer.h panel.o: panel.c panel.h $(CC) $(CFLAGS) -o panel.o -c panel.c +radar.o: radar.c radar.h + $(CC) $(CFLAGS) -o radar.o -c radar.c screen.o: screen.c screen.h $(CC) $(CFLAGS) -o screen.o -c screen.c diff --git a/src/client/game.c b/src/client/game.c index 7ea9145..66da14e 100644 --- a/src/client/game.c +++ b/src/client/game.c @@ -23,6 +23,7 @@ #include "client/keytable.h" #include "client/language.h" #include "client/panel.h" +#include "client/radar.h" #include "audio/audio.h" #include "audio/sound.h" diff --git a/src/client/radar.c b/src/client/radar.c new file mode 100644 index 0000000..d993d41 --- /dev/null +++ b/src/client/radar.c @@ -0,0 +1,117 @@ + +#include <stdio.h> +#include <assert.h> + +#include "base/main.h" +#include "base/list.h" +#include "base/tux.h" +#include "base/arena.h" + +#include "client/interface.h" +#include "client/image.h" +#include "client/radar.h" + +static SDL_Surface *g_radar; +static list_t *listRadar; + +typedef struct radar_item_struct +{ + int id; + int x, y; + int type; +} radar_item_t; + +static radar_item_t* newRadarItem(int id, int x, int y, int type) +{ + radar_item_t *new; + + new = malloc( sizeof(radar_item_t) ); + new->id = id; + new->x = x; + new->y = y; + new->type = type; + + return new; +} + +static void destroyRadarItem(radar_item_t *p) +{ + assert( p != NULL ); + free(p); +} + +void addToRadar(int id, int x, int y, int type) +{ + int i; + + for( i = 0 ; i < listRadar->count ; i++ ) + { + radar_item_t *thisRadarItem; + + thisRadarItem = (radar_item_t *)listRadar->list[i]; + + if( thisRadarItem->id == id ) + { + thisRadarItem->x = x; + thisRadarItem->y = y; + thisRadarItem->type = type; + return; + } + } + + addList(listRadar, newRadarItem(id, x, y, type) ); +} + +void delFromRadar(int id) +{ + int i; + + for( i = 0 ; i < listRadar->count ; i++ ) + { + radar_item_t *thisRadarItem; + + thisRadarItem = (radar_item_t *)listRadar->list[i]; + + if( thisRadarItem->id == id ) + { + delListItem(listRadar, i, destroyRadarItem); + return; + } + } +} + +void initRadar() +{ + assert( isImageInicialized() == TRUE ); + assert( isInterfaceInicialized() == TRUE ); + + g_radar = addImageData("radar.png", IMAGE_ALPHA, "radar", IMAGE_GROUP_USER); + listRadar = newList(); +} + +void drawRadar(arena_t *arena) +{ + int i; + + drawImage(g_radar, RADAR_LOCATION_X, RADAR_LOCATION_Y, 0, 0, RADAR_SIZE_X+2, RADAR_SIZE_Y+2); + + for( i = 0 ; i < listRadar->count ; i++ ) + { + radar_item_t *thisRadarItem; + int x, y; + + thisRadarItem = (radar_item_t *)listRadar->list[i]; + + x = ( ( (float)RADAR_SIZE_X) / ( (float)arena->w ) ) * ( (float)thisRadarItem->x ); + y = ( ( (float)RADAR_SIZE_Y) / ( (float)arena->h ) ) * ( (float)thisRadarItem->y ); + + drawImage(g_radar, + RADAR_LOCATION_X+1+x, RADAR_LOCATION_Y+1+y, + 2*thisRadarItem->type, RADAR_SIZE_Y+2, 2, 2); + } +} + +void quitRadar() +{ + destroyListItem(listRadar, destroyRadarItem); +} diff --git a/src/client/radar.h b/src/client/radar.h new file mode 100644 index 0000000..989856a --- /dev/null +++ b/src/client/radar.h @@ -0,0 +1,24 @@ + +#ifndef RADAR_H + +#define RADAR_H + +#include "base/arena.h" + +#define RADAR_LOCATION_X (WINDOW_SIZE_X-110) +#define RADAR_LOCATION_Y (10) + +#define RADAR_SIZE_X 100 +#define RADAR_SIZE_Y 100 + +#define RADAR_TYPE_YOU 3 +#define RADAR_TYPE_TUX 1 +#define RADAR_TYPE_ITEM 2 + +extern void initRadar(); +extern void addToRadar(int id, int x, int y, int type); +extern void delFromRadar(int id); +extern void drawRadar(arena_t *arena); +extern void quitRadar(); + +#endif |