[Add] Zoom in/out, for minimap.

[Add] Weapons are now displayed on minimap.
This commit is contained in:
Allanis 2013-02-06 20:24:45 +00:00
parent 7d4f94acc7
commit c2ec11a7c3
4 changed files with 94 additions and 35 deletions

13
README
View File

@ -3,6 +3,19 @@ Lephisto : SaraCraft Studio's
Lephisto was the first game project I worked on. I have decided to start a new project and as originally planned when
ceasing work on the original, re-use the name!
Keys:
Movement:
-- w : Accelerate.
-- a : Left.
-- d : Right.
Combat:
-- Space : Primary weapons.
GUI:
-- UP : Zoom in.
-- DOWN : Zoom out.
Developers:
Allanis

View File

@ -80,6 +80,8 @@ int main(int argc, char** argv) {
input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, 0);
input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, 0);
input_setKeybind("primary", KEYBIND_KEYBOARD, SDLK_SPACE, 0);
input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_UP, 0);
input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_DOWN, 0);
// Use Lua to parse configuration file.
lua_State* L = luaL_newstate();

View File

@ -19,7 +19,8 @@ typedef struct {
} Keybind;
static Keybind** player_input; // Contains the players keybindings.
// Name of each keybinding.
const char* keybindNames[] = { "accel", "left", "right", "primary" };
const char* keybindNames[] = { "accel", "left", "right", "primary",
"mapzoomin", "mapzoomout" };
// Player stuff.
Pilot* player = NULL; // extern in pilot.h
@ -31,6 +32,9 @@ static int player_primary = 0; // Player is shooting primary weapon.
extern Pilot** pilot_stack;
extern int pilots;
// Weapon stuff for GUI.
extern void weapon_minimap(double res, double w, double h);
// GUI crap.
// Need these offsets to render properly. -- Used in opengl.c
// -- Colors.
@ -40,6 +44,8 @@ typedef struct {
#define COLOR(x) (x).r, (x).g, (x).b, (x).a
Color cRadar_player = { .r = 0.4, .g = 0.8, .b = 0.9, .a = 1. };
Color cRadar_neut = { .r = 0.8, .g = 0.8, .b = 0.8, .a = 1. };
Color cRadar_weap = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. };
Color cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. };
Color cArmor = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. };
Color cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
@ -52,6 +58,11 @@ typedef struct {
double res; // Resolution.
} Radar;
// Radar res.
#define RADAR_RES_MAX 100.
#define RADAR_RES_MIN 10.
#define RADAR_RES_INTERVAL 10.
typedef struct {
double w,h;
} Rect;
@ -105,6 +116,8 @@ void player_render(void) {
Pilot* p;
switch(gui.radar.shape) {
case RADAR_RECT:
glColor4d(COLOR(cRadar_weap));
weapon_minimap(gui.radar.res, gui.radar.w, gui.radar.h);
glEnd(); // Put end to those points.
for(i = 1; i < pilots; i++) {
p = pilot_stack[i];
@ -113,6 +126,9 @@ void player_render(void) {
sx = PILOT_SIZE_APROX/2. * p->ship->gfx_space->sw / gui.radar.res;
sy = PILOT_SIZE_APROX/2. * p->ship->gfx_space->sh / gui.radar.res;
if(sx < 1.) sx = 1.;
if(sy < 1.) sy = 1.;
if((ABS(x) > gui.radar.w / 2+sx) || (ABS(y) > gui.radar.h / 2. + sy))
continue; // Pilot isn't in range.
@ -292,6 +308,14 @@ static void input_key(int keynum, double value, int abs) {
if(value==KEY_PRESS) player_primary = 1;
else if(value == KEY_RELEASE) player_primary = 0;
}
else if(strcmp(player_input[keynum]->name, "mapzoomin")==0) {
if(value == KEY_PRESS && gui.radar.res < RADAR_RES_MAX)
gui.radar.res += RADAR_RES_INTERVAL;
}
else if(strcmp(player_input[keynum]->name, "mapzoomout")==0) {
if(value == KEY_PRESS && gui.radar.res > RADAR_RES_MIN)
gui.radar.res -= RADAR_RES_INTERVAL;
}
//Make sure values are sane.
player_acc = ABS(player_acc);

View File

@ -27,13 +27,13 @@ typedef struct Weapon {
} Weapon;
// Behind Pilot layer.
static Weapon** backLayer = NULL; // Behind pilots.
static int nbackLayer = 0; // Number of elements.
static int mbackLayer = 0; // Allocated memory size.
static Weapon** wbackLayer = NULL; // Behind pilots.
static int nwbackLayer = 0; // Number of elements.
static int mwbackLayer = 0; // Allocated memory size.
// Behind player layer.
static Weapon** frontLayer = NULL; // Behind pilots.
static int nfrontLayer = 0; // Number of elements.
static int mfrontLayer = 0; // Allocated memory size.
static Weapon** wfrontLayer = NULL; // Behind pilots.
static int nwfrontLayer = 0; // Number of elements.
static int mwfrontLayer = 0; // Allocated memory size.
static Weapon* weapon_create(const Outfit* outfit, const double dir,
@ -44,6 +44,26 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer);
static void weapon_destroy(Weapon* w, WeaponLayer layer);
static void weapon_free(Weapon* w);
// Draw the minimap weapons (player.c).
void weapon_minimap(double res, double w, double h) {
int i;
double x, y;
for(i = 0; i < nwbackLayer; i++) {
x = (wbackLayer[i]->solid->pos.x - player->solid->pos.x) / res;
y = (wbackLayer[i]->solid->pos.y - player->solid->pos.y) / res;
if(ABS(x) < w/2. && ABS(y) < h/2.)
glVertex2d(x,y);
}
for(i = 0; i < nwfrontLayer; i++) {
x = (wfrontLayer[i]->solid->pos.x - player->solid->pos.x) / res;
y = (wfrontLayer[i]->solid->pos.y - player->solid->pos.y) / res;
if(ABS(x) < w/2. && ABS(y) < h/2.)
glVertex2d(x,y);
}
}
// Update all weapons in the layer.
void weapons_update(const double dt, WeaponLayer layer) {
Weapon** wlayer;
@ -51,12 +71,12 @@ void weapons_update(const double dt, WeaponLayer layer) {
switch(layer) {
case WEAPON_LAYER_BG:
wlayer = backLayer;
nlayer = nbackLayer;
wlayer = wbackLayer;
nlayer = nwbackLayer;
break;
case WEAPON_LAYER_FG:
wlayer = frontLayer;
nlayer = nfrontLayer;
wlayer = wfrontLayer;
nlayer = nwfrontLayer;
break;
}
int i;
@ -146,14 +166,14 @@ void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, const V
int* nLayer = NULL;
switch(layer) {
case WEAPON_LAYER_BG:
curLayer = backLayer;
nLayer = &nbackLayer;
mLayer = &mbackLayer;
curLayer = wbackLayer;
nLayer = &nwbackLayer;
mLayer = &mwbackLayer;
break;
case WEAPON_LAYER_FG:
curLayer = frontLayer;
nLayer = &nfrontLayer;
mLayer = &mfrontLayer;
curLayer = wfrontLayer;
nLayer = &nwfrontLayer;
mLayer = &mwfrontLayer;
break;
default:
ERR("Invalid WEAPON_LAYER specified.");
@ -164,10 +184,10 @@ void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, const V
else { // Need to allocate more memory.
switch(layer) {
case WEAPON_LAYER_BG:
curLayer = backLayer = realloc(curLayer, (++(*mLayer))*sizeof(Weapon));
curLayer = wbackLayer = realloc(curLayer, (++(*mLayer))*sizeof(Weapon));
break;
case WEAPON_LAYER_FG:
curLayer = frontLayer = realloc(curLayer, (++(*mLayer))*sizeof(Weapon*));
curLayer = wfrontLayer = realloc(curLayer, (++(*mLayer))*sizeof(Weapon*));
break;
}
curLayer[(*nLayer)++] = w;
@ -181,12 +201,12 @@ static void weapon_destroy(Weapon* w, WeaponLayer layer) {
int* nlayer;
switch(layer) {
case WEAPON_LAYER_BG:
wlayer = backLayer;
nlayer = &nbackLayer;
wlayer = wbackLayer;
nlayer = &nwbackLayer;
break;
case WEAPON_LAYER_FG:
wlayer = frontLayer;
nlayer = &nfrontLayer;
wlayer = wfrontLayer;
nlayer = &nwfrontLayer;
break;
}
for(i = 0; wlayer[i] != w; i++); // Get us to the current posision.
@ -206,17 +226,17 @@ static void weapon_free(Weapon* w) {
// Clear all the weapons, do not free the layers.
void weapon_clear(void) {
int i;
for(i = 0; i < nbackLayer; i++)
weapon_free(backLayer[i]);
nbackLayer = 0;
for(i = 0; i < nfrontLayer; i++)
weapon_free(frontLayer[i]);
nfrontLayer = 0;
for(i = 0; i < nwbackLayer; i++)
weapon_free(wbackLayer[i]);
nwbackLayer = 0;
for(i = 0; i < nwfrontLayer; i++)
weapon_free(wfrontLayer[i]);
nwfrontLayer = 0;
}
void weapon_exit(void) {
weapon_clear();
free(backLayer);
free(frontLayer);
free(wbackLayer);
free(wfrontLayer);
}