|
@@ -0,0 +1,196 @@ |
|
|
|
|
|
/* |
|
|
|
|
|
* ttyvaders Textmode shoot'em up |
|
|
|
|
|
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
|
|
|
|
|
* All Rights Reserved |
|
|
|
|
|
* |
|
|
|
|
|
* $Id$ |
|
|
|
|
|
* |
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
|
|
|
|
* it under the terms of the GNU General Public License as published by |
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
|
|
|
|
* (at your option) any later version. |
|
|
|
|
|
* |
|
|
|
|
|
* This program is distributed in the hope that it will be useful, |
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
* GNU General Public License for more details. |
|
|
|
|
|
* |
|
|
|
|
|
* You should have received a copy of the GNU General Public License |
|
|
|
|
|
* along with this program; if not, write to the Free Software |
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include "config.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <caca.h> |
|
|
|
|
|
|
|
|
|
|
|
cucul_canvas_t *cv; |
|
|
|
|
|
caca_display_t *dp; |
|
|
|
|
|
|
|
|
|
|
|
cucul_canvas_t *ship, *alien; |
|
|
|
|
|
|
|
|
|
|
|
unsigned int shipx, shipy; |
|
|
|
|
|
|
|
|
|
|
|
unsigned int frame, w, h; |
|
|
|
|
|
int ground[80]; |
|
|
|
|
|
|
|
|
|
|
|
static void run_game(void); |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) |
|
|
|
|
|
{ |
|
|
|
|
|
cucul_buffer_t *b; |
|
|
|
|
|
|
|
|
|
|
|
cv = cucul_create_canvas(80, 24); |
|
|
|
|
|
if(!cv) |
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
dp = caca_create_display(cv); |
|
|
|
|
|
if(!dp) |
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
caca_set_display_time(dp, 80000); |
|
|
|
|
|
|
|
|
|
|
|
/* Initialize our program */ |
|
|
|
|
|
w = cucul_get_canvas_width(cv); |
|
|
|
|
|
h = cucul_get_canvas_height(cv); |
|
|
|
|
|
|
|
|
|
|
|
/* Load data */ |
|
|
|
|
|
b = cucul_load_file("data/ship.ans"); |
|
|
|
|
|
ship = cucul_import_canvas(b, ""); |
|
|
|
|
|
cucul_free_buffer(b); |
|
|
|
|
|
b = cucul_load_file("data/alien.ans"); |
|
|
|
|
|
alien = cucul_import_canvas(b, ""); |
|
|
|
|
|
cucul_free_buffer(b); |
|
|
|
|
|
|
|
|
|
|
|
/* Go ! */ |
|
|
|
|
|
run_game(); |
|
|
|
|
|
|
|
|
|
|
|
/* Clean up */ |
|
|
|
|
|
caca_free_display(dp); |
|
|
|
|
|
cucul_free_canvas(cv); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void update_ground(void) |
|
|
|
|
|
{ |
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < 80; i++) |
|
|
|
|
|
ground[i] = ground[i + 1]; |
|
|
|
|
|
|
|
|
|
|
|
ground[80] = ground[79]; |
|
|
|
|
|
|
|
|
|
|
|
if(frame % 3) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
ground[80] += cucul_rand(-1, 2); |
|
|
|
|
|
if(ground[80] < 2) |
|
|
|
|
|
ground[80] = 3; |
|
|
|
|
|
else if(ground[80] > 7) |
|
|
|
|
|
ground[80] = 7; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void fill_ground(void) |
|
|
|
|
|
{ |
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
ground[80] = 5; |
|
|
|
|
|
for(i = 0; i < 80; i++) |
|
|
|
|
|
update_ground(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void display_ground(void) |
|
|
|
|
|
{ |
|
|
|
|
|
unsigned int i, j; |
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < 80; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
/* Draw the sky */ |
|
|
|
|
|
cucul_set_color(cv, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_LIGHTCYAN); |
|
|
|
|
|
for(j = h - 24; j < h - 18 + ((40 - i) * (40 - i) / (40 * 40 / 10)) + (i & 1); j++) |
|
|
|
|
|
cucul_putchar(cv, i, j, ' '); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2591); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2591); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2591); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2592); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2592); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2592); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2593); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2593); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2593); |
|
|
|
|
|
cucul_set_color(cv, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_LIGHTBLUE); |
|
|
|
|
|
for( ; j < h; j++) |
|
|
|
|
|
cucul_putchar(cv, i, j, ' '); |
|
|
|
|
|
|
|
|
|
|
|
/* TODO: Draw the mountains */ |
|
|
|
|
|
|
|
|
|
|
|
/* Draw the ground */ |
|
|
|
|
|
j = h - ground[i]; |
|
|
|
|
|
cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_LIGHTBLUE); |
|
|
|
|
|
if(i >= 4 && ground[i] == ground[i - 3] |
|
|
|
|
|
&& ground[i] != ground[i - 4]) |
|
|
|
|
|
{ |
|
|
|
|
|
cucul_putstr(cv, i - 3, j - 2, "||\\"); |
|
|
|
|
|
cucul_putstr(cv, i - 3, j - 1, "o--o"); |
|
|
|
|
|
} |
|
|
|
|
|
cucul_set_color(cv, CUCUL_COLOR_RED, CUCUL_COLOR_GREEN); |
|
|
|
|
|
if(ground[i + 1] > ground[i]) |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x259f); |
|
|
|
|
|
else if(ground[i + 1] < ground[i]) |
|
|
|
|
|
{ |
|
|
|
|
|
j++; |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2599); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2584); |
|
|
|
|
|
cucul_set_color(cv, CUCUL_COLOR_RED, CUCUL_COLOR_BROWN); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2593); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2592); |
|
|
|
|
|
cucul_putchar(cv, i, j++, 0x2591); |
|
|
|
|
|
for( ; j < h; j++) |
|
|
|
|
|
cucul_putchar(cv, i, j, ' '); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void display_stuff(void) |
|
|
|
|
|
{ |
|
|
|
|
|
cucul_blit(cv, shipx, shipy, ship, NULL); |
|
|
|
|
|
cucul_blit(cv, 68, h - 22, alien, NULL); |
|
|
|
|
|
cucul_blit(cv, 52, h - 16, alien, NULL); |
|
|
|
|
|
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); |
|
|
|
|
|
cucul_printf(cv, 2, h - 2, " %i fps ", 1000000 / (1 + caca_get_display_time(dp))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void run_game(void) |
|
|
|
|
|
{ |
|
|
|
|
|
fill_ground(); |
|
|
|
|
|
shipx = 5; |
|
|
|
|
|
shipy = h - 20; |
|
|
|
|
|
|
|
|
|
|
|
for(;;) |
|
|
|
|
|
{ |
|
|
|
|
|
caca_event_t ev; |
|
|
|
|
|
|
|
|
|
|
|
update_ground(); |
|
|
|
|
|
display_ground(); |
|
|
|
|
|
display_stuff(); |
|
|
|
|
|
caca_refresh_display(dp); |
|
|
|
|
|
frame++; |
|
|
|
|
|
|
|
|
|
|
|
while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0)) |
|
|
|
|
|
{ |
|
|
|
|
|
switch(ev.data.key.ch) |
|
|
|
|
|
{ |
|
|
|
|
|
case CACA_KEY_ESCAPE: goto end; break; |
|
|
|
|
|
case CACA_KEY_UP: shipy -= 1; break; |
|
|
|
|
|
case CACA_KEY_DOWN: shipy += 1; break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
continue; end: break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|