Browse Source

Port cacatris to the unified libcaca 0.99.beta15 API.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/cacatris/trunk@2981 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 16 years ago
parent
commit
5eb647f197
3 changed files with 35 additions and 38 deletions
  1. +2
    -2
      configure.ac
  2. +1
    -4
      src/cacatris.h
  3. +32
    -32
      src/main.c

+ 2
- 2
configure.ac View File

@@ -26,10 +26,10 @@ if test "$build" != "$host" -a "${PKG_CONFIG_LIBDIR}" = ""; then
fi fi


CACA="no" CACA="no"
PKG_CHECK_MODULES(CACA, caca >= 0.99.beta9,
PKG_CHECK_MODULES(CACA, caca >= 0.99.beta15,
[CACA="yes"], [CACA="yes"],
[AC_MSG_RESULT(no) [AC_MSG_RESULT(no)
AC_MSG_ERROR([you need libcaca version 0.99.beta9 or later])])
AC_MSG_ERROR([you need libcaca version 0.99.beta15 or later])])


# Optimizations # Optimizations
CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer" CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer"


+ 1
- 4
src/cacatris.h View File

@@ -19,10 +19,7 @@
# define M_PI 3.14159265358979323846 # define M_PI 3.14159265358979323846
#endif #endif



#include "cucul.h"
#include "caca.h"

#include <caca.h>


#define INFO_WIDTH 20 #define INFO_WIDTH 20
#define FIELD_WIDTH 10 #define FIELD_WIDTH 10


+ 32
- 32
src/main.c View File

@@ -27,16 +27,16 @@ int main(int argc, char *argv[])
unsigned char level = 0; unsigned char level = 0;
unsigned char total_lines = 0; unsigned char total_lines = 0;


field = cucul_create_canvas(0, 0);
infos = cucul_create_canvas(0, 0);
screen = cucul_create_canvas(0, 0);
field = caca_create_canvas(0, 0);
infos = caca_create_canvas(0, 0);
screen = caca_create_canvas(0, 0);


dp = caca_create_display(screen); dp = caca_create_display(screen);
if(!dp) if(!dp)
return 1; return 1;


cucul_set_canvas_size(infos, INFO_WIDTH, cucul_get_canvas_height(screen));
cucul_set_canvas_size(field, FIELD_CANVAS_WIDTH, FIELD_CANVAS_HEIGHT);
caca_set_canvas_size(infos, INFO_WIDTH, caca_get_canvas_height(screen));
caca_set_canvas_size(field, FIELD_CANVAS_WIDTH, FIELD_CANVAS_HEIGHT);


caca_set_display_time(dp, 20000); caca_set_display_time(dp, 20000);


@@ -45,8 +45,8 @@ int main(int argc, char *argv[])




/* Set current and next piece to random */ /* Set current and next piece to random */
current_piece = cucul_rand(0, 6);
next_piece = cucul_rand(0, 6);
current_piece = caca_rand(0, 6);
next_piece = caca_rand(0, 6);




for(;;) for(;;)
@@ -137,9 +137,9 @@ int main(int argc, char *argv[])
playfield_draw(field); playfield_draw(field);
remove_piece(current_piece, x ,y, rotation); remove_piece(current_piece, x ,y, rotation);
/* blit infos canvas into general one */ /* blit infos canvas into general one */
cucul_blit(screen, (cucul_get_canvas_width(screen)) - INFO_WIDTH, 0, infos, NULL);
caca_blit(screen, (caca_get_canvas_width(screen)) - INFO_WIDTH, 0, infos, NULL);
/* blit playfield canvas into general one */ /* blit playfield canvas into general one */
cucul_blit(screen, 18, 0, field, NULL);
caca_blit(screen, 18, 0, field, NULL);


caca_refresh_display(dp); caca_refresh_display(dp);


