Add alt versions to 2011/toledo + formatting

The first version allows one to reconfigure the controls and the size of
the game field (which previously was done by changing the Makefile and
updating the code respectively but now is possible at compilation time)
and the second version uses the author's supplied layer.c file that
should work for Windows.

The keysym.h file is actually keysymdef.h from X11 so that users can see
the macro names of the keys.

The README.md file has been format/typo checked.

This should complete the review of 2011/toledo.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-27 08:15:26 -08:00
1 parent 2c62fa163c
commit 6f8e5fb229
7 files changed
+2751 -27

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
toledo
toledo.alt
toledo.alt2
toledo.orig
prog.orig
+6 -2
View File
@@ -120,8 +120,8 @@ OBJ= ${PROG}.o
DATA=
TARGET= ${PROG}
#
ALT_OBJ=
ALT_TARGET=
ALT_OBJ= ${PROG}.alt.o
ALT_TARGET= ${PROG}.alt
#################
@@ -139,11 +139,15 @@ all: data ${TARGET}
${PROG}: ${PROG}.c
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
# alternative executable
#
alt: data ${ALT_TARGET}
@${TRUE}
${PROG}.alt: ${PROG}.alt.c
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
# data files
#
data: ${DATA}
+76 -25
View File
@@ -1,9 +1,15 @@
## To build:
If you have X11 installed:
```sh
make
```
There are two alternate versions, [one that lets you reconfigure the
controls and size](toledo.alt.c) and [another that should work for
Windows](toledo.alt2.c). See [Alternate code](#alternate-code) below.
## To use:
@@ -11,25 +17,58 @@ make
./toledo
```
NOTE: This requires X11 to run or modifications to use [layer.c](layer.c) on
Windows (see below).
## Alternate code:
The first alt version, [toledo.alt.c](toledo.alt.c), allows you to reconfigure
the controls and the dimensions more easily.
The second version, [toledo.alt2.c](toledo.alt2.c), should work for Windows but
does not allow you to reconfigure the keys or dimensions.
### Try:
### Alternate build:
For the one that lets you reconfigure the keys you will want to look at the
included header file, [keysym.h](keysym.h), to find the correct macros. Once you
have the right names you can define the macros `A`, `B`, `C`, `D` and/or `E`. It
will use the default for any you do not specify. For instance, to swap what `A`
and `B` are (see below for defaults of all keys):
```sh
echo "Do or do not. There is no try."
make clobber CDEFINE="-DA=XK_Left:XK_a -DB=XK_Up:XK_w" alt
```
but you can specify something completely else and you can pick and choose which
controls you wish to redefine. You might also wish to change the dimensions of
the game, `M` and `N` which have an arbitrarily selected lower limit as well as
the default values.
Here are the defaults:
```c
#define A XK_Up:XK_w
#define B XK_Left:XK_a
#define C XK_Right:XK_d
#define D XK_Down:XK_s
#define E XK_BackSpace:XK_Tab
#define M 512
#define N 288
```
Observe that each of the controls are a pair in the form of `player2:player1`.
## Judges' remarks:
This two player game uses X11. The control keys can be configured by
modifying the `A`, `B`, `C` and `D` macros at compilation.
modifying the `A`, `B`, `C`, `D` and `E` macros at compilation.
After a quick splash screen the objective should be clear. There
are Red, Green and Cyan tanks. A larger window can be made by altering
the source early on, right before the code gets hard to follow.
the source early on, right before the code gets hard to follow, or using the
[alternate version](#alternate-code).
Like Oscar's previous winning X11 program for the 19th IOCCC, if
you remove both the X11 include files and replace them with
@@ -37,8 +76,9 @@ you remove both the X11 include files and replace them with
```c
#include "layer.c"
```
\
you ought to be able to compile and run this program on Windows.
NOTE: this is what [toledo.alt2.c](toledo.alt2.c) is for.
## Author's remarks:
@@ -58,26 +98,29 @@ and run it without arguments.
You will see briefly a tank spinning before each level.
Left half of the window shows the red player view and right
half shows the green player view, the background will change to
The Left half of the window shows the red player view and the right
half shows the green player view; the background will change to
blue when the view goes inactive.
The objective is to chase and destroy the other player's tank,
there is also an aqua tank for testing your aim and getting
The objective is to chase and destroy the other player's tank.
There is also an aqua tank for testing your aim and getting
extra points.
> Caveat: You can shoot only 3 bullets at a time.
> Trick: You can fire faster if they explode on anything.
> Believe it or not, it has strategy!
Caveat: You can shoot only 3 bullets at a time.
\
Trick: You can fire faster if they explode on anything.
\
Believe it or not, it has strategy!
When only one tank remains on the field, the level will advance.
Don't forget to destroy the aqua tank.
The <strike>battle</strike>playground is surrounded by mountains and each level is
The <strike>battle</strike>playground is surrounded by mountains and each level is
filled with random obstacles (pyramids and cubes).
The bars show players energy and score, each bar shows energy
and indicates current player view (wider on the left), right
The bars show players energy and score; each bar shows energy
and indicates the current player view (wider on the left). The right
part grows with every point.
Keys for player 1 (lowercase):
@@ -96,18 +139,21 @@ Keys for player 2:
* Left arrow - Turn left
* Right arrow - Turn right
> Note: Numeric keys don't work.
Note: Numeric keys don't work.
If you don't like the keys assignment, you can change it in the
Makefile.
Makefile or use the [alternate version](#alternate-code).
### PARENTAL ADVISORY WARNING:
This game is highly violent, when the tank explodes you can
This game is highly violent: when the tank explodes you can
see the little stick man blowing in parts.
Not really, just kidding :D
### PLATFORMS TESTED:
* openSUSE 10.2 x86-32, X11R6 1024x768 32-bits color.
@@ -115,6 +161,7 @@ Not really, just kidding :D
* Fedora Core 11 x86-64, X11R6 1024x768 32-bits color.
* Fedora Core 14 x86-64, X11R6 1024x768 32-bits color.
### COMPLETE FEATURE SET:
* Multiplayer out of the box.
@@ -127,7 +174,8 @@ Not really, just kidding :D
* There is an infinite number of levels.
* Always different levels.
* Animated intro.
* It has color!.
* It has color!
### FEATURES THAT PROGRAMMERS WILL FIND APPEALING:
@@ -140,9 +188,9 @@ Not really, just kidding :D
x86-64 512 MB).
* It is written in the only true C: K&R, and no, that doesn't mean
Katherine & Rose.
* Vectorial scalable graphics, do you want a bigger viewport? Change variables M
`&` `N`.
* Half of the program is formatted as 3D cube. View with tabs at 8 columns and a\
* Vectorial scalable graphics: do you want a bigger viewport? Change variables
`M` and `N` (see the [alternate code](#alternate-code)).
* Half of the program is formatted as 3D cube. View with tabs at 8 columns and a
square font.
* The other half of the program is unprintable source code, so no typing from
paper, you have to write a converter of tabs and form-feeds to its C escaped
@@ -152,6 +200,7 @@ Not really, just kidding :D
* Virtual world with its own physics laws.
* When closing the window it will show an X11 error :P
### OBFUSCATION TRICKS:
* Loop code included inside loop test.
@@ -185,6 +234,7 @@ Not really, just kidding :D
```
### THE HISTORY OF THIS PROGRAM:
When I started working on this program, I figured that it would
@@ -203,7 +253,7 @@ the user.
And finally, the third "Thing" was growing and growing, and
growing, eating bytes for lunch... after endless rounds of
crunching I obtained three-hundred seventy-eight bytes of
crunching I obtained three-hundred seventy-eight bytes of
artwork and guess what? It doesn't fit.
So I had to integrate a decompressor based on the space, tabulators and other
@@ -229,6 +279,7 @@ exceeded the character limits. The crunched vectors were generated by another
special program and the tank that surrounds this text was generated by yet
another program.
*Have fun!*
+2501
View File
File diff suppressed because it is too large. Load diff
+95
View File
@@ -0,0 +1,95 @@
#include <X11/Xlib.h>
#include <X11/keysym.h>
#define I XDrawLine(W,X,Y,
#define l rand()%
#define R while(
#define n *h++
#define x _ c].
#define S if(
#define _ _[
#ifndef A
#define A XK_Up:XK_w
#endif
#ifndef B
#define B XK_Left:XK_a
#endif
#ifndef C
#define C XK_Right:XK_d
#endif
#ifndef D
#define D XK_Down:XK_s
#endif
#ifndef E
#define E XK_BackSpace:XK_Tab
#endif
#ifndef Q
#define Q XFillRectangle(W,X,Y,
#endif
#ifndef M
#define M 512
#elif M < 250
#undef M
#define M 512
#endif
#ifndef N
#define N 288
#elif N < 100
#undef N
#define N 288
#endif
*h ;
; i;
e; d; u; p; L[1
<<28]; float w=11.46; m; a ;
P; k[9304]; *j=k; c; f; q; r; t; v ;
* z; K(H,i) { t=u*+cos(H/w)-i*sin(H/w); p=i*
cos(H/w)+u*sin(H/w); u=t; } Display*W; GC Y; Pixmap
X; s(o,t,g,w,v) { h=v+k; q=2*n; R u=n, r=12+n, K(t,n), K(o,+
p+w,u+=g), d=1>p?1:p, u=u*N/d+M/2, d=N/2+r*N/d, u=u>
-M*2 ?u<M*2?u:2*M:-2*M, 1&q?i>0|p>0?I f,e,u,d):0: (i=p
,e=d,f=u ), --q); } struct{ int c,o,m,f,u,s,i ,e,r; }
_ 21 ] ; Window O; b(y) { XGCValues g ; g .
foreground=y; g. line_width = 2 ; XChangeGC(W,Y,20
,&g); } G(o) { z=x f + k; h=(x f= 381+193*c)+k; i=2*(n
=*z++); R--i&1?d=l 9-4,e =l 9 -4*(8>o):0,n=*z+++d,0<(n
=*z+++e)?h[-1]=0:0,n=*z+++d, i); } g(o) { u=0; K(x s,o<<9
); x u-=u; x r-=p; } F(m,c ) { f=5120*c; c=12; R +c--&&m
==+c |abs(x u-_ m].u)>f |x i <1|x c>2 |abs(x r-_ m].r)>f)
; return c+1; } T(o) { c=11; S!P){ a=++a%72; S!a){ P=1; R
c--){ x c=x m=0; x i=c>2?2:1 ; R x u=l 978-499<<8, x s= l
71, x r=l 979-501<<8, F(c,2) ); x f=c>2?l +2*+73:147; x o
=2>c?249<<16-c*8:64987<<8*(c >2); } } } S P){ c=11; R 4&x
i? ++x m-64&&x m-71? o=1,64> x m?(d=F(c,1))?x m=64,d<4?j[
x e]++,++_ --d].c:0:g(7):G(x m -65) :_ x i=0,x e].e-- :0,
20>++c); c=3; R c--) { S 1&x i) { o++; S x c>2) x m>15? x
i=0:G(x m++); else { S x m ) S x m-->6) g(4); S c<2) { x
s=(72+x s+L[c?B]-L[c?C])%72; S d=4*L[c?A]-L[c?D]*4) { g(d
); S F(c,2)) g(-d); } S L[c? E]&!x m&x e<3) { d=10; R _++
d].i) ; g(-4); _ d]=_ c]; _ d].e=c; x e++; x m=7; c=d; x
f = 122 ; x i=4; g(19); x o= 4092<<12; c=x e; } } } } } P
-=o<2; } v=2; R v--){ m=(108 - _ v].s)%72; b(3^_ v].c?0:
128); Q c=0,0,M,N); S!P) s(+ 36,54-a,0,-120,-+-+-+-+147,b
((1<<16)-1)); S P) { b(255); I 0,N/2,M,N/2); t=-.889*m; h
=k+340; R u=(t+=q=n)*M/32,d= n*N/48,q?I f,e,u,d):0,f=u,e=
+d,k+378>h); R x i&&c-v?s(m, x s,x u-_ v].u>>8,x r-_ v].r
>>8,x f,b(x o)):0,20>c++); c =0; R e=16+32*c,Q v^c?16:8,e
,(c^v?68:76)+c[b(x o),j] , 16), b(0,d=20*x c), Q
80-d,4+e,d,8),2>c++) ; } b(255); I M,0,M,
N); XCopyArea(W, X,O,Y,0,0,M,N,v*
M,0); } }
char*o="{ } { } { { } ; { } ; { ; { ; { ; { } ; { } ; { ; { ; } ; { ; { } } ; { ; } { } ; { ; { } ; { ; } { } { { } ; { } ; { ; { ; } { } { } } { } { } { } } { } } { } { } { } } { } { } { ; ; ; ; } { ; } { { } ; } } ; { ; } { ; } { { } ; { } ; { ; { ; } } { ; } { { } } } { ; } { ; { } ; } } } { } { } ; } } } } } { } ; } ; } ; { } { } ; { } ; } ; } } { } { } } { } { } } } } { { } } } } } { { } } { ; { { } ; { ; { { ; { ; { { } ; { ; { { ; ; } ; ; } ; ; } } { { } { { } { { { { } } } } } { { { { } { } { { } { { } { { { { } } ";
main(){
XEvent e; W=
XOpenDisplay(k);
XSelectInput(W,O=
XCreateSimpleWindow(W,DefaultRootWindow(W),64,64,M*2,N,2,P,r),3);
XMapWindow(W,O); srand(time(0)); Y=
XCreateGC(W,X=
XCreatePixmap(W,O,M,N,DefaultDepth(W,r)),P,r); R*o){ S*o^59)d=64&*o?'{'^*o++:3,
32^*o?d+=*o^9?2:1:0,*j+=P?d*9-43:d,j+=P,P=!P; else R*j=j[-3],j++,*++o^9); o++;
} R 7){ T(0);
XFlush(W); usleep(33367); R
XPending(W)) L[
XLookupKeysym(&e,
XNextEvent(W,&e)&0)]^=1==e.type/2; } }
+63
View File
@@ -0,0 +1,63 @@
#include "layer.h"
#define I XDrawLine(W,X,Y,
#define l rand()%
#define R while(
#define n *h++
#define x _ c].
#define S if(
#define _ _[
*h ;
M=512; i; N=
288; e; d; u; p; L[1
<<28]; float w=11.46; m; a ;
P; k[9304]; *j=k; c; f; q; r; t; v ;
* z; K(N,i) { t=u*+cos(N/w)-i*sin(N/w); p=i*
cos(N/w)+u*sin(N/w); u=t; } Display*W; GC Y; Pixmap
X; s(o,t,g,w,v) { h=v+k; q=2*n; R u=n, r=12+n, K(t,n), K(o,+
p+w,u+=g), d=1>p?1:p, u=u*N/d+M/2, d=N/2+r*N/d, u=u>
-M*2 ?u<M*2?u:2*M:-2*M, 1&q?i>0|p>0?I f,e,u,d):0: (i=p
,e=d,f=u ), --q); } struct{ int c,o,m,f,u,s,i ,e,r; }
_ 21 ] ; Window O; b(y) { XGCValues g ; g .
foreground=y; g. line_width = 2 ; XChangeGC(W,Y,20
,&g); } G(o) { z=x f + k; h=(x f= 381+193*c)+k; i=2*(n
=*z++); R--i&1?d=l 9-4,e =l 9 -4*(8>o):0,n=*z+++d,0<(n
=*z+++e)?h[-1]=0:0,n=*z+++d, i); } g(o) { u=0; K(x s,o<<9
); x u-=u; x r-=p; } F(m,c ) { f=5120*c; c=12; R +c--&&m
==+c |abs(x u-_ m].u)>f |x i <1|x c>2 |abs(x r-_ m].r)>f)
; return c+1; } T(o) { c=11; S!P){ a=++a%72; S!a){ P=1; R
c--){ x c=x m=0; x i=c>2?2:1 ; R x u=l 978-499<<8, x s= l
71, x r=l 979-501<<8, F(c,2) ); x f=c>2?l +2*+73:147; x o
=2>c?249<<16-c*8:64987<<8*(c >2); } } } S P){ c=11; R 4&x
i? ++x m-64&&x m-71? o=1,64> x m?(d=F(c,1))?x m=64,d<4?j[
x e]++,++_ --d].c:0:g(7):G(x m -65) :_ x i=0,x e].e-- :0,
20>++c); c=3; R c--) { S 1&x i) { o++; S x c>2) x m>15? x
i=0:G(x m++); else { S x m ) S x m-->6) g(4); S c<2) { x
s=(72+x s+L[c?B]-L[c?C])%72; S d=4*L[c?A]-L[c?D]*4) { g(d
); S F(c,2)) g(-d); } S L[c? E]&!x m&x e<3) { d=10; R _++
d].i) ; g(-4); _ d]=_ c]; _ d].e=c; x e++; x m=7; c=d; x
f = 122 ; x i=4; g(19); x o= 4092<<12; c=x e; } } } } } P
-=o<2; } v=2; R v--){ m=(108 - _ v].s)%72; b(3^_ v].c?0:
128); Q c=0,0,M,N); S!P) s(+ 36,54-a,0,-120,-+-+-+-+147,b
((1<<16)-1)); S P) { b(255); I 0,N/2,M,N/2); t=-.889*m; h
=k+340; R u=(t+=q=n)*M/32,d= n*N/48,q?I f,e,u,d):0,f=u,e=
+d,k+378>h); R x i&&c-v?s(m, x s,x u-_ v].u>>8,x r-_ v].r
>>8,x f,b(x o)):0,20>c++); c =0; R e=16+32*c,Q v^c?16:8,e
,(c^v?68:76)+c[b(x o),j] , 16), b(0,d=20*x c), Q
80-d,4+e,d,8),2>c++) ; } b(255); I M,0,M,
N); XCopyArea(W, X,O,Y,0,0,M,N,v*
M,0); } }
char*o="{ } { } { { } ; { } ; { ; { ; { ; { } ; { } ; { ; { ; } ; { ; { } } ; { ; } { } ; { ; { } ; { ; } { } { { } ; { } ; { ; { ; } { } { } } { } { } { } } { } } { } { } { } } { } { } { ; ; ; ; } { ; } { { } ; } } ; { ; } { ; } { { } ; { } ; { ; { ; } } { ; } { { } } } { ; } { ; { } ; } } } { } { } ; } } } } } { } ; } ; } ; { } { } ; { } ; } ; } } { } { } } { } { } } } } { { } } } } } { { } } { ; { { } ; { ; { { ; { ; { { } ; { ; { { ; ; } ; ; } ; ; } } { { } { { } { { { { } } } } } { { { { } { } { { } { { } { { { { } } ";
main(){
XEvent e; W=
XOpenDisplay(k);
XSelectInput(W,O=
XCreateSimpleWindow(W,DefaultRootWindow(W),64,64,M*2,N,2,P,r),3);
XMapWindow(W,O); srand(time(0)); Y=
XCreateGC(W,X=
XCreatePixmap(W,O,M,N,DefaultDepth(W,r)),P,r); R*o){ S*o^59)d=64&*o?'{'^*o++:3,
32^*o?d+=*o^9?2:1:0,*j+=P?d*9-43:d,j+=P,P=!P; else R*j=j[-3],j++,*++o^9); o++;
} R 7){ T(0);
XFlush(W); usleep(33367); R
XPending(W)) L[
XLookupKeysym(&e,
XNextEvent(W,&e)&0)]^=1==e.type/2; } }
+8
View File
@@ -3259,6 +3259,14 @@ try. If they do they might want to look also at
not be worth.
## [2011/toledo](2011/toledo/toledo.c) ([README.md](2011/toledo/README.md]))
Cody added two [alternate versions](2011/toledo/README.md#alternate-code): one that
lets one reconfigure the controls and also the size of the game and another
version that should work in Windows, based on the author's remarks and support
file, `layer.c`.
## [2011/vik](2011/vik/vik.c) ([README.md](2011/vik/README.md]))
Cody added an [alternate version](2011/vik/README.md#alternate-code) for Windows