|
|
@@ -1,184 +0,0 @@ |
|
|
|
/* |
|
|
|
* ttyvaders Textmode shoot'em up |
|
|
|
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
|
|
|
* All Rights Reserved |
|
|
|
* |
|
|
|
* $Id$ |
|
|
|
* |
|
|
|
* This program is free software. It comes without any warranty, to |
|
|
|
* the extent permitted by applicable law. You can redistribute it |
|
|
|
* and/or modify it under the terms of the Do What The Fuck You Want |
|
|
|
* To Public License, Version 2, as published by Sam Hocevar. See |
|
|
|
* http://sam.zoy.org/wtfpl/COPYING for more details. |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "config.h" |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
#include <caca.h> |
|
|
|
|
|
|
|
caca_canvas_t *cv; |
|
|
|
caca_display_t *dp; |
|
|
|
|
|
|
|
caca_canvas_t *ship, *alien; |
|
|
|
|
|
|
|
unsigned int shipx, shipy; |
|
|
|
|
|
|
|
unsigned int frame, w, h; |
|
|
|
int ground[81]; |
|
|
|
|
|
|
|
static void run_game(void); |
|
|
|
|
|
|
|
int main(int argc, char **argv) |
|
|
|
{ |
|
|
|
cv = caca_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 = caca_get_canvas_width(cv); |
|
|
|
h = caca_get_canvas_height(cv); |
|
|
|
|
|
|
|
/* Load data */ |
|
|
|
ship = caca_create_canvas(0, 0); |
|
|
|
caca_import_file(ship, "data/ship.ans", ""); |
|
|
|
alien = caca_create_canvas(0, 0); |
|
|
|
caca_import_file(alien, "data/alien.ans", ""); |
|
|
|
|
|
|
|
/* Go ! */ |
|
|
|
run_game(); |
|
|
|
|
|
|
|
/* Clean up */ |
|
|
|
caca_free_display(dp); |
|
|
|
caca_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] += caca_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 */ |
|
|
|
caca_set_color_ansi(cv, CACA_LIGHTBLUE, CACA_LIGHTCYAN); |
|
|
|
for(j = h - 24; j < h - 18 + ((40 - i) * (40 - i) / (40 * 40 / 10)) + (i & 1); j++) |
|
|
|
caca_put_char(cv, i, j, ' '); |
|
|
|
caca_put_char(cv, i, j++, 0x2591); |
|
|
|
caca_put_char(cv, i, j++, 0x2591); |
|
|
|
caca_put_char(cv, i, j++, 0x2591); |
|
|
|
caca_put_char(cv, i, j++, 0x2592); |
|
|
|
caca_put_char(cv, i, j++, 0x2592); |
|
|
|
caca_put_char(cv, i, j++, 0x2592); |
|
|
|
caca_put_char(cv, i, j++, 0x2593); |
|
|
|
caca_put_char(cv, i, j++, 0x2593); |
|
|
|
caca_put_char(cv, i, j++, 0x2593); |
|
|
|
caca_set_color_ansi(cv, CACA_LIGHTBLUE, CACA_LIGHTBLUE); |
|
|
|
for( ; j < h; j++) |
|
|
|
caca_put_char(cv, i, j, ' '); |
|
|
|
|
|
|
|
/* TODO: Draw the mountains */ |
|
|
|
|
|
|
|
/* Draw the ground */ |
|
|
|
j = h - ground[i]; |
|
|
|
caca_set_color_ansi(cv, CACA_BLACK, CACA_LIGHTBLUE); |
|
|
|
/* if(i >= 4 && ground[i] == ground[i - 6] |
|
|
|
&& ground[i] != ground[i - 7]) |
|
|
|
{ |
|
|
|
caca_putstr(cv, i - 3, j - 2, "Omm"); |
|
|
|
caca_putstr(cv, i - 6, j - 1, "(/)-(/)"); |
|
|
|
}*/ |
|
|
|
caca_set_color_ansi(cv, CACA_RED, CACA_GREEN); |
|
|
|
if(ground[i + 1] > ground[i]) |
|
|
|
caca_put_char(cv, i, j++, 0x2588); // UTF-8: 0x259f |
|
|
|
else if(ground[i + 1] < ground[i]) |
|
|
|
{ |
|
|
|
j++; |
|
|
|
caca_put_char(cv, i, j++, 0x2588); // UTF-8: 0x2599 |
|
|
|
} |
|
|
|
else |
|
|
|
caca_put_char(cv, i, j++, 0x2584); |
|
|
|
caca_set_color_ansi(cv, CACA_RED, CACA_BROWN); |
|
|
|
caca_put_char(cv, i, j++, 0x2593); |
|
|
|
caca_put_char(cv, i, j++, 0x2592); |
|
|
|
caca_put_char(cv, i, j++, 0x2591); |
|
|
|
for( ; j < h; j++) |
|
|
|
caca_put_char(cv, i, j, ' '); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void display_stuff(void) |
|
|
|
{ |
|
|
|
caca_blit(cv, shipx, shipy, ship, NULL); |
|
|
|
caca_blit(cv, 68, h - 22, alien, NULL); |
|
|
|
caca_blit(cv, 52, h - 16, alien, NULL); |
|
|
|
caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE); |
|
|
|
caca_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; |
|
|
|
} |
|
|
|
} |
|
|
|
|