Files
ioccc/2011/toledo/toledo.alt.c
T
Cody Boone Ferguson 6f8e5fb229 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.
2023-11-27 08:15:26 -08:00

96 lines
3.8 KiB
C

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