@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
x = (FIELD_WIDTH/2)-1; x = (FIELD_WIDTH/2)-1;
current_piece = next_piece; current_piece = next_piece;
rotation = 0; rotation = 0;
next_piece = cucul_rand(0, 6);
next_piece = caca_rand(0, 6);
last_has_landed = 1; last_has_landed = 1;
old_x = x; old_x = x;
old_y = 0; old_y = 0;
@@ -180,45 +180,45 @@ int main(int argc, char *argv[])


end: end:
caca_free_display(dp); caca_free_display(dp);
cucul_free_canvas(field);
cucul_free_canvas(infos);
cucul_free_canvas(screen);
caca_free_canvas(field);
caca_free_canvas(infos);
caca_free_canvas(screen);


return 0; return 0;
} }




void infos_populate(cucul_canvas_t *inf, unsigned int score,
void infos_populate(caca_canvas_t *inf, unsigned int score,
unsigned char level, unsigned char total) unsigned char level, unsigned char total)
{ {
unsigned int i;
char scoreline[256]; char scoreline[256];
char levelline[256]; char levelline[256];
char totalline[256]; char totalline[256];
int i;


sprintf(scoreline, " Score : %05d ", score); sprintf(scoreline, " Score : %05d ", score);
sprintf(levelline, " Level : %02d ", level); sprintf(levelline, " Level : %02d ", level);
sprintf(totalline, " Lines : %02d ", total); sprintf(totalline, " Lines : %02d ", total);


cucul_set_color_ansi(inf, CUCUL_WHITE, CUCUL_BLUE);
cucul_put_str(inf, 0, 0, " =Cacatris= ");
cucul_put_str(inf, 0, 1, " Arrows : move ");
cucul_put_str(inf, 0, 2, " Space : pouf ");
cucul_put_str(inf, 0, 3, " __________________ ");
cucul_put_str(inf, 0, 4, " ");
cucul_put_str(inf, 0, 5, levelline);
cucul_put_str(inf, 0, 6, scoreline);
cucul_put_str(inf, 0, 7, totalline);
cucul_put_str(inf, 0, 8, " Time : XX:XX ");
for(i = 8; i < cucul_get_canvas_height(inf); i++)
caca_set_color_ansi(inf, CACA_WHITE, CACA_BLUE);
caca_put_str(inf, 0, 0, " =Cacatris= ");
caca_put_str(inf, 0, 1, " Arrows : move ");
caca_put_str(inf, 0, 2, " Space : pouf ");
caca_put_str(inf, 0, 3, " __________________ ");
caca_put_str(inf, 0, 4, " ");
caca_put_str(inf, 0, 5, levelline);
caca_put_str(inf, 0, 6, scoreline);
caca_put_str(inf, 0, 7, totalline);
caca_put_str(inf, 0, 8, " Time : XX:XX ");
for(i = 8; i < caca_get_canvas_height(inf); i++)
{ {
cucul_put_str(inf, 0, i," ");
caca_put_str(inf, 0, i," ");
} }
} }




void playfield_draw(cucul_canvas_t *canvas)
void playfield_draw(caca_canvas_t *canvas)
{ {
unsigned int x, y; unsigned int x, y;
float ox=0, oy=0; float ox=0, oy=0;
@@ -232,9 +232,9 @@ void playfield_draw(cucul_canvas_t *canvas)
unsigned int oxi = (unsigned int) ox; unsigned int oxi = (unsigned int) ox;
unsigned int oyi = (unsigned int) oy; unsigned int oyi = (unsigned int) oy;
unsigned int c = playfield[oxi+oyi*FIELD_WIDTH]; unsigned int c = playfield[oxi+oyi*FIELD_WIDTH];
cucul_set_color_ansi(canvas, CUCUL_BLACK,
c ? blocks_palette[c-1] : CUCUL_DARKGRAY);
cucul_put_char(canvas, x, y, ' ');
caca_set_color_ansi(canvas, CACA_BLACK,
c ? blocks_palette[c-1] : CACA_DARKGRAY);
caca_put_char(canvas, x, y, ' ');
ox+=incx; ox+=incx;
} }
ox = 0; ox = 0;


Loading…
Cancel
Save