Include and link physfs properly.
[tuxanci.git] / src / client / radar.c
blobe8457e96b447958573eb75119993f03a83d70d8c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
5 #include "main.h"
6 #include "list.h"
7 #include "tux.h"
8 #include "arena.h"
10 #include "interface.h"
11 #include "image.h"
12 #include "radar.h"
14 static image_t *g_radar;
15 static list_t *listRadar;
17 typedef struct radar_item_struct {
18 int id;
19 int x, y;
20 int type;
21 } radar_item_t;
23 static radar_item_t *newRadarItem(int id, int x, int y, int type)
25 radar_item_t *new;
27 new = malloc(sizeof(radar_item_t));
28 new->id = id;
29 new->x = x;
30 new->y = y;
31 new->type = type;
33 return new;
36 static void destroyRadarItem(radar_item_t *p)
38 assert(p != NULL);
39 free(p);
42 void radar_add(int id, int x, int y, int type)
44 int i;
46 for (i = 0; i < listRadar->count; i++) {
47 radar_item_t *thisRadarItem;
49 thisRadarItem = (radar_item_t *) listRadar->list[i];
51 if (thisRadarItem->id == id) {
52 thisRadarItem->x = x;
53 thisRadarItem->y = y;
54 thisRadarItem->type = type;
55 return;
59 list_add(listRadar, newRadarItem(id, x, y, type));
62 void radar_del(int id)
64 int i;
66 for (i = 0; i < listRadar->count; i++) {
67 radar_item_t *thisRadarItem;
69 thisRadarItem = (radar_item_t *) listRadar->list[i];
71 if (thisRadarItem->id == id) {
72 list_del_item(listRadar, i, destroyRadarItem);
73 return;
78 void radar_init()
80 assert(image_is_inicialized() == TRUE);
81 assert(interface_is_inicialized() == TRUE);
83 g_radar = image_add("radar.png", IMAGE_NO_ALPHA, "radar", IMAGE_GROUP_USER);
84 listRadar = list_new();
87 void radar_draw(arena_t *arena)
89 int i;
91 image_draw(g_radar, RADAR_LOCATION_X, RADAR_LOCATION_Y, 0, 0, RADAR_SIZE_X + 2, RADAR_SIZE_Y + 2);
93 for (i = 0; i < listRadar->count; i++) {
94 radar_item_t *thisRadarItem;
95 int x, y;
97 thisRadarItem = (radar_item_t *) listRadar->list[i];
99 x = (((float) RADAR_SIZE_X) / ((float) arena->w)) * ((float) thisRadarItem->x);
101 y = (((float) RADAR_SIZE_Y) / ((float) arena->h)) * ((float) thisRadarItem->y);
103 if (x >= 0 && x <= RADAR_SIZE_X && y >= 0 && y <= RADAR_SIZE_Y) {
104 image_draw(g_radar, RADAR_LOCATION_X + 1 + x, RADAR_LOCATION_Y + 1 + y,
105 2 * thisRadarItem->type, RADAR_SIZE_Y + 2, 2, 2);
110 void radar_quit()
112 list_destroy_item(listRadar, destroyRadarItem);