* two new types of aliens. only one rules. * removed gfx_write in favor of gfx_putchar and gfx_putstr. * added bonuses at alien death. they do nothing yet. * seeker missiles. 'b' to test. * weapon resolution is now 16*char. needs to be generalized. * fixed the supernova bugs. center could collide with the tunnel, and the last frame was badly displayed. * lots of cleanups everywhere. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@20 92316355-f0b4-4df1-b90c-862c8a59935fmaster
@@ -76,16 +76,16 @@ OBJEXT = o | |||
PACKAGE = ttyvaders | |||
PACKAGE_BUGREPORT = | |||
PACKAGE_NAME = ttyvaders | |||
PACKAGE_STRING = ttyvaders 0.0-cvs | |||
PACKAGE_STRING = ttyvaders 0.0cvs | |||
PACKAGE_TARNAME = ttyvaders | |||
PACKAGE_VERSION = 0.0-cvs | |||
PACKAGE_VERSION = 0.0cvs | |||
PATH_SEPARATOR = : | |||
SET_MAKE = | |||
SHELL = /bin/sh | |||
STRIP = | |||
USE_NCURSES_FALSE = | |||
USE_NCURSES_TRUE = # | |||
VERSION = 0.0-cvs | |||
VERSION = 0.0cvs | |||
ac_ct_CC = gcc | |||
ac_ct_STRIP = | |||
am__fastdepCC_FALSE = | |||
@@ -1,12 +1,12 @@ | |||
dnl Autoconf settings for ttyvaders | |||
AC_INIT(ttyvaders,0.0-cvs) | |||
AC_INIT(ttyvaders,0.0cvs) | |||
AC_PREREQ(2.50) | |||
AC_CONFIG_SRCDIR(src/main.c) | |||
AC_CANONICAL_SYSTEM | |||
AM_INIT_AUTOMAKE(ttyvaders,0.0-cvs) | |||
AM_INIT_AUTOMAKE(ttyvaders,0.0cvs) | |||
AM_CONFIG_HEADER(config.h) | |||
AM_PROG_CC_C_O | |||
@@ -0,0 +1,5 @@ | |||
ttyvaders (0.0cvs-1) unstable; urgency=low | |||
* Not yet released. | |||
-- Samuel Hocevar <sam@zoy.org> Sat, 14 Dec 2002 15:22:25 +0100 |
@@ -0,0 +1,15 @@ | |||
Source: ttyvaders | |||
Section: games | |||
Priority: optional | |||
Maintainer: Samuel Hocevar <sam@zoy.org> | |||
Build-Depends: debhelper (>=2.2.0), slang1-dev | |||
Standards-Version: 3.5.6 | |||
Package: ttyvaders | |||
Section: games | |||
Architecture: any | |||
Depends: ${shlibs:Depends} | |||
Description: A vertical shoot 'em up with text-mode graphics. | |||
TTYvaders is a vertical shoot 'em up for the console or the terminal. | |||
. | |||
It rules. |
@@ -0,0 +1,77 @@ | |||
#!/usr/bin/make -f | |||
#export DH_VERBOSE=1 | |||
export DH_COMPAT=3 | |||
export DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) | |||
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) | |||
# FOR AUTOCONF 2.52 AND NEWER ONLY | |||
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE)) | |||
confflags += --build $(DEB_HOST_GNU_TYPE) | |||
else | |||
confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE) | |||
endif | |||
confflags += --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info | |||
configure: configure-stamp | |||
configure-stamp: | |||
dh_testdir | |||
./configure $(confflags) --prefix=/usr | |||
touch configure-stamp | |||
build: configure-stamp build-stamp | |||
build-stamp: | |||
dh_testdir | |||
$(MAKE) | |||
touch build-stamp | |||
clean: | |||
dh_testdir | |||
dh_testroot | |||
rm -f build-stamp configure-stamp | |||
-$(MAKE) distclean | |||
dh_clean | |||
install: build | |||
dh_testdir | |||
dh_testroot | |||
dh_clean -k | |||
dh_installdirs | |||
DESTDIR=`pwd`/debian/ttyvaders/ $(MAKE) install prefix=/usr | |||
# Build architecture-independent files here. | |||
binary-indep: build install | |||
# We have nothing to do by default. | |||
# Build architecture-dependent files here. | |||
binary-arch: build install | |||
# dh_testversion | |||
dh_testdir | |||
dh_testroot | |||
# dh_installdebconf | |||
dh_installdocs | |||
# dh_installexamples | |||
dh_installmenu | |||
# dh_installemacsen | |||
# dh_installpam | |||
# dh_installinit | |||
dh_installcron | |||
dh_installmanpages | |||
dh_installinfo | |||
# dh_undocumented | |||
dh_installchangelogs | |||
dh_link | |||
dh_strip | |||
dh_compress | |||
dh_fixperms | |||
# dh_makeshlibs | |||
dh_installdeb | |||
# dh_perl | |||
dh_shlibdeps | |||
dh_gencontrol | |||
dh_md5sums | |||
dh_builddeb | |||
binary: binary-indep binary-arch | |||
.PHONY: build clean binary-indep binary-arch binary install configure |
@@ -2,9 +2,9 @@ | |||
Starship | |||
-------- | |||
/\ | |||
(()) | |||
I<__>I | |||
/\ /~\ | |||
(()) ]O[ | |||
I<__>I I\#/I | |||
Aliens | |||
@@ -13,12 +13,45 @@ Aliens | |||
,---. ,---. | |||
\O o/ \o O/ | |||
^^^^^ ^^^^^ | |||
. , . , | |||
\oXo/ `-oXo-' `--oXo--' ,-oXo-. ,oXo. | |||
`V' `V' `V' ' `V' ` / `V' \ | |||
,---. ,---. ,---. ,---. ,---. | |||
(_°_°_) (__°_°) (°__°_) (_°__°) (°_°__) | |||
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ | |||
,---. ,---. ,---. ,---. ,---. | |||
(((o))) ((((o)) (((o))) ((o)))) (((o))) | |||
`---' `---' `---' `---' `---' | |||
_o|o_ | |||
T|T | |||
Bonus | |||
----- | |||
_ _ _ | |||
/|\ / \ /.\ | |||
\|/ \_/ \_/ | |||
,--. ,--. ,--. | |||
\VV/ \~~/ \ / | |||
\/ \/ \/ | |||
_ _ _ _ | |||
( `' ) ( ' ) | |||
\ / `v' | |||
\/ | |||
___ | |||
/ g \ | |||
\___/ | |||
Shots | |||
----- | |||
| / _, ___ \ | |||
| / ' \ | |||
.o@ . o @ . o @ | |||
.o() . o () . o () | |||
| / _, ___ ._ \ | |||
| / ' ` \ | |||
| __/ \__ | | |||
@@ -2,10 +2,10 @@ | |||
# Automake targets and declarations for ttyvaders | |||
############################################################################### | |||
AM_CPPFLAGS = -g -O6 -fno-strength-reduce -fomit-frame-pointer | |||
AM_CFLAGS = -g -O6 -fno-strength-reduce -fomit-frame-pointer | |||
# Code qui fait des warnings == code de porc == deux baffes dans ta gueule | |||
AM_CPPFLAGS += -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs | |||
AM_CFLAGS += -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs | |||
if USE_NCURSES | |||
CPPFLAGS_gfx = -DUSE_NCURSES | |||
@@ -19,6 +19,7 @@ bin_PROGRAMS = ttyvaders | |||
ttyvaders_SOURCES = \ | |||
aliens.c \ | |||
bonus.c \ | |||
common.h \ | |||
explosions.c \ | |||
main.c \ | |||
@@ -3,7 +3,9 @@ | |||
#include "common.h" | |||
static void draw_alien( game *g, int x, int y, int type ); | |||
static void draw_alien_poolp( game *g, int x, int y, int frame ); | |||
static void draw_alien_bool( game *g, int x, int y, int frame ); | |||
static void draw_alien_brah( game *g, int x, int y, int frame ); | |||
void init_aliens( game *g, aliens *al ) | |||
{ | |||
@@ -11,10 +13,7 @@ void init_aliens( game *g, aliens *al ) | |||
for( i = 0; i < ALIENS; i++ ) | |||
{ | |||
al->x[i] = -1; | |||
al->y[i] = -1; | |||
al->img[i] = 0; | |||
al->life[i] = 0; | |||
al->type[i] = ALIEN_NONE; | |||
} | |||
} | |||
@@ -24,9 +23,19 @@ void draw_aliens( game *g, aliens *al ) | |||
for( i = 0; i < ALIENS; i++ ) | |||
{ | |||
if( al->y[i] >= 0 ) | |||
switch( al->type[i] ) | |||
{ | |||
draw_alien( g, al->x[i], al->y[i], al->img[i] % 2 ); | |||
case ALIEN_BRAH: | |||
draw_alien_brah( g, al->x[i], al->y[i], al->img[i] % 8 ); | |||
break; | |||
case ALIEN_POOLP: | |||
draw_alien_poolp( g, al->x[i], al->y[i], al->img[i] % 2 ); | |||
break; | |||
case ALIEN_BOOL: | |||
draw_alien_bool( g, al->x[i], al->y[i], al->img[i] % 5 ); | |||
break; | |||
case ALIEN_NONE: | |||
break; | |||
} | |||
} | |||
} | |||
@@ -37,140 +46,183 @@ void update_aliens( game *g, aliens *al ) | |||
for( i = 0; i < ALIENS; i++ ) | |||
{ | |||
if( al->y[i] < 0 ) | |||
switch( al->type[i] ) | |||
{ | |||
//al->x[i] = g->w; | |||
} | |||
else | |||
{ | |||
al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3; | |||
al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7; | |||
al->img[i] = al->img[i] + rand() % 4; | |||
case ALIEN_POOLP: | |||
case ALIEN_BOOL: | |||
case ALIEN_BRAH: | |||
al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3; | |||
al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7; | |||
al->img[i] = al->img[i] + 1; | |||
/* Check collisions */ | |||
if( al->y[i] < 0 ) al->y[i] = 0; | |||
if( al->y[i] > g->w - 1 ) al->y[i] = g->w - 1; | |||
/* Check bounds */ | |||
if( al->y[i] < 0 ) al->y[i] = 0; | |||
if( al->y[i] > g->w - 1 ) al->y[i] = g->w - 1; | |||
break; | |||
case ALIEN_NONE: | |||
break; | |||
} | |||
} | |||
} | |||
void add_alien( game *g, aliens *al, int x, int y ) | |||
void add_alien( game *g, aliens *al, int x, int y, int type ) | |||
{ | |||
int i; | |||
for( i = 0; i < ALIENS; i++ ) | |||
{ | |||
if( al->y[i] < 0 ) | |||
if( al->type[i] == ALIEN_NONE ) | |||
{ | |||
al->type[i] = type; | |||
al->x[i] = x; | |||
al->y[i] = y; | |||
al->img[i] = 0; | |||
al->life[i] = 2; | |||
switch( al->type[i] ) | |||
{ | |||
case ALIEN_POOLP: | |||
al->life[i] = 2; | |||
break; | |||
case ALIEN_BOOL: | |||
al->life[i] = 2; | |||
break; | |||
case ALIEN_BRAH: | |||
al->life[i] = 2; | |||
break; | |||
case ALIEN_NONE: | |||
break; | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
static void draw_alien( game *g, int x, int y, int type ) | |||
static void draw_alien_poolp( game *g, int x, int y, int frame ) | |||
{ | |||
switch( type ) | |||
switch( frame ) | |||
{ | |||
case 0: | |||
GFX_COLOR( MAGENTA ); | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( ',' ); | |||
GFX_WRITE( '-' ); | |||
GFX_WRITE( '-' ); | |||
GFX_WRITE( '-' ); | |||
GFX_WRITE( '.' ); | |||
GFX_GOTO( x, y+1 ); | |||
GFX_WRITE( '\\' ); | |||
GFX_COLOR( WHITE ); | |||
GFX_WRITE( 'o' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( 'O' ); | |||
GFX_COLOR( MAGENTA ); | |||
GFX_WRITE( '/' ); | |||
GFX_GOTO( x, y+2 ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
gfx_color( MAGENTA ); | |||
gfx_goto( x, y ); | |||
gfx_putstr( ",---." ); | |||
gfx_goto( x, y+1 ); | |||
gfx_putchar( '\\' ); | |||
gfx_color( WHITE ); | |||
gfx_putstr( "o O" ); | |||
gfx_color( MAGENTA ); | |||
gfx_putchar( '/' ); | |||
gfx_goto( x, y+2 ); | |||
gfx_putstr( "^^^^^" ); | |||
break; | |||
case 1: | |||
gfx_color( MAGENTA ); | |||
gfx_goto( x, y ); | |||
gfx_putstr( ",---." ); | |||
gfx_goto( x, y+1 ); | |||
gfx_putchar( '\\' ); | |||
gfx_color( WHITE ); | |||
gfx_putstr( "O o" ); | |||
gfx_color( MAGENTA ); | |||
gfx_putchar( '/' ); | |||
gfx_goto( x, y+2 ); | |||
gfx_putstr( "^^^^^" ); | |||
break; | |||
} | |||
} | |||
static void draw_alien_bool( game *g, int x, int y, int frame ) | |||
{ | |||
gfx_color( GREEN ); | |||
gfx_goto( x+1, y ); | |||
gfx_putstr( ",---." ); | |||
gfx_goto( x, y+1 ); | |||
gfx_putchar( '(' ); | |||
gfx_color( WHITE ); | |||
switch( frame ) | |||
{ | |||
case 4: | |||
gfx_putstr( "##( )" ); | |||
break; | |||
case 3: | |||
gfx_putstr( ")##( " ); | |||
break; | |||
case 2: | |||
gfx_putstr( " )##(" ); | |||
break; | |||
case 1: | |||
GFX_COLOR( MAGENTA ); | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( ',' ); | |||
GFX_WRITE( '-' ); | |||
GFX_WRITE( '-' ); | |||
GFX_WRITE( '-' ); | |||
GFX_WRITE( '.' ); | |||
GFX_GOTO( x, y+1 ); | |||
GFX_WRITE( '\\' ); | |||
GFX_COLOR( WHITE ); | |||
GFX_WRITE( 'O' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( 'o' ); | |||
GFX_COLOR( MAGENTA ); | |||
GFX_WRITE( '/' ); | |||
GFX_GOTO( x, y+2 ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '^' ); | |||
gfx_putstr( "( )##" ); | |||
break; | |||
case 0: | |||
gfx_putstr( "#( )#" ); | |||
break; | |||
} | |||
gfx_color( GREEN ); | |||
gfx_goto( x+6, y+1 ); | |||
gfx_putchar( ')' ); | |||
gfx_goto( x+1, y+2 ); | |||
gfx_putstr( "`---'" ); | |||
} | |||
#if 0 | |||
void draw_rock( int x, int y, int type ) | |||
static void draw_alien_brah( game *g, int x, int y, int frame ) | |||
{ | |||
switch( type ) | |||
gfx_color( YELLOW ); | |||
switch( frame ) | |||
{ | |||
case 0: | |||
GFX_COLOR( RED ); | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_GOTO( x, y+1 ); | |||
GFX_WRITE( '>' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '/' ); | |||
GFX_GOTO( x, y+2 ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '>' ); | |||
gfx_goto( x, y ); | |||
gfx_putchar( '.' ); | |||
gfx_goto( x+6, y ); | |||
gfx_putchar( ',' ); | |||
gfx_goto( x+1, y+1 ); | |||
gfx_putstr( "\\ X /" ); | |||
break; | |||
case 7: | |||
case 1: | |||
GFX_COLOR( RED ); | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '>' ); | |||
GFX_GOTO( x, y+1 ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_GOTO( x, y+2 ); | |||
GFX_WRITE( '<' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( '/' ); | |||
gfx_goto( x-1, y ); | |||
gfx_putchar( '.' ); | |||
gfx_goto( x+7, y ); | |||
gfx_putchar( ',' ); | |||
gfx_goto( x, y+1 ); | |||
gfx_putstr( "`- X -'" ); | |||
break; | |||
case 6: | |||
case 2: | |||
gfx_goto( x-1, y+1 ); | |||
gfx_putstr( "`-- X --'" ); | |||
break; | |||
case 5: | |||
case 3: | |||
gfx_goto( x, y+1 ); | |||
gfx_putstr( ",- X -." ); | |||
gfx_goto( x-1, y+2 ); | |||
gfx_putchar( '\'' ); | |||
gfx_goto( x+7, y+2 ); | |||
gfx_putchar( '`' ); | |||
break; | |||
case 4: | |||
gfx_goto( x+1, y+1 ); | |||
gfx_putstr( ", X ." ); | |||
gfx_goto( x, y+2 ); | |||
gfx_putchar( '/' ); | |||
gfx_goto( x+6, y+2 ); | |||
gfx_putchar( '\\' ); | |||
break; | |||
} | |||
gfx_goto( x+2, y+2 ); | |||
gfx_putstr( "`V'" ); | |||
gfx_color( WHITE ); | |||
gfx_goto( x+2, y+1 ); | |||
gfx_putchar( 'o' ); | |||
gfx_goto( x+4, y+1 ); | |||
gfx_putchar( 'o' ); | |||
} | |||
#endif | |||
@@ -0,0 +1,102 @@ | |||
#include <stdlib.h> | |||
#include "common.h" | |||
void init_bonus( game *g, bonus *bo ) | |||
{ | |||
int i; | |||
for( i = 0; i < BONUS; i++ ) | |||
{ | |||
bo->type[i] = BONUS_NONE; | |||
} | |||
} | |||
void draw_bonus( game *g, bonus *bo ) | |||
{ | |||
int i; | |||
for( i = 0; i < BONUS; i++ ) | |||
{ | |||
switch( bo->type[i] ) | |||
{ | |||
case BONUS_GREEN: | |||
gfx_color( (bo->n[i]/2 % 3) ? GREEN : WHITE ); | |||
gfx_goto( bo->x[i]+1, bo->y[i]-1 ); | |||
gfx_putchar( '_' ); | |||
gfx_goto( bo->x[i], bo->y[i] ); | |||
gfx_putstr( "/ \\" ); | |||
gfx_goto( bo->x[i], bo->y[i]+1 ); | |||
gfx_putstr( "\\_/" ); | |||
gfx_color( WHITE ); | |||
gfx_goto( bo->x[i]+1, bo->y[i] ); | |||
gfx_putchar( 'g' ); | |||
break; | |||
case BONUS_LIFE: | |||
gfx_color( (bo->n[i] % 3) ? RED : WHITE ); | |||
gfx_goto( bo->x[i]+1, bo->y[i]-1 ); | |||
gfx_putchar( '_' ); | |||
gfx_goto( bo->x[i]+3, bo->y[i]-1 ); | |||
gfx_putchar( '_' ); | |||
gfx_goto( bo->x[i], bo->y[i] ); | |||
gfx_putstr( "( ' )" ); | |||
gfx_goto( bo->x[i]+1, bo->y[i]+1 ); | |||
gfx_putstr( "`v'" ); | |||
gfx_color( WHITE ); | |||
gfx_goto( bo->x[i]+3, bo->y[i] ); | |||
gfx_putchar( '^' ); | |||
break; | |||
case BONUS_NONE: | |||
break; | |||
} | |||
} | |||
} | |||
void update_bonus( game *g, bonus *bo ) | |||
{ | |||
int i; | |||
for( i = 0; i < BONUS; i++ ) | |||
{ | |||
switch( bo->type[i] ) | |||
{ | |||
case BONUS_GREEN: | |||
bo->n[i]++; | |||
bo->y[i]++; | |||
if( bo->y[i] > g->h ) | |||
{ | |||
bo->type[i] = BONUS_NONE; | |||
} | |||
break; | |||
case BONUS_LIFE: | |||
bo->n[i]++; | |||
bo->y[i]++; | |||
if( bo->y[i] > g->h ) | |||
{ | |||
bo->type[i] = BONUS_NONE; | |||
} | |||
break; | |||
case BONUS_NONE: | |||
break; | |||
} | |||
} | |||
} | |||
void add_bonus( game *g, bonus *bo, int x, int y, int type ) | |||
{ | |||
int i; | |||
for( i = 0; i < BONUS; i++ ) | |||
{ | |||
if( bo->type[i] == BONUS_NONE ) | |||
{ | |||
bo->type[i] = type; | |||
bo->x[i] = x; | |||
bo->y[i] = y; | |||
bo->n[i] = 0; | |||
break; | |||
} | |||
} | |||
} | |||
@@ -5,121 +5,184 @@ | |||
void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||
{ | |||
int i; | |||
int i, x, y; | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
if( wp->y[i] >= 0 ) | |||
{ | |||
if( wp->x[i] <= t->left[wp->y[i]+1] | |||
|| wp->x[i] >= t->right[wp->y[i]+1] ) | |||
{ | |||
add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 1, 0 ); | |||
x = wp->x[i] >> 4; | |||
y = wp->y[i] >> 4; | |||
if( wp->x[i] <= t->left[wp->y[i]+1] ) | |||
switch( wp->type[i] ) | |||
{ | |||
case WEAPON_NONE: | |||
break; | |||
case WEAPON_SEEKER: | |||
if( x <= t->left[y] | |||
|| x >= t->right[y] ) | |||
{ | |||
t->left[wp->y[i]]--; | |||
t->left[wp->y[i]+1]-=2; | |||
t->left[wp->y[i]+2]--; | |||
add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); | |||
if( x <= t->left[y] ) | |||
{ | |||
t->left[y-1]--; | |||
t->left[y]-=2; | |||
t->left[y+1]--; | |||
} | |||
else | |||
{ | |||
t->right[y-1]++; | |||
t->right[y]+=2; | |||
t->right[y+1]++; | |||
} | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
else | |||
break; | |||
case WEAPON_LASER: | |||
if( x <= t->left[y+1] | |||
|| x >= t->right[y+1] ) | |||
{ | |||
t->right[wp->y[i]]++; | |||
t->right[wp->y[i]+1]+=2; | |||
t->right[wp->y[i]+2]++; | |||
} | |||
add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL ); | |||
wp->y[i] = -1; | |||
} | |||
else if( wp->x[i] <= t->left[wp->y[i]] | |||
|| wp->x[i] >= t->right[wp->y[i]] ) | |||
{ | |||
add_explosion( g, ex, wp->x[i], wp->y[i], 0, 1, 0 ); | |||
if( x <= t->left[y+1] ) | |||
{ | |||
t->left[y]--; | |||
t->left[y+1]-=2; | |||
t->left[y+2]--; | |||
} | |||
else | |||
{ | |||
t->right[y]++; | |||
t->right[y+1]+=2; | |||
t->right[y+2]++; | |||
} | |||
if( wp->x[i] <= t->left[wp->y[i]] ) | |||
{ | |||
t->left[wp->y[i]-1]--; | |||
t->left[wp->y[i]]-=2; | |||
t->left[wp->y[i]+1]--; | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
else | |||
else if( x <= t->left[y] | |||
|| x >= t->right[y] ) | |||
{ | |||
t->right[wp->y[i]-1]++; | |||
t->right[wp->y[i]]+=2; | |||
t->right[wp->y[i]+1]++; | |||
} | |||
add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); | |||
wp->y[i] = -1; | |||
} | |||
if( x <= t->left[y] ) | |||
{ | |||
t->left[y-1]--; | |||
t->left[y]-=2; | |||
t->left[y+1]--; | |||
} | |||
else | |||
{ | |||
t->right[y-1]++; | |||
t->right[y]+=2; | |||
t->right[y+1]++; | |||
} | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
break; | |||
case WEAPON_NUKE: | |||
/* The nuke does not break the tunnel */ | |||
break; | |||
} | |||
} | |||
} | |||
void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) | |||
{ | |||
int i, j; | |||
int i, j, x, y; | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
if( wp->y[i] >= 0 ) | |||
{ | |||
int ok = 0; | |||
int r; | |||
int ok = 0; | |||
int r; | |||
x = wp->x[i] >> 4; | |||
y = wp->y[i] >> 4; | |||
switch( wp->type[i] ) | |||
{ | |||
case 2: | |||
switch( wp->type[i] ) | |||
{ | |||
case WEAPON_NONE: | |||
break; | |||
case WEAPON_NUKE: | |||
/* Big nuke */ | |||
r = (34 - wp->n[i]) * (34 - wp->n[i]) / 10; | |||
r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; | |||
for( j = 0; j < ALIENS; j++ ) | |||
{ | |||
if( al->x[j] < 0 ) | |||
if( al->type[j] == ALIEN_NONE ) | |||
{ | |||
continue; | |||
} | |||
if( (al->x[j] - wp->x[i]) * (al->x[j] - wp->x[i]) | |||
+ 4 * (al->y[j] - wp->y[i]) * (al->y[j] - wp->y[i]) | |||
if( wp->n[i] == 0 /* Nuke destroys _everything_ */ || | |||
(al->x[j] - x) * (al->x[j] - x) | |||
+ 4 * (al->y[j] - y) * (al->y[j] - y) | |||
<= r * r ) | |||
{ | |||
/* Kill alien, not nuke */ | |||
add_explosion( g, ex, al->x[j], al->y[j], 0, 0, 1 ); | |||
al->x[j] = -1; | |||
al->y[j] = -1; | |||
al->type[j] = ALIEN_NONE; | |||
add_explosion( g, ex, al->x[j], al->y[j], 0, 0, EXPLOSION_MEDIUM ); | |||
add_bonus( g, g->bo, al->x[j], al->y[j], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); | |||
} | |||
} | |||
break; | |||
case 1: | |||
default: | |||
case WEAPON_LASER: | |||
for( j = 0; j < ALIENS; j++ ) | |||
{ | |||
if( wp->x[i] >= al->x[j] | |||
&& wp->x[i] <= al->x[j] + 4 | |||
&& wp->y[i] >= al->y[j] | |||
&& wp->y[i] <= al->y[j] + 2 ) | |||
if( al->type[j] == ALIEN_NONE ) | |||
{ | |||
continue; | |||
} | |||
if( x >= al->x[j] && x <= al->x[j] + 4 | |||
&& y >= al->y[j] && y <= al->y[j] + 2 ) | |||
{ | |||
al->life[j]--; | |||
if( al->life[j] <= 0 ) | |||
{ | |||
al->type[j] = ALIEN_NONE; | |||
add_explosion( g, ex, x, y, 0, 0, EXPLOSION_MEDIUM ); | |||
add_bonus( g, g->bo, x, y, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); | |||
} | |||
ok = 1; | |||
} | |||
else if( x >= al->x[j] && x <= al->x[j] + 4 | |||
&& y+1 >= al->y[j] && y+1 <= al->y[j] + 2 ) | |||
{ | |||
al->life[j]--; | |||
if( al->life[j] == 0 ) | |||
if( al->life[j] <= 0 ) | |||
{ | |||
al->x[j] = -1; | |||
al->y[j] = -1; | |||
add_explosion( g, ex, wp->x[i], wp->y[i], 0, 0, 1 ); | |||
al->type[j] = ALIEN_NONE; | |||
add_explosion( g, ex, x, y+1, 0, 0, EXPLOSION_MEDIUM ); | |||
add_bonus( g, g->bo, x, y+1, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); | |||
} | |||
ok = 1; | |||
} | |||
else if( wp->x[i] >= al->x[j] | |||
&& wp->x[i] <= al->x[j] + 4 | |||
&& wp->y[i]+1 >= al->y[j] | |||
&& wp->y[i]+1 <= al->y[j] + 2 ) | |||
} | |||
if( ok ) | |||
{ | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
break; | |||
case WEAPON_SEEKER: | |||
for( j = 0; j < ALIENS; j++ ) | |||
{ | |||
if( al->type[j] == ALIEN_NONE ) | |||
{ | |||
continue; | |||
} | |||
if( x >= al->x[j] && x <= al->x[j] + 4 | |||
&& y >= al->y[j] && y <= al->y[j] + 2 ) | |||
{ | |||
al->life[j]--; | |||
if( al->life[j] == 0 ) | |||
if( al->life[j] <= 0 ) | |||
{ | |||
al->x[j] = -1; | |||
al->y[j] = -1; | |||
add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 0, 1 ); | |||
al->type[j] = ALIEN_NONE; | |||
add_explosion( g, ex, x, y, 0, 0, EXPLOSION_MEDIUM ); | |||
add_bonus( g, g->bo, x, y, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); | |||
} | |||
ok = 1; | |||
} | |||
@@ -127,10 +190,9 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) | |||
if( ok ) | |||
{ | |||
wp->y[i] = -1; | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
@@ -139,13 +201,13 @@ void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ) | |||
{ | |||
if( p->x <= t->left[p->y] ) | |||
{ | |||
p->x += 3; | |||
//add_explosion( g, ex, x+1, y-2, 0, 1, 0 ); | |||
p->x += 2; | |||
add_explosion( g, ex, p->x+1, p->y-2, 0, 0, EXPLOSION_SMALL ); | |||
} | |||
else if( p->x + 5 >= t->right[p->y] ) | |||
{ | |||
p->x -= 3; | |||
//add_explosion( g, ex, x+4, y-2, 0, 1, 0 ); | |||
p->x -= 2; | |||
add_explosion( g, ex, p->x+4, p->y-2, 0, 0, EXPLOSION_SMALL ); | |||
} | |||
} | |||
@@ -1,32 +1,28 @@ | |||
#define STARS 50 | |||
#define WEAPONS 50 | |||
#define ROCKS 10 | |||
#define ALIENS 10 | |||
#define BONUS 30 | |||
#define ALIENS 30 | |||
#define EXPLOSIONS 20 | |||
#ifdef USE_SLANG | |||
# include <slang.h> | |||
# define GFX_COLOR(x) SLsmg_set_color(x) | |||
# define GFX_GOTO(x,y) SLsmg_gotorc(y,x) | |||
# define GFX_WRITE(x) SLsmg_write_char(x) | |||
# define gfx_color(x) SLsmg_set_color(x) | |||
# define gfx_goto(x,y) SLsmg_gotorc(y,x) | |||
# define gfx_putchar(x) SLsmg_write_char(x) | |||
# define gfx_putstr(x) SLsmg_write_string(x) | |||
#else | |||
# include <curses.h> | |||
# define GFX_COLOR(x) attrset(COLOR_PAIR(x)) | |||
# define GFX_GOTO(x,y) move(y,x) | |||
# define GFX_WRITE(x) addch(x) | |||
# define gfx_color(x) attrset(COLOR_PAIR(x)) | |||
# define gfx_goto(x,y) move(y,x) | |||
# define gfx_putchar(x) addch(x) | |||
# define gfx_putstr(x) addstr(x) | |||
#endif | |||
#define GFX_WRITETO(x,y,c) do{ GFX_GOTO(x,y); GFX_WRITE(c); }while(0) | |||
#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) | |||
#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) | |||
typedef struct | |||
{ | |||
int w, h; | |||
} game; | |||
typedef struct | |||
{ | |||
int w, h, *left, *right; | |||
@@ -45,25 +41,39 @@ typedef struct | |||
typedef struct | |||
{ | |||
enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS]; | |||
int x[EXPLOSIONS]; | |||
int y[EXPLOSIONS]; | |||
int vx[EXPLOSIONS]; | |||
int vy[EXPLOSIONS]; | |||
int type[EXPLOSIONS]; | |||
int n[EXPLOSIONS]; | |||
} explosions; | |||
typedef struct | |||
{ | |||
enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE } type[WEAPONS]; | |||
int x[WEAPONS]; | |||
int y[WEAPONS]; | |||
int v[WEAPONS]; | |||
int x2[WEAPONS]; | |||
int y2[WEAPONS]; | |||
int x3[WEAPONS]; | |||
int y3[WEAPONS]; | |||
int vx[WEAPONS]; | |||
int vy[WEAPONS]; | |||
int n[WEAPONS]; | |||
int type[WEAPONS]; | |||
} weapons; | |||
typedef struct | |||
{ | |||
enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS]; | |||
int x[BONUS]; | |||
int y[BONUS]; | |||
int n[BONUS]; | |||
} bonus; | |||
typedef struct | |||
{ | |||
int x, y; | |||
@@ -74,6 +84,7 @@ typedef struct | |||
typedef struct | |||
{ | |||
enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS]; | |||
int x[ALIENS]; | |||
int y[ALIENS]; | |||
int life[ALIENS]; | |||
@@ -81,6 +92,20 @@ typedef struct | |||
} aliens; | |||
typedef struct | |||
{ | |||
int w, h; | |||
starfield *sf; | |||
weapons *wp; | |||
explosions *ex; | |||
tunnel *t; | |||
player *p; | |||
aliens *al; | |||
bonus *bo; | |||
} game; | |||
#define BLACK 1 | |||
#define GREEN 2 | |||
#define YELLOW 3 | |||
@@ -99,7 +124,7 @@ void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ); | |||
void init_aliens( game *g, aliens *al ); | |||
void draw_aliens( game *g, aliens *al ); | |||
void update_aliens( game *g, aliens *al ); | |||
void add_alien( game *g, aliens *al, int x, int y ); | |||
void add_alien( game *g, aliens *al, int x, int y, int type ); | |||
int init_graphics( void ); | |||
void init_game( game *g ); | |||
@@ -116,7 +141,12 @@ void update_player( game *g, player *p ); | |||
void init_weapons( game *g, weapons *wp ); | |||
void draw_weapons( game *g, weapons *wp ); | |||
void update_weapons( game *g, weapons *wp ); | |||
void add_weapon( game *g, weapons *wp, int x, int y, int type ); | |||
void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ); | |||
void init_bonus( game *g, bonus *bo ); | |||
void draw_bonus( game *g, bonus *bo ); | |||
void update_bonus( game *g, bonus *bo ); | |||
void add_bonus( game *g, bonus *bo, int x, int y, int type ); | |||
void init_starfield( game *g, starfield *s ); | |||
void draw_starfield( game *g, starfield *s ); | |||
@@ -4,7 +4,7 @@ | |||
#include "common.h" | |||
static void draw_small_explosion( int x, int y, int frame ); | |||
static void draw_big_explosion( int x, int y, int frame ); | |||
static void draw_medium_explosion( int x, int y, int frame ); | |||
void init_explosions( game *g, explosions *ex ) | |||
{ | |||
@@ -12,12 +12,7 @@ void init_explosions( game *g, explosions *ex ) | |||
for( i = 0; i < EXPLOSIONS; i++ ) | |||
{ | |||
ex->n[i] = 0; | |||
ex->x[i] = -1; | |||
ex->y[i] = -1; | |||
ex->vx[i] = -1; | |||
ex->vy[i] = -1; | |||
ex->type[i] = 0; | |||
ex->type[i] = EXPLOSION_NONE; | |||
} | |||
} | |||
@@ -27,19 +22,22 @@ void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int t | |||
for( i = 0; i < EXPLOSIONS; i++ ) | |||
{ | |||
if( ex->n[i] <= 0 ) | |||
if( ex->type[i] == EXPLOSION_NONE ) | |||
{ | |||
ex->type[i] = type; | |||
ex->x[i] = x; | |||
ex->y[i] = y; | |||
ex->vx[i] = vx; | |||
ex->vy[i] = vy; | |||
switch( type ) | |||
{ | |||
case 1: ex->n[i] = 13; break; | |||
case 2: ex->n[i] = 30; break; | |||
case 0: default: ex->n[i] = 7; break; | |||
case EXPLOSION_MEDIUM: | |||
ex->n[i] = 11; | |||
break; | |||
case EXPLOSION_SMALL: | |||
ex->n[i] = 7; | |||
break; | |||
} | |||
ex->type[i] = type; | |||
break; | |||
} | |||
} | |||
@@ -51,47 +49,42 @@ void draw_explosions( game *g, explosions *ex ) | |||
for( i = 0; i < EXPLOSIONS; i++ ) | |||
{ | |||
if( ex->n[i] <= 0 ) | |||
{ | |||
continue; | |||
} | |||
#if 0 | |||
GFX_COLOR( GREEN ); | |||
GFX_GOTO( ex->x[i] + 3, ex->y[i] ); | |||
gfx_color( GREEN ); | |||
gfx_goto( ex->x[i] + 3, ex->y[i] ); | |||
switch( GET_RAND(0,3) ) | |||
{ | |||
case 0: | |||
GFX_WRITE( 'p' ); | |||
GFX_WRITE( 'i' ); | |||
GFX_WRITE( 'f' ); | |||
gfx_putchar( 'p' ); | |||
gfx_putchar( 'i' ); | |||
gfx_putchar( 'f' ); | |||
break; | |||
case 1: | |||
GFX_WRITE( 'p' ); | |||
GFX_WRITE( 'a' ); | |||
GFX_WRITE( 'f' ); | |||
gfx_putchar( 'p' ); | |||
gfx_putchar( 'a' ); | |||
gfx_putchar( 'f' ); | |||
break; | |||
case 2: | |||
GFX_WRITE( 'p' ); | |||
GFX_WRITE( 'o' ); | |||
GFX_WRITE( 'u' ); | |||
GFX_WRITE( 'f' ); | |||
gfx_putchar( 'p' ); | |||
gfx_putchar( 'o' ); | |||
gfx_putchar( 'u' ); | |||
gfx_putchar( 'f' ); | |||
break; | |||
} | |||
GFX_WRITE( '!' ); | |||
gfx_putchar( '!' ); | |||
#endif | |||
switch( ex->type[i] ) | |||
{ | |||
case 1: | |||
draw_big_explosion( ex->x[i], ex->y[i], ex->n[i] ); | |||
case EXPLOSION_MEDIUM: | |||
draw_medium_explosion( ex->x[i], ex->y[i], ex->n[i] ); | |||
break; | |||
case 0: | |||
default: | |||
case EXPLOSION_SMALL: | |||
draw_small_explosion( ex->x[i], ex->y[i], ex->n[i] ); | |||
break; | |||
case EXPLOSION_NONE: | |||
break; | |||
} | |||
} | |||
} | |||
@@ -101,11 +94,20 @@ void update_explosions( game *g, explosions *ex ) | |||
for( i = 0; i < EXPLOSIONS; i++ ) | |||
{ | |||
if( ex->n[i] > 0 ) | |||
switch( ex->type[i] ) | |||
{ | |||
ex->x[i] += ex->vx[i]; | |||
ex->y[i] += ex->vy[i]; | |||
ex->n[i]--; | |||
case EXPLOSION_MEDIUM: | |||
case EXPLOSION_SMALL: | |||
ex->x[i] += ex->vx[i]; | |||
ex->y[i] += ex->vy[i]; | |||
ex->n[i]--; | |||
if( ex->n[i] < 0 ) | |||
{ | |||
ex->type[i] = EXPLOSION_NONE; | |||
} | |||
break; | |||
case EXPLOSION_NONE: | |||
break; | |||
} | |||
} | |||
} | |||
@@ -114,191 +116,117 @@ static void draw_small_explosion( int x, int y, int frame ) | |||
{ | |||
switch( frame ) | |||
{ | |||
default: | |||
case 6: | |||
GFX_COLOR( YELLOW ); | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( '+' ); | |||
gfx_color( YELLOW ); | |||
gfx_goto( x, y ); | |||
gfx_putchar( '+' ); | |||
break; | |||
case 5: | |||
GFX_COLOR( YELLOW ); | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( 'o' ); | |||
gfx_color( YELLOW ); | |||
gfx_goto( x, y ); | |||
gfx_putchar( 'o' ); | |||
break; | |||
case 4: | |||
GFX_COLOR( YELLOW ); | |||
GFX_GOTO( x, y-1 ); | |||
GFX_WRITE( '_' ); | |||
GFX_GOTO( x-1, y ); | |||
GFX_WRITE( ')' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '(' ); | |||
gfx_color( YELLOW ); | |||
gfx_goto( x, y-1 ); | |||
gfx_putchar( '_' ); | |||
gfx_goto( x-1, y ); | |||
gfx_putstr( ")_(" ); | |||
break; | |||
case 3: | |||
GFX_COLOR( YELLOW ); | |||
GFX_GOTO( x-1, y-1 ); | |||
GFX_WRITE( '.' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( ',' ); | |||
GFX_GOTO( x-1, y ); | |||
GFX_WRITE( ')' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '(' ); | |||
GFX_GOTO( x-1, y+1 ); | |||
GFX_WRITE( '\'' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '`' ); | |||
gfx_color( YELLOW ); | |||
gfx_goto( x-1, y-1 ); | |||
gfx_putstr( "._," ); | |||
gfx_goto( x-1, y ); | |||
gfx_putstr( ")_(" ); | |||
gfx_goto( x-1, y+1 ); | |||
gfx_putstr( "\' `" ); | |||
break; | |||
case 2: | |||
GFX_COLOR( YELLOW ); | |||
GFX_GOTO( x-1, y-1 ); | |||
GFX_WRITE( '.' ); | |||
GFX_WRITE( 'v' ); | |||
GFX_WRITE( ',' ); | |||
GFX_GOTO( x-1, y ); | |||
GFX_WRITE( '>' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '<' ); | |||
GFX_GOTO( x-1, y+1 ); | |||
GFX_WRITE( '\'' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '`' ); | |||
gfx_color( YELLOW ); | |||
gfx_goto( x-1, y-1 ); | |||
gfx_putstr( ".v," ); | |||
gfx_goto( x-1, y ); | |||
gfx_putstr( "> <" ); | |||
gfx_goto( x-1, y+1 ); | |||
gfx_putstr( "\'^`" ); | |||
break; | |||
case 1: | |||
GFX_COLOR( WHITE ); | |||
GFX_GOTO( x-1, y-1 ); | |||
GFX_WRITE( '.' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ',' ); | |||
GFX_GOTO( x-1, y ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_GOTO( x-1, y+1 ); | |||
GFX_WRITE( '\'' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '`' ); | |||
gfx_color( WHITE ); | |||
gfx_goto( x-1, y-1 ); | |||
gfx_putstr( ". ," ); | |||
gfx_goto( x-1, y ); | |||
gfx_putstr( " " ); | |||
gfx_goto( x-1, y+1 ); | |||
gfx_putstr( "\' `" ); | |||
break; | |||
} | |||
} | |||
static void draw_big_explosion( int x, int y, int frame ) | |||
static void draw_medium_explosion( int x, int y, int frame ) | |||
{ | |||
GFX_COLOR( YELLOW ); | |||
gfx_color( YELLOW ); | |||
switch( frame ) | |||
{ | |||
default: | |||
case 12: | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( '+' ); | |||
break; | |||
case 11: | |||
GFX_GOTO( x, y ); | |||
GFX_WRITE( 'o' ); | |||
break; | |||
case 10: | |||
GFX_GOTO( x, y-1 ); | |||
GFX_WRITE( '_' ); | |||
GFX_GOTO( x-1, y ); | |||
GFX_WRITE( ')' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '(' ); | |||
gfx_goto( x, y ); | |||
gfx_putchar( '+' ); | |||
break; | |||
case 9: | |||
GFX_GOTO( x-1, y-1 ); | |||
GFX_WRITE( '.' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( ',' ); | |||
GFX_GOTO( x-1, y ); | |||
GFX_WRITE( ')' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '(' ); | |||
GFX_GOTO( x-1, y+1 ); | |||
GFX_WRITE( '\'' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '`' ); | |||
gfx_goto( x, y ); | |||
gfx_putchar( 'o' ); | |||
break; | |||
case 8: | |||
GFX_GOTO( x-1, y-1 ); | |||
GFX_WRITE( '.' ); | |||
GFX_WRITE( 'v' ); | |||
GFX_WRITE( ',' ); | |||
GFX_GOTO( x-1, y ); | |||
GFX_WRITE( '>' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '<' ); | |||
GFX_GOTO( x-1, y+1 ); | |||
GFX_WRITE( '\'' ); | |||
GFX_WRITE( '^' ); | |||
GFX_WRITE( '`' ); | |||
gfx_goto( x, y-1 ); | |||
gfx_putchar( '_' ); | |||
gfx_goto( x-1, y ); | |||
gfx_putstr( ")_(" ); | |||
break; | |||
case 6: | |||
GFX_COLOR( RED ); | |||
case 7: | |||
gfx_goto( x-1, y-1 ); | |||
gfx_putstr( "._," ); | |||
gfx_goto( x-1, y ); | |||
gfx_putstr( ")_(" ); | |||
gfx_goto( x-1, y+1 ); | |||
gfx_putstr( "\' `" ); | |||
break; | |||
case 6: | |||
gfx_goto( x-1, y-1 ); | |||
gfx_putstr( ".v," ); | |||
gfx_goto( x-1, y ); | |||
gfx_putstr( "> <" ); | |||
gfx_goto( x-1, y+1 ); | |||
gfx_putstr( "\'^`" ); | |||
break; | |||
case 5: | |||
GFX_GOTO( x-2, y-1 ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( '~' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '_' ); | |||
GFX_GOTO( x-2, y ); | |||
GFX_WRITE( '>' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '<' ); | |||
GFX_GOTO( x-2, y+1 ); | |||
GFX_WRITE( '~' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( '~' ); | |||
gfx_color( RED ); | |||
case 4: | |||
gfx_goto( x-2, y-1 ); | |||
gfx_putstr( "_\\~/_" ); | |||
gfx_goto( x-2, y ); | |||
gfx_putstr( "> <" ); | |||
gfx_goto( x-2, y+1 ); | |||
gfx_putstr( "~/_\\~" ); | |||
break; | |||
case 3: | |||
GFX_COLOR( RED ); | |||
case 4: | |||
gfx_color( RED ); | |||
case 2: | |||
GFX_GOTO( x-2, y-1 ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '_' ); | |||
GFX_GOTO( x-2, y ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '_' ); | |||
GFX_GOTO( x-2, y+1 ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_WRITE( ' ' ); | |||
gfx_goto( x-2, y-1 ); | |||
gfx_putstr( "_\\ /_" ); | |||
gfx_goto( x-2, y ); | |||
gfx_putstr( "_ _" ); | |||
gfx_goto( x-2, y+1 ); | |||
gfx_putstr( " / \\ " ); | |||
break; | |||
case 1: | |||
GFX_COLOR( WHITE ); | |||
GFX_GOTO( x-2, y-1 ); | |||
GFX_WRITE( '.' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '\'' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ',' ); | |||
GFX_GOTO( x-2, y ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_GOTO( x-2, y+1 ); | |||
GFX_WRITE( '\'' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '.' ); | |||
GFX_WRITE( ' ' ); | |||
GFX_WRITE( '`' ); | |||
gfx_color( WHITE ); | |||
gfx_goto( x-2, y-1 ); | |||
gfx_putstr( ". \' ," ); | |||
gfx_goto( x-2, y ); | |||
gfx_putstr( " " ); | |||
gfx_goto( x-2, y+1 ); | |||
gfx_putstr( "\' . `" ); | |||
break; | |||
} | |||
} | |||
@@ -108,7 +108,7 @@ void clear_graphics( void ) | |||
void refresh_graphics( void ) | |||
{ | |||
GFX_GOTO( 0, 0 ); | |||
gfx_goto( 0, 0 ); | |||
#ifdef USE_SLANG | |||
SLsmg_refresh(); | |||
#else | |||
@@ -32,7 +32,7 @@ int main (int argc, char **argv) | |||
{ | |||
game *g = malloc(sizeof(game)); | |||
// srand(time(NULL)); | |||
//srand(time(NULL)); | |||
if( init_graphics() ) | |||
{ | |||
@@ -57,25 +57,28 @@ static void start_game (game *g) | |||
int quit = 0; | |||
int poz = 0; | |||
int skip = 0; | |||
int purcompteur = 0; | |||
starfield *sf = malloc(sizeof(starfield)); | |||
weapons *wp = malloc(sizeof(weapons)); | |||
explosions *ex = malloc(sizeof(explosions)); | |||
tunnel *t = create_tunnel( g, g->w, g->h ); | |||
player *p = create_player( g ); | |||
aliens *al = malloc(sizeof(aliens)); | |||
g->sf = malloc(sizeof(starfield)); | |||
g->wp = malloc(sizeof(weapons)); | |||
g->ex = malloc(sizeof(explosions)); | |||
g->bo = malloc(sizeof(bonus)); | |||
g->t = create_tunnel( g, g->w, g->h ); | |||
g->p = create_player( g ); | |||
g->al = malloc(sizeof(aliens)); | |||
init_starfield( g, sf ); | |||
init_weapons( g, wp ); | |||
init_explosions( g, ex ); | |||
init_aliens( g, al ); | |||
init_starfield( g, g->sf ); | |||
init_weapons( g, g->wp ); | |||
init_explosions( g, g->ex ); | |||
init_aliens( g, g->al ); | |||
/* Temporary stuff */ | |||
for( i = 0; i < 5; i++ ) | |||
{ | |||
add_alien( g, al, rand() % g->w, rand() % g->h / 2 ); | |||
add_alien( g, g->al, rand() % g->w, rand() % g->h / 2, ALIEN_POOLP ); | |||
} | |||
t->w = 25; | |||
g->t->w = 25; | |||
while( !quit ) | |||
{ | |||
@@ -95,30 +98,37 @@ static void start_game (game *g) | |||
skip = 1; | |||
break; | |||
case 'h': | |||
p->dir = -3; | |||
g->p->dir = -3; | |||
break; | |||
case 'j': | |||
if( p->y < g->h - 2 ) p->y += 1; | |||
if( g->p->y < g->h - 2 ) g->p->y += 1; | |||
break; | |||
case 'k': | |||
if( p->y > 1 ) p->y -= 1; | |||
if( g->p->y > 1 ) g->p->y -= 1; | |||
break; | |||
case 'l': | |||
p->dir = 3; | |||
g->p->dir = 3; | |||
break; | |||
case '\r': | |||
if( p->nuke == 0 ) | |||
if( g->p->nuke == 0 ) | |||
{ | |||
p->nuke = 40; | |||
add_weapon( g, wp, p->x + 2, p->y, 2 ); | |||
g->p->nuke = 40; | |||
add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE ); | |||
} | |||
break; | |||
case 'b': | |||
if( g->p->weapon == 0 ) | |||
{ | |||
g->p->weapon = 4; | |||
add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -24, -16, WEAPON_SEEKER ); | |||
add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 24, -16, WEAPON_SEEKER ); | |||
} | |||
case ' ': | |||
if( p->weapon == 0 ) | |||
if( g->p->weapon == 0 ) | |||
{ | |||
p->weapon = 4; | |||
add_weapon( g, wp, p->x, p->y, 1 ); | |||
add_weapon( g, wp, p->x + 5, p->y, 1 ); | |||
g->p->weapon = 4; | |||
add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, 0, -16, WEAPON_LASER ); | |||
add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 0, -16, WEAPON_LASER ); | |||
} | |||
break; | |||
} | |||
@@ -128,7 +138,9 @@ static void start_game (game *g) | |||
if( GET_RAND(0,10) == 0 ) | |||
{ | |||
add_alien( g, al, 0, rand() % g->h / 2 ); | |||
int list[3] = { ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH }; | |||
add_alien( g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)] ); | |||
} | |||
if( poz ) | |||
@@ -143,41 +155,51 @@ static void start_game (game *g) | |||
} | |||
} | |||
/* Update game rules */ | |||
if( g->t->right[1] - g->t->left[1] == g->t->w ) | |||
{ | |||
g->t->w = 85 - g->t->w; | |||
} | |||
/* Scroll and update positions */ | |||
collide_player_tunnel( g, p, t, ex ); | |||
update_player( g, p ); | |||
collide_player_tunnel( g, p, t, ex ); | |||
collide_player_tunnel( g, g->p, g->t, g->ex ); | |||
update_player( g, g->p ); | |||
collide_player_tunnel( g, g->p, g->t, g->ex ); | |||
update_starfield( g, sf ); | |||
update_aliens( g, al ); | |||
update_starfield( g, g->sf ); | |||
update_bonus( g, g->bo ); | |||
update_aliens( g, g->al ); | |||
collide_weapons_tunnel( g, wp, t, ex ); | |||
collide_weapons_aliens( g, wp, al, ex ); | |||
update_weapons( g, wp ); | |||
collide_weapons_tunnel( g, wp, t, ex ); | |||
collide_weapons_aliens( g, wp, al, ex ); | |||
collide_weapons_tunnel( g, g->wp, g->t, g->ex ); | |||
collide_weapons_aliens( g, g->wp, g->al, g->ex ); | |||
update_weapons( g, g->wp ); | |||
collide_weapons_tunnel( g, g->wp, g->t, g->ex ); | |||
collide_weapons_aliens( g, g->wp, g->al, g->ex ); | |||
update_explosions( g, ex ); | |||
update_tunnel( g, t ); | |||
update_explosions( g, g->ex ); | |||
/*if(purcompteur%2)*/ update_tunnel( g, g->t ); | |||
/* Clear screen */ | |||
clear_graphics(); | |||
/* Print starfield, tunnel, aliens, player and explosions */ | |||
draw_starfield( g, sf ); | |||
draw_tunnel( g, t ); | |||
draw_aliens( g, al ); | |||
draw_player( g, p ); | |||
draw_weapons( g, wp ); | |||
draw_explosions( g, ex ); | |||
draw_starfield( g, g->sf ); | |||
draw_tunnel( g, g->t ); | |||
draw_bonus( g, g->bo ); | |||
draw_aliens( g, g->al ); | |||
draw_player( g, g->p ); | |||
draw_weapons( g, g->wp ); | |||
draw_explosions( g, g->ex ); | |||
/* Refresh */ | |||
refresh_graphics(); | |||
purcompteur++; | |||
} | |||
#if 0 | |||
free_player( p ); | |||
free_tunnel( t ); | |||
free_tunnel( g->t ); | |||
#endif | |||
} | |||
@@ -9,7 +9,7 @@ player * create_player( game *g ) | |||
player *p = malloc(sizeof(player)); | |||
p->x = g->w / 2; | |||
p->y = g->h - 3; | |||
p->y = g->h - 2; | |||
p->dir = 0; | |||
p->weapon = 0; | |||
p->nuke = 0; | |||
@@ -24,25 +24,18 @@ void free_player( player *p ) | |||
void draw_player( game *g, player *p ) | |||
{ | |||
GFX_GOTO( p->x + 2, p->y - 2 ); | |||
GFX_COLOR( GREEN ); | |||
GFX_WRITE( '/' ); | |||
GFX_WRITE( '\\' ); | |||
GFX_GOTO( p->x + 1, p->y - 1 ); | |||
GFX_WRITE( '(' ); | |||
GFX_COLOR( YELLOW ); | |||
GFX_WRITE( '(' ); | |||
GFX_WRITE( ')' ); | |||
GFX_COLOR( GREEN ); | |||
GFX_WRITE( ')' ); | |||
GFX_GOTO( p->x, p->y ); | |||
GFX_COLOR( GREEN ); | |||
GFX_WRITE( 'I' ); | |||
GFX_WRITE( '<' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '_' ); | |||
GFX_WRITE( '>' ); | |||
GFX_WRITE( 'I' ); | |||
gfx_goto( p->x + 2, p->y - 2 ); | |||
gfx_color( GREEN ); | |||
gfx_putstr( "/\\" ); | |||
gfx_goto( p->x + 1, p->y - 1 ); | |||
gfx_putchar( '(' ); | |||
gfx_color( YELLOW ); | |||
gfx_putstr( "()" ); | |||
gfx_color( GREEN ); | |||
gfx_putchar( ')' ); | |||
gfx_goto( p->x, p->y ); | |||
gfx_color( GREEN ); | |||
gfx_putstr( "I<__>I" ); | |||
} | |||
void update_player( game *g, player *p ) | |||
@@ -25,9 +25,9 @@ void draw_starfield( game *g, starfield *s ) | |||
{ | |||
if( s->x[i] >= 0 ) | |||
{ | |||
GFX_COLOR( s->c[i] ); | |||
GFX_GOTO( s->x[i], s->y[i] ); | |||
GFX_WRITE( s->ch[i] ); | |||
gfx_color( s->c[i] ); | |||
gfx_goto( s->x[i], s->y[i] ); | |||
gfx_putchar( s->ch[i] ); | |||
} | |||
} | |||
} | |||
@@ -134,9 +134,11 @@ static void draw_wall( game *g, int *wall ) | |||
{ | |||
int i; | |||
gfx_color( RED ); | |||
for( i = 0; i < g->h ; i++ ) | |||
{ | |||
char c; | |||
char *str; | |||
if( wall[i] < 0 || wall[i] >= g->w ) | |||
{ | |||
@@ -145,27 +147,22 @@ static void draw_wall( game *g, int *wall ) | |||
if( wall[i] > wall[i+1] ) | |||
{ | |||
c = wall[i] > wall[i-1] ? '>' : '/'; | |||
str = wall[i] > wall[i-1] ? ">##>" : "/##/"; | |||
} | |||
else | |||
{ | |||
c = wall[i] > wall[i-1] ? '\\' : '<'; | |||
str = wall[i] > wall[i-1] ? "\\##\\" : "<##<"; | |||
} | |||
GFX_COLOR( RED ); | |||
if( wall[i] == wall[i+1] + 2 ) | |||
{ | |||
GFX_GOTO( wall[i] - 1, i ); | |||
GFX_WRITE( '_' ); | |||
gfx_goto( wall[i] - 1, i ); | |||
gfx_putchar( '_' ); | |||
} | |||
else | |||
{ | |||
GFX_GOTO( wall[i], i ); | |||
} | |||
GFX_WRITE( c ); | |||
GFX_WRITE( '#' ); | |||
GFX_WRITE( c ); | |||
if( wall[i] == wall[i+1] - 2 ) GFX_WRITE( '_' ); | |||
gfx_goto( wall[i], i ); | |||
gfx_putstr( str ); | |||
if( wall[i] == wall[i+1] - 2 ) gfx_putchar( '_' ); | |||
} | |||
} | |||
@@ -1,10 +1,11 @@ | |||
#include <stdlib.h> | |||
#include <math.h> | |||
#include "common.h" | |||
static void draw_nuke( int x, int y, int frame ); | |||
static void draw_circle( int x, int y, int r ); | |||
static void draw_circle( int x, int y, int r, char c ); | |||
void init_weapons( game *g, weapons *wp ) | |||
{ | |||
@@ -12,11 +13,7 @@ void init_weapons( game *g, weapons *wp ) | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
wp->x[i] = -1; | |||
wp->y[i] = -1; | |||
wp->v[i] = 0; | |||
wp->n[i] = 0; | |||
wp->type[i] = 0; | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
} | |||
@@ -26,73 +23,157 @@ void draw_weapons( game *g, weapons *wp ) | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
if( wp->x[i] >= 0 ) | |||
switch( wp->type[i] ) | |||
{ | |||
switch( wp->type[i] ) | |||
{ | |||
case 2: | |||
draw_nuke( wp->x[i], wp->y[i], wp->n[i] ); | |||
break; | |||
case 1: | |||
default: | |||
GFX_COLOR( WHITE ); | |||
GFX_GOTO( wp->x[i], wp->y[i] ); | |||
GFX_WRITE( '|' ); | |||
GFX_COLOR( CYAN ); | |||
GFX_GOTO( wp->x[i], wp->y[i] + 1 ); | |||
GFX_WRITE( '|' ); | |||
break; | |||
} | |||
case WEAPON_LASER: | |||
gfx_color( WHITE ); | |||
gfx_goto( wp->x[i] >> 4, wp->y[i] >> 4 ); | |||
gfx_putchar( '|' ); | |||
gfx_color( CYAN ); | |||
gfx_goto( wp->x[i] >> 4, (wp->y[i] >> 4) + 1 ); | |||
gfx_putchar( '|' ); | |||
break; | |||
case WEAPON_SEEKER: | |||
gfx_color( CYAN ); | |||
gfx_goto( wp->x3[i] >> 4, wp->y3[i] >> 4 ); | |||
gfx_putchar( '.' ); | |||
gfx_goto( wp->x2[i] >> 4, wp->y2[i] >> 4 ); | |||
gfx_putchar( 'o' ); | |||
gfx_color( WHITE ); | |||
gfx_goto( wp->x[i] >> 4, wp->y[i] >> 4 ); | |||
gfx_putchar( '@' ); | |||
break; | |||
case WEAPON_NUKE: | |||
draw_nuke( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] ); | |||
break; | |||
case WEAPON_NONE: | |||
break; | |||
} | |||
} | |||
} | |||
void update_weapons( game *g, weapons *wp ) | |||
{ | |||
int i; | |||
int i, j, dist, xmin, ymin, dx, dy, xnew, ynew; | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
if( wp->y[i] < 0 ) | |||
{ | |||
wp->x[i] = -1; | |||
wp->y[i] = -1; | |||
} | |||
else | |||
switch( wp->type[i] ) | |||
{ | |||
switch( wp->type[i] ) | |||
{ | |||
case 2: | |||
case WEAPON_LASER: | |||
wp->x[i] += wp->vx[i]; | |||
wp->y[i] += wp->vy[i]; | |||
if( wp->y[i] < 0 ) | |||
{ | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
break; | |||
case WEAPON_SEEKER: | |||
/* Update tail */ | |||
wp->x3[i] = wp->x2[i]; | |||
wp->y3[i] = wp->y2[i]; | |||
wp->x2[i] = wp->x[i]; | |||
wp->y2[i] = wp->y[i]; | |||
wp->x[i] += wp->vx[i]; | |||
wp->y[i] += wp->vy[i]; | |||
if( wp->y[i] < 0 ) | |||
{ | |||
wp->type[i] = WEAPON_NONE; | |||
break; | |||
} | |||
if( wp->n[i] < 0 ) | |||
{ | |||
/* Stop updating direction */ | |||
break; | |||
} | |||
wp->n[i]--; | |||
/* Estimate our position in 2 frames */ | |||
xnew = wp->x[i] + 4 * wp->vx[i]; | |||
ynew = wp->y[i] + 4 * wp->vy[i]; | |||
xmin = xnew; | |||
ymin = - (g->h << 4); | |||
dist = (xnew - xmin) * (xnew - xmin) | |||
+ 4 * (ynew - ymin) * (ynew - ymin); | |||
/* Find the nearest alien */ | |||
for( j = 0; j < ALIENS; j++ ) | |||
{ | |||
if( g->al->type[j] != ALIEN_NONE ) | |||
{ | |||
int alx = g->al->x[j] << 4; | |||
int aly = g->al->y[j] << 4; | |||
int new = (xnew - alx) * (xnew - alx) | |||
+ 4 * (ynew - aly) * (ynew - aly); | |||
if( new <= dist ) | |||
{ | |||
dist = new; | |||
xmin = alx; | |||
ymin = aly; | |||
} | |||
} | |||
} | |||
/* Find our new direction */ | |||
dx = xmin - wp->x[i]; | |||
dy = ymin - wp->y[i]; | |||
/* Normalize and update speed */ | |||
wp->vx[i] = (7 * wp->vx[i] | |||
+ (dx * 48) / sqrt(dx*dx+dy*dy) ) / 8; | |||
wp->vy[i] = (7 * wp->vy[i] | |||
+ (dy * 24) / sqrt(dx*dx+dy*dy) ) / 8; | |||
break; | |||
case WEAPON_NUKE: | |||
wp->n[i]--; | |||
if( wp->n[i]-- < 0 ) | |||
if( wp->n[i] < 0 ) | |||
{ | |||
wp->y[i] = -1; | |||
wp->type[i] = WEAPON_NONE; | |||
} | |||
break; | |||
case 1: | |||
default: | |||
wp->y[i] += wp->v[i]; | |||
case WEAPON_NONE: | |||
break; | |||
} | |||
/* Check collisions */ | |||
} | |||
} | |||
} | |||
void add_weapon( game *g, weapons *wp, int x, int y, int type ) | |||
void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ) | |||
{ | |||
int i; | |||
for( i = 0; i < WEAPONS; i++ ) | |||
{ | |||
if( wp->y[i] < 0 ) | |||
if( wp->type[i] == WEAPON_NONE ) | |||
{ | |||
wp->x[i] = x; | |||
wp->y[i] = y; | |||
wp->vx[i] = vx; | |||
wp->vy[i] = vy; | |||
wp->type[i] = type; | |||
wp->v[i] = -2; | |||
wp->n[i] = 30; | |||
switch( type ) | |||
{ | |||
case WEAPON_LASER: | |||
break; | |||
case WEAPON_SEEKER: | |||
wp->x2[i] = x; | |||
wp->y2[i] = y; | |||
wp->x3[i] = x; | |||
wp->y3[i] = y; | |||
wp->n[i] = 10; | |||
break; | |||
case WEAPON_NUKE: | |||
wp->n[i] = 25; | |||
break; | |||
case WEAPON_NONE: | |||
break; | |||
} | |||
break; | |||
} | |||
} | |||
@@ -100,34 +181,34 @@ void add_weapon( game *g, weapons *wp, int x, int y, int type ) | |||
static void draw_nuke( int x, int y, int frame ) | |||
{ | |||
int r = (34 - frame) * (34 - frame) / 10; | |||
int r = (29 - frame) * (29 - frame) / 8; | |||
/* Lots of duplicate pixels, but we don't care */ | |||
GFX_COLOR( BLUE ); | |||
draw_circle( x, y, r++ ); | |||
GFX_COLOR( CYAN ); | |||
draw_circle( x, y, r++ ); | |||
GFX_COLOR( WHITE ); | |||
draw_circle( x, y, r++ ); | |||
draw_circle( x, y, r++ ); | |||
gfx_color( BLUE ); | |||
draw_circle( x, y, r++, ':' ); | |||
gfx_color( CYAN ); | |||
draw_circle( x, y, r++, '%' ); | |||
gfx_color( WHITE ); | |||
draw_circle( x, y, r++, '#' ); | |||
draw_circle( x, y, r++, '#' ); | |||
} | |||
static void draw_circle( int x, int y, int r ) | |||
static void draw_circle( int x, int y, int r, char c ) | |||
{ | |||
int test, dx, dy; | |||
/* Optimized Bresenham. Kick ass. */ | |||
for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++ ) | |||
{ | |||
GFX_WRITETO( x + dx, y + dy / 2, '#' ); | |||
GFX_WRITETO( x - dx, y + dy / 2, '#' ); | |||
GFX_WRITETO( x + dx, y - dy / 2, '#' ); | |||
GFX_WRITETO( x - dx, y - dy / 2, '#' ); | |||
GFX_WRITETO( x + dy, y + dx / 2, '#' ); | |||
GFX_WRITETO( x - dy, y + dx / 2, '#' ); | |||
GFX_WRITETO( x + dy, y - dx / 2, '#' ); | |||
GFX_WRITETO( x - dy, y - dx / 2, '#' ); | |||
gfx_putcharTO( x + dx, y + dy / 2, c ); | |||
gfx_putcharTO( x - dx, y + dy / 2, c ); | |||
gfx_putcharTO( x + dx, y - dy / 2, c ); | |||
gfx_putcharTO( x - dx, y - dy / 2, c ); | |||
gfx_putcharTO( x + dy, y + dx / 2, c ); | |||
gfx_putcharTO( x - dy, y + dx / 2, c ); | |||
gfx_putcharTO( x + dy, y - dx / 2, c ); | |||
gfx_putcharTO( x - dy, y - dx / 2, c ); | |||
test += test > 0 ? dx - dy-- : dx; | |||
} | |||