From 854322ea519d2bea7c9e0f7486faa1641d9c56a9 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 28 Apr 2009 21:01:12 +0000 Subject: [PATCH] ttyvaders: go back to the old vertical scrolling git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@3424 92316355-f0b4-4df1-b90c-862c8a59935f --- src/Makefile.am | 15 +++- src/main.c | 2 +- src/ttyvaders.c | 184 ------------------------------------------------ 3 files changed, 14 insertions(+), 187 deletions(-) delete mode 100644 src/ttyvaders.c diff --git a/src/Makefile.am b/src/Makefile.am index 6adddea..87b8c94 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,8 +5,19 @@ bin_PROGRAMS = ttyvaders ttyvaders_SOURCES = \ - ttyvaders.c \ - ground.c \ + aliens.c \ + bonus.c \ + box.c \ + ceo.c \ + collide.c \ + explosions.c \ + intro.c \ + main.c \ + overlay.c \ + player.c \ + starfield.c \ + tunnel.c \ + weapons.c \ $(NULL) ttyvaders_CFLAGS = @CACA_CFLAGS@ ttyvaders_LDADD = @CACA_LIBS@ -lm diff --git a/src/main.c b/src/main.c index 21c8082..2a43572 100644 --- a/src/main.c +++ b/src/main.c @@ -196,7 +196,7 @@ static void start_game (game *g) { int list[3] = { ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ }; - add_alien(g, g->al, 0, rand() % g->h / 2, list[caca_rand(0,2)]); + add_alien(g, g->al, 0, rand() % g->h / 2, list[caca_rand(0,3)]); } /* Update game rules */ diff --git a/src/ttyvaders.c b/src/ttyvaders.c deleted file mode 100644 index ab1a99b..0000000 --- a/src/ttyvaders.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * ttyvaders Textmode shoot'em up - * Copyright (c) 2006 Sam Hocevar - * 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 - -#include - -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; - } -} -