Skip to content

Commit

Permalink
Optimization in statusbar, use graphics instead of TTF
Browse files Browse the repository at this point in the history
 create mode 100644 graphics/fonts.png
  • Loading branch information
nevat committed Aug 24, 2014
1 parent 110d4cc commit 647077d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 58 deletions.
Binary file added graphics/fonts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 36 additions & 55 deletions src/barradeestado.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,52 @@
#include <SDL_ttf.h>
#include "comun.h"

static const char *nome_habitacion[] = {
":)",
"A prayer of Hope",
"Tower of the Bell",
"Wine supplies"
":$",
"Escape !!!",
"Death is close",
"Abandoned church",
"The Altar",
"Hangman tree",
"Pestilent Beast",
"Cave of illusions",
"Plagued ruins",
"Catacombs",
"Hidden garden",
"Gloomy tunels",
"Lake of despair",
"The wheel of faith",
"Banquet of Death",
"Underground river",
"Unexpected gate",
"Evil church",
"Tortured souls",
"Ashes to ashes",
"Satan !!!"};

void barradeestado (SDL_Surface *ventana, SDL_Surface *tiles, int habitacion, int vidas, int cruces, TTF_Font *fuente) {
void barradeestado (SDL_Surface *ventana, SDL_Surface *tiles, int habitacion, int vidas, int cruces, TTF_Font *fuente, SDL_Surface *fuentes) {

SDL_Rect srcbarra = {448,104,13,12};
SDL_Rect desbarra = {0,177,0,0};
SDL_Color fgcolor = {255,255,255}; /* Color de la fuente, blanco */
SDL_Surface *marcador = NULL;
SDL_Rect desmarcador = {0,0,0,0};
SDL_Rect srcnumbers = {0,460,10,10};
SDL_Rect desnumbers = {18,178,10,10};
SDL_Rect srctext = {0,0,140,20};
SDL_Rect destext = {115,176,136,18};
int i = 0;

char datos[1];
const char *nompantalla;
int ancho = 0;
int alto = 0;

SDL_BlitSurface(tiles, &srcbarra, ventana, &desbarra);
srcbarra.x = 461;
srcbarra.w = 12;
desbarra.x = 32;
SDL_BlitSurface(tiles, &srcbarra, ventana, &desbarra);

desmarcador.y = 174;

sprintf(datos, "%d", vidas);
marcador = TTF_RenderText_Solid(fuente, datos, fgcolor);
desmarcador.x = 18;
SDL_BlitSurface(marcador, NULL, ventana, &desmarcador);

sprintf(datos, "%d", cruces);
marcador = TTF_RenderText_Solid(fuente, datos, fgcolor);
desmarcador.x = 50;
SDL_BlitSurface(marcador, NULL, ventana, &desmarcador);
for (i=0; i<=2; i++) {
switch (i) {
case 0: srcnumbers.x = vidas * 10;
SDL_BlitSurface(fuentes,&srcnumbers,ventana,&desnumbers);
break;
case 1: if (cruces < 10) {
desnumbers.x = 50;
srcnumbers.x = cruces * 10;
SDL_BlitSurface(fuentes,&srcnumbers,ventana,&desnumbers);
}
else {
desnumbers.x = 50;
srcnumbers.x = 10;
SDL_BlitSurface(fuentes,&srcnumbers,ventana,&desnumbers);
desnumbers.x = 55;
srcnumbers.x = (cruces - 10) * 10;
SDL_BlitSurface(fuentes,&srcnumbers,ventana,&desnumbers);
}
break;
case 2: if ((habitacion > 0) && (habitacion < 4)) {
srctext.y = (habitacion - 1) * 20;
SDL_BlitSurface(fuentes,&srctext,ventana,&destext);
}
if (habitacion > 4) {
srctext.y = (habitacion - 2) * 20;
SDL_BlitSurface(fuentes,&srctext,ventana,&destext);
}
break;
}

}

nompantalla = nome_habitacion[habitacion];
marcador = TTF_RenderText_Solid(fuente, nompantalla, fgcolor);
TTF_SizeText(fuente, nompantalla, &ancho, &alto);
desmarcador.x = 256 - ancho;

SDL_BlitSurface(marcador, NULL, ventana, &desmarcador);
SDL_FreeSurface (marcador);

}
2 changes: 1 addition & 1 deletion src/barradeestado.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* barradeestado.h */
/* Header para barraestado.c */

void barradeestado (SDL_Surface *ventana, SDL_Surface *tiles, int habitacion, int vidas, int cruces, TT_Font *fuente);
void barradeestado (SDL_Surface *ventana, SDL_Surface *tiles, int habitacion, int vidas, int cruces, TT_Font *fuente, SDL_Surface *fuentes);
2 changes: 2 additions & 0 deletions src/comun.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define RUTA_GRA_INTRO "graphics/intro.png"
#define RUTA_GRA_INTRO2 "graphics/intro2.png"
#define RUTA_GRA_TILES "graphics/tiles.png"
#define RUTA_GRA_FUENTES "graphics/fonts.png"
#define RUTA_GRA_TEMP "graphics/temp.png"
#define RUTA_GRA_PERGAMINO "graphics/pergamino.png"
#define RUTA_GRA_PERGAMINO_ROJO "graphics/pergaminorojo.png"
Expand Down Expand Up @@ -77,6 +78,7 @@
#define RUTA_GRA_INTRO "/usr/share/abbaye/graphics/intro.png"
#define RUTA_GRA_INTRO2 "/usr/share/abbaye/graphics/intro2.png"
#define RUTA_GRA_TILES "/usr/share/abbaye/graphics/tiles.png"
#define RUTA_GRA_FUENTES "/usr/share/abbaye/graphics/fonts.png"
#define RUTA_GRA_TEMP "/usr/share/abbaye/graphics/temp.png"
#define RUTA_GRA_PERGAMINO "/usr/share/abbaye/graphics/pergamino.png"
#define RUTA_GRA_PERGAMINO_ROJO "/usr/share/abbaye/graphics/pergaminorojo.png"
Expand Down
8 changes: 6 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int framerate (int i, int frate1) {

if (i == 1) {
return now;

}

if (i == 2) {
Expand All @@ -167,6 +167,7 @@ void juego (SDL_Surface *pantalla, int *estadoj, int *cambiot) {

SDL_Surface *ventana = NULL;
SDL_Surface *tiles = NULL;
SDL_Surface *fuentes = NULL;
SDL_Surface *temp = NULL;
#ifdef _RENDER_320_240
SDL_Rect desventana = {32,24,0,0};
Expand Down Expand Up @@ -241,6 +242,9 @@ void juego (SDL_Surface *pantalla, int *estadoj, int *cambiot) {
temp = IMG_Load(RUTA_GRA_TEMP);
ventana = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
temp = IMG_Load(RUTA_GRA_FUENTES);
fuentes = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
if (*cambiot == 0)
temp = IMG_Load(RUTA_GRA_TILES);
else
Expand Down Expand Up @@ -351,7 +355,7 @@ void juego (SDL_Surface *pantalla, int *estadoj, int *cambiot) {
animitems (fase, habitacion, ciclo);
dibujarfase (ventana, fase, tiles, habitacion, ciclo, *cambiot, fondomd, fx);
if (habitacion != 4)
barradeestado (ventana, tiles, habitacion, jean.estado[0], jean.estado[1], fuente);
barradeestado (ventana, tiles, habitacion, jean.estado[0], jean.estado[1], fuente, fuentes);
if (jean.flags[6] < 8)
dibujarjean (ventana, tiles, &jean, ciclo, fx);
/* Gestion de enemigos */
Expand Down

0 comments on commit 647077d

Please sign in to comment.