home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!zephyr.ens.tek.com!master!saab!billr
- From: billr@saab.CNA.TEK.COM (Bill Randle)
- Newsgroups: comp.sources.games
- Subject: v13i087: perp - a multiscreen diamond collection game, Part01/01
- Message-ID: <2893@master.CNA.TEK.COM>
- Date: 14 May 92 01:08:10 GMT
- Sender: news@master.CNA.TEK.COM
- Lines: 1492
- Approved: billr@saab.CNA.TEK.COM
-
- Submitted-by: James Bonfield <rince@dcs.warwick.ac.uk>
- Posting-number: Volume 13, Issue 87
- Archive-name: perp/Part01
- Environment: curses
-
- [From the author...]
- [[This is a simple game I knocked up over a year ago. It's not exactly 100%
- finished (it hasn't a high score table etc), but it is functional. It was the
- game that I originally wrote before doing the obfuscated one. (That is also
- included).]]
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: README MANIFEST Makefile expand_spr map obfus.c perp.6
- # perp.c perp.h shrink_spr spr.expand
- # Wrapped by billr@saab on Wed May 13 18:05:44 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(1462 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XUsages:
- X perp [level_number]
- X
- X expand_spr < sprite_file > expanded_file
- X
- X shrink_spr < expanded_file > sprite_file
- X
- X
- XThis is the game of 'perp' written by James 'Rince' Bonfield.
- X
- XThe original idea was taken from the game of Perplexity on the BBC micro.
- XAlthough the game play is somewhat different from this. There is currently
- Xonly one screen in existance. This screen was also designed by James Bonfield.
- X
- XIf you like the game and design a few screens then I'd be interesting in
- Xseeing and playing them. (Mail them to rince@dcs.warwick.ac.uk). The map file
- Xformat is simple. It simply consists of 34x32 sized screens. Each character
- Xrepresents a sprite in the sprite file.
- X
- Xd = diamonds
- Xo = crushable boulders
- XO = non crushable boulders
- Xh,j,k,l = keys to open the locks
- XH,J,K,L = the locks
- Xspace = blank space - ie you can walk/push over it
- Xanything else is classed as a piece wall.
- X
- XThe sprite file is a stream of characters representing 128 sprites, each of 18
- Xcharacters long (6x3). To make this file into a more understandable and
- Xreadable format use the expand_spr utility ; edit the expanded file; and
- Xshrink with the shrink_spr util.
- X
- XYou may redistribute and modify any of this source provided that my name is
- Xstill mentioned in connection with the pieces of code I have written.
- X
- XPS.
- X
- XThe programming in this game is BAD! It was one of the first C programs I
- Xwrote ages ago. Please don't assume all my code is like this.. It isn't you
- Xknow - honest!
- END_OF_FILE
- if test 1462 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(455 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1 This shipping list
- X Makefile 1
- X README 1
- X expand_spr 1
- X map 1
- X obfus.c 1
- X perp.6 1
- X perp.c 1
- X perp.h 1
- X shrink_spr 1
- X spr.expand 1
- END_OF_FILE
- if test 455 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(963 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# compiler flags
- XCC = gcc
- XCFLAGS = -O
- XLDFLAGS = -s
- XLIBS = -lcurses -ltermcap
- X
- X# directories
- XBINDIR = /dcs/89/rince/open/bin.$(ARCH)
- XLIBDIR = /dcs/89/rince/open/lib/perp
- XMANDIR = /dcs/89/rince/open/man
- X
- X# files
- XMAPFILE = map
- XSPRFILE = spr
- X
- XDEFS = -DMAPFILE=\"$(LIBDIR)/$(MAPFILE)\"\
- X -DSPRFILE=\"$(LIBDIR)/$(SPRFILE)\"
- X
- Xperp: perp.c perp.h
- X $(CC) $(CFLAGS) $(DEFS) $(LDFLAGS) $@.c -o $@ $(LIBS)
- X
- Xobfus: obfus.c
- X $(CC) -O -s obfus.c -o obfus -lcurses -ltermcap
- X
- Xspr: spr.expand
- X shrink_spr < spr.expand > spr
- X
- Xperp.c: perp.h
- X
- Xinstall: perp perp.6 spr
- X # the game
- X -mkdir -p $(BINDIR)
- X chmod a+xr $(BINDIR)
- X -cp perp $(BINDIR)
- X chmod a+x $(BINDIR)/perp
- X
- X # the data files
- X -mkdir -p $(LIBDIR)
- X chmod a+xr $(LIBDIR)
- X -cp $(MAPFILE) $(SPRFILE) $(LIBDIR)
- X chmod a+r $(LIBDIR)/$(MAPFILE) $(LIBDIR)/$(SPRFILE)
- X
- X # the man page
- X -mkdir -p $(MANDIR)/man6
- X chmod a+xr $(MANDIR)/man6
- X -cp perp.6 $(MANDIR)/man6
- X chmod a+r $(MANDIR)/man6/perp.6
- X
- Xclean:
- X -rm perp spr *~
- END_OF_FILE
- if test 963 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'expand_spr' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'expand_spr'\"
- else
- echo shar: Extracting \"'expand_spr'\" \(64 characters\)
- sed "s/^X//" >'expand_spr' <<'END_OF_FILE'
- X#!/bin/sed -f
- Xs/\(......\)\(......\)\(......\)/\1\
- X\2\
- X\3\
- X\
- X/g
- END_OF_FILE
- if test 64 -ne `wc -c <'expand_spr'`; then
- echo shar: \"'expand_spr'\" unpacked with wrong size!
- fi
- chmod +x 'expand_spr'
- # end of 'expand_spr'
- fi
- if test -f 'map' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'map'\"
- else
- echo shar: Extracting \"'map'\" \(2240 characters\)
- sed "s/^X//" >'map' <<'END_OF_FILE'
- X5222225225222222222222225522222255
- X6 U o|Oooooooooooooo43 o oOo45
- X5] o o | O 7883 OoO 45
- X6 O0k[]l | ooD Doo oo453OOO 45
- X6 OO 4===3 1==8=853 O D o45
- X6 0oOOo | | 43 O O 73 45
- X6O o D O | 789 79 4=3OOO O73 o15
- X6 lDo4]o[3 123K46 | O 73 O 4
- X6 d4=3 L 13 Uo o O 73 O 4
- X6 jU 7=9 79 L o O73 O oD 4
- X6 |o| 46JJ79 Do o 73 O oJ|o4
- X5======6o| 13io13 | 73 O oD |o4
- X6odoood|d| 4==83 O oJ| |o4
- X6dooodo|d4==9 7==83 | oD | |d4
- X6odoood|o| U U | | L| | |o4
- X6od7===3o| j j j | D 1===9oUoUo|d4
- X6doUo | | | o oU o |d4
- X6dd oDdD 1==]J7==3 Uo0oo D |d4
- X5==]K1=3 j | o 19 l|d4
- X6odo Ddood| o 19 |o4
- X5==9 [===2=8==2===8==9 D d19k|o4
- X6do| | o o | Uk1] 186d4
- X6ooU DK[=] Uj 0 D |h Dd d16d4
- X6 U H hhU |odDKDk19 185
- X6oo H 7==9k0d | o|d| o19d d15
- X5==88=]J|o | o0 73 o| |o d19 4
- X6dd16oo |o 489ddo| | U k 19 4
- X6 Od1=] U o1259do| d| 4] 4
- X6 o H 12==3o | D 0K[3 4
- X6 oo7] 0O O O O o|dUl L o4
- X6d |ooooO oD O | D Dd4
- X5888588888885888888885888858888585
- X##################################
- X#oooddodddOddOdoodddododddddodo###
- X#dOddddoodddddodoooddOOOooodood###
- X#oooddOOOooooodododdddoOddOOdod###
- X#oddddddddoodoodododdOodoododdd###
- X#oOodoodddddddooOooOddOoddddddo###
- X#oodOddddododoOdooddooodddddodO###
- X#OoddooddOoddddodOdooddOOdoodoo###
- X#odoOOdoododOddoodOddodOdodoOOd###
- X#doOodddoddodOdodoOoddodoodddod###
- X#dddoodOododdddoddoOdddoddddooO###
- X#OooOodddddddooOOdddddodOddoddo###
- X#doddodOddodoodoooooddddOddoood###
- X#oOooooOOooOododdOOodOOOdoodddO###
- X#OOodooodoOdoOOoooddOddOdoOoddd###
- X#OddddddddodoOOddoddodooddoodod###
- X#doddddooooooddddOoddddddOddodd###
- X#doododdddOdoOOddddodddddddddoO###
- X#oddoodooododOdddddddddddddddod###
- X#oOOOOddoodoOoddooOOdoOdodoOddd###
- X#ododdoOOOddooOoodddoddoOodoodd###
- X#odododdodoiddddddodoOododddodo###
- X#oododooOodOOododooododoOoddddd###
- X#dodddOdddOddddddddoddOOdddoOod###
- X#ddodooooOoddddddOdodddoddooddd###
- X#oOdodddddOddddddodddooOddOOOdd###
- X#dooddoodododoooddddOodddoooOod###
- X#ddoOodddddoddooododdodoOoooood###
- X#OOddooOdoOddodooOdoOOOOodOdddo###
- X#OoddodddododoodoOooOddOooOdddd###
- X#ooddddOOodoOdoOddOdoodododoOOO###
- X##################################
- END_OF_FILE
- if test 2240 -ne `wc -c <'map'`; then
- echo shar: \"'map'\" unpacked with wrong size!
- fi
- # end of 'map'
- fi
- if test -f 'obfus.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'obfus.c'\"
- else
- echo shar: Extracting \"'obfus.c'\" \(1531 characters\)
- sed "s/^X//" >'obfus.c' <<'END_OF_FILE'
- X#include <curses.h>
- X#define R break
- X#define U M[h][f]
- X#define W M[g][e]
- X#define T M[y][x]
- X#define B(a) "A"#a"A",
- X#define A "AAAAAAAAAAAAAAAAAAAAAA"
- X#define z(a) case a:if(U=='B')U=W,x=e,y=g,u--;
- X#define Z(a,b) else if(U==a&&d==b)U=W='B';R;
- X#define K(a) a##a##a
- X#define k(a) #a#a#a#a#a#a"\0"
- X#define V " \0"
- X#define S " \0/----\\\0_/ \\_"
- Xint u=484,X[]={-1,0,0,1},Y[]={0,1,-1,0},x,y,D,i,j,a;char o,m,*t,*O="MNOH"
- X,*k="hjkl",*s=K(k(#))V V V" ___ \0 / \\\0 \\___/\0 ___ \0 /@@@\\\0 \
- X\\@@@/\0| | /\\\0----||\0 \\/\0 /--\\\0 \\/ \0 ==| \0 ==| \0 \
- X /\\ \0 \\--/\0 /O__o\0 \\___/\0 /_\\_ \0"K(" << \0")V k(v)V V k(^)V
- X" /\\ \0 < > \0 \\/ \0o__O\\ \0\\___/ \0 _/_\\ \0 O__O"S"\0 ^__^"S,
- XM[12][22]={A,B(LCABBBBBBBABBCBBCABB)B(CCABAKAAABAFBABABAEB
- X)B(BBBBABBIBBBBBEEABACL)B(CCBNIBBAAAAGALBBBABC)B(AAAAAAJACBABBCABAABC
- X)B(LLAACCBACBAAALLCABBB)B(BDLAAABABCAAAALCABBL)B(BCBIBBBBBBBBAAAAACBB
- X)B(BCCAABBADBBBBDBDBDBC)B(LBBACCCCDBCABBBDBBBB)A};main(){initscr();clear();
- Xnoecho();cbreak();x=y=4;D=39,o='M';m=T;while(D&&u){for(i=j=a=0;j<7;!(mvaddstr(
- Xj*3+a,i*6,s+(((M[((y-1)/5)*5+j][((x-1)/10)*10+i]-'A')*3+a++)*7)),a^3)&&(a=0,!
- X(++i^12))&&(a=i=0,j++));refresh();T='B';if(t=(char*)strchr(k,getch())){int e=
- Xx,g=y,f=x,h=y,d=t-k;o=O[d];f=(e=x+X[d])+d[X];h=(g=y+Y[d])+d[Y];switch(W){case
- X'B':x=e;y=g,u--;R;z('C')else if(U=='C')U=W='L';R;z('D')R;case'L':x=e;y=g,u--;D
- X--;R;z('E')Z('I',0)z('F')Z('J',1)z('G')Z('K',2)}}m=T;T=o;}clear();mvaddstr(12
- X,31,u?"Well done!":"Too many moves");move(23,0);refresh();endwin();return 0;}
- END_OF_FILE
- if test 1531 -ne `wc -c <'obfus.c'`; then
- echo shar: \"'obfus.c'\" unpacked with wrong size!
- fi
- # end of 'obfus.c'
- fi
- if test -f 'perp.6' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'perp.6'\"
- else
- echo shar: Extracting \"'perp.6'\" \(2046 characters\)
- sed "s/^X//" >'perp.6' <<'END_OF_FILE'
- X.TH PERP 6 "9th April 1992"
- X.SH NAME
- Xperp \- a multiscreen diamond collection game
- X.SH SYNOPSIS
- X.I perp
- X[ level_num ]
- X.SH DESCRIPTION
- XThe idea of
- X.I perp
- Xis to collect all the diamonds necessary to advance to the next level. Having
- Xdone this you will be presented with a small end of level screen, and the new
- Xscreen.
- X.sp
- XDiamonds can be found either lying around, or manufactured from crushing
- Xthe lighter coloured boulders together. The darker @-filled bolders cannot be
- Xcrushed into diamonds, only moved around.
- X.sp
- XTo move around use the h,j,k and l keys.
- X.br
- XThere is a save and load feature which can be invoked using S and L keys. The
- Xsave file is $HOME/cod.save. (This is one of the less buggy features of the
- Xgame - so please make good use of it)
- X.br
- XTo quit and restart a level, press 'q'. To redraw the screen, press control L.
- XTo exit the game press control C (or interrupt).
- X.SH OPTIONS
- X.I
- Xperp \fBlevel_num\fP
- X.PP
- XThe start level is level number 0. To start on another level simply state the
- Xnumber as the first (and only) argument to
- X.I perp.
- X.SH FILES
- XFiles are used for the sprites and the map data. These are by default
- X.I LIBDIR/map
- Xand
- X.I LIBDIR/spr
- Xwhere LIBDIR is usually /usr/games/lib/perp.
- X.SH AUTHOR
- X.I perp
- Xwas written by James 'Rince' Bonfield.
- X.SH BUGS
- XThere are quite likely to be thousands of bugs. However, the author wishes to
- Xstress that the game is not likely to be updated and corrected any more than
- Xit's current state. Feel free to fix things yourself :-)
- X.sp
- XThere are no checks on which levels exist. If you attempt to start on a non
- Xexistant level then the game will simply go loopy. This will also happen upon
- Xfinishing the last level.
- X.sp
- XAlso, the level argument can be supplied as a
- Xnegative number. This, also understandably causes a few worried looks from the
- Xprogram. If you try harder then it'll probably just have a nervouse breakdown
- Xand burst into tears with a segmentation fault.
- X.sp
- XVery little (in fact none) integrity checking is done on the map and sprite
- Xdata files read in by the game.
- END_OF_FILE
- if test 2046 -ne `wc -c <'perp.6'`; then
- echo shar: \"'perp.6'\" unpacked with wrong size!
- fi
- # end of 'perp.6'
- fi
- if test -f 'perp.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'perp.c'\"
- else
- echo shar: Extracting \"'perp.c'\" \(10088 characters\)
- sed "s/^X//" >'perp.c' <<'END_OF_FILE'
- X/*
- X * Perp
- X *
- X * Written by James 'Rince' Bonfield
- X *
- X */
- X
- X#include <stdlib.h>
- X#include <stdio.h>
- X#include <signal.h>
- X#include <curses.h>
- X#include <errno.h>
- X#include <fcntl.h>
- X#include <string.h>
- X#include <memory.h>
- X#include "perp.h"
- X
- Xchar code[] = "abhds87\013as\333ashj";
- Xchar allmap[HEIGHT][MX];
- Xchar map[MY][MX];
- Xchar spr[128][YSPRSZ][XSPRSZ];
- X
- Xint x,y,dleft,score = 0,bleft = 0,level = 0,moves = 0;
- Xchar you,*home;
- X
- XWINDOW *win,*statwin;
- X
- Xint main(ac,av)
- X int ac;
- X char **av;
- X{
- X char ch,mapch;
- X int a,b,stscore;
- X
- X if (ac == 2)
- X level = atoi(av[1]);
- X signal(SIGINT,cleanup);
- X if ((home=getenv("HOME")) == (char *)0) {
- X puts("Cannot get HOME environment variable");
- X exit(1);
- X }
- X read_map();
- X read_spr();
- X /* Initialise and clear screen */
- X initscr();
- X clear();
- X noecho();
- X cbreak();
- X /* main loop */
- X
- X stscore = score;
- X loop:
- X mapcpy(level);
- X startxy();
- X calc_diamonds();
- X init_display();
- X you = 'i';
- X mapch = map[y][x];
- X map[y][x] = 'i';
- X drawmap(((y-1)/5)*5,((x-1)&-8));
- X wrefresh(win);
- X wrefresh(statwin);
- X while (dleft) {
- X map[y][x] = ' ';
- X switch((read(0,&ch,1),ch)) {
- X case 'h':
- X move_dir(0);
- X break;
- X case 'l':
- X move_dir(3);
- X break;
- X case 'k':
- X move_dir(2);
- X break;
- X case 'j':
- X move_dir(1);
- X break;
- X case 'q':
- X for (a=0;a<33;a+=2) {
- X for (b=0;b<23;b++) {
- X mvwaddstr(win,b,28+a," >");
- X mvwaddstr(win,b,28-a,"< ");
- X }
- X wrefresh(win);
- X }
- X wclear(win);
- X wrefresh(win);
- X score = stscore;
- X goto loop;
- X case 'S':
- X moves++;
- X do_save();
- X break;
- X case 'L':
- X do_load();
- X moves++;
- X draw_status();
- X wrefresh(statwin);
- X break;
- X case '\014':
- X /* Kludge of the century - clearok() doesn't work for
- X * screens other than stdscr - so.... :-)
- X */
- X clear();
- X wclear(statwin);
- X wclear(win);
- X wrefresh(win);
- X drawmap(((y-1)/5)*5,((x-1)&-8));
- X draw_status();
- X draw_start();
- X refresh();
- X wrefresh(win);
- X wrefresh(statwin);
- X }
- X mapch = map[y][x];
- X map[y][x] = you;
- X drawmap(((y-1)/5)*5,((x-1)&-8));
- X wrefresh(win);
- X }
- X level ++;
- X end_scr();
- X stscore = score;
- X goto loop;
- X}
- X
- Xvoid init_display() {
- X int i;
- X draw_start();
- X refresh();
- X win = newwin(YSCRSZ*YSPRSZ,XSCRSZ*XSPRSZ,2,1);
- X statwin = newwin(YSCRSZ*YSPRSZ,76-XSCRSZ*XSPRSZ,2,XSCRSZ*XSPRSZ+2);
- X
- X draw_status();
- X wrefresh(statwin);
- X}
- X
- Xvoid draw_start() {
- X int i;
- X for (i=1; i<23; i++) {
- X mvaddch(i,61,'|');
- X mvaddch(i,0,'|');
- X mvaddch(i,79,'|');
- X }
- X mvaddstr(1,0,"+------------------------------------------------------------+-----------------+");
- X mvaddstr(23,0,"+------------------------------------------------------------+-----------------");
- X}
- X
- Xvoid draw_status() {
- X char buff[100];
- X drawspr(1,1,'d',statwin);
- X drawspr(5,1,'o',statwin);
- X update_status();
- X mvwaddstr(statwin,14,2,sprintf(buff,"Moves : %6d",moves));
- X mvwaddstr(statwin,15,2," _ ");
- X mvwaddstr(statwin,16,2," /.>_ __ _ ");
- X mvwaddstr(statwin,17,2," /_//.> /_//.>");
- X mvwaddstr(statwin,18,2,"</ \\_></ /_/ ");
- X mvwaddstr(statwin,19,2," </ ");
- X}
- X
- Xvoid read_map() {
- X int fd;
- X char dummy;
- X
- X if ((fd = open(map_file, O_RDONLY)) < 0) {
- X perror(map_file);
- X exit(errno);
- X }
- X read(fd,allmap,MX*HEIGHT);
- X close (fd);
- X}
- X
- Xvoid read_spr() {
- X int fd;
- X
- X if ((fd = open(spr_file, O_RDONLY)) < 0) {
- X perror(spr_file);
- X exit(errno);
- X }
- X read(fd,spr,128*YSPRSZ*XSPRSZ);
- X close (fd);
- X}
- X
- Xvoid move_dir(dir)
- X char dir;
- X{
- X char x1=x,x2=x,y1=y,y2=y;
- X char buff[100];
- X /* dir, left = 0;
- X down = 1;
- X up = 2;
- X right = 3;
- X */
- X switch(dir) {
- X case 0:
- X x1 = x-1;
- X x2 = x-2;
- X you = '<';
- X break;
- X case 1:
- X y1 = y+1;
- X y2 = y+2;
- X you = 'i';
- X break;
- X case 2:
- X y1 = y-1;
- X y2 = y-2;
- X you = '^';
- X break;
- X case 3:
- X x1 = x+1;
- X x2 = x+2;
- X you = '>';
- X break;
- X }
- X /* Map ' ' blank space
- X * 'o' crushable boulder
- X * 'O' uncrushable boulder
- X * 'd' diamond
- X * 'h' left key
- X * 'j' down key
- X * 'k' up key
- X * 'l' right key
- X * 'H' left door
- X * 'J' down door
- X * 'K' up door
- X * 'L' right door
- X */
- X switch(map[y1][x1]) {
- X case ' ':
- X x=x1;y=y1;
- X moves++;
- X break;
- X case 'o':
- X if (map[y2][x2] == ' ') {
- X map[y2][x2] = map[y1][x1];
- X x=x1;y=y1;
- X moves++;
- X }
- X else if (map[y2][x2] == 'o') {
- X map[y2][x2] = map[y1][x1] = 'd';
- X bleft -= 2;
- X score += 5;
- X update_status();
- X }
- X break;
- X case 'O':
- X if (map[y2][x2] == ' ') {
- X map[y2][x2] = map[y1][x1];
- X x=x1;y=y1;
- X moves++;
- X }
- X break;
- X case 'd':
- X x=x1;y=y1;
- X moves++;
- X dleft--;
- X score += 10;
- X update_status();
- X break;
- X case 'h':
- X if (map[y2][x2] == ' ') {
- X map[y2][x2] = map[y1][x1];
- X x=x1;y=y1;
- X moves++;
- X }
- X else if (map[y2][x2] == 'H' && dir == 0) {
- X map[y2][x2] = map[y1][x1] = ' ';
- X score += 5;
- X update_status();
- X }
- X break;
- X case 'j':
- X if (map[y2][x2] == ' ') {
- X map[y2][x2] = map[y1][x1];
- X x=x1;y=y1;
- X moves++;
- X }
- X else if (map[y2][x2] == 'J' && dir == 1) {
- X map[y2][x2] = map[y1][x1] = ' ';
- X score += 5;
- X update_status();
- X }
- X break;
- X case 'k':
- X if (map[y2][x2] == ' ') {
- X map[y2][x2] = map[y1][x1];
- X x=x1;y=y1;
- X moves++;
- X }
- X else if (map[y2][x2] == 'K' && dir == 2) {
- X map[y2][x2] = map[y1][x1] = ' ';
- X score += 5;
- X update_status();
- X }
- X break;
- X case 'l':
- X if (map[y2][x2] == ' ') {
- X map[y2][x2] = map[y1][x1];
- X x=x1;y=y1;
- X moves++;
- X }
- X else if (map[y2][x2] == 'L' && dir == 3) {
- X map[y2][x2] = map[y1][x1] = ' ';
- X score += 5;
- X update_status();
- X }
- X break;
- X }
- X mvwaddstr(statwin,14,2,sprintf(buff,"Moves : %6d",moves));
- X wrefresh(statwin);
- X}
- X
- Xvoid drawmap(y,x)
- X int y,x;
- X{
- X int i,j;
- X for (j=0;j<YSCRSZ;j++)
- X for (i=0;i<XSCRSZ;i++)
- X drawspr(j*YSPRSZ,i*XSPRSZ,map[y+j][x+i],win);
- X}
- X
- Xvoid drawspr(y,x,ch,w)
- X int y,x;
- X char ch;
- X WINDOW *w;
- X{
- X int i,j;
- X
- X for (j=0;j<YSPRSZ;j++)
- X for (i=0;i<XSPRSZ;i++)
- X mvwaddch(w,y+j,x+i,spr[ch][j][i]);
- X}
- X
- Xvoid update_status() {
- X char buff[100];
- X
- X mvwaddstr(statwin,2,9,sprintf(buff,"= %3d",dleft));
- X mvwaddstr(statwin,6,9,sprintf(buff,"= %3d",bleft));
- X mvwaddstr(statwin,10,2,sprintf(buff,"Score : %06d",score));
- X mvwaddstr(statwin,12,2,sprintf(buff,"Level : %6d",level+1));
- X}
- X
- Xvoid cleanup() {
- X nocbreak();
- X echo();
- X move(0,0);
- X clear();
- X refresh();
- X endwin();
- X exit(0);
- X}
- X
- Xvoid calc_diamonds() {
- X int i,j;
- X bleft=dleft=0;
- X for (i=0; i<MX; i++)
- X for (j=0; j<MY; j++) {
- X if (map[j][i] == 'd') dleft++;
- X if (map[j][i] == 'o') dleft++,bleft++;
- X }
- X}
- X
- Xvoid mapcpy(mnum)
- X char mnum;
- X{
- X memcpy(map,allmap[mnum*MY],MY*MX);
- X}
- X
- Xvoid startxy()
- X{
- X int i;
- X char *tmp;
- X
- X for (i=0; i<MY;i++) {
- X if (tmp=strchr(map[i],'i')) {
- X y=i;
- X x=tmp - map[i];
- X }
- X }
- X}
- X
- Xvoid end_scr() {
- X int i,j;
- X char ch;
- X
- X wclear(win);
- X mvwaddstr(win,10,0,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
- X wrefresh(win);
- X mvwaddstr(win,15,16,"/--/ / /----/ /---/ /");
- X wrefresh(win);
- X mvwaddstr(win,14,16,"/ / / / / /");
- X mvwaddstr(win,16,16,"/ / / / / ");
- X wrefresh(win);
- X mvwaddstr(win,13,16,"/----/ /-/-/ /----/ / / /");
- X mvwaddstr(win,17,16,"/ /-/-/ /----/ / / !");
- X wrefresh(win);
- X for (i=-7;i<30;i++) {
- X drawspr(7,i-1,' ',win);
- X drawspr(7,i,'>',win);
- X wrefresh(win);
- X }
- X drawspr(7,i,'i',win);
- X wrefresh(win);
- X sleep(1);
- X mvwaddstr(win,4,19,"/----------\\");
- X mvwaddstr(win,5,19,"|Well Done! \\");
- X mvwaddstr(win,6,19,"\\----------/\\\\");
- X wrefresh(win);
- X sleep(1);
- X drawspr(7,i,'^',win);
- X wrefresh(win);
- X sleep(1);
- X drawspr(7,i,'i',win);
- X wrefresh(win);
- X sleep(1);
- X mvwaddstr(win,4,19," ");
- X mvwaddstr(win,5,19," ");
- X mvwaddstr(win,6,19," ");
- X for (i=30;i<60;i++) {
- X drawspr(7,i-1,' ',win);
- X drawspr(7,i,'>',win);
- X wrefresh(win);
- X }
- X wclear(win);
- X wrefresh(win);
- X}
- X
- Xvoid do_save() {
- X struct savetype savebuf;
- X char save_file[128];
- X FILE *fp;
- X int chk;
- X
- X memcpy(savebuf.map,map,MX*MY);
- X savebuf.x = x;
- X savebuf.y = y;
- X savebuf.dleft = dleft;
- X savebuf.bleft = bleft;
- X savebuf.level = level;
- X savebuf.moves = moves;
- X savebuf.score = score;
- X encode(&savebuf,sizeof(savebuf));
- X strcpy(save_file,home);
- X strcat(save_file,"/cod.save");
- X if ((fp = fopen(save_file,"w")) == NULL) {
- X perror(save_file);
- X return;
- X }
- X fwrite(&savebuf,sizeof(savebuf),1,fp);
- X fclose(fp);
- X}
- X
- Xvoid do_load() {
- X struct savetype loadbuf;
- X FILE *fp;
- X char save_file[128];
- X int chk;
- X
- X strcpy(save_file,home);
- X strcat(save_file,"/cod.save");
- X if ((fp = fopen(save_file,"r")) == NULL)
- X return;
- X fread(&loadbuf,sizeof(loadbuf),1,fp);
- X fclose(fp);
- X if (!decode(&loadbuf,sizeof(loadbuf)))
- X return;
- X memcpy(map,loadbuf.map,MX*MY);
- X x = loadbuf.x;
- X y = loadbuf.y;
- X dleft = loadbuf.dleft;
- X bleft = loadbuf.bleft;
- X level = loadbuf.level;
- X moves = loadbuf.moves;
- X score = loadbuf.score;
- X}
- X
- Xvoid encode(buf,size)
- X struct savetype *buf;
- X int size;
- X{
- X short offset;
- X int chk=0;
- X char *ptr = (char *)buf;
- X buf->chk = 42;
- X for (offset = 0; offset < size;offset++) {
- X chk += ptr[offset]^ptr[offset/7]+3*ptr[size-offset/3];
- X }
- X buf->chk = chk;
- X for (offset = 0; offset < size; offset++) {
- X ptr[offset] = ptr[offset]^170^(code[offset%16]);
- X }
- X}
- X
- Xchar decode(buf,size)
- X struct savetype *buf;
- X int size;
- X{
- X short offset;
- X int chk=0,chk2;
- X char *ptr = (char *)buf;
- X
- X for (offset = 0; offset < size; offset++) {
- X ptr[offset] = ptr[offset]^170^(code[offset%16]);
- X }
- X chk2 = buf->chk;
- X buf->chk = 42;
- X for (offset = 0; offset < size;offset++) {
- X chk += ptr[offset]^ptr[offset/7]+3*ptr[size-offset/3];
- X }
- X return (chk == chk2);
- X}
- END_OF_FILE
- if test 10088 -ne `wc -c <'perp.c'`; then
- echo shar: \"'perp.c'\" unpacked with wrong size!
- fi
- # end of 'perp.c'
- fi
- if test -f 'perp.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'perp.h'\"
- else
- echo shar: Extracting \"'perp.h'\" \(785 characters\)
- sed "s/^X//" >'perp.h' <<'END_OF_FILE'
- X
- X#define YSPRSZ 3
- X#define XSPRSZ 6
- X#define YSCRSZ 7
- X#define XSCRSZ 10
- X
- X#define MX 35
- X#define MY 32
- X#define HEIGHT 128
- X
- X/* Predeclarations */
- Xvoid update_status();
- Xvoid move_dir();
- Xvoid cleanup();
- Xvoid read_spr();
- Xvoid read_map();
- Xvoid drawmap();
- Xvoid drawspr();
- Xvoid init_display();
- Xvoid startxy();
- Xvoid mapcpy();
- Xvoid draw_status();
- Xvoid draw_start();
- Xvoid end_scr();
- Xvoid do_save();
- Xvoid do_load();
- Xvoid encode();
- Xvoid calc_diamonds();
- Xchar decode();
- X
- X/* Files used */
- X#ifndef MAPFILE
- Xchar *map_file = "/home/lily/cs/uba/open/lib/perp_map";
- X#else
- Xchar *map_file = MAPFILE;
- X#endif
- X
- X#ifndef SPRFILE
- Xchar *spr_file = "/home/lily/cs/uba/open/lib/perp_spr";
- X#else
- Xchar *spr_file = SPRFILE;
- X#endif
- X
- Xstruct savetype {
- X char map[MY][MX];
- X int x,y,dleft,bleft,level,moves,score,chk;
- X};
- END_OF_FILE
- if test 785 -ne `wc -c <'perp.h'`; then
- echo shar: \"'perp.h'\" unpacked with wrong size!
- fi
- # end of 'perp.h'
- fi
- if test -f 'shrink_spr' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'shrink_spr'\"
- else
- echo shar: Extracting \"'shrink_spr'\" \(57 characters\)
- sed "s/^X//" >'shrink_spr' <<'END_OF_FILE'
- X#!/bin/awk -f
- X/....../ {printf "%s",$0}
- XEND {printf"\n"}
- END_OF_FILE
- if test 57 -ne `wc -c <'shrink_spr'`; then
- echo shar: \"'shrink_spr'\" unpacked with wrong size!
- fi
- chmod +x 'shrink_spr'
- # end of 'shrink_spr'
- fi
- if test -f 'spr.expand' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'spr.expand'\"
- else
- echo shar: Extracting \"'spr.expand'\" \(2795 characters\)
- sed "s/^X//" >'spr.expand' <<'END_OF_FILE'
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X
- X
- X
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X+.--.+
- X--.++.
- X.++.--
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X======
- X######
- X######
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X/====\
- X|####|
- X\====/
- X
- X|#####
- X|#####
- X\=====
- X
- X######
- X######
- X======
- X
- X#####|
- X#####|
- X=====/
- X
- X|#####
- X|#####
- X|#####
- X
- X######
- X######
- X######
- X
- X#####|
- X#####|
- X#####|
- X
- X/=====
- X|#####
- X|#####
- X
- X======
- X######
- X######
- X
- X=====\
- X#####|
- X#####|
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- Xo__O\
- X\___/
- X _/_\
- X
- X======
- X######
- X======
- X
- X /O__o
- X \___/
- X /_\_
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X/====\
- X|####|
- X|####|
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X <<
- X <<
- X <<
- X
- X??????
- X??????
- X??????
- X
- X
- Xvvvvvv
- X
- X
- X
- X^^^^^^
- X
- X
- X >>
- X >>
- X >>
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X ___
- X /@@@\
- X \@@@/
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X|####|
- X|####|
- X\====/
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X/=====
- X|#####
- X\=====
- X
- X??????
- X??????
- X??????
- X
- X=====\
- X#####|
- X=====/
- X
- X ^__^
- X/----\
- X_/ \_
- X
- X######
- X######
- X======
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X /\
- X < >
- X \/
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X| | /\
- X----||
- X \/
- X
- X O__O
- X/----\
- X_/ \_
- X
- X /--\
- X \/
- X ==|
- X
- X ==|
- X /\
- X \--/
- X
- X/\ | |
- X||-+-+
- X\/
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X ___
- X / \
- X \___/
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X||##||
- X||##||
- X\====/
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X??????
- X??????
- X??????
- X
- X|#####
- X|#####
- X|#####
- X
- X|####|
- X|####|
- X|####|
- X
- X#####|
- X#####|
- X#####|
- X
- X??????
- X??????
- X??????
- X
- X
- END_OF_FILE
- if test 2795 -ne `wc -c <'spr.expand'`; then
- echo shar: \"'spr.expand'\" unpacked with wrong size!
- fi
- # end of 'spr.expand'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-