[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 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! 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: Developers:
Allanis Allanis

View File

@ -80,6 +80,8 @@ int main(int argc, char** argv) {
input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, 0); input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, 0);
input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, 0); input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, 0);
input_setKeybind("primary", KEYBIND_KEYBOARD, SDLK_SPACE, 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. // Use Lua to parse configuration file.
lua_State* L = luaL_newstate(); lua_State* L = luaL_newstate();

View File

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

View File

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