Bläddra i källkod

* Totally restarted the project. This is just a test.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@990 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 18 år sedan
förälder
incheckning
890b411352
4 ändrade filer med 215 tillägg och 32 borttagningar
  1. +15
    -16
      configure.ac
  2. +4
    -16
      src/Makefile.am
  3. +0
    -0
      src/ground.c
  4. +196
    -0
      src/ttyvaders.c

+ 15
- 16
configure.ac Visa fil

@@ -14,24 +14,23 @@ AM_PROG_CC_C_O
AC_PROG_CPP

dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right
dnl now otherwise it might be set in an obscure if statement.
AC_EGREP_CPP(foo,foo)

AC_MSG_CHECKING(for libcaca support)
video_caca=no
AC_TRY_COMPILE([
#include <caca.h>
],[ ],[video_caca=yes])
AC_MSG_RESULT($video_caca)
if test "$video_caca" = "yes"; then
CACA_CFLAGS="${CFLAGS} `caca-config --cflags`"
CACA_LIBS="${LIBS} `caca-config --libs`"
AC_SUBST(CACA_CFLAGS)
AC_SUBST(CACA_LIBS)
else
AC_MSG_ERROR([cannot find libcaca])
dnl now otherwise it might be set in an obscure if statement. Same thing for
dnl PKG_PROG_PKG_CONFIG which needs to be called first.
AC_EGREP_CPP(yes, foo)
PKG_PROG_PKG_CONFIG()

dnl Don't let pkg-config fuck our cross-compilation environment
m4_pattern_allow([^PKG_CONFIG_LIBDIR$])
if test "$build" != "$host" -a "${PKG_CONFIG_LIBDIR}" = ""; then
export PKG_CONFIG_LIBDIR=/dev/null
fi

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

# Optimizations
CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer"
# Code qui fait des warnings == code de porc == deux baffes dans ta gueule


+ 4
- 16
src/Makefile.am Visa fil

@@ -5,21 +5,9 @@
bin_PROGRAMS = ttyvaders

ttyvaders_SOURCES = \
aliens.c \
bonus.c \
box.c \
ceo.c \
collide.c \
common.h \
explosions.c \
intro.c \
main.c \
overlay.c \
player.c \
starfield.c \
tunnel.c \
weapons.c \
ttyvaders.c \
ground.c \
$(NULL)
ttyvaders_CFLAGS = @CACA_CFLAGS@
ttyvaders_LDADD = @CACA_LIBS@ -lm
ttyvaders_CFLAGS = `pkg-config --cflags caca`
ttyvaders_LDFLAGS = `pkg-config --libs caca` -lm


+ 0
- 0
src/ground.c Visa fil


+ 196
- 0
src/ttyvaders.c Visa fil

@@ -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;
}
}


Laddar…
Avbryt
Spara