From 5f87eb694787dc30c77ec47be144ec96e4a80094 Mon Sep 17 00:00:00 2001 From: Matthew Mondor Date: Thu, 6 Apr 2023 03:30:19 +0000 Subject: [PATCH] Initial import of ninvaders-0.1.1 --- ChangeLog | 320 +++++++++++++++++++++++++++++++++ Makefile | 16 ++ README | 52 ++++++ aliens.c | 308 +++++++++++++++++++++++++++++++ aliens.h | 78 ++++++++ globals.c | 530 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ globals.h | 35 ++++ gpl.txt | 340 +++++++++++++++++++++++++++++++++++ nInvaders.c | 367 +++++++++++++++++++++++++++++++++++++ nInvaders.h | 60 +++++++ player.c | 240 +++++++++++++++++++++++++ player.h | 55 ++++++ ufo.c | 101 +++++++++++ ufo.h | 49 +++++ view.c | 589 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ view.h | 78 ++++++++ 16 files changed, 3218 insertions(+) create mode 100644 ChangeLog create mode 100644 Makefile create mode 100644 README create mode 100644 aliens.c create mode 100644 aliens.h create mode 100644 globals.c create mode 100644 globals.h create mode 100644 gpl.txt create mode 100644 nInvaders.c create mode 100644 nInvaders.h create mode 100644 player.c create mode 100644 player.h create mode 100644 ufo.c create mode 100644 ufo.h create mode 100644 view.c create mode 100644 view.h diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..f6ba535 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,320 @@ + +****** Release 0.1.1 ****** + +2003-04-22 Alexander Hollinger + + * globas.c: changed version from 0.0.11 to 0.1.1 + +2003-05-06 Sebastian Gutsfeld + + * aliens.c (aliensMissileMove): added test if there is an alien + ship left when starting a new missile; this was the bug which is + responsible for freezing the game when shooting at the last alien + +2003-05-05 Sebastian Gutsfeld + + * nInvaders.c (readInput): updated readInput for reading input in + different states (see status var) + + * nInvaders.c (handleTimer): added code for status GAME_HIGHSCORE + so a title screen with animation is shown; updated status + GAME_OVER + + * nInvaders.c (main): updated status initialisation from + GAME_NEXTLEVEL to GAME_HIGHSCORE + + * view.c: added WINDOW wTitleScreen; added titleScreenInit; added + titleScreenDisplay; added titleScreenClear; added battleFieldClear + + * view.c (aliensRefresh): formatted some code + + * view.c (ufoRefresh): fixed array length + + * view.c (gameOverDisplay): simpified function + + * view.c (graphicEngineInit): updated with titleScreenInit + + * view.h: sorted function declarations; updated gameOverDisplay, + titleScreenClear, titleScreenDisplay and battleFieldClear + +2003-04-22 Alexander Hollinger + + * globals.c (doSleep): added again. still needed in + view.c. added "#ifdef win32" instruction again. + +2003-04-22 Alexander Hollinger + + * globals.c (doSleep): deleted method. not used any more. + + * globals.c: incremented version number from 0.0.10 to 0.0.11 + + * globals.c: removed '#ifdef win32' instruction. + + * *.c, *.h: added license notice to each file + + * renamed ToDo to TODO + +2003-04-18 Alexander Hollinger + + * nInvaders.c (finish): "barely mediocre" and "show promise" + both "< 10000". Changed latter to "< 12500" + +2003-04-17 Alexander Hollinger + + * view.c (statusDisplay): modified so that buffer is written + to wBattleField. new variable WINDOW* wStatus. added method + (statusInit) which does initialisation of WINDOW wStatus. + Problem: Alien missiles go right to the bottom of screen, + where status is located and overwritten with missile sprite. + Fix: see next point + Changed behaviour of display of lives. Now the _remaining_ + lives are displayed. i.e. at the beginning you will see + two little spaceshuttles, because you have two lives left. + + * aliens.c (aliensMissileMove): added some checking, if missile + reached bottom where player moves. if so, do not move further + and reload missile. this reduces number of missiles which have + to be hit-tested each round, yet made it necessary to change + the shot-threshold otherwise too many missiles would have been + coming down. Not limiting ALIENS_MAX_MISSILES from 50 to 10 is + possible, because missiles are reloaded when they reach the + bottom. 10 concurrent missiles should be quite hard to manage.. + Removed ALIENS_MAX_MISSILES-definition from view.h. Was defined + twice, now only in aliens.h. + optimized threshold-checking. calculation outside for- + instruction, and only comparison within. + + +2003-04-17 Alexander Hollinger + + * nInvaders.c (readInput): removed (ch==27) for exit + sequence. as dettus pointed out there would be problems + on some terminals. pressing some keys too long will send + an KEY_ESC and quit the game. + +2003-04-17 Alexander Hollinger + + * nInvaders.c (setUpTimer): changed method to call handleTimer. + The call signal(SIG_ALRM, handleTimer) didn't work on irix. + There, the timer was only fired once and then the programm + exited. Now using call to sigaction() with flag SA_RESTART. + +2003-04-16 Alexander Hollinger + + * nInvaders.c: added a real-time timer that does 50 fps. if you + want it slower toggle the constant FPS. the higher the slower. + A timer is created and does all the gaming stuff while key + checking is still done in (main). Gamehandling is done by + simulating a deterministic finite automaton by setting the + 'status'-attribute to e.g. GAME_LOOP, GAME_PAUSED, GAME_EXIT. + the following methods were modified/ added: + (setUpTimer): creates and initializes timer + (handleTimer): this method is called every 1/FPS seconds and + contains most code from old (main) + (readInput): changed so that the 'status'-variable is affected. + pressing of 'p' now changes 'status' + (main): most code moved to (handleTimer), calls setUpTimer and + sets 'status' to GAME_NEXTLEVEL + (gameOver): completely moved to handleTimer + + * view.c (graphicEngineInit): removed 'timeout(0);' no longer + needed as we now hava a timer. another advantage: call to + (readInput) in nInvaders.c no longer called permanently. + in (readInput) the getch()-call waits till a key is pressed. + doSleep(1) no longer needed in nInvaders.c (readInput). + +2003-04-08 Sebastian Gutsfeld + + * ufo.c:replaced 'u' with 'ufo' (see ufo.h) and 'a' with 'aliens' + + * ufo.h: added typedef for Ufo and renamed 'u' into 'ufo', + + * player.c: added typedef for Player and renamed 'p' into 'player', + replaced 'p' with 'player and 'a' with 'aliens' + + * aliens.c: replaced 'a' with 'aliens' (see aliens.h) + + * aliens.h: added typedef for Aliens and renamed 'a' into 'aliens' + + * globals.c (RELEASE): updated release number + +2003-04-07 Sebastian Gutsfeld + + * view.c (ufoRefresh): reverted 'frame' assignement + + * nInvaders.c (main): reverted to old ufo speed from revision 1.3 + +2003-04-06 Alexander Hollinger + + * nInvaders.c (resetPlayer): added a call to playerMisisleClear(); + + * view.c (aliensRefresh): fully encapsulated. access to aliens-Array + by pointer. + + * aliens.c (*HitCheck): moved hit_alien_test and hit_bunker_test to + aliens.c and renamed to aliensHitCheck and bunkersHitCheck. Added + comments and did improvement of bunkersHitCheck-Algorithm + (shoty < BUNKERY + BUNKERHEIGHT instead of <=). + + * nInvaders.c (finish): moved short version of GPL to globals.c + (showGplShort) + + * view.c (gameOverInit): fixed color code + + * player.h: removed lives from structPlayer. This variable belongs + more to the gamehandling in nInvaders.c that to the model of the + player in player.c. This is done because of better encapsulation + of player.c. + + * player.c (playerReset): added a playerDisplay. Removed playerDisplay + from nInvaders.c just before refreshScreen() and added another + playerDisplay in the player.c (playerMissileMove) so that the + playerMissileClear does not clear the middle of the player when + a new shot is fired. + + * aliens.c (aliensHitCheck): added support for return of alienType so + that different scoring according to type of aliens is possible. + had to change values für alien_type constants in nInvaders.h and + the order of scores in the points-array in nInvaders.c (doScoring). + ufo gets 500pt, aliens 100pt, 150pt or 200pt. + + * aliens.c (aliensReset): clears missiles of aliens, if any + + * nInvaders.c (main): changed some variable names (*_counter) and + contracted some if-statements. + + * view.c (playerExplosionDisplay): renamed from playerExplode. Added + player.c (playerExplode) which calls playerExplosionDisplay and + playerDisplay. Thus, I could remove the playerExplode(p.posX, p.posY) + from nInvaders.c and add a playerExplode(). All Elements of the + structure structPlayer now are "private". + + +2003-04-05 Sebastian Gutsfeld + + * Makefile: Updated file for ufo + + * aliens.c (aliensMissileMove): fixed comment + + * aliens.h: fixed indentation + + * globals.h: fixed indentation + + * nInvaders.c: included ufo.h, fixed some comments and linebreaks + + * nInvaders.c (initlevel): added initialisation for ufo + + * nInvaders.c (main): added code for ufo + + * nInvaders.c (doScoring): different score for different alien types + + * nInvaders.h: added constants for alien types needed by + nInvaders.c (doScoring), fixed declaration of doScoring, fixed + Indentation + + * player.c: included ufo.h (needed for playerMoveMissile) + + * player.c (playerMoveMissile): added code needed for ufo, fixed + doScoring for alien type + + * player.h: fixed indentation, fixed declaration of doScoring + + * view.c: added WINDOW *wUfo, void ufoRefresh, static void ufoInit, + void ufoDisplay and void ufoClear + + * view.c (aliensRefresh): fixed indentation and color codes + + * view.c (graphicEngineInit): added ufoInit to last init section + + * view.h: fixed indentation, added constans UFOWIDTH and UFOPOSY, added + declarations of ufoDisplay, ufoRefresh and ufoClear + + * ufo.c: files for ufo handling (initial import into cvs) + + * ufo.h: header file for ufo.c (initial import into cvs) + +2003-04-04 Sebastian Gutsfeld + + * nInvaders.h, player.c: updated every occurance of hit_player_test + to hit_alientest + + * nInvaders.c (hit_alien_test): renamed from 'hit_player_test' + +2003-04-05 Alexander Hollinger + + * [view.c] (bunkersDisplay): now fully encapsulated using pointer + *pBunker to get access to bunker-array. Method is called from + [aliens.c] (bunkersReset) instead of [aliens.c] (render) thus + saving some cpu-time. The bunker has to be displayed only at the + beginning of a new level. Then we use bunkerClearElement or + bunkerClear to remove bunker elements. No need why it was in + [aliens.c] (render). + +2003-04-04 Sebastian Gutsfeld + + * nInvaders.c (readInput): draw new number of lives in live-cheat + + * aliens.c (aliensReset): put declaration of 'level' at + beginning of function + +2003-04-04 Alexander Hollinger + + * [nInvaders.c] added a new cheat: "L" gives player one new life + for better testing + * [aliens.c, player.c] (*Reset) forgot to reset alien-block and + bunkers-block. Now there is a bunkersReset in aliens.c + * [view.c] added method graphicEngineInit() + * [view.c] (refreshScreen) fixed problem with graphic display on some + terminals. bunker and player are now displayed at startup. + * removed init.c and init.h from project + * [globals.c] some minor changes to names of methods. moved code for + displaying version from nInvaders.c to globals.c. Added code to + redefine usleep for WIN32-platforms, this should hopefully fix the + bug that the game was too fast there. + +2003-04-03 Alexander Hollinger + + * removed deprecated multi-line-strings in globals.c and nInvaders.c + +2003-04-02 Alexander Hollinger + + * view.c now contains all methods which do graphical display + (by using ncurses) + + * added file aliens.c and aliens.h. Perhaps these can later melt + with player.c and player.h. + +2003-04-01 Sebastian Gutsfeld + + * *.c (*): formatted with 'indent -kr -i8 -l90' and fixed + some linebreaks + +2003-03-30 Alexander Hollinger + + * added file "ToDo": put feature-requests and alike in here + + * player.c (player*Missile*): processing of missiles moved to these + functions to reduce size of main(). + + +2003-03-29 Sebastian Gutsfeld + + * init.c (initplayer): fixed comment + + * player.c (playerInit): put declaration of 'playerSprite' at beginning + of function + + * init.c (initshots): put declaration of 'a' at beginning of function + +2003-03-29 Alexander Hollinger + + * added more comments and added player.c which is intended to hold all + functions concearning the player + + * added method playerLaunchMissile in player.c + +2003-03-28 Alexander Hollinger + + * added some comments and split up some functions, especially in init.c. + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d815e2f --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +CC=gcc +CFLAGS=-O3 -Wall +LIBS=-lncurses + +CFILES=globals.c view.c aliens.c ufo.c player.c nInvaders.c +HFILES=globals.h view.h aliens.h ufo.h player.h nInvaders.h +OFILES=globals.o view.o aliens.o ufo.o player.o nInvaders.o +all: nInvaders + +nInvaders: $(OFILES) $(HFILES) + $(CC) $(LDFLAGS) -o$@ $(OFILES) $(LIBS) + +.c.o: + $(CC) -c -I. $(CFLAGS) $(OPTIONS) $< +clean: + rm -f nInvaders $(OFILES) diff --git a/README b/README new file mode 100644 index 0000000..288819e --- /dev/null +++ b/README @@ -0,0 +1,52 @@ +*** nInvaders +*** (C)opyleft 2k2 by dettus +*** dettus@matrixx-bielefeld.de + +Hello and welcome to nInvaders! Right now you are earth's only hope to save +it from alien invaders from space. Make your job, and make it good, mankind +believes in you... + +1. INSTALLING +------------- +Compiling and installing should be really straightforward, just type in +"make" on your command prompt and you'll get the binary file. If not, please +edit the makefile. Once you have compiled it, copy it (as root) to your +/usr/bin directory, or /usr/local/games, or just run it by typeing +./nInvaders. + +2. REQUIREMENTS +--------------- +nInvaders is known to compile and run on Solaris, Linux and OpenBSD. On all of +them were ncurses 5.2 installed. If you are capable of running it on other +platforms, tell me! + +3. CONTROL KEYS +--------------- +Controlling nInvaders is really simple. Just press the cursor left/right keys +to move it left or right, and press space to fire. The esc-key lets you quit +at any time you want. + +4. COMMAND LINE OPTIONS +----------------------- +nInvaders accepts the following command line options +-l x where x is your skill as a number between 0(nightmare) and 9(may i play + daddy) +-gpl prints out the license information. + +Any other option gives you a help screen. + +5. LICENSING +------------ +nInvaders is protected under the laws of the GPL and other countries. Any re- +distribution, reselling or copying is strictly allowed. You should have received +a copy of it with this package, if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Or just start nInvaders with the -gpl option to learn more. + +6. GREETZ +--------- +hello mom, hello dad, hello katja, hello there, hello elitza, hello wizzard, +hello walli, hello melanie, hello judith, hello you folks at freshmeat, hello +skyper, hello gamma, hello sunfreeware, hello abuse, hello linus, hello alan, +hello herr von boedefeld, hello god, hello world. +and thank you Mike Saarna for adding ANIMATION! diff --git a/aliens.c b/aliens.c new file mode 100644 index 0000000..fa87c5c --- /dev/null +++ b/aliens.c @@ -0,0 +1,308 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include "aliens.h" +#include "player.h" +#include "nInvaders.h" + +/** + * initialize aliens attributes + */ +void aliensReset() +{ + int i,j; + + // three different types of aliens [5], [10] + int level[ALIENS_MAX_NUMBER_Y][ALIENS_MAX_NUMBER_X]={ + {1,1,1,1,1,1,1,1,1,1}, + {2,2,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2}, + {3,3,3,3,3,3,3,3,3,3}, + {3,3,3,3,3,3,3,3,3,3} + }; + + aliensClear(aliens.posX, aliens.posY, aliens.right, aliens.bottom); // clear old position of aliens + + // reset alien position + aliens.posX = 0; + aliens.posY = 0; + aliens.right = 0; + aliens.bottom = 0; + aliens.left = 0; + aliens.speed = 1; + + // copy level-array to enemy-array + for (i=0;ialiens.left) {aliens.left=-k;} + if (aliens.right==-1 || k>aliens.right) {aliens.right=k;} + if (aliens.bottom==-1 || c>aliens.bottom) {aliens.bottom=c;} + } + } + } else { + c++; + } + } + aliens.bottom=aliens.bottom*2; // every 2nd row is an empty row + aliens.left=aliens.left*3; // alien sprite is 3 chars wide + aliens.right=aliens.right*3; // alien sprite is 3 chars wide + + // display remaining aliens with animation + aliensRefresh(level, &alienBlock[0][0]); + +} + + +/** + * move aliens' missiles and do player/bunker hit testing + * a zero value in alienshotx indicates that the appropriate missile is loaded, but not fired + */ +int aliensMissileMove() +{ + int i, tmp; + int fPlayerWasHit = 0; + int shootThreshold; + static int alienshot_counter = 0; + + + // calculate threshold when next missile should be fired + // it is done here to save calculation time in for-instruction + shootThreshold = (skill_level * 8) * (shipnum + 2); + alienshot_counter = alienshot_counter + 10 ; + + // loop all possible missiles + for (i = 0; i < ALIENS_MAX_MISSILES; i++) { + + // if the current missile is flying we should do movements + if (alienshotx[i] != 0) { + + aliensMissileClear(alienshotx[i],alienshoty[i]); // clear old position + + // if missile hit the bunkers + if (bunkersHitCheck(alienshotx[i], alienshoty[i]) == 1) { + alienshotx[i] = 0; // value of zero reloads missile + } + + alienshoty[i]++; // move missile downwards + + // check if player was hit by an alien missile + if (playerHitCheck(alienshotx[i], alienshoty[i]) == 1) { + alienshotx[i] = 0; // value of zero reloads missile + fPlayerWasHit = 1; + } + + + } else { // missile not launched yet + + // start new missile if counter says so + if (alienshot_counter > shootThreshold && shipnum > 0) {// only shot if there's an alien left + alienshot_counter = 0; // reset counter + tmp = random() % ALIENS_MAX_NUMBER_X; // randomly select one of the ... + while (lowest_ship[tmp] == -1) { // ...aliens at the bottom of ... + tmp = random() % ALIENS_MAX_NUMBER_X; // ...a column to launch missile + } + alienshoty[i]=aliens.posY+lowest_ship[tmp]; // set y position of missile + alienshotx[i]=aliens.posX+tmp*3; // set x position of missile + } + } // if + + // display missiles if still running or just launched; could have been modified in the above code + if (alienshotx[i] != 0) { + // if missile is out of battlefield + if (alienshoty[i] == SCREENHEIGHT - 1) { + alienshotx[i] = 0; // reload missile + } else { + aliensMissileDisplay(alienshotx[i], alienshoty[i]); // display Missile at new position + } + } + + } // for + + + return fPlayerWasHit; +} + + + +/** + * check if missile hit an alien + */ +int aliensHitCheck(int shotx, int shoty) +{ + int alienType = 0; + int shipx, shipy; + // if missile is within alien-rectangle + if (shotx >= aliens.posX && shotx <= aliens.posX + ALIENS_MAX_NUMBER_X * 3 - 1 + && shoty >= aliens.posY && shoty <= aliens.posY + (ALIENS_MAX_NUMBER_Y - 1) * 2) { + // calculate the ship that was hit + shipx = (shotx - aliens.posX) / 3; + shipy = (shoty - aliens.posY) / 2; + // if there is still a ship at this position + alienType = alienBlock[shipy][shipx]; + if (alienType != 0) { + alienBlock[shipy][shipx] = 0; // delete alien ship + } + } + return alienType; // returns 0 if no alien was hit, else returns type-code of alien +} + +/** + * check if missile hit an element of bunker + */ +int bunkersHitCheck(int shotx, int shoty) +{ + int adjx, adjy; + int fBunkerWasHit = 0; + // if missile is within bunker-rectangle + if (shotx >= BUNKERX && shotx < BUNKERX + BUNKERWIDTH + && shoty >= BUNKERY && shoty < BUNKERY + BUNKERHEIGHT) { + // calculate the element of the bunker that was hit + adjy = shoty - BUNKERY; + adjx = shotx - BUNKERX; + // if there is still an element + if(bunker[adjy][adjx] == 1){ + bunker[adjy][adjx] = 0; // delete element + fBunkerWasHit = 1; // bunker was hit! + } + } + return fBunkerWasHit; +} diff --git a/aliens.h b/aliens.h new file mode 100644 index 0000000..040d93f --- /dev/null +++ b/aliens.h @@ -0,0 +1,78 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include "view.h" + +#ifndef ALIENS +#define ALIENS + +typedef struct Aliens Aliens; + +struct Aliens { + int posX; // horizontal position of aliens + int posY; // vertical position of aliens + int right; + int left; + int bottom; + int speed; // 0: no movement; 1: one per turn; etc. +}; + +Aliens aliens; + +int shipnum; + +#define ALIENS_MAX_NUMBER_X 10 +#define ALIENS_MAX_NUMBER_Y 5 +#define ALIENS_MAX_MISSILES 10 + +// todo: move to structure +int lowest_ship[ALIENS_MAX_NUMBER_X]; +int alienshotx[ALIENS_MAX_MISSILES]; +int alienshoty[ALIENS_MAX_MISSILES]; +int alienshotnum; +int alienBlock[ALIENS_MAX_NUMBER_Y][ALIENS_MAX_NUMBER_X]; + +int bunker[BUNKERHEIGHT][BUNKERWIDTH + 1]; + + +void aliensReset(); +void bunkersReset(); +int aliensMove(); +int aliensMissileMove(); +void render(); +int aliensHitCheck(int shotx, int shoty); +int bunkersHitCheck(int shotx, int shoty); + + +// methods that handle graphic display, from view.c +extern void aliensDisplay(int x, int y, int wid, int hgt); +extern void aliensClear(int x, int y, int wid, int hgt); +extern void aliensRefresh(int level, int *pAliens); +extern void aliensMissileDisplay(int x, int y); +extern void aliensMissileClear(int x, int y); +extern void bunkersClearElement(int x, int y); +extern void bunkersClear(); +extern void bunkersRefresh(); + +#endif diff --git a/globals.c b/globals.c new file mode 100644 index 0000000..b0ea03d --- /dev/null +++ b/globals.c @@ -0,0 +1,530 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include +#include +#include "globals.h" + + +#define MAJOR 0 +#define MINOR 1 +#define RELEASE 1 + + + +#ifdef WIN32 +#define usleep(x) Sleep(x/1000) +#endif + + +/** + * sleep for specified time + */ +void doSleep(int microseconds) +{ + usleep(microseconds); +} + + +/** + * show version information + */ +void showVersion() +{ + fprintf(stderr, "*** nInvaders %i.%i.%i\n", MAJOR, MINOR, RELEASE); + fprintf(stderr, "*** (C)opyleft 2k2 by Dettus\n"); + fprintf(stderr, "*** dettus@matrixx-bielefeld.de\n"); + fprintf(stderr, "Additional code by Mike Saarna,\n"); + fprintf(stderr, "Sebastian Gutsfeld -> segoh@gmx.net,\n"); + fprintf(stderr, "Alexander Hollinger -> alexander.hollinger@gmx.net and\n"); + fprintf(stderr, "Matthias Thar -> hiast2@compuserve.de\n"); +} + + +/** + * show usage of command line parameters + */ +void showUsage() +{ + + fprintf(stderr, "\n\nUsage: nInvaders [-l skill] [-gpl]\n"); + fprintf(stderr, " where -l 0=NIGHTMARE\n"); + fprintf(stderr, " -l 1=okay\n"); + fprintf(stderr, " -l 9=May I play daddy?!\n"); + fprintf(stderr, "\n -gpl shows you the license file\n"); +} + + +/** + * wait for input of return to continue + */ +void waitForReturn() +{ + char b[2]; + fprintf(stderr, "...Please press to read on..."); + fgets(b, sizeof(b), stdin); +} + +/** + * show short version of Gnu GPL + */ +void showGplShort() +{ + fprintf(stderr,"\n"); + fprintf(stderr,"This program is free software; you can redistribute it and/or modify\n"); + fprintf(stderr,"it under the terms of the GNU General Public License as published by\n"); + fprintf(stderr,"the Free Software Foundation; either version 2 of the License, or\n"); + fprintf(stderr,"(at your option) any later version.\n"); + fprintf(stderr,"\n"); + fprintf(stderr,"This program is distributed in the hope that it will be useful,\n"); + fprintf(stderr,"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); + fprintf(stderr,"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); + fprintf(stderr,"GNU General Public License for more details.\n"); + fprintf(stderr,"\n"); + fprintf(stderr,"You should have received a copy of the GNU General Public License\n"); + fprintf(stderr,"along with this program; if not, write to the Free Software\n"); + fprintf(stderr,"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"); + fprintf(stderr,"\n"); + fprintf(stderr,"Use the -gpl command line switch to see the full license of this program\n"); + fprintf(stderr,"Use the -help command line switch to see who wrote this program \n"); + fprintf(stderr,"\n"); +} + +/** + * show GNU GENERAL PUBLIC LICENSE + */ +void showGpl() +{ + fprintf(stderr, "\n"); + fprintf(stderr, " GNU GENERAL PUBLIC LICENSE\n"); + fprintf(stderr, " Version 2, June 1991\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n"); + fprintf(stderr, " 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"); + fprintf(stderr, " Everyone is permitted to copy and distribute verbatim copies\n"); + fprintf(stderr, " of this license document, but changing it is not allowed.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " Preamble\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " The licenses for most software are designed to take away your\n"); + fprintf(stderr, "freedom to share and change it. By contrast, the GNU General Public\n"); + fprintf(stderr, "License is intended to guarantee your freedom to share and change free \n"); + fprintf(stderr, "software--to make sure the software is free for all its users. This\n"); + fprintf(stderr, "General Public License applies to most of the Free Software\n"); + fprintf(stderr, "Foundation's software and to any other program whose authors commit to\n"); + fprintf(stderr, "using it. (Some other Free Software Foundation software is covered by\n"); + fprintf(stderr, "the GNU Library General Public License instead.) You can apply it to\n"); + fprintf(stderr, "your programs, too.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " When we speak of free software, we are referring to freedom, not\n"); + fprintf(stderr, "price. Our General Public Licenses are designed to make sure that you\n"); + fprintf(stderr, "have the freedom to distribute copies of free software (and charge for\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "this service if you wish), that you receive source code or can get it\n"); + fprintf(stderr, "if you want it, that you can change the software or use pieces of it\n"); + fprintf(stderr, "in new free programs; and that you know you can do these things.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " To protect your rights, we need to make restrictions that forbid\n"); + fprintf(stderr, "anyone to deny you these rights or to ask you to surrender the rights.\n"); + fprintf(stderr, "These restrictions translate to certain responsibilities for you if you\n"); + fprintf(stderr, "distribute copies of the software, or if you modify it.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " For example, if you distribute copies of such a program, whether\n"); + fprintf(stderr, "gratis or for a fee, you must give the recipients all the rights that\n"); + fprintf(stderr, "you have. You must make sure that they, too, receive or can get the\n"); + fprintf(stderr, "source code. And you must show them these terms so they know their\n"); + fprintf(stderr, "rights.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " We protect your rights with two steps: (1) copyright the software, and\n"); + fprintf(stderr, "(2) offer you this license which gives you legal permission to copy,\n"); + fprintf(stderr, "distribute and/or modify the software.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " Also, for each author's protection and ours, we want to make certain\n"); + fprintf(stderr, "that everyone understands that there is no warranty for this free\n"); + fprintf(stderr, "software. If the software is modified by someone else and passed on, we\n"); + fprintf(stderr, "want its recipients to know that what they have is not the original, so\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "that any problems introduced by others will not reflect on the original\n"); + fprintf(stderr, "authors' reputations.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " Finally, any free program is threatened constantly by software\n"); + fprintf(stderr, "patents. We wish to avoid the danger that redistributors of a free\n"); + fprintf(stderr, "program will individually obtain patent licenses, in effect making the\n"); + fprintf(stderr, "program proprietary. To prevent this, we have made it clear that any\n"); + fprintf(stderr, "patent must be licensed for everyone's free use or not licensed at all.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " The precise terms and conditions for copying, distribution and\n"); + fprintf(stderr, "modification follow.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " GNU GENERAL PUBLIC LICENSE\n"); + fprintf(stderr, " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 0. This License applies to any program or other work which contains\n"); + fprintf(stderr, "a notice placed by the copyright holder saying it may be distributed\n"); + fprintf(stderr, "under the terms of this General Public License. The 'Program', below,\n"); + fprintf(stderr, "refers to any such program or work, and a 'work based on the Program'\n"); + fprintf(stderr, "means either the Program or any derivative work under copyright law:\n"); + fprintf(stderr, "that is to say, a work containing the Program or a portion of it,\n"); + fprintf(stderr, "either verbatim or with modifications and/or translated into another\n"); + fprintf(stderr, "language. (Hereinafter, translation is included without limitation in\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "the term 'modification'.) Each licensee is addressed as 'you'.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Activities other than copying, distribution and modification are not\n"); + fprintf(stderr, "covered by this License; they are outside its scope. The act of\n"); + fprintf(stderr, "running the Program is not restricted, and the output from the Program\n"); + fprintf(stderr, "is covered only if its contents constitute a work based on the\n"); + fprintf(stderr, "Program (independent of having been made by running the Program).\n"); + fprintf(stderr, "Whether that is true depends on what the Program does.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 1. You may copy and distribute verbatim copies of the Program's\n"); + fprintf(stderr, "source code as you receive it, in any medium, provided that you\n"); + fprintf(stderr, "conspicuously and appropriately publish on each copy an appropriate\n"); + fprintf(stderr, "copyright notice and disclaimer of warranty; keep intact all the\n"); + fprintf(stderr, "notices that refer to this License and to the absence of any warranty;\n"); + fprintf(stderr, "and give any other recipients of the Program a copy of this License\n"); + fprintf(stderr, "along with the Program.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "You may charge a fee for the physical act of transferring a copy, and\n"); + fprintf(stderr, "you may at your option offer warranty protection in exchange for a fee.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 2. You may modify your copy or copies of the Program or any portion\n"); + fprintf(stderr, "of it, thus forming a work based on the Program, and copy and\n"); + fprintf(stderr, "distribute such modifications or work under the terms of Section 1\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "above, provided that you also meet all of these conditions:\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " a) You must cause the modified files to carry prominent notices\n"); + fprintf(stderr, " stating that you changed the files and the date of any change.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " b) You must cause any work that you distribute or publish, that in\n"); + fprintf(stderr, " whole or in part contains or is derived from the Program or any\n"); + fprintf(stderr, " part thereof, to be licensed as a whole at no charge to all third\n"); + fprintf(stderr, " parties under the terms of this License.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " c) If the modified program normally reads commands interactively\n"); + fprintf(stderr, " when run, you must cause it, when started running for such\n"); + fprintf(stderr, " interactive use in the most ordinary way, to print or display an\n"); + fprintf(stderr, " announcement including an appropriate copyright notice and a\n"); + fprintf(stderr, " notice that there is no warranty (or else, saying that you provide\n"); + fprintf(stderr, " a warranty) and that users may redistribute the program under\n"); + fprintf(stderr, " these conditions, and telling the user how to view a copy of this\n"); + fprintf(stderr, " License. (Exception: if the Program itself is interactive but\n"); + fprintf(stderr, " does not normally print such an announcement, your work based on\n"); + fprintf(stderr, " the Program is not required to print an announcement.)\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "These requirements apply to the modified work as a whole. If\n"); + fprintf(stderr, "identifiable sections of that work are not derived from the Program,\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "and can be reasonably considered independent and separate works in\n"); + fprintf(stderr, "themselves, then this License, and its terms, do not apply to those\n"); + fprintf(stderr, "sections when you distribute them as separate works. But when you\n"); + fprintf(stderr, "distribute the same sections as part of a whole which is a work based\n"); + fprintf(stderr, "on the Program, the distribution of the whole must be on the terms of\n"); + fprintf(stderr, "this License, whose permissions for other licensees extend to the\n"); + fprintf(stderr, "entire whole, and thus to each and every part regardless of who wrote it.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Thus, it is not the intent of this section to claim rights or contest\n"); + fprintf(stderr, "your rights to work written entirely by you; rather, the intent is to\n"); + fprintf(stderr, "exercise the right to control the distribution of derivative or\n"); + fprintf(stderr, "collective works based on the Program.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "In addition, mere aggregation of another work not based on the Program\n"); + fprintf(stderr, "with the Program (or with a work based on the Program) on a volume of\n"); + fprintf(stderr, "a storage or distribution medium does not bring the other work under\n"); + fprintf(stderr, "the scope of this License.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 3. You may copy and distribute the Program (or a work based on it,\n"); + fprintf(stderr, "under Section 2) in object code or executable form under the terms of\n"); + fprintf(stderr, "Sections 1 and 2 above provided that you also do one of the following:\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " a) Accompany it with the complete corresponding machine-readable\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, " source code, which must be distributed under the terms of Sections\n"); + fprintf(stderr, " 1 and 2 above on a medium customarily used for software interchange; or,\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " b) Accompany it with a written offer, valid for at least three\n"); + fprintf(stderr, " years, to give any third party, for a charge no more than your\n"); + fprintf(stderr, " cost of physically performing source distribution, a complete\n"); + fprintf(stderr, " machine-readable copy of the corresponding source code, to be\n"); + fprintf(stderr, " distributed under the terms of Sections 1 and 2 above on a medium\n"); + fprintf(stderr, " customarily used for software interchange; or,\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " c) Accompany it with the information you received as to the offer\n"); + fprintf(stderr, " to distribute corresponding source code. (This alternative is\n"); + fprintf(stderr, " allowed only for noncommercial distribution and only if you\n"); + fprintf(stderr, " received the program in object code or executable form with such\n"); + fprintf(stderr, " an offer, in accord with Subsection b above.)\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "The source code for a work means the preferred form of the work for\n"); + fprintf(stderr, "making modifications to it. For an executable work, complete source\n"); + fprintf(stderr, "code means all the source code for all modules it contains, plus any\n"); + fprintf(stderr, "associated interface definition files, plus the scripts used to\n"); + fprintf(stderr, "control compilation and installation of the executable. However, as a\n"); + fprintf(stderr, "special exception, the source code distributed need not include\n"); + fprintf(stderr, "anything that is normally distributed (in either source or binary\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "form) with the major components (compiler, kernel, and so on) of the\n"); + fprintf(stderr, "operating system on which the executable runs, unless that component\n"); + fprintf(stderr, "itself accompanies the executable.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "If distribution of executable or object code is made by offering\n"); + fprintf(stderr, "access to copy from a designated place, then offering equivalent\n"); + fprintf(stderr, "access to copy the source code from the same place counts as\n"); + fprintf(stderr, "distribution of the source code, even though third parties are not\n"); + fprintf(stderr, "compelled to copy the source along with the object code.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 4. You may not copy, modify, sublicense, or distribute the Program\n"); + fprintf(stderr, "except as expressly provided under this License. Any attempt\n"); + fprintf(stderr, "otherwise to copy, modify, sublicense or distribute the Program is\n"); + fprintf(stderr, "void, and will automatically terminate your rights under this License.\n"); + fprintf(stderr, "However, parties who have received copies, or rights, from you under\n"); + fprintf(stderr, "this License will not have their licenses terminated so long as such\n"); + fprintf(stderr, "parties remain in full compliance.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 5. You are not required to accept this License, since you have not\n"); + fprintf(stderr, "signed it. However, nothing else grants you permission to modify or\n"); + fprintf(stderr, "distribute the Program or its derivative works. These actions are\n"); + fprintf(stderr, "prohibited by law if you do not accept this License. Therefore, by\n"); + fprintf(stderr, "modifying or distributing the Program (or any work based on the\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "Program), you indicate your acceptance of this License to do so, and\n"); + fprintf(stderr, "all its terms and conditions for copying, distributing or modifying\n"); + fprintf(stderr, "the Program or works based on it.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 6. Each time you redistribute the Program (or any work based on the\n"); + fprintf(stderr, "Program), the recipient automatically receives a license from the\n"); + fprintf(stderr, "original licensor to copy, distribute or modify the Program subject to\n"); + fprintf(stderr, "these terms and conditions. You may not impose any further\n"); + fprintf(stderr, "restrictions on the recipients' exercise of the rights granted herein.\n"); + fprintf(stderr, "You are not responsible for enforcing compliance by third parties to\n"); + fprintf(stderr, "this License.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 7. If, as a consequence of a court judgment or allegation of patent\n"); + fprintf(stderr, "infringement or for any other reason (not limited to patent issues),\n"); + fprintf(stderr, "conditions are imposed on you (whether by court order, agreement or\n"); + fprintf(stderr, "otherwise) that contradict the conditions of this License, they do not\n"); + fprintf(stderr, "excuse you from the conditions of this License. If you cannot\n"); + fprintf(stderr, "distribute so as to satisfy simultaneously your obligations under this\n"); + fprintf(stderr, "License and any other pertinent obligations, then as a consequence you\n"); + fprintf(stderr, "may not distribute the Program at all. For example, if a patent\n"); + fprintf(stderr, "license would not permit royalty-free redistribution of the Program by\n"); + fprintf(stderr, "all those who receive copies directly or indirectly through you, then\n"); + fprintf(stderr, "the only way you could satisfy both it and this License would be to\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "refrain entirely from distribution of the Program.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "If any portion of this section is held invalid or unenforceable under\n"); + fprintf(stderr, "any particular circumstance, the balance of the section is intended to\n"); + fprintf(stderr, "apply and the section as a whole is intended to apply in other\n"); + fprintf(stderr, "circumstances.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "It is not the purpose of this section to induce you to infringe any\n"); + fprintf(stderr, "patents or other property right claims or to contest validity of any\n"); + fprintf(stderr, "such claims; this section has the sole purpose of protecting the\n"); + fprintf(stderr, "integrity of the free software distribution system, which is\n"); + fprintf(stderr, "implemented by public license practices. Many people have made\n"); + fprintf(stderr, "generous contributions to the wide range of software distributed\n"); + fprintf(stderr, "through that system in reliance on consistent application of that\n"); + fprintf(stderr, "system; it is up to the author/donor to decide if he or she is willing\n"); + fprintf(stderr, "to distribute software through any other system and a licensee cannot\n"); + fprintf(stderr, "impose that choice.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "This section is intended to make thoroughly clear what is believed to\n"); + fprintf(stderr, "be a consequence of the rest of this License.\n"); + fprintf(stderr, " 8. If the distribution and/or use of the Program is restricted in\n"); + fprintf(stderr, "certain countries either by patents or by copyrighted interfaces, the\n"); + fprintf(stderr, "original copyright holder who places the Program under this License\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "may add an explicit geographical distribution limitation excluding\n"); + fprintf(stderr, "those countries, so that distribution is permitted only in or among\n"); + fprintf(stderr, "countries not thus excluded. In such case, this License incorporates\n"); + fprintf(stderr, "the limitation as if written in the body of this License.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 9. The Free Software Foundation may publish revised and/or new versions\n"); + fprintf(stderr, "of the General Public License from time to time. Such new versions will\n"); + fprintf(stderr, "be similar in spirit to the present version, but may differ in detail to\n"); + fprintf(stderr, "address new problems or concerns.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Each version is given a distinguishing version number. If the Program\n"); + fprintf(stderr, "specifies a version number of this License which applies to it and 'any\n"); + fprintf(stderr, "later version', you have the option of following the terms and conditions\n"); + fprintf(stderr, "either of that version or of any later version published by the Free\n"); + fprintf(stderr, "Software Foundation. If the Program does not specify a version number of\n"); + fprintf(stderr, "this License, you may choose any version ever published by the Free Software\n"); + fprintf(stderr, "Foundation.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 10. If you wish to incorporate parts of the Program into other free\n"); + fprintf(stderr, "programs whose distribution conditions are different, write to the author\n"); + fprintf(stderr, "to ask for permission. For software which is copyrighted by the Free\n"); + fprintf(stderr, "Software Foundation, write to the Free Software Foundation; we sometimes\n"); + fprintf(stderr, "make exceptions for this. Our decision will be guided by the two goals\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "of preserving the free status of all derivatives of our free software and\n"); + fprintf(stderr, "of promoting the sharing and reuse of software generally.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " NO WARRANTY\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"); + fprintf(stderr, "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"); + fprintf(stderr, "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"); + fprintf(stderr, "PROVIDE THE PROGRAM 'AS IS' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"); + fprintf(stderr, "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"); + fprintf(stderr, "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"); + fprintf(stderr, "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"); + fprintf(stderr, "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"); + fprintf(stderr, "REPAIR OR CORRECTION.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"); + fprintf(stderr, "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"); + fprintf(stderr, "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"); + fprintf(stderr, "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"); + fprintf(stderr, "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"); + fprintf(stderr, "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"); + fprintf(stderr, "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"); + fprintf(stderr, "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "POSSIBILITY OF SUCH DAMAGES.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " END OF TERMS AND CONDITIONS\n"); + fprintf(stderr, " How to Apply These Terms to Your New Programs\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " If you develop a new program, and you want it to be of the greatest\n"); + fprintf(stderr, "possible use to the public, the best way to achieve this is to make it\n"); + fprintf(stderr, "free software which everyone can redistribute and change under these terms.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " To do so, attach the following notices to the program. It is safest\n"); + fprintf(stderr, "to attach them to the start of each source file to most effectively\n"); + fprintf(stderr, "convey the exclusion of warranty; and each file should have at least\n"); + fprintf(stderr, "the 'copyright' line and a pointer to where the full notice is found.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " \n"); + fprintf(stderr, " Copyright (C) \n"); + fprintf(stderr, "\n"); + fprintf(stderr, " This program is free software; you can redistribute it and/or modify\n"); + fprintf(stderr, " it under the terms of the GNU General Public License as published by\n"); + fprintf(stderr, " the Free Software Foundation; either version 2 of the License, or\n"); + fprintf(stderr, " (at your option) any later version.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " This program is distributed in the hope that it will be useful,\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); + fprintf(stderr, " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); + fprintf(stderr, " GNU General Public License for more details.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " You should have received a copy of the GNU General Public License\n"); + fprintf(stderr, " along with this program; if not, write to the Free Software\n"); + fprintf(stderr, " Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Also add information on how to contact you by electronic and paper mail.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "If the program is interactive, make it output a short notice like this\n"); + fprintf(stderr, "when it starts in an interactive mode:\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " Gnomovision version 69, Copyright (C) year name of author\n"); + fprintf(stderr, " Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n"); + fprintf(stderr, " This is free software, and you are welcome to redistribute it\n"); + fprintf(stderr, " under certain conditions; type `show c' for details.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "The hypothetical commands `show w' and `show c' should show the appropriate\n"); + fprintf(stderr, "parts of the General Public License. Of course, the commands you use may\n"); + fprintf(stderr, "be called something other than `show w' and `show c'; they could even be\n"); + fprintf(stderr, "mouse-clicks or menu items--whatever suits your program.\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + + fprintf(stderr, "\n"); + fprintf(stderr, "You should also get your employer (if you work as a programmer) or your\n"); + fprintf(stderr, "school, if any, to sign a 'copyright disclaimer' for the program, if\n"); + fprintf(stderr, "necessary. Here is a sample; alter the names:\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n"); + fprintf(stderr, " `Gnomovision' (which makes passes at compilers) written by James Hacker.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, " , 1 April 1989\n"); + fprintf(stderr, " Ty Coon, President of Vice\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "This General Public License does not permit incorporating your program into\n"); + fprintf(stderr, "proprietary programs. If your program is a subroutine library, you may\n"); + fprintf(stderr, "consider it more useful to permit linking proprietary applications with the\n"); + fprintf(stderr, "library. If this is what you want to do, use the GNU Library General\n"); + fprintf(stderr, "Public License instead of this License.\n"); + fprintf(stderr, "\n"); + + waitForReturn(); + +} diff --git a/globals.h b/globals.h new file mode 100644 index 0000000..7eacb9a --- /dev/null +++ b/globals.h @@ -0,0 +1,35 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#ifndef GLOBALS +#define GLOBALS + +extern void doSleep(); + +extern void showUsage(); +extern void showVersion(); +extern void showGplShort(); +extern void showGpl(); + +#endif diff --git a/gpl.txt b/gpl.txt new file mode 100644 index 0000000..5b6e7c6 --- /dev/null +++ b/gpl.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/nInvaders.c b/nInvaders.c new file mode 100644 index 0000000..793139c --- /dev/null +++ b/nInvaders.c @@ -0,0 +1,367 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include +#include +#include +#include "nInvaders.h" +#include "player.h" +#include "aliens.h" +#include "ufo.h" + +#define FPS 50 + +int lives; +long score; +int status; // status handled in timer + +#define GAME_LOOP 1 +#define GAME_NEXTLEVEL 2 +#define GAME_PAUSED 3 +#define GAME_OVER 4 +#define GAME_EXIT 5 +#define GAME_HIGHSCORE 6 + + + + +/** + * initialize level: reset attributes of most units + */ +static void initLevel() +{ + playerReset(); + aliensReset(); + ufoReset(); + bunkersReset(); + render(); + drawscore(); +} + + +/** + * evaluate command line parameters + */ +static void evaluateCommandLine(int argc, char **argv) +{ + + // -l : set skill level + if (argc == 3 && strcmp(argv[1], "-l") == 0) { + if (argv[2][0] >= '0' && argv[2][0] <= '9') { + skill_level = argv[2][0] - 48; + } else { + argc = 2; + } + } + + // -gpl : show GNU GPL + if (argc == 2 && strcmp(argv[1], "-gpl") == 0) { + showGpl(); + } + + // wrong command line: show usage + if (argc == 2 || (argc == 3 && strcmp(argv[1], "-l") != 0)) { + showVersion(); + showUsage(); + exit(1); + } +} + + +static void finish(int sig) +{ + endwin(); + showGplShort(); + + fprintf(stderr,"\n"); + fprintf(stderr,"\n"); + fprintf(stderr,"=========================================================================\n"); + fprintf(stderr,"\n"); + + fprintf(stderr,"Final score: %7.7ld, Final level: %2.2d\nFinal rating... ",score,level); + if (lives>0) + fprintf(stderr,"Quitter\n\n"); + else if(score<5000) + fprintf(stderr,"Alien Fodder\n\n"); + else if(score<7500) + fprintf(stderr,"Easy Target\n\n"); + else if(score<10000) + fprintf(stderr,"Barely Mediocre\n\n"); + else if(score<12500) + fprintf(stderr,"Shows Promise\n\n"); + else if(score<15000) + fprintf(stderr,"Alien Blaster\n\n"); + else if(score<20000) + fprintf(stderr,"Earth Defender\n\n"); + else if(score>19999) + fprintf(stderr,"Supreme Protector\n\n"); + + showVersion(); + exit(0); +} + + +void drawscore() +{ + statusDisplay(level, score, lives); +} + + +/** + * reads input from keyboard and do action + */ +void readInput() +{ + int ch; + static int lastmove; + + ch = getch(); // get key pressed + + switch (status) { + + case GAME_PAUSED: + + if (ch == 'p') { + status = GAME_LOOP; + } + break; + + case GAME_HIGHSCORE: + + if (ch == ' ') { + titleScreenClear(); + level = 0; // reset level + score = 0; // reset score + lives = 3; // restore lives + status = GAME_NEXTLEVEL; + } else if (ch == 'q') { // quit game + status = GAME_EXIT; + } + break; + + case GAME_OVER: + break; // don't do anything + + default: + + if (ch == 'l' || ch == KEY_RIGHT) { // move player right + if (lastmove == 'l') { + playerTurboOn(); // enable Turbo + } else { + playerTurboOff(); // disable Turbo + } + playerMoveRight(); // move player + lastmove = 'l'; // remember last move for turbo mode + } else if (ch == 'h' || ch == KEY_LEFT) { // move player left + if (lastmove == 'h') { + playerTurboOn(); // enable Turbo + } else { + playerTurboOff(); // disable Turbo + } + playerMoveLeft(); // move player + lastmove = 'h'; // remember last move for turbo mode + } else if (ch == 'k' || ch == ' ') { // shoot missile + playerLaunchMissile(); + } else if (ch == 'p') { // pause game until 'p' pressed again + // set status to game paused + status = GAME_PAUSED; + } else if (ch == 'W') { // cheat: goto next level + status = GAME_NEXTLEVEL; + } else if (ch == 'L') { // cheat: one more live + lives++; + drawscore(); + } else if (ch == 'q') { // quit game + status = GAME_EXIT; + } else { // disable turbo mode if key is not kept pressed + lastmove = ' '; + } + + } // switch + +} + + +/** + * timer + * this method is executed every 1 / FPS seconds + */ +void handleTimer() +{ + static int aliens_move_counter = 0; + static int aliens_shot_counter = 0; + static int player_shot_counter = 0; + static int ufo_move_counter = 0; + static int title_animation_counter = 0; + static int game_over_counter = 0; + + switch (status) { + + case GAME_NEXTLEVEL: // go to next level + + level++; // increase level + + initLevel(); // initialize level + + aliens_move_counter = 0; + aliens_shot_counter = 0; + player_shot_counter = 0; + ufo_move_counter = 0; + + weite = (shipnum+(skill_level*10)-(level*5)+5)/10; + + if (weite < 0) { + weite = 0; + } + + // change status and start game! + status = GAME_LOOP; + + case GAME_LOOP: // do game handling + + // move aliens + if (aliens_move_counter == 0 && aliensMove() == 1) { + // aliens reached player + lives = 0; + status = GAME_OVER; + } + + // move player missile + if (player_shot_counter == 0 && playerMoveMissile() == 1) { + // no aliens left + status = GAME_NEXTLEVEL; + } + + // move aliens' missiles + if (aliens_shot_counter == 0 && aliensMissileMove() == 1) { + // player was hit + lives--; // player looses one life + drawscore(); // draw score + playerExplode(); // display some explosion graphics + if (lives == 0) { // if no lives left ... + status = GAME_OVER; // ... exit game + } + } + + // move ufo + if (ufo_move_counter == 0 && ufoShowUfo() == 1) { + ufoMoveLeft(); // move it one position to the left + } + + + if (aliens_shot_counter++ >= 5) {aliens_shot_counter=0;} // speed of alien shot + if (player_shot_counter++ >= 1) {player_shot_counter=0;} // speed of player shot + if (aliens_move_counter++ >= weite) {aliens_move_counter=0;} // speed of aliend + if (ufo_move_counter++ >= 3) {ufo_move_counter=0;} // speed of ufo + + refreshScreen(); + break; + + case GAME_PAUSED: // game is paused + break; + + case GAME_OVER: // game over + if (game_over_counter == 100) { + battleFieldClear(); + status = GAME_HIGHSCORE; + game_over_counter = 0; + } else { + gameOverDisplay(); + game_over_counter++; + } + break; + + case GAME_EXIT: // exit game + finish(0); + break; + + case GAME_HIGHSCORE: // display highscore + if (title_animation_counter == 0) { + titleScreenDisplay(); + } + + if (title_animation_counter++ >= 6) {title_animation_counter = 0;} // speed of animation + break; + + } +} + + +/** + * set up timer + */ +void setUpTimer() +{ + struct itimerval myTimer; + struct sigaction myAction; + myTimer.it_value.tv_sec = 0; + myTimer.it_value.tv_usec = 1000000 / FPS; + myTimer.it_interval.tv_sec = 0; + myTimer.it_interval.tv_usec = 1000000 / FPS; + setitimer(ITIMER_REAL, &myTimer, NULL); + + myAction.sa_handler = &handleTimer; + myAction.sa_flags = SA_RESTART; + sigaction(SIGALRM, &myAction, NULL); +} + + +int main(int argc, char **argv) +{ + weite = 0; + score = 0; + lives = 3; + level = 0; + skill_level = 1; + + evaluateCommandLine(argc, argv); // evaluate command line parameters + graphicEngineInit(); // initialize graphic engine + + // set up timer/ game handling + setUpTimer(); + status = GAME_HIGHSCORE; + + // read keyboard input + do { + // do movements and key-checking + readInput(); + } while (0 == 0); + + return 0; +} + + +void doScoring(int alienType) +{ + int points[4] = {500, 200, 150, 100}; // 0: ufo, 1:red, 2:green, 3:blue + + score += points[alienType]; // every alien type does different scoring points + + // every 6000 pts player gets a new live + if (score % 6000 == 0){ + lives++; + } + + drawscore(); // display score +} + diff --git a/nInvaders.h b/nInvaders.h new file mode 100644 index 0000000..1161321 --- /dev/null +++ b/nInvaders.h @@ -0,0 +1,60 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include +#include +#include "view.h" +#include "globals.h" + + +#ifndef NINVADERS +#define NINVADERS + +#define UFO_ALIEN_TYPE 0 +#define RED_ALIEN_TYPE 1 +#define GREEN_ALIEN_TYPE 2 +#define BLUE_ALIEN_TYPE 3 + +int main(int argv, char **argc); // hey! it has to start somewhere! + +extern void render(void); + +void game_over(int a); +void drawscore(); + +void doScoring(int alienType); + +// todo: let's try to not having to declare these "public" +int weite; +int level; +int skill_level; + +// included from globals.h +extern void doSleep(); +extern void showUsage(); +extern void showVersion(); +extern void showGplShort(); +extern void showGpl(); + +#endif diff --git a/player.c b/player.c new file mode 100644 index 0000000..698d426 --- /dev/null +++ b/player.c @@ -0,0 +1,240 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include "player.h" +#include "aliens.h" +#include "ufo.h" +#include "nInvaders.h" + +typedef struct Player Player; + +struct Player { + int posX; // horizontal position of player + int posY; // vertical position of player + int speed; // 0: no movement; 1: one per turn; etc. + int missileFired; // 0: missile not running; 1: missile running + int missileX; // horizontal position of missile + int missileY; // vertical position of missile +}; + +Player player; + +/** + * initialize player attributes + */ +void playerReset() +{ + // if missile was fired clear that position + if (player.missileFired == 1) { + playerMissileClear(player.missileX, player.missileY); + } + + playerClear(player.posX, player.posY); // clear old position of player + + player.posY = PLAYERPOSY; // set vertical Position + player.posX = 0; // set horizontal Position + player.speed = 1; + player.missileFired = 0; + player.missileX=0; + player.missileY=0; + + playerDisplay(player.posX, player.posY); // display new position of player +} + + +/** + * move player horizontally to position newPosX + */ +static void playerMove(int newPosX) +{ + playerClear(player.posX, player.posY); // clear sprite + player.posX = newPosX; // make movement + playerDisplay(player.posX, player.posY); // display sprite +} + + +/** + * move player left + */ +void playerMoveLeft() +{ + // check if space between player and border of screen is big enough + if (player.posX > 0 + player.speed) { + // desired movement is possible + playerMove(player.posX - player.speed); + } else { + // space too small, move to left-most position + playerMove(0); + } +} + + +/** + * move player right + */ +void playerMoveRight() +{ + // check if space between player and border of screen is big enough + if (player.posX < SCREENWIDTH - PLAYERWIDTH - player.speed) { + // desired movement is possible + playerMove(player.posX + player.speed); + } else { + // space too small, move to right-most position + playerMove(SCREENWIDTH - PLAYERWIDTH); + } +} + + +/** + * toggle turbo mode on (if key is kept pressed) + */ +void playerTurboOn() +{ + player.speed = 2; +} + + +/** + * toggle turbo mode off (if key is kept pressed) + */ +void playerTurboOff() +{ + player.speed = 1; +} + + +/** + * player was hit by an alien shot + */ +int playerHitCheck(int hostileShotX, int hostileShotY) +{ + int fPlayerWasHit = 0; + + // if shot reached vertikal position of player + if (hostileShotY == PLAYERPOSY) { + // if shot hits player + if (hostileShotX >= player.posX && hostileShotX <= player.posX + PLAYERWIDTH -1) { + fPlayerWasHit = 1; // set return value + } + } + + return fPlayerWasHit; // return if player was hit +} + + +/** + * Launch Missile + */ +void playerLaunchMissile() +{ + // only launch missile if no other is on its way + if (player.missileFired == 0) { + player.missileFired = 1; // missile is on its way + player.missileX = player.posX + PLAYERWIDTH / 2; // launched from the middle of player... + player.missileY = PLAYERPOSY; // ...at same horizontal position + } +} + + +/** + * Reload Missile + */ +static void playerReloadMissile() +{ + player.missileFired = 0; // no player missile flying +} + + +/** + * move player missile and do alien/bunker hit testing + * return value - 0: still some aliens left, 1: no aliens left + */ +int playerMoveMissile() +{ + int fNoAliensLeft = 0; // return value + int alienTypeHit = 0; + + // only do movements if there is a missile to move + if (player.missileFired == 1) { + + playerMissileClear(player.missileX, player.missileY); // clear old missile position + playerDisplay(player.posX, player.posY); // todo: check if this can be removed later if missiled is fired, + //the middle of player is cleared + player.missileY--; // move missile + + // if missile out of battlefield + if (player.missileY < 0) { + playerReloadMissile(); // reload missile + } else { + playerMissileDisplay(player.missileX, player.missileY); // display missile at new position + } + + // if missile hits an alien (TODO) + alienTypeHit = aliensHitCheck(player.missileX, player.missileY); + if (alienTypeHit != 0) { + + doScoring(alienTypeHit); // increase score + playerReloadMissile(); // reload missile + + aliensClear(aliens.posX, aliens.posY, aliens.right, aliens.bottom); // clear old posiiton of aliens + + render(); + if (shipnum == 0) { + fNoAliensLeft = 1; + } + + // speed of aliens + weite = (shipnum + (skill_level * 10) - (level * 5) + 5) / 10; + if (weite < 0) { + weite = 0; + } + + playerMissileClear(player.missileX, player.missileY); // clear old missile position + aliensDisplay(aliens.posX, aliens.posY, aliens.right, aliens.bottom); // display aliens + } + + // if missile hits a bunker + if (bunkersHitCheck(player.missileX, player.missileY) == 1) { + bunkersClearElement(player.missileX, player.missileY); // clear element of bunker + playerReloadMissile(); // reload player missile + } + + // if missile hits ufo + if (ufoHitCheck(player.missileX, player.missileY) == 1) { + doScoring(UFO_ALIEN_TYPE); + playerReloadMissile(); + } + } + + return fNoAliensLeft; + +} + +/** + * let player explode + */ +void playerExplode(){ + playerExplosionDisplay(player.posX, player.posY); + playerDisplay(player.posX, player.posY); +} diff --git a/player.h b/player.h new file mode 100644 index 0000000..b48701c --- /dev/null +++ b/player.h @@ -0,0 +1,55 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#ifndef PLAYER +#define PLAYER + +#include "view.h" + + +void playerReset(); + +void playerMoveLeft(); +void playerMoveRight(); +void playerTurboOn(); +void playerTurboOff(); +int playerHitCheck(int hostileShotX, int hostileShotY); +void playerLaunchMissile(); +int playerMoveMissile(); +void playerExplode(); + +// methods that handle graphic display, from view.c +extern void playerInit(); +extern void playerDisplay(int x, int y); +extern void playerClear(int x, int y); +extern void playerMissileInit(); +extern void playerMissileDisplay(int x, int y); +extern void playerMissileClear(int x, int y); +extern void playerExplosionDisplay(int x, int y); +extern void bunkersClearElement(int x, int y); + +extern void doScoring(int alienType); + +#endif + diff --git a/ufo.c b/ufo.c new file mode 100644 index 0000000..928872b --- /dev/null +++ b/ufo.c @@ -0,0 +1,101 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include "ufo.h" +#include "aliens.h" +#include "nInvaders.h" + +static int fShowUfo = 0; + +/** + * initialize ufo attributes + */ +void ufoReset() +{ + ufoClear(ufo.posX, ufo.posY); // clear old position of player + + fShowUfo = 0; // do not show ufo + ufo.posY = UFOPOSY; // set vertical Position + ufo.posX = SCREENWIDTH - UFOWIDTH;// set horizontal Position +} + +/** + * move ufo horizontally to position posX + */ +static void ufoMove(int posX) +{ + ufoClear(ufo.posX, ufo.posY); // clear sprite + ufo.posX = posX; + ufoRefresh(); + ufoDisplay(ufo.posX, ufo.posY); +} + + +/** + * move ufo and check if it reached the left screen border + */ +void ufoMoveLeft() +{ + // check if space between ufo and screen border is big enough + if (ufo.posX > 1) { + // desired movement is possible + ufoMove(ufo.posX - 1); + } else { + ufoReset(); + } +} + +/** + * check if the first screen line is free for the ufo and + * display it randomly + */ +int ufoShowUfo() +{ + if (aliens.posY > 0 && fShowUfo == 0) { // aliens one line down + if ((random() % 200) == 0) { + fShowUfo = 1; + } + } + + return fShowUfo; +} + +/** + * check if ufo was hit by player and delete it from screen + */ +int ufoHitCheck(int shotX, int shotY) +{ + int fUfoWasHit = 0; + + // if shot reached vertikal position of ufo + if (shotY == UFOPOSY) { + // if shot hits ufo + if (shotX >= ufo.posX && shotX <= ufo.posX + UFOWIDTH -1) { + ufoReset(); + fUfoWasHit = 1; + } + } + + return fUfoWasHit; +} diff --git a/ufo.h b/ufo.h new file mode 100644 index 0000000..60dc493 --- /dev/null +++ b/ufo.h @@ -0,0 +1,49 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include "view.h" + +#ifndef UFO +#define UFO + +typedef struct Ufo Ufo; + +struct Ufo { + int posX; // horizontal position of aliens + int posY; // vertical position of aliens +}; + +Ufo ufo; + +void ufoReset(); +int ufoShowUfo(); +void ufoMoveLeft(); +int ufoHitCheck(int shotX, int shotY); + +// methods that handle graphic display, from view.c +extern void ufoDisplay(int x, int y); +extern void ufoRefresh(); +extern void ufoClear(int x, int y); + +#endif diff --git a/view.c b/view.c new file mode 100644 index 0000000..aa75a6d --- /dev/null +++ b/view.c @@ -0,0 +1,589 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include "view.h" +#include "globals.h" +#include +#include +#include + +#define RED 1 +#define GREEN 2 +#define YELLOW 3 +#define BLUE 4 +#define CYAN 5 +#define MAGENTA 6 +#define WHITE 7 + +WINDOW *wBattleField; +WINDOW *wEmpty; +WINDOW *wScores; + +WINDOW *wPlayer; +WINDOW *wPlayerMissile; +WINDOW *wAliens; +WINDOW *wAliensMissile; +WINDOW *wBunkers; +WINDOW *wGameOver; +WINDOW *wUfo; +WINDOW *wStatus; +WINDOW *wTitleScreen; + +/** + * initialize player sprites + */ +static void playerInit() +{ + wPlayer = newpad(1, PLAYERWIDTH); // new pad with appropriate size + wclear(wPlayer); // clear pad + wattrset(wPlayer,COLOR_PAIR(YELLOW)); // set color + waddstr(wPlayer,"/-^-\\"); // set sprite +} + + +/** + * display player sprite + */ +void playerDisplay(int x, int y) +{ + copywin(wPlayer,wBattleField,0,0,y,x,y,x+PLAYERWIDTH-1,0); +} + + +/** + * clear player sprite + */ +void playerClear(int x, int y) +{ + copywin(wEmpty,wBattleField,0,0,y,x,y,x+PLAYERWIDTH-1,0); +} + + +/** + * initialize missile sprites + */ +static void playerMissileInit() +{ + wPlayerMissile = newpad(1, 1); // new pad with appropriate size + wclear(wPlayerMissile); // clear pad + wattrset(wPlayerMissile,COLOR_PAIR(WHITE)); // set color + waddch(wPlayerMissile,'!'); // set sprite + wrefresh(wPlayerMissile); +} + + +/** + * display missile sprite + */ +void playerMissileDisplay(int x, int y) +{ + copywin(wPlayerMissile,wBattleField,0,0,y,x,y,x,0); +} + + +/** + * clear missile sprite + */ +void playerMissileClear(int x, int y) +{ + copywin(wEmpty,wBattleField,0,0,y,x,y,x,0); +} + + +/** + * some explosion animation + */ +void playerExplosionDisplay(int x, int y) +{ + WINDOW* wPlayerExplosion; + char playerExplosionChars[16+1]="@~`.,^#*-_=\\/%{}"; + int t,s; + + wPlayerExplosion=newpad(1,PLAYERWIDTH); // new pad + wattrset(wPlayerExplosion,COLOR_PAIR(YELLOW)); // set color + + for(t=0;t<5;t++){ // 5 frames + wclear(wPlayerExplosion); // clear pad + for(s=0;s", "_x_", "*^*", "\\_/", "o o"}, + {".-.", "-O_", "/o\\", "o-o", "", "-x-", "o^o", "/~\\", "oo "} + }; + int colors[9] = {RED, GREEN, BLUE, RED, YELLOW, WHITE, WHITE, YELLOW, RED}; + + wclear(wAliens); // clear pad + wattrset(wAliens,COLOR_PAIR(RED)); // set color + + frame++; // next frame + + // draw alien if there is one + for (row = 0; row < ALIENS_MAX_NUMBER_Y*2; row++) { + for (k = 0; k < ALIENS_MAX_NUMBER_X; k++) { + if ((row % 2) == 0) { // display aliens every even row + alienType = *(pAliens + c * (ALIENS_MAX_NUMBER_X) + k); // get type of alien //alienBlock[c][k] + + if (alienType != 0) { // if there is an alien to display + wattrset(wAliens,COLOR_PAIR(colors[alienType-1])); // set color + waddch(wAliens,ships[frame%2][alienType-1+(3*((level-1)%3))][0]); // set char1 + waddch(wAliens,ships[frame%2][alienType-1+(3*((level-1)%3))][1]); // set char2 + waddch(wAliens,ships[frame%2][alienType-1+(3*((level-1)%3))][2]); // set char3 + if (alienType > 4) { + *(pAliens + c * ALIENS_MAX_NUMBER_X + k) = (alienType + 1) % 9; + } // todo: what's that? If alien_type > 4 then do a modulo operation??? + } else { + waddstr(wAliens," "); // no alien + } + + } else { + waddstr(wAliens," "); // no aliens at odd rows + } + } + if ((row % 2) == 1) {c++;} // goto next row at alienblock + } +} + + +/** + * initialize bunkers sprites + */ +static void bunkersInit() +{ + wBunkers = newpad(BUNKERHEIGHT, BUNKERWIDTH); // new pad data + wclear(wBunkers); +} + + +/** + * display bunkers sprite + * needs pointer to bunker-array + */ +void bunkersDisplay(int *pBunker) +{ + int l, k; + wclear(wBunkers); + wattrset(wBunkers,COLOR_PAIR(CYAN)); + for (l=0;l", "", "", "< oo>"}; + static int frame = 0; + + wclear(wUfo); + wattrset(wUfo, COLOR_PAIR(MAGENTA)); + waddstr(wUfo, ufo[frame % 4]); + + frame++; +} + + +/** + * initialize ufo sprite + */ +static void ufoInit() +{ + wUfo = newpad(1, UFOWIDTH); // new pad with appropriate size + wclear(wUfo); // clear pad + wattrset(wUfo, COLOR_PAIR(MAGENTA)); // set color +} + + +/** + * display ufo sprite + */ +void ufoDisplay(int x, int y) +{ + copywin(wUfo, wBattleField, 0, 0, y, x, y, x + UFOWIDTH - 1, 0); +} + + +/** + * clear ufo sprite + */ +void ufoClear(int x, int y) +{ + copywin(wEmpty, wBattleField, 0, 0, y, x, y, x + UFOWIDTH - 1, 0); +} + + +/** + * initialize gameover graphic + */ +static void gameOverInit() +{ + // init game-over banner + wGameOver = newpad(13, 31); + wclear(wGameOver); + wattrset(wGameOver, COLOR_PAIR(WHITE)); + waddstr(wGameOver, " "); + waddstr(wGameOver, " ##### #### ## ## ###### "); + waddstr(wGameOver, " ## ## ## ####### ## "); + waddstr(wGameOver, " ## ### ###### ## # ## ##### "); + waddstr(wGameOver, " ## ## ## ## ## ## ## "); + waddstr(wGameOver, " ##### ## ## ## ## ###### "); + waddstr(wGameOver, " "); + waddstr(wGameOver, " #### ## ## ###### ###### "); + waddstr(wGameOver, " ## ## ## ## ## ## ## "); + waddstr(wGameOver, " ## ## ## ## ##### ###### "); + waddstr(wGameOver, " ## ## ## ## ## ## ## "); + waddstr(wGameOver, " #### ### ###### ## ## "); + waddstr(wGameOver, " "); +} + +/** + * display game over graphic + */ +void gameOverDisplay() +{ + int x = (SCREENWIDTH / 2) - (31 / 2); + int y = (SCREENHEIGHT / 2) - (13 / 2); + copywin(wGameOver, wBattleField, 0, 0, y, x, y + 12, x + 30, 0); + wrefresh(wBattleField); +} + + +/** + * initialize title screen + */ +static void titleScreenInit() +{ + wTitleScreen = newpad(SCREENHEIGHT, SCREENWIDTH); + wclear(wTitleScreen); +} + + +/** + * display title screen + */ +void titleScreenDisplay() +{ + static int frame = 0; + int x, y; + int i; + WINDOW *wTitleText; + WINDOW *wAliens; + WINDOW *wStartText; + char ufo[4][6] = {"", "", "", "< oo>"}; + char aliens[2][9][3+1] = { + {",^,", "_O-", "-o-", "o=o", "", "_x_", "*^*", "\\_/", "o o"}, + {".-.", "-O_", "/o\\", "o-o", "", "-x-", "o^o", "/~\\", "oo "} + }; + int score[3] = {200, 150, 100}; + int colors[9] = {RED, GREEN, BLUE, RED, GREEN, BLUE, RED, GREEN, BLUE}; + char buffer[12]; + static int alien_type = 0; + + wTitleText = newpad(4, 41); + wclear(wTitleText); + wattrset(wTitleText, COLOR_PAIR(YELLOW)); + waddstr(wTitleText, " ____ __ "); + waddstr(wTitleText, " ___ / _/__ _ _____ ___/ /__ _______"); + waddstr(wTitleText, " / _ \\_/ // _ \\ |/ / _ `/ _ / -_) __(_-<"); + waddstr(wTitleText, "/_//_/___/_//_/___/\\_,_/\\_,_/\\__/_/ /___/"); + + frame++; + wAliens = newpad(7, 11); + wclear(wAliens); + snprintf(buffer, sizeof(buffer),"%s = 500", ufo[frame % 4]); + wattrset(wAliens, COLOR_PAIR(MAGENTA)); + waddstr(wAliens, buffer); + if ((frame = frame % 60) == 0) { + alien_type = 0; + } else if (frame == 20) { + alien_type = 3; + } else if (frame == 40) { + alien_type = 6; + } + for (i = alien_type; i < alien_type + 3; i++) { + waddstr(wAliens, " "); + snprintf(buffer, sizeof(buffer), "%s = %d", aliens[frame % 2][i], score[i % 3]); + wattrset(wAliens, COLOR_PAIR(colors[i])); + waddstr(wAliens, buffer); + } + + wStartText = newpad(1, 20); + wclear(wStartText); + wattrset(wStartText, COLOR_PAIR(RED)); + waddstr(wStartText, "Press SPACE to start"); + + x = (SCREENWIDTH / 2) - (41 / 2); + y = 0; + copywin(wTitleText, wTitleScreen, 0, 0, y, x, y + 3, x + 40, 0); + + x = (SCREENWIDTH / 2) - (11 / 2); + y = 8; + copywin(wAliens, wTitleScreen, 0, 0, y, x , y + 6, x + 10, 0); + + x = (SCREENWIDTH / 2) - (20 / 2); + y = SCREENHEIGHT - 2; + copywin(wStartText, wTitleScreen, 0, 0, y, x, y, x + 19, 0); + + copywin(wTitleScreen, wBattleField, 0, 0, 0, 0, SCREENHEIGHT-1, SCREENWIDTH-1, 0); + + wrefresh(wBattleField); +} + + +/** + * clear title screen + */ +void titleScreenClear() +{ + battleFieldClear(); +} + + +/** + * initialize scores + */ +void statusInit() +{ + wStatus = newpad(1, 55); + wclear(wStatus); +} + + +/** + * display scores + */ +void statusDisplay(int level, int score, int lives) +{ + int t, xOffset; + char strStatus[55]; + // "Level: 01 Score: 0001450 Lives: /-\ /-\ /-\ /-\ /-\ " + // "1234567890123456789012345678901234567890123456789012" + + + xOffset = (SCREENWIDTH / 2) - 24; + + + + sprintf (strStatus, "Level: %2.2d Score: %2.7d Lives: ", level, score); + + wclear(wStatus); + wattrset(wStatus, COLOR_PAIR(RED)); + waddstr(wStatus, strStatus); + + // show maximal five lives + for (t = 1; ((t <= 5) && (t < lives)); t++){ + waddstr(wStatus, "/-\\ "); + } + + copywin(wStatus, wBattleField, 0, 0, SCREENHEIGHT-1, xOffset, SCREENHEIGHT-1, xOffset + 54, 0); + + +} + + +/** + * initialize battlefield + */ +static void battleFieldInit() +{ + wEmpty = newpad(SCREENHEIGHT, SCREENWIDTH); + wclear(wEmpty); + + wBattleField = newwin(SCREENHEIGHT, SCREENWIDTH, 0, 0); // new window + wclear(wBattleField); // clear window + mvwin(wBattleField, 0, 0); // move window +} + + +/** + * clear battlefield + */ +void battleFieldClear() +{ + copywin(wEmpty,wBattleField,0,0,0,0,SCREENHEIGHT-1,SCREENWIDTH-1,0); +} + + +/** + * refresh screen so that modified graphic buffers get visible + */ +void refreshScreen() +{ + redrawwin(wBattleField); // needed to display graphics properly at startup on some terminals + wrefresh(wBattleField); + +} + + +/** + * do proper cleanup + */ +static void finish(int sig) +{ + endwin(); // reset terminal into proper non-visual mode + exit(0); +} + + +/** + * initialize n_courses + */ +void graphicEngineInit() +{ + (void) signal(SIGINT, finish); // on signal "SIGINT" call method "finish" + (void) initscr(); // do initialization work + keypad(stdscr, TRUE); // enable keypad for input + (void) nonl(); // disable translation return/ newline for detection of return key + (void) cbreak(); // do not buffer typed characters, use at once + (void) noecho(); // do not echo typed characters + start_color(); // use colors + init_pair(RED, COLOR_RED, COLOR_BLACK); // define color-pair + init_pair(GREEN, COLOR_GREEN, COLOR_BLACK); // define color-pair + init_pair(YELLOW, COLOR_YELLOW, COLOR_BLACK); // define color-pair + init_pair(BLUE, COLOR_BLUE, COLOR_BLACK); // define color-pair + init_pair(CYAN, COLOR_CYAN, COLOR_BLACK); // define color-pair + init_pair(MAGENTA, COLOR_MAGENTA, COLOR_BLACK); // define color-pair + init_pair(WHITE, COLOR_WHITE, COLOR_BLACK); // define color-pair + + //timeout(0); // do not wait for input + + // initialize sprites + battleFieldInit(); + playerInit(); + playerMissileInit(); + aliensInit(); + aliensMissileInit(); + bunkersInit(); + ufoInit(); + gameOverInit(); + statusInit(); + titleScreenInit(); +} + diff --git a/view.h b/view.h new file mode 100644 index 0000000..873585a --- /dev/null +++ b/view.h @@ -0,0 +1,78 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include +#include +#include + +#ifndef VIEW +#define VIEW + +#include "globals.h" + +#define SCREENHEIGHT 24 +#define SCREENWIDTH 80 + +#define PLAYERWIDTH 5 +#define PLAYERPOSY (SCREENHEIGHT-2) + +#define BUNKERWIDTH 80 +#define BUNKERHEIGHT 4 +#define BUNKERX 0 +#define BUNKERY (SCREENHEIGHT-8) + +#define ALIENS_MAX_NUMBER_X 10 +#define ALIENS_MAX_NUMBER_Y 5 + +#define UFOWIDTH 5 +#define UFOPOSY 0 + + +void graphicEngineInit(); + +void aliensClear(int x, int y, int wid, int hgt); +void aliensDisplay(int x, int y, int wid, int hgt); +void aliensMissileClear(int x, int y); +void aliensMissileDisplay(int x, int y); +void aliensRefresh(int level, int *pAliens); +void battleFieldClear(); +void bunkersClear(); +void bunkersClearElement(int x, int y); +void bunkersDisplay(int *pBunker); +void gameOverDisplay(); +void playerClear(int x, int y); +void playerDisplay(int x, int y); +void playerExplosionDisplay(int x, int y); +void playerMissileClear(int x, int y); +void playerMissileDisplay(int x, int y); +void titleScreenClear(); +void titleScreenDisplay(); +void ufoClear(int x, int y); +void ufoDisplay(int x, int y); +void ufoRefresh(); + +void statusDisplay(int level, int score, int lives); +void refreshScreen(); + +#endif -- 2.9.0