149858Sbostic /*-
2*60873Sbostic * Copyright (c) 1991, 1993
3*60873Sbostic * The Regents of the University of California. All rights reserved.
449858Sbostic *
549858Sbostic * %sccs.include.redist.c%
649858Sbostic */
749858Sbostic
849858Sbostic #ifndef lint
9*60873Sbostic static char copyright[] =
10*60873Sbostic "@(#) Copyright (c) 1991, 1993\n\
11*60873Sbostic The Regents of the University of California. All rights reserved.\n";
1249858Sbostic #endif /* not lint */
1349858Sbostic
1449858Sbostic #ifndef lint
15*60873Sbostic static char sccsid[] = "@(#)xneko.c 8.1 (Berkeley) 05/31/93";
1649858Sbostic #endif /* not lint */
1749858Sbostic
1849855Sbostic /*--------------------------------------------------------------
1949855Sbostic *
2049855Sbostic * xneko - X11 G-
2149855Sbostic *
2249855Sbostic * Original Writer: Masayuki Koba
2349855Sbostic * Programmed by Masayuki Koba, 1990
2449855Sbostic *
2549855Sbostic *--------------------------------------------------------------
2649855Sbostic *
2749855Sbostic *!!Introduction:
2849855Sbostic *
29*60873Sbostic *!!!!K\@(#)xneko.c 8.1m%0%i%`$O Macintosh $N05/31/939%/%"%/%;%5%j!< "neko" $N
3049855Sbostic *!!F0:n$r X11 $G%^%M$?$b$N$G$9!#
3149855Sbostic *
32*60873Sbostic *!!!!Macintosh "neko" $N=(0o$J05/31/936%$%s$K7I0U$rI=$7$D$D!"$3$N
33*60873Sbostic *!!@(#)xneko.c 8.1m%0%i%`$r3'$5$s$KJ{$2$^$9!#
3449855Sbostic *
3549855Sbostic *--------------------------------------------------------------
3649855Sbostic *
3749855Sbostic *!!Special Thanks to
3849855Sbostic *
3949855Sbostic * toshi-w !D!!Macintosh neko $N>R2p<T
4049855Sbostic * shio-m !D!!!VX11 $N neko $,M_$7$$!*!W$H%?%@$r$3$M$??M
41*60873Sbostic * disco !D!!X11 s.xneko.c/%K%+%k!&%"8.1P%$%6!<
4249855Sbostic *
4349855Sbostic * HOMY !D!!/usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.c0;XE&<T
44*60873Sbostic * BNS !D!!J#?t@(#)xneko.c 8.1l!<%sBP1~C%ADs6!<T
4549855Sbostic *
4649855Sbostic * "xneko" Presented by Masayuki Koba (masa-k).
4749855Sbostic *
4849855Sbostic *--------------------------------------------------------------
4949855Sbostic *
5049855Sbostic *!!Manifest:
5149855Sbostic *
52*60873Sbostic *!!!!K\@(#)xneko.c 8.1m%0%i%`$O Public Domain Software $G$9!#E>:\!&2~NI$O
5349855Sbostic *!!<+M3$K9T$C$F2<$5$$!#
5449855Sbostic *
55*60873Sbostic *!!!!$J$*!"86:n<T$O!"K\@(#)xneko.c 8.1m%0%i%`$r;HMQ$9$k$3$H$K$h$C$F@8$8$?
5649855Sbostic *!!>c32$dITMx1W$K$D$$$F$$$C$5$$@UG$$r;}$A$^$;$s!#
5749855Sbostic *
5849855Sbostic *--------------------------------------------------------------
5949855Sbostic *
6049855Sbostic *!!Bugs:
6149855Sbostic *
6249855Sbostic *!!!!!J#1!KX11 $N .Xdefaults $N@_Dj$r$^$k$C$-$jL5;k$7$F$$$^$9!#
6349855Sbostic *
6449855Sbostic *!!!!!J#2!KG-$NF0:n$,;~4V$HF14|$7$F$$$k$?$a!"%^%&%9$N0\F0>pJs
6549855Sbostic *!!!!!!!!$r%]!<%j%s%0$7$F$$$^$9!#=>$C$F!"%^%&%9$,A4$/F0:n$7$F
6649855Sbostic *!!!!!!!!$$$J$$;~$OL5BL$J%^%&%9:BI8FI$_<h$j$r9T$C$F$7$^$$$^$9!#
6749855Sbostic *
68*60873Sbostic *!!!!!J#3!K%&%#%s8.1&$,%"%$%3%s2=$5$l$F$b!"$7$i$s$W$j$GIA2h$7
69*60873Sbostic *!!!!!!!!$D$E$1$^$9!#$3$NItJ,$O!"8=:_$N%&%#%s8.1&$N>uBV$r@(#) xneko.c 8.1@(#)'
7049858Sbostic *!!!!!!!!70/$7$F!"%"%$%3%s2=$5$l$F$$$k;~$O40A4$K%$s%HBT$A
7149855Sbostic *!!!!!!!!$K$J$k$h$&$K=q$-JQ$($J$1$l$P$J$j$^$;$s!# ($=$s$J$3$H!"
7249855Sbostic *!!!!!!!!$G$-$k$N$+$J$!!#X10 $G$O$G$-$^$7$?$,!#)
7349855Sbostic *
74*60873Sbostic *!!!!!J#4!K%j%5%$%:8e$N%&%#%s8.1&$,6KC<$K>.$5$/$J$C$?;~$NF0:n
7549855Sbostic *!!!!!!!!$OJ]>Z$G$-$^$;$s!#
7649855Sbostic *
77*60873Sbostic *!!!!!J#5!KK\Mh$J$i$P3NJ]$7$?%&%#%s8.1&$d Pixmap $O@(#)xneko.c 8.1m%0%i%`
78*60873Sbostic *!!!!!!!!=*N;;~$K2rJ|$9$kI,MW$,$"$j$^$9$,!"K\@(#)xneko.c 8.1m%0%i%`$O$=$N
7949855Sbostic *!!!!!!!!$X$s$r%5%\$C$F$*$j!"Hs>o$K$*9T57$,0-$/$J$C$F$$$^$9!#
8049855Sbostic *!!!!!!!!IaDL$O exit() ;~$K%7%9s.xneko.c`$,M>J,$J%j%=!<%9$r2rJ|$7$F
8149855Sbostic *!!!!!!!!$/$l$^$9$,!"#O#S$K/usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.c0$,$"$k>l9g$O xneko $r2?EY$b5/
8249858Sbostic *!!!!!!!!F0$9$k$H!"$=$N$&$A%9%o82WNN0h$,ITB-$7$F$7$^$&$3$H$K
8349855Sbostic *!!!!!!!!$J$k$+$b$7$l$^$;$s!#
8449855Sbostic *
8549855Sbostic *!!!!!J#6!K;~4V$KF14|$7$FI,$:IA2h=hM}$r<B9T$9$k$?$a!"0BDj>uBV
8649855Sbostic *!!!!!!!!$G$b Idle 90 !A 95% $H$J$j!"%7%9s.xneko.c`#C#P#U$r 5 !A 10%
8749855Sbostic *!!!!!!!!Dx>CHq$7$^$9!#!Jxtachos $GD4$Y$^$7$?!#!K
8849855Sbostic *
8949855Sbostic *--------------------------------------------------------------
9049855Sbostic *
9149855Sbostic *!!System (Machine):
9249855Sbostic *
93*60873Sbostic *!!!!K\@(#)xneko.c 8.1m%0%i%`$NF0:n$r3NG'$7$?%7%9s.xneko.c`9=@.$O0J2<$NDL$j!#
9449855Sbostic *
9549855Sbostic * !&NWS-1750!"NWS-1720 (NEWS)!"NWP-512D
9649855Sbostic * !!NEWS-OS 3.2a (UNIX 4.3BSD)!"X11 Release 2
9749855Sbostic *
9849855Sbostic * !&NWS-1750!"NWS-1720 (NEWS)!"NWP-512D
9949855Sbostic * !!NEWS-OS 3.3 (UNIX 4.3BSD)!"X11 Release 3
10049855Sbostic *
10149855Sbostic * !&Sun 3!"X11 Release 4
10249855Sbostic *
10349855Sbostic * !&LUNA!"X11 Release 3
10449855Sbostic *
10549855Sbostic * !&DECstation 3100!"ULTRIX!"X11
10649855Sbostic *
10749855Sbostic *--------------------------------------------------------------*/
10849855Sbostic
10949855Sbostic
11049855Sbostic #include <X11/Xlib.h>
11149855Sbostic #include <X11/Xutil.h>
11249855Sbostic #include <X11/keysym.h>
11349855Sbostic
11449855Sbostic #include <stdio.h>
11549855Sbostic
11649855Sbostic #include <signal.h>
11749855Sbostic #include <math.h>
11849855Sbostic #include <sys/time.h>
11949855Sbostic
12049855Sbostic
12149855Sbostic #ifndef lint
12249855Sbostic static char
12349855Sbostic rcsid[] = "$Header: /afs/athena.mit.edu/user/j/jik/sipbsrc/src/xneko/RCS/xneko.c,v 1.2 90/09/01 23:40:01 jik Exp $";
12449855Sbostic static char WriterMessage[] = "xneko: Programmed by Masayuki Koba, 1990";
12549855Sbostic #endif
12649855Sbostic
12749855Sbostic
12849855Sbostic /*
129*60873Sbostic * X11 G- 0C10/14/12^129W18:45:52!%$%k0lMw!'
13049855Sbostic *
13149855Sbostic * "icon.xbm" !D!!%"%$%3%s
13249855Sbostic * "cursor.xbm" !D!!%+!<%=%k
13349855Sbostic * "cursor_mask.xbm" !D!!%+!<%=%k!J%^%9%/!K
13449855Sbostic *
13549855Sbostic * "space.xbm" !D!!%9%Z!<%9
13649855Sbostic *
13749855Sbostic * "mati2.xbm" !D!!BT$A#2
13849855Sbostic * "jare2.xbm" !D!!$8$c$l#2
13949855Sbostic * "kaki1.xbm" !D!!A_$-#1
14049855Sbostic * "kaki2.xbm" !D!!A_$-#2
14149855Sbostic * "mati3.xbm" !D!!BT$A#3!J$"$/$S!K
14249855Sbostic * "sleep1.xbm" !D!!?2$k#1
14349855Sbostic * "sleep2.xbm" !D!!?2$k#2
14449855Sbostic *
14549855Sbostic * "awake.xbm" !D!!L\3P$a
14649855Sbostic *
14749855Sbostic * "up1.xbm" !D!!>e#1
14849855Sbostic * "up2.xbm" !D!!>e#2
14949855Sbostic * "down1.xbm" !D!!2<#1
15049855Sbostic * "down2.xbm" !D!!2<#2
15149855Sbostic * "left1.xbm" !D!!:8#1
15249855Sbostic * "left2.xbm" !D!!:8#2
15349855Sbostic * "right1.xbm" !D!!1
15449855Sbostic * "right2.xbm" !D!!1
15549855Sbostic * "upleft1.xbm" !D!!:8>e#1
15649855Sbostic * "upleft2.xbm" !D!!:8>e#2
15749855Sbostic * "upright1.xbm" !D!!1&>e#1
15849855Sbostic * "upright2.xbm" !D!!1&>e#2
15949855Sbostic * "dwleft1.xbm" !D!!:82<#1
16049855Sbostic * "dwleft2.xbm" !D!!:82<#2
16149855Sbostic * "dwright1.xbm" !D!!1&2<#1
16249855Sbostic * "dwright2.xbm" !D!!1&2<#2
16349855Sbostic *
16449855Sbostic * "utogi1.xbm" !D!!>eKa$.#1
16549855Sbostic * "utogi2.xbm" !D!!>eKa$.#2
16649855Sbostic * "dtogi1.xbm" !D!!2<Ka$.#1
16749855Sbostic * "dtogi2.xbm" !D!!2<Ka$.#2
16849855Sbostic * "ltogi1.xbm" !D!!:8Ka$.#1
16949855Sbostic * "ltogi2.xbm" !D!!:8Ka$.#2
17049855Sbostic * "rtogi1.xbm" !D!!1&Ka$.#1
17149855Sbostic * "rtogi2.xbm" !D!!1&Ka$.#2
17249855Sbostic *
173*60873Sbostic * !!$3$l$i$N18:45:52!%$%k$O bitmap %3%^%s%I$GJT=82DG=$G$9!#
17449855Sbostic *
17549855Sbostic * (bitmap size "* 32x32 ... Macintosh ICON resource size.)
17649855Sbostic *
17749855Sbostic */
17849855Sbostic
17949855Sbostic
18049855Sbostic #include "bitmaps/icon.xbm"
18149855Sbostic #include "bitmaps/cursor.xbm"
18249855Sbostic #include "bitmaps/cursor_mask.xbm"
18349855Sbostic
18449855Sbostic #include "bitmaps/space.xbm"
18549855Sbostic
18649855Sbostic #include "bitmaps/mati2.xbm"
18749855Sbostic #include "bitmaps/jare2.xbm"
18849855Sbostic #include "bitmaps/kaki1.xbm"
18949855Sbostic #include "bitmaps/kaki2.xbm"
19049855Sbostic #include "bitmaps/mati3.xbm"
19149855Sbostic #include "bitmaps/sleep1.xbm"
19249855Sbostic #include "bitmaps/sleep2.xbm"
19349855Sbostic
19449855Sbostic #include "bitmaps/awake.xbm"
19549855Sbostic
19649855Sbostic #include "bitmaps/up1.xbm"
19749855Sbostic #include "bitmaps/up2.xbm"
19849855Sbostic #include "bitmaps/down1.xbm"
19949855Sbostic #include "bitmaps/down2.xbm"
20049855Sbostic #include "bitmaps/left1.xbm"
20149855Sbostic #include "bitmaps/left2.xbm"
20249855Sbostic #include "bitmaps/right1.xbm"
20349855Sbostic #include "bitmaps/right2.xbm"
20449855Sbostic #include "bitmaps/upright1.xbm"
20549855Sbostic #include "bitmaps/upright2.xbm"
20649855Sbostic #include "bitmaps/upleft1.xbm"
20749855Sbostic #include "bitmaps/upleft2.xbm"
20849855Sbostic #include "bitmaps/dwleft1.xbm"
20949855Sbostic #include "bitmaps/dwleft2.xbm"
21049855Sbostic #include "bitmaps/dwright1.xbm"
21149855Sbostic #include "bitmaps/dwright2.xbm"
21249855Sbostic
21349855Sbostic #include "bitmaps/utogi1.xbm"
21449855Sbostic #include "bitmaps/utogi2.xbm"
21549855Sbostic #include "bitmaps/dtogi1.xbm"
21649855Sbostic #include "bitmaps/dtogi2.xbm"
21749855Sbostic #include "bitmaps/ltogi1.xbm"
21849855Sbostic #include "bitmaps/ltogi2.xbm"
21949855Sbostic #include "bitmaps/rtogi1.xbm"
22049855Sbostic #include "bitmaps/rtogi2.xbm"
22149855Sbostic
22249855Sbostic
22349855Sbostic /*
22449855Sbostic * Dj?tDj5A
22549855Sbostic */
22649855Sbostic
227*60873Sbostic #define BITMAP_WIDTH 32 /* #1%-%c%i%/%?$NI} (17:01:51/%;%k) */
228*60873Sbostic #define BITMAP_HEIGHT 32 /* #1%-%c%i%/%?$N9b$5 (17:01:51/%;%k) */
22949855Sbostic
230*60873Sbostic #define WINDOW_WIDTH 320 /* %&%#%s8.1&$NI} (17:01:51/%;%k) */
231*60873Sbostic #define WINDOW_HEIGHT 256 /* %&%#%s8.1&$N9b$5 (17:01:51/%;%k) */
23249855Sbostic
23349855Sbostic #define DEFAULT_BORDER 2 /* %\!<%@!<%5%$%: */
23449855Sbostic
235*60873Sbostic #define DEFAULT_WIN_X 1 /* %&%#%s8.1&@8@.#X:BI8 */
236*60873Sbostic #define DEFAULT_WIN_Y 1 /* %&%#%s8.1&@8@.#Y:BI8 */
23749855Sbostic
23849855Sbostic #define AVAIL_KEYBUF 255
23949855Sbostic
24049855Sbostic #define EVENT_MASK1 ( KeyPressMask | StructureNotifyMask )
24149855Sbostic
24249855Sbostic #define EVENT_MASK2 ( KeyPressMask | \
24349855Sbostic ExposureMask | \
24449855Sbostic StructureNotifyMask )
24549855Sbostic
24649855Sbostic #define MAX_TICK 9999 /* Odd Only! */
24749855Sbostic
24849855Sbostic #define INTERVAL 125000L /* %$%s%?!</usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.ck%?%$%` */
24949855Sbostic
25049855Sbostic #define NEKO_SPEED 16
25149855Sbostic
25249855Sbostic #define IDLE_SPACE 6
25349855Sbostic
25449855Sbostic #define NORMAL_STATE 1
25549855Sbostic #define DEBUG_LIST 2
25649855Sbostic #define DEBUG_MOVE 3
25749855Sbostic
25849855Sbostic /* G-$N>uBVDj?t */
25949855Sbostic
26049855Sbostic #define NEKO_STOP 0 /* N)$A;_$^$C$? */
26149855Sbostic #define NEKO_JARE 1 /* 4i$r@v$C$F$$$k */
26249855Sbostic #define NEKO_KAKI 2 /* F,$rA_$$$F$$$k */
26349855Sbostic #define NEKO_AKUBI 3 /* $"$/$S$r$7$F$$$k */
26449855Sbostic #define NEKO_SLEEP 4 /* ?2$F$7$^$C$? */
26549855Sbostic #define NEKO_AWAKE 5 /* L\$,3P$a$? */
26649855Sbostic #define NEKO_U_MOVE 6 /* >e$K0\F0Cf */
26749855Sbostic #define NEKO_D_MOVE 7 /* 2<$K0\F0Cf */
26849855Sbostic #define NEKO_L_MOVE 8 /* :8$K0\F0Cf */
26949855Sbostic #define NEKO_R_MOVE 9 /* 1&$K0\F0Cf */
27049855Sbostic #define NEKO_UL_MOVE 10 /* :8>e$K0\F0Cf */
27149855Sbostic #define NEKO_UR_MOVE 11 /* 1&>e$K0\F0Cf */
27249855Sbostic #define NEKO_DL_MOVE 12 /* :82<$K0\F0Cf */
27349855Sbostic #define NEKO_DR_MOVE 13 /* 1&2<$K0\F0Cf */
27449855Sbostic #define NEKO_U_TOGI 14 /* >e$NJI$r0z$CA_$$$F$$$k */
27549855Sbostic #define NEKO_D_TOGI 15 /* 2<$NJI$r0z$CA_$$$F$$$k */
27649855Sbostic #define NEKO_L_TOGI 16 /* :8$NJI$r0z$CA_$$$F$$$k */
27749855Sbostic #define NEKO_R_TOGI 17 /* 1&$NJI$r0z$CA_$$$F$$$k */
27849855Sbostic
27949855Sbostic /* G-$N%"%K%a!<%7%g%s7+$jJV$72s?t */
28049855Sbostic
28149855Sbostic #define NEKO_STOP_TIME 4
28249855Sbostic #define NEKO_JARE_TIME 10
28349855Sbostic #define NEKO_KAKI_TIME 4
28449855Sbostic #define NEKO_AKUBI_TIME 3
28549855Sbostic #define NEKO_AWAKE_TIME 3
28649855Sbostic #define NEKO_TOGI_TIME 10
28749855Sbostic
28849855Sbostic #define PI_PER8 ((double)3.1415926535/(double)8)
28949855Sbostic
29049855Sbostic #define DIRNAMELEN 255
29149855Sbostic
29249855Sbostic
29349855Sbostic /*
29449855Sbostic * %0%m!</usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.ckJQ?t
29549855Sbostic */
29649855Sbostic
29749855Sbostic static char *ProgramName; /* %3%^%s%IL>>N */
29849855Sbostic
29949855Sbostic Display *theDisplay;
30049855Sbostic int theScreen;
30149855Sbostic unsigned int theDepth;
30249855Sbostic unsigned long theBlackPixel;
30349855Sbostic unsigned long theWhitePixel;
30449855Sbostic Window theWindow;
30549855Sbostic Cursor theCursor;
30649855Sbostic
30749855Sbostic static unsigned int WindowWidth;
30849855Sbostic static unsigned int WindowHeight;
30949855Sbostic
31049855Sbostic static int WindowPointX;
31149855Sbostic static int WindowPointY;
31249855Sbostic
31349855Sbostic static unsigned int BorderWidth = DEFAULT_BORDER;
31449855Sbostic
31549855Sbostic long IntervalTime = INTERVAL;
31649855Sbostic
31749855Sbostic int EventState; /* %$s%H=hM}MQ >uBVJQ?t */
31849855Sbostic
31949855Sbostic int NekoTickCount; /* G-F0:n%+%&%s%? */
32049855Sbostic int NekoStateCount; /* G-F10l>uBV%+%&%s%? */
32149855Sbostic int NekoState; /* G-$N>uBV */
32249855Sbostic
32349855Sbostic int MouseX; /* %^%&%9#X:BI8 */
32449855Sbostic int MouseY; /* %^%&%9#Y:BI8 */
32549855Sbostic
32649855Sbostic int PrevMouseX = 0; /* D>A0$N%^%&%9#X:BI8 */
32749855Sbostic int PrevMouseY = 0; /* D>A0$N%^%&%9#Y:BI8 */
32849855Sbostic
32949855Sbostic int NekoX; /* G-#X:BI8 */
33049855Sbostic int NekoY; /* G-#Y:BI8 */
33149855Sbostic
33249855Sbostic int NekoMoveDx; /* G-0\F05wN%#X */
33349855Sbostic int NekoMoveDy; /* G-0\F05wN%#Y */
33449855Sbostic
33549855Sbostic int NekoLastX; /* G-:G=*IA2h#X:BI8 */
33649855Sbostic int NekoLastY; /* G-:G=*IA2h#Y:BI8 */
33749855Sbostic GC NekoLastGC; /* G-:G=*IA2h GC */
33849855Sbostic
33949855Sbostic double NekoSpeed = (double)NEKO_SPEED;
34049855Sbostic
34149855Sbostic double SinPiPer8Times3; /* sin( #3&P!?#8 ) */
34249855Sbostic double SinPiPer8; /* sin( &P!?#8 ) */
34349855Sbostic
34449855Sbostic Pixmap SpaceXbm;
34549855Sbostic
34649855Sbostic Pixmap Mati2Xbm;
34749855Sbostic Pixmap Jare2Xbm;
34849855Sbostic Pixmap Kaki1Xbm;
34949855Sbostic Pixmap Kaki2Xbm;
35049855Sbostic Pixmap Mati3Xbm;
35149855Sbostic Pixmap Sleep1Xbm;
35249855Sbostic Pixmap Sleep2Xbm;
35349855Sbostic
35449855Sbostic Pixmap AwakeXbm;
35549855Sbostic
35649855Sbostic Pixmap Up1Xbm;
35749855Sbostic Pixmap Up2Xbm;
35849855Sbostic Pixmap Down1Xbm;
35949855Sbostic Pixmap Down2Xbm;
36049855Sbostic Pixmap Left1Xbm;
36149855Sbostic Pixmap Left2Xbm;
36249855Sbostic Pixmap Right1Xbm;
36349855Sbostic Pixmap Right2Xbm;
36449855Sbostic Pixmap UpLeft1Xbm;
36549855Sbostic Pixmap UpLeft2Xbm;
36649855Sbostic Pixmap UpRight1Xbm;
36749855Sbostic Pixmap UpRight2Xbm;
36849855Sbostic Pixmap DownLeft1Xbm;
36949855Sbostic Pixmap DownLeft2Xbm;
37049855Sbostic Pixmap DownRight1Xbm;
37149855Sbostic Pixmap DownRight2Xbm;
37249855Sbostic
37349855Sbostic Pixmap UpTogi1Xbm;
37449855Sbostic Pixmap UpTogi2Xbm;
37549855Sbostic Pixmap DownTogi1Xbm;
37649855Sbostic Pixmap DownTogi2Xbm;
37749855Sbostic Pixmap LeftTogi1Xbm;
37849855Sbostic Pixmap LeftTogi2Xbm;
37949855Sbostic Pixmap RightTogi1Xbm;
38049855Sbostic Pixmap RightTogi2Xbm;
38149855Sbostic
38249855Sbostic GC SpaceGC;
38349855Sbostic
38449855Sbostic GC Mati2GC;
38549855Sbostic GC Jare2GC;
38649855Sbostic GC Kaki1GC;
38749855Sbostic GC Kaki2GC;
38849855Sbostic GC Mati3GC;
38949855Sbostic GC Sleep1GC;
39049855Sbostic GC Sleep2GC;
39149855Sbostic
39249855Sbostic GC AwakeGC;
39349855Sbostic
39449855Sbostic GC Up1GC;
39549855Sbostic GC Up2GC;
39649855Sbostic GC Down1GC;
39749855Sbostic GC Down2GC;
39849855Sbostic GC Left1GC;
39949855Sbostic GC Left2GC;
40049855Sbostic GC Right1GC;
40149855Sbostic GC Right2GC;
40249855Sbostic GC UpLeft1GC;
40349855Sbostic GC UpLeft2GC;
40449855Sbostic GC UpRight1GC;
40549855Sbostic GC UpRight2GC;
40649855Sbostic GC DownLeft1GC;
40749855Sbostic GC DownLeft2GC;
40849855Sbostic GC DownRight1GC;
40949855Sbostic GC DownRight2GC;
41049855Sbostic
41149855Sbostic GC UpTogi1GC;
41249855Sbostic GC UpTogi2GC;
41349855Sbostic GC DownTogi1GC;
41449855Sbostic GC DownTogi2GC;
41549855Sbostic GC LeftTogi1GC;
41649855Sbostic GC LeftTogi2GC;
41749855Sbostic GC RightTogi1GC;
41849855Sbostic GC RightTogi2GC;
41949855Sbostic
42049855Sbostic typedef struct {
42149855Sbostic GC *GCCreatePtr;
42249855Sbostic Pixmap *BitmapCreatePtr;
42349855Sbostic char *PixelPattern;
42449855Sbostic unsigned int PixelWidth;
42549855Sbostic unsigned int PixelHeight;
42649855Sbostic } BitmapGCData;
42749855Sbostic
42849855Sbostic BitmapGCData BitmapGCDataTable[] =
42949855Sbostic {
43049855Sbostic { &SpaceGC, &SpaceXbm, space_bits, space_width, space_height },
43149855Sbostic { &Mati2GC, &Mati2Xbm, mati2_bits, mati2_width, mati2_height },
43249855Sbostic { &Jare2GC, &Jare2Xbm, jare2_bits, jare2_width, jare2_height },
43349855Sbostic { &Kaki1GC, &Kaki1Xbm, kaki1_bits, kaki1_width, kaki1_height },
43449855Sbostic { &Kaki2GC, &Kaki2Xbm, kaki2_bits, kaki2_width, kaki2_height },
43549855Sbostic { &Mati3GC, &Mati3Xbm, mati3_bits, mati3_width, mati3_height },
43649855Sbostic { &Sleep1GC, &Sleep1Xbm, sleep1_bits, sleep1_width, sleep1_height },
43749855Sbostic { &Sleep2GC, &Sleep2Xbm, sleep2_bits, sleep2_width, sleep2_height },
43849855Sbostic { &AwakeGC, &AwakeXbm, awake_bits, awake_width, awake_height },
43949855Sbostic { &Up1GC, &Up1Xbm, up1_bits, up1_width, up1_height },
44049855Sbostic { &Up2GC, &Up2Xbm, up2_bits, up2_width, up2_height },
44149855Sbostic { &Down1GC, &Down1Xbm, down1_bits, down1_width, down1_height },
44249855Sbostic { &Down2GC, &Down2Xbm, down2_bits, down2_width, down2_height },
44349855Sbostic { &Left1GC, &Left1Xbm, left1_bits, left1_width, left1_height },
44449855Sbostic { &Left2GC, &Left2Xbm, left2_bits, left2_width, left2_height },
44549855Sbostic { &Right1GC, &Right1Xbm, right1_bits, right1_width, right1_height },
44649855Sbostic { &Right2GC, &Right2Xbm, right2_bits, right2_width, right2_height },
44749855Sbostic { &UpLeft1GC, &UpLeft1Xbm, upleft1_bits, upleft1_width, upleft1_height },
44849855Sbostic { &UpLeft2GC, &UpLeft2Xbm, upleft2_bits, upleft2_width, upleft2_height },
44949855Sbostic { &UpRight1GC,
45049855Sbostic &UpRight1Xbm, upright1_bits, upright1_width, upright1_height },
45149855Sbostic { &UpRight2GC,
45249855Sbostic &UpRight2Xbm, upright2_bits, upright2_width, upright2_height },
45349855Sbostic { &DownLeft1GC,
45449855Sbostic &DownLeft1Xbm, dwleft1_bits, dwleft1_width, dwleft1_height },
45549855Sbostic { &DownLeft2GC,
45649855Sbostic &DownLeft2Xbm, dwleft2_bits, dwleft2_width, dwleft2_height },
45749855Sbostic { &DownRight1GC,
45849855Sbostic &DownRight1Xbm, dwright1_bits, dwright1_width, dwright1_height },
45949855Sbostic { &DownRight2GC,
46049855Sbostic &DownRight2Xbm, dwright2_bits, dwright2_width, dwright2_height },
46149855Sbostic { &UpTogi1GC, &UpTogi1Xbm, utogi1_bits, utogi1_width, utogi1_height },
46249855Sbostic { &UpTogi2GC, &UpTogi2Xbm, utogi2_bits, utogi2_width, utogi2_height },
46349855Sbostic { &DownTogi1GC, &DownTogi1Xbm, dtogi1_bits, dtogi1_width, dtogi1_height },
46449855Sbostic { &DownTogi2GC, &DownTogi2Xbm, dtogi2_bits, dtogi2_width, dtogi2_height },
46549855Sbostic { &LeftTogi1GC, &LeftTogi1Xbm, ltogi1_bits, ltogi1_width, ltogi1_height },
46649855Sbostic { &LeftTogi2GC, &LeftTogi2Xbm, ltogi2_bits, ltogi2_width, ltogi2_height },
46749855Sbostic { &RightTogi1GC,
46849855Sbostic &RightTogi1Xbm, rtogi1_bits, rtogi1_width, rtogi1_height },
46949855Sbostic { &RightTogi2GC,
47049855Sbostic &RightTogi2Xbm, rtogi2_bits, rtogi2_width, rtogi2_height },
47149855Sbostic { NULL, NULL, NULL, NULL, NULL }
47249855Sbostic };
47349855Sbostic
47449855Sbostic typedef struct {
47549855Sbostic GC *TickEvenGCPtr;
47649855Sbostic GC *TickOddGCPtr;
47749855Sbostic } Animation;
47849855Sbostic
47949855Sbostic Animation AnimationPattern[] =
48049855Sbostic {
48149855Sbostic { &Mati2GC, &Mati2GC }, /* NekoState == NEKO_STOP */
48249855Sbostic { &Jare2GC, &Mati2GC }, /* NekoState == NEKO_JARE */
48349855Sbostic { &Kaki1GC, &Kaki2GC }, /* NekoState == NEKO_KAKI */
48449855Sbostic { &Mati3GC, &Mati3GC }, /* NekoState == NEKO_AKUBI */
48549855Sbostic { &Sleep1GC, &Sleep2GC }, /* NekoState == NEKO_SLEEP */
48649855Sbostic { &AwakeGC, &AwakeGC }, /* NekoState == NEKO_AWAKE */
48749855Sbostic { &Up1GC, &Up2GC } , /* NekoState == NEKO_U_MOVE */
48849855Sbostic { &Down1GC, &Down2GC }, /* NekoState == NEKO_D_MOVE */
48949855Sbostic { &Left1GC, &Left2GC }, /* NekoState == NEKO_L_MOVE */
49049855Sbostic { &Right1GC, &Right2GC }, /* NekoState == NEKO_R_MOVE */
49149855Sbostic { &UpLeft1GC, &UpLeft2GC }, /* NekoState == NEKO_UL_MOVE */
49249855Sbostic { &UpRight1GC, &UpRight2GC }, /* NekoState == NEKO_UR_MOVE */
49349855Sbostic { &DownLeft1GC, &DownLeft2GC }, /* NekoState == NEKO_DL_MOVE */
49449855Sbostic { &DownRight1GC, &DownRight2GC }, /* NekoState == NEKO_DR_MOVE */
49549855Sbostic { &UpTogi1GC, &UpTogi2GC }, /* NekoState == NEKO_U_TOGI */
49649855Sbostic { &DownTogi1GC, &DownTogi2GC }, /* NekoState == NEKO_D_TOGI */
49749855Sbostic { &LeftTogi1GC, &LeftTogi2GC }, /* NekoState == NEKO_L_TOGI */
49849855Sbostic { &RightTogi1GC, &RightTogi2GC }, /* NekoState == NEKO_R_TOGI */
49949855Sbostic };
50049855Sbostic
50149855Sbostic
50249855Sbostic /*--------------------------------------------------------------
50349855Sbostic *
50449858Sbostic * 0C10/14/12^504W%G!<%?!&GC =i4|2=
50549855Sbostic *
50649855Sbostic *--------------------------------------------------------------*/
50749855Sbostic
50849855Sbostic void
InitBitmapAndGCs()50949855Sbostic InitBitmapAndGCs()
51049855Sbostic {
51149855Sbostic BitmapGCData *BitmapGCDataTablePtr;
51249855Sbostic XGCValues theGCValues;
51349855Sbostic
51449855Sbostic theGCValues.function = GXcopy;
51549855Sbostic theGCValues.foreground = BlackPixel( theDisplay, theScreen );
51649855Sbostic theGCValues.background = WhitePixel( theDisplay, theScreen );
51749855Sbostic theGCValues.fill_style = FillTiled;
51849855Sbostic
51949855Sbostic for ( BitmapGCDataTablePtr = BitmapGCDataTable;
52049855Sbostic BitmapGCDataTablePtr->GCCreatePtr != NULL;
52149855Sbostic BitmapGCDataTablePtr++ ) {
52249855Sbostic
52349855Sbostic *(BitmapGCDataTablePtr->BitmapCreatePtr)
52449855Sbostic = XCreatePixmapFromBitmapData(
52549855Sbostic theDisplay,
52649855Sbostic RootWindow( theDisplay, theScreen ),
52749855Sbostic BitmapGCDataTablePtr->PixelPattern,
52849855Sbostic BitmapGCDataTablePtr->PixelWidth,
52949855Sbostic BitmapGCDataTablePtr->PixelHeight,
53049855Sbostic BlackPixel( theDisplay, theScreen ),
53149855Sbostic WhitePixel( theDisplay, theScreen ),
53249855Sbostic DefaultDepth( theDisplay, theScreen ) );
53349855Sbostic
53449855Sbostic theGCValues.tile = *(BitmapGCDataTablePtr->BitmapCreatePtr);
53549855Sbostic
53649855Sbostic *(BitmapGCDataTablePtr->GCCreatePtr)
53749855Sbostic = XCreateGC( theDisplay, theWindow,
53849855Sbostic GCFunction | GCForeground | GCBackground |
53949855Sbostic GCTile | GCFillStyle,
54049855Sbostic &theGCValues );
54149855Sbostic }
54249855Sbostic
54349855Sbostic XFlush( theDisplay );
54449855Sbostic }
54549855Sbostic
54649855Sbostic
54749855Sbostic /*--------------------------------------------------------------
54849855Sbostic *
54949855Sbostic * %9%/%j!<%s4D6-=i4|2=
55049855Sbostic *
55149855Sbostic *--------------------------------------------------------------*/
55249855Sbostic
55349855Sbostic void
InitScreen(DisplayName,theGeometry,TitleName,iconicState)55449855Sbostic InitScreen( DisplayName, theGeometry, TitleName, iconicState )
55549855Sbostic char *DisplayName;
55649855Sbostic char *theGeometry;
55749855Sbostic char *TitleName;
55849855Sbostic Bool iconicState;
55949855Sbostic {
56049855Sbostic int GeometryStatus;
56149855Sbostic XSetWindowAttributes theWindowAttributes;
56249855Sbostic XSizeHints theSizeHints;
56349855Sbostic unsigned long theWindowMask;
56449855Sbostic Pixmap theIconPixmap;
56549855Sbostic Pixmap theCursorSource;
56649855Sbostic Pixmap theCursorMask;
56749855Sbostic XWMHints theWMHints;
56849855Sbostic Window theRoot;
56949855Sbostic Colormap theColormap;
57049855Sbostic XColor theWhiteColor, theBlackColor, theExactColor;
57149855Sbostic
57249855Sbostic if ( ( theDisplay = XOpenDisplay( DisplayName ) ) == NULL ) {
57349855Sbostic fprintf( stderr, "%s: Can't open display", ProgramName );
57449855Sbostic if ( DisplayName != NULL ) {
57549855Sbostic fprintf( stderr, " %s.\n", DisplayName );
57649855Sbostic } else {
57749855Sbostic fprintf( stderr, ".\n" );
57849855Sbostic }
57949855Sbostic exit( 1 );
58049855Sbostic }
58149855Sbostic
58249855Sbostic theScreen = DefaultScreen( theDisplay );
58349855Sbostic theDepth = DefaultDepth( theDisplay, theScreen );
58449855Sbostic
58549855Sbostic theBlackPixel = BlackPixel( theDisplay, theScreen );
58649855Sbostic theWhitePixel = WhitePixel( theDisplay, theScreen );
58749855Sbostic
58849855Sbostic GeometryStatus = XParseGeometry( theGeometry,
58949855Sbostic &WindowPointX, &WindowPointY,
59049855Sbostic &WindowWidth, &WindowHeight );
59149855Sbostic
59249855Sbostic if ( !( GeometryStatus & XValue ) ) {
59349855Sbostic WindowPointX = DEFAULT_WIN_X;
59449855Sbostic }
59549855Sbostic if ( !( GeometryStatus & YValue ) ) {
59649855Sbostic WindowPointY = DEFAULT_WIN_Y;
59749855Sbostic }
59849855Sbostic if ( !( GeometryStatus & WidthValue ) ) {
59949855Sbostic WindowWidth = WINDOW_WIDTH;
60049855Sbostic }
60149855Sbostic if ( !( GeometryStatus & HeightValue ) ) {
60249855Sbostic WindowHeight = WINDOW_HEIGHT;
60349855Sbostic }
60449855Sbostic
60549855Sbostic theCursorSource
60649855Sbostic = XCreateBitmapFromData( theDisplay,
60749855Sbostic RootWindow( theDisplay, theScreen ),
60849855Sbostic cursor_bits,
60949855Sbostic cursor_width,
61049855Sbostic cursor_height );
61149855Sbostic
61249855Sbostic theCursorMask
61349855Sbostic = XCreateBitmapFromData( theDisplay,
61449855Sbostic RootWindow( theDisplay, theScreen ),
61549855Sbostic cursor_mask_bits,
61649855Sbostic cursor_mask_width,
61749855Sbostic cursor_mask_height );
61849855Sbostic
61949855Sbostic theColormap = DefaultColormap( theDisplay, theScreen );
62049855Sbostic
62149855Sbostic if ( !XAllocNamedColor( theDisplay, theColormap,
62249855Sbostic "white", &theWhiteColor, &theExactColor ) ) {
62349855Sbostic fprintf( stderr,
62449855Sbostic "%s: Can't XAllocNamedColor( \"white\" ).\n", ProgramName );
62549855Sbostic exit( 1 );
62649855Sbostic }
62749855Sbostic
62849855Sbostic if ( !XAllocNamedColor( theDisplay, theColormap,
62949855Sbostic "black", &theBlackColor, &theExactColor ) ) {
63049855Sbostic fprintf( stderr,
63149855Sbostic "%s: Can't XAllocNamedColor( \"black\" ).\n", ProgramName );
63249855Sbostic exit( 1 );
63349855Sbostic }
63449855Sbostic
63549855Sbostic theCursor = XCreatePixmapCursor( theDisplay,
63649855Sbostic theCursorSource, theCursorMask,
63749855Sbostic &theBlackColor, &theWhiteColor,
63849855Sbostic cursor_x_hot, cursor_y_hot );
63949855Sbostic
64049855Sbostic theWindowAttributes.border_pixel = theBlackPixel;
64149855Sbostic theWindowAttributes.background_pixel = theWhitePixel;
64249855Sbostic theWindowAttributes.cursor = theCursor;
64349855Sbostic theWindowAttributes.override_redirect = False;
64449855Sbostic
64549855Sbostic theWindowMask = CWBackPixel |
64649855Sbostic CWBorderPixel |
64749855Sbostic CWCursor |
64849855Sbostic CWOverrideRedirect;
64949855Sbostic
65049855Sbostic theWindow = XCreateWindow( theDisplay,
65149855Sbostic RootWindow( theDisplay, theScreen ),
65249855Sbostic WindowPointX, WindowPointY,
65349855Sbostic WindowWidth, WindowHeight,
65449855Sbostic BorderWidth,
65549855Sbostic theDepth,
65649855Sbostic InputOutput,
65749855Sbostic CopyFromParent,
65849855Sbostic theWindowMask,
65949855Sbostic &theWindowAttributes );
66049855Sbostic
66149855Sbostic theIconPixmap = XCreateBitmapFromData( theDisplay, theWindow,
66249855Sbostic icon_bits,
66349855Sbostic icon_width,
66449855Sbostic icon_height );
66549855Sbostic
66649855Sbostic theWMHints.icon_pixmap = theIconPixmap;
66749855Sbostic if ( iconicState ) {
66849855Sbostic theWMHints.initial_state = IconicState;
66949855Sbostic } else {
67049855Sbostic theWMHints.initial_state = NormalState;
67149855Sbostic }
67249855Sbostic theWMHints.flags = IconPixmapHint | StateHint;
67349855Sbostic
67449855Sbostic XSetWMHints( theDisplay, theWindow, &theWMHints );
67549855Sbostic
67649855Sbostic theSizeHints.flags = PPosition | PSize;
67749855Sbostic theSizeHints.x = WindowPointX;
67849855Sbostic theSizeHints.y = WindowPointY;
67949855Sbostic theSizeHints.width = WindowWidth;
68049855Sbostic theSizeHints.height = WindowHeight;
68149855Sbostic
68249855Sbostic XSetNormalHints( theDisplay, theWindow, &theSizeHints );
68349855Sbostic
68449855Sbostic if ( strlen( TitleName ) >= 1 ) {
68549855Sbostic XStoreName( theDisplay, theWindow, TitleName );
68649855Sbostic XSetIconName( theDisplay, theWindow, TitleName );
68749855Sbostic } else {
68849855Sbostic XStoreName( theDisplay, theWindow, ProgramName );
68949855Sbostic XSetIconName( theDisplay, theWindow, ProgramName );
69049855Sbostic }
69149855Sbostic
69249855Sbostic XMapWindow( theDisplay, theWindow );
69349855Sbostic
69449855Sbostic XFlush( theDisplay );
69549855Sbostic
69649855Sbostic XGetGeometry( theDisplay, theWindow,
69749855Sbostic &theRoot,
69849855Sbostic &WindowPointX, &WindowPointY,
69949855Sbostic &WindowWidth, &WindowHeight,
70049855Sbostic &BorderWidth, &theDepth );
70149855Sbostic
70249855Sbostic InitBitmapAndGCs();
70349855Sbostic
70449855Sbostic XSelectInput( theDisplay, theWindow, EVENT_MASK1 );
70549855Sbostic
70649855Sbostic XFlush( theDisplay );
70749855Sbostic }
70849855Sbostic
70949855Sbostic
71049855Sbostic /*--------------------------------------------------------------
71149855Sbostic *
71249855Sbostic * %$%s%?!</usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.ck
71349855Sbostic *
71449855Sbostic * !!$3$N4X?t$r8F$V$H!"$"$k0lDj$N;~4VJV$C$F$3$J$/$J$k!#G-
71549855Sbostic * $NF0:n%?%$%_%s%0D4@0$KMxMQ$9$k$3$H!#
71649855Sbostic *
71749855Sbostic *--------------------------------------------------------------*/
71849855Sbostic
71949855Sbostic void
Interval()72049855Sbostic Interval()
72149855Sbostic {
72249855Sbostic pause();
72349855Sbostic }
72449855Sbostic
72549855Sbostic
72649855Sbostic /*--------------------------------------------------------------
72749855Sbostic *
72849858Sbostic * s.xneko.c#728/%+%&%s%H=hM}
72949855Sbostic *
73049855Sbostic *--------------------------------------------------------------*/
73149855Sbostic
73249855Sbostic void
TickCount()73349855Sbostic TickCount()
73449855Sbostic {
73549855Sbostic if ( ++NekoTickCount >= MAX_TICK ) {
73649855Sbostic NekoTickCount = 0;
73749855Sbostic }
73849855Sbostic
73949855Sbostic if ( NekoTickCount % 2 == 0 ) {
74049855Sbostic if ( NekoStateCount < MAX_TICK ) {
74149855Sbostic NekoStateCount++;
74249855Sbostic }
74349855Sbostic }
74449855Sbostic }
74549855Sbostic
74649855Sbostic
74749855Sbostic /*--------------------------------------------------------------
74849855Sbostic *
74949855Sbostic * G->uBV@_Dj
75049855Sbostic *
75149855Sbostic *--------------------------------------------------------------*/
75249855Sbostic
75349855Sbostic void
SetNekoState(SetValue)75449855Sbostic SetNekoState( SetValue )
75549855Sbostic int SetValue;
75649855Sbostic {
75749855Sbostic NekoTickCount = 0;
75849855Sbostic NekoStateCount = 0;
75949855Sbostic
76049855Sbostic NekoState = SetValue;
76149855Sbostic
76249855Sbostic #ifdef DEBUG
76349855Sbostic switch ( NekoState ) {
76449855Sbostic case NEKO_STOP:
76549855Sbostic case NEKO_JARE:
76649855Sbostic case NEKO_KAKI:
76749855Sbostic case NEKO_AKUBI:
76849855Sbostic case NEKO_SLEEP:
76949855Sbostic case NEKO_U_TOGI:
77049855Sbostic case NEKO_D_TOGI:
77149855Sbostic case NEKO_L_TOGI:
77249855Sbostic case NEKO_R_TOGI:
77349855Sbostic NekoMoveDx = NekoMoveDy = 0;
77449855Sbostic break;
77549855Sbostic default:
77649855Sbostic break;
77749855Sbostic }
77849855Sbostic #endif
77949855Sbostic }
78049855Sbostic
78149855Sbostic
78249855Sbostic /*--------------------------------------------------------------
78349855Sbostic *
78449855Sbostic * G-IA2h=hM}
78549855Sbostic *
78649855Sbostic *--------------------------------------------------------------*/
78749855Sbostic
78849855Sbostic void
DrawNeko(x,y,DrawGC)78949855Sbostic DrawNeko( x, y, DrawGC )
79049855Sbostic int x;
79149855Sbostic int y;
79249855Sbostic GC DrawGC;
79349855Sbostic {
79449855Sbostic if ( ( x != NekoLastX || y != NekoLastY )
79549855Sbostic && ( EventState != DEBUG_LIST ) ) {
79649855Sbostic XFillRectangle( theDisplay, theWindow, SpaceGC,
79749855Sbostic NekoLastX, NekoLastY,
79849855Sbostic BITMAP_WIDTH, BITMAP_HEIGHT );
79949855Sbostic }
80049855Sbostic
80149855Sbostic XSetTSOrigin( theDisplay, DrawGC, x, y );
80249855Sbostic
80349855Sbostic XFillRectangle( theDisplay, theWindow, DrawGC,
80449855Sbostic x, y, BITMAP_WIDTH, BITMAP_HEIGHT );
80549855Sbostic
80649855Sbostic XFlush( theDisplay );
80749855Sbostic
80849855Sbostic NekoLastX = x;
80949855Sbostic NekoLastY = y;
81049855Sbostic
81149855Sbostic NekoLastGC = DrawGC;
81249855Sbostic }
81349855Sbostic
81449855Sbostic
81549855Sbostic /*--------------------------------------------------------------
81649855Sbostic *
81749855Sbostic * G-:FIA2h=hM}
81849855Sbostic *
81949855Sbostic *--------------------------------------------------------------*/
82049855Sbostic
82149855Sbostic void
RedrawNeko()82249855Sbostic RedrawNeko()
82349855Sbostic {
82449855Sbostic XFillRectangle( theDisplay, theWindow, NekoLastGC,
82549855Sbostic NekoLastX, NekoLastY,
82649855Sbostic BITMAP_WIDTH, BITMAP_HEIGHT );
82749855Sbostic
82849855Sbostic XFlush( theDisplay );
82949855Sbostic }
83049855Sbostic
83149855Sbostic
83249855Sbostic /*--------------------------------------------------------------
83349855Sbostic *
83449855Sbostic * G-0\F0J}K!7hDj
83549855Sbostic *
83649855Sbostic *--------------------------------------------------------------*/
83749855Sbostic
83849855Sbostic void
NekoDirection()83949855Sbostic NekoDirection()
84049855Sbostic {
84149855Sbostic int NewState;
84249855Sbostic double LargeX, LargeY;
84349855Sbostic double Length;
84449855Sbostic double SinTheta;
84549855Sbostic
84649855Sbostic if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) {
84749855Sbostic NewState = NEKO_STOP;
84849855Sbostic } else {
84949855Sbostic LargeX = (double)NekoMoveDx;
85049855Sbostic LargeY = (double)(-NekoMoveDy);
85149855Sbostic Length = sqrt( LargeX * LargeX + LargeY * LargeY );
85249855Sbostic SinTheta = LargeY / Length;
85349855Sbostic
85449855Sbostic if ( NekoMoveDx > 0 ) {
85549855Sbostic if ( SinTheta > SinPiPer8Times3 ) {
85649855Sbostic NewState = NEKO_U_MOVE;
85749855Sbostic } else if ( ( SinTheta <= SinPiPer8Times3 )
85849855Sbostic && ( SinTheta > SinPiPer8 ) ) {
85949855Sbostic NewState = NEKO_UR_MOVE;
86049855Sbostic } else if ( ( SinTheta <= SinPiPer8 )
86149855Sbostic && ( SinTheta > -( SinPiPer8 ) ) ) {
86249855Sbostic NewState = NEKO_R_MOVE;
86349855Sbostic } else if ( ( SinTheta <= -( SinPiPer8 ) )
86449855Sbostic && ( SinTheta > -( SinPiPer8Times3 ) ) ) {
86549855Sbostic NewState = NEKO_DR_MOVE;
86649855Sbostic } else {
86749855Sbostic NewState = NEKO_D_MOVE;
86849855Sbostic }
86949855Sbostic } else {
87049855Sbostic if ( SinTheta > SinPiPer8Times3 ) {
87149855Sbostic NewState = NEKO_U_MOVE;
87249855Sbostic } else if ( ( SinTheta <= SinPiPer8Times3 )
87349855Sbostic && ( SinTheta > SinPiPer8 ) ) {
87449855Sbostic NewState = NEKO_UL_MOVE;
87549855Sbostic } else if ( ( SinTheta <= SinPiPer8 )
87649855Sbostic && ( SinTheta > -( SinPiPer8 ) ) ) {
87749855Sbostic NewState = NEKO_L_MOVE;
87849855Sbostic } else if ( ( SinTheta <= -( SinPiPer8 ) )
87949855Sbostic && ( SinTheta > -( SinPiPer8Times3 ) ) ) {
88049855Sbostic NewState = NEKO_DL_MOVE;
88149855Sbostic } else {
88249855Sbostic NewState = NEKO_D_MOVE;
88349855Sbostic }
88449855Sbostic }
88549855Sbostic }
88649855Sbostic
88749855Sbostic if ( NekoState != NewState ) {
88849855Sbostic SetNekoState( NewState );
88949855Sbostic }
89049855Sbostic }
89149855Sbostic
89249855Sbostic
89349855Sbostic /*--------------------------------------------------------------
89449855Sbostic *
89549855Sbostic * G-JI$V$D$+$jH=Dj
89649855Sbostic *
89749855Sbostic *--------------------------------------------------------------*/
89849855Sbostic
89949855Sbostic Bool
IsWindowOver()90049855Sbostic IsWindowOver()
90149855Sbostic {
90249855Sbostic Bool ReturnValue = False;
90349855Sbostic
90449855Sbostic if ( NekoY <= 0 ) {
90549855Sbostic NekoY = 0;
90649855Sbostic ReturnValue = True;
90749855Sbostic } else if ( NekoY >= WindowHeight - BITMAP_HEIGHT ) {
90849855Sbostic NekoY = WindowHeight - BITMAP_HEIGHT;
90949855Sbostic ReturnValue = True;
91049855Sbostic }
91149855Sbostic if ( NekoX <= 0 ) {
91249855Sbostic NekoX = 0;
91349855Sbostic ReturnValue = True;
91449855Sbostic } else if ( NekoX >= WindowWidth - BITMAP_WIDTH ) {
91549855Sbostic NekoX = WindowWidth - BITMAP_WIDTH;
91649855Sbostic ReturnValue = True;
91749855Sbostic }
91849855Sbostic
91949855Sbostic return( ReturnValue );
92049855Sbostic }
92149855Sbostic
92249855Sbostic
92349855Sbostic /*--------------------------------------------------------------
92449855Sbostic *
92549855Sbostic * G-0\F0>u67H=Dj
92649855Sbostic *
92749855Sbostic *--------------------------------------------------------------*/
92849855Sbostic
92949855Sbostic Bool
IsNekoDontMove()93049855Sbostic IsNekoDontMove()
93149855Sbostic {
93249855Sbostic if ( NekoX == NekoLastX && NekoY == NekoLastY ) {
93349855Sbostic return( True );
93449855Sbostic } else {
93549855Sbostic return( False );
93649855Sbostic }
93749855Sbostic }
93849855Sbostic
93949855Sbostic
94049855Sbostic /*--------------------------------------------------------------
94149855Sbostic *
94249855Sbostic * G-0\F03+;OH=Dj
94349855Sbostic *
94449855Sbostic *--------------------------------------------------------------*/
94549855Sbostic
94649855Sbostic Bool
IsNekoMoveStart()94749855Sbostic IsNekoMoveStart()
94849855Sbostic {
94949855Sbostic #ifndef DEBUG
95049855Sbostic if ( ( PrevMouseX >= MouseX - IDLE_SPACE
95149855Sbostic && PrevMouseX <= MouseX + IDLE_SPACE ) &&
95249855Sbostic ( PrevMouseY >= MouseY - IDLE_SPACE
95349855Sbostic && PrevMouseY <= MouseY + IDLE_SPACE ) ) {
95449855Sbostic return( False );
95549855Sbostic } else {
95649855Sbostic return( True );
95749855Sbostic }
95849855Sbostic #else
95949855Sbostic if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) {
96049855Sbostic return( False );
96149855Sbostic } else {
96249855Sbostic return( True );
96349855Sbostic }
96449855Sbostic #endif
96549855Sbostic }
96649855Sbostic
96749855Sbostic
96849855Sbostic /*--------------------------------------------------------------
96949855Sbostic *
97049855Sbostic * G-0\F0 dx, dy 7W;;
97149855Sbostic *
97249855Sbostic *--------------------------------------------------------------*/
97349855Sbostic
97449855Sbostic void
CalcDxDy()97549855Sbostic CalcDxDy()
97649855Sbostic {
97749855Sbostic Window QueryRoot, QueryChild;
97849855Sbostic int AbsoluteX, AbsoluteY;
97949855Sbostic int RelativeX, RelativeY;
98049855Sbostic unsigned int ModKeyMask;
98149855Sbostic double LargeX, LargeY;
98249855Sbostic double DoubleLength, Length;
98349855Sbostic
98449855Sbostic XQueryPointer( theDisplay, theWindow,
98549855Sbostic &QueryRoot, &QueryChild,
98649855Sbostic &AbsoluteX, &AbsoluteY,
98749855Sbostic &RelativeX, &RelativeY,
98849855Sbostic &ModKeyMask );
98949855Sbostic
99049855Sbostic PrevMouseX = MouseX;
99149855Sbostic PrevMouseY = MouseY;
99249855Sbostic
99349855Sbostic MouseX = RelativeX;
99449855Sbostic MouseY = RelativeY;
99549855Sbostic
99649855Sbostic LargeX = (double)( MouseX - NekoX - BITMAP_WIDTH / 2 );
99749855Sbostic LargeY = (double)( MouseY - NekoY - BITMAP_HEIGHT );
99849855Sbostic
99949855Sbostic DoubleLength = LargeX * LargeX + LargeY * LargeY;
100049855Sbostic
100149855Sbostic if ( DoubleLength != (double)0 ) {
100249855Sbostic Length = sqrt( DoubleLength );
100349855Sbostic if ( Length <= NekoSpeed ) {
100449855Sbostic NekoMoveDx = (int)LargeX;
100549855Sbostic NekoMoveDy = (int)LargeY;
100649855Sbostic } else {
100749855Sbostic NekoMoveDx = (int)( ( NekoSpeed * LargeX ) / Length );
100849855Sbostic NekoMoveDy = (int)( ( NekoSpeed * LargeY ) / Length );
100949855Sbostic }
101049855Sbostic } else {
101149855Sbostic NekoMoveDx = NekoMoveDy = 0;
101249855Sbostic }
101349855Sbostic }
101449855Sbostic
101549855Sbostic
101649855Sbostic /*--------------------------------------------------------------
101749855Sbostic *
101849855Sbostic * F0:n2r@OG-IA2h=hM}
101949855Sbostic *
102049855Sbostic *--------------------------------------------------------------*/
102149855Sbostic
102249855Sbostic void
NekoThinkDraw()102349855Sbostic NekoThinkDraw()
102449855Sbostic {
102549855Sbostic #ifndef DEBUG
102649855Sbostic CalcDxDy();
102749855Sbostic #endif
102849855Sbostic
102949855Sbostic if ( NekoState != NEKO_SLEEP ) {
103049855Sbostic DrawNeko( NekoX, NekoY,
103149855Sbostic NekoTickCount % 2 == 0 ?
103249855Sbostic *(AnimationPattern[ NekoState ].TickEvenGCPtr) :
103349855Sbostic *(AnimationPattern[ NekoState ].TickOddGCPtr) );
103449855Sbostic } else {
103549855Sbostic DrawNeko( NekoX, NekoY,
103649855Sbostic NekoTickCount % 8 <= 3 ?
103749855Sbostic *(AnimationPattern[ NekoState ].TickEvenGCPtr) :
103849855Sbostic *(AnimationPattern[ NekoState ].TickOddGCPtr) );
103949855Sbostic }
104049855Sbostic
104149855Sbostic TickCount();
104249855Sbostic
104349855Sbostic switch ( NekoState ) {
104449855Sbostic case NEKO_STOP:
104549855Sbostic if ( IsNekoMoveStart() ) {
104649855Sbostic SetNekoState( NEKO_AWAKE );
104749855Sbostic break;
104849855Sbostic }
104949855Sbostic if ( NekoStateCount < NEKO_STOP_TIME ) {
105049855Sbostic break;
105149855Sbostic }
105249855Sbostic if ( NekoMoveDx < 0 && NekoX <= 0 ) {
105349855Sbostic SetNekoState( NEKO_L_TOGI );
105449855Sbostic } else if ( NekoMoveDx > 0 && NekoX >= WindowWidth - BITMAP_WIDTH ) {
105549855Sbostic SetNekoState( NEKO_R_TOGI );
105649855Sbostic } else if ( NekoMoveDy < 0 && NekoY <= 0 ) {
105749855Sbostic SetNekoState( NEKO_U_TOGI );
105849855Sbostic } else if ( NekoMoveDy > 0 && NekoY >= WindowHeight - BITMAP_HEIGHT ) {
105949855Sbostic SetNekoState( NEKO_D_TOGI );
106049855Sbostic } else {
106149855Sbostic SetNekoState( NEKO_JARE );
106249855Sbostic }
106349855Sbostic break;
106449855Sbostic case NEKO_JARE:
106549855Sbostic if ( IsNekoMoveStart() ) {
106649855Sbostic SetNekoState( NEKO_AWAKE );
106749855Sbostic break;
106849855Sbostic }
106949855Sbostic if ( NekoStateCount < NEKO_JARE_TIME ) {
107049855Sbostic break;
107149855Sbostic }
107249855Sbostic SetNekoState( NEKO_KAKI );
107349855Sbostic break;
107449855Sbostic case NEKO_KAKI:
107549855Sbostic if ( IsNekoMoveStart() ) {
107649855Sbostic SetNekoState( NEKO_AWAKE );
107749855Sbostic break;
107849855Sbostic }
107949855Sbostic if ( NekoStateCount < NEKO_KAKI_TIME ) {
108049855Sbostic break;
108149855Sbostic }
108249855Sbostic SetNekoState( NEKO_AKUBI );
108349855Sbostic break;
108449855Sbostic case NEKO_AKUBI:
108549855Sbostic if ( IsNekoMoveStart() ) {
108649855Sbostic SetNekoState( NEKO_AWAKE );
108749855Sbostic break;
108849855Sbostic }
108949855Sbostic if ( NekoStateCount < NEKO_AKUBI_TIME ) {
109049855Sbostic break;
109149855Sbostic }
109249855Sbostic SetNekoState( NEKO_SLEEP );
109349855Sbostic break;
109449855Sbostic case NEKO_SLEEP:
109549855Sbostic if ( IsNekoMoveStart() ) {
109649855Sbostic SetNekoState( NEKO_AWAKE );
109749855Sbostic break;
109849855Sbostic }
109949855Sbostic break;
110049855Sbostic case NEKO_AWAKE:
110149855Sbostic if ( NekoStateCount < NEKO_AWAKE_TIME ) {
110249855Sbostic break;
110349855Sbostic }
110449855Sbostic NekoDirection(); /* G-$,F0$/8~$-$r5a$a$k */
110549855Sbostic break;
110649855Sbostic case NEKO_U_MOVE:
110749855Sbostic case NEKO_D_MOVE:
110849855Sbostic case NEKO_L_MOVE:
110949855Sbostic case NEKO_R_MOVE:
111049855Sbostic case NEKO_UL_MOVE:
111149855Sbostic case NEKO_UR_MOVE:
111249855Sbostic case NEKO_DL_MOVE:
111349855Sbostic case NEKO_DR_MOVE:
111449855Sbostic NekoX += NekoMoveDx;
111549855Sbostic NekoY += NekoMoveDy;
111649855Sbostic NekoDirection();
111749855Sbostic if ( IsWindowOver() ) {
111849855Sbostic if ( IsNekoDontMove() ) {
111949855Sbostic SetNekoState( NEKO_STOP );
112049855Sbostic }
112149855Sbostic }
112249855Sbostic break;
112349855Sbostic case NEKO_U_TOGI:
112449855Sbostic case NEKO_D_TOGI:
112549855Sbostic case NEKO_L_TOGI:
112649855Sbostic case NEKO_R_TOGI:
112749855Sbostic if ( IsNekoMoveStart() ) {
112849855Sbostic SetNekoState( NEKO_AWAKE );
112949855Sbostic break;
113049855Sbostic }
113149855Sbostic if ( NekoStateCount < NEKO_TOGI_TIME ) {
113249855Sbostic break;
113349855Sbostic }
113449855Sbostic SetNekoState( NEKO_KAKI );
113549855Sbostic break;
113649855Sbostic default:
113749855Sbostic /* Internal Error */
113849855Sbostic SetNekoState( NEKO_STOP );
113949855Sbostic break;
114049855Sbostic }
114149855Sbostic
114249855Sbostic Interval();
114349855Sbostic }
114449855Sbostic
114549855Sbostic
114649855Sbostic #ifdef DEBUG
114749855Sbostic
114849855Sbostic /*--------------------------------------------------------------
114949855Sbostic *
1150*60873Sbostic * %-%c%i%/%?!<0lMwI=<(!J05/31/93P11500MQ!K
115149855Sbostic *
115249855Sbostic *--------------------------------------------------------------*/
115349855Sbostic
115449855Sbostic void
DisplayCharacters()115549855Sbostic DisplayCharacters()
115649855Sbostic {
115749855Sbostic int Index;
115849855Sbostic int x, y;
115949855Sbostic
116049855Sbostic for ( Index = 0, x = 0, y = 0;
116149855Sbostic BitmapGCDataTable[ Index ].GCCreatePtr != NULL; Index++ ) {
116249855Sbostic
116349855Sbostic DrawNeko( x, y, *(BitmapGCDataTable[ Index ].GCCreatePtr) );
116449855Sbostic XFlush( theDisplay );
116549855Sbostic
116649855Sbostic x += BITMAP_WIDTH;
116749855Sbostic
116849855Sbostic if ( x > WindowWidth - BITMAP_WIDTH ) {
116949855Sbostic x = 0;
117049855Sbostic y += BITMAP_HEIGHT;
117149855Sbostic if ( y > WindowHeight - BITMAP_HEIGHT) {
117249855Sbostic break;
117349855Sbostic }
117449855Sbostic }
117549855Sbostic }
117649855Sbostic }
117749855Sbostic
117849855Sbostic #endif /* DEBUG */
117949855Sbostic
118049855Sbostic
118149855Sbostic /*--------------------------------------------------------------
118249855Sbostic *
118349855Sbostic * %-!<%$s%H=hM}
118449855Sbostic *
118549855Sbostic *--------------------------------------------------------------*/
118649855Sbostic
118749855Sbostic Bool
ProcessKeyPress(theKeyEvent)118849855Sbostic ProcessKeyPress( theKeyEvent )
118949855Sbostic XKeyEvent *theKeyEvent;
119049855Sbostic {
119149855Sbostic int Length;
119249855Sbostic int theKeyBufferMaxLen = AVAIL_KEYBUF;
119349855Sbostic char theKeyBuffer[ AVAIL_KEYBUF + 1 ];
119449855Sbostic KeySym theKeySym;
119549855Sbostic XComposeStatus theComposeStatus;
119649855Sbostic Bool ReturnState;
119749855Sbostic
119849855Sbostic ReturnState = True;
119949855Sbostic
120049855Sbostic Length = XLookupString( theKeyEvent,
120149855Sbostic theKeyBuffer, theKeyBufferMaxLen,
120249855Sbostic &theKeySym, &theComposeStatus );
120349855Sbostic
120449855Sbostic if ( Length > 0 ) {
120549855Sbostic switch ( theKeyBuffer[ 0 ] ) {
120649855Sbostic case 'q':
120749855Sbostic case 'Q':
120849855Sbostic if ( theKeyEvent->state & Mod1Mask ) { /* META (Alt) %-!< */
120949855Sbostic ReturnState = False;
121049855Sbostic }
121149855Sbostic break;
121249855Sbostic default:
121349855Sbostic break;
121449855Sbostic }
121549855Sbostic }
121649855Sbostic
121749855Sbostic #ifdef DEBUG
121849855Sbostic if ( EventState == DEBUG_MOVE ) {
121949855Sbostic switch ( theKeySym ) {
122049855Sbostic case XK_KP_1:
122149855Sbostic NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );
122249855Sbostic NekoMoveDy = -NekoMoveDx;
122349855Sbostic break;
122449855Sbostic case XK_KP_2:
122549855Sbostic NekoMoveDx = 0;
122649855Sbostic NekoMoveDy = (int)NekoSpeed;
122749855Sbostic break;
122849855Sbostic case XK_KP_3:
122949855Sbostic NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );
123049855Sbostic NekoMoveDy = NekoMoveDx;
123149855Sbostic break;
123249855Sbostic case XK_KP_4:
123349855Sbostic NekoMoveDx = -(int)NekoSpeed;
123449855Sbostic NekoMoveDy = 0;
123549855Sbostic break;
123649855Sbostic case XK_KP_5:
123749855Sbostic NekoMoveDx = 0;
123849855Sbostic NekoMoveDy = 0;
123949855Sbostic break;
124049855Sbostic case XK_KP_6:
124149855Sbostic NekoMoveDx = (int)NekoSpeed;
124249855Sbostic NekoMoveDy = 0;
124349855Sbostic break;
124449855Sbostic case XK_KP_7:
124549855Sbostic NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );
124649855Sbostic NekoMoveDy = NekoMoveDx;
124749855Sbostic break;
124849855Sbostic case XK_KP_8:
124949855Sbostic NekoMoveDx = 0;
125049855Sbostic NekoMoveDy = -(int)NekoSpeed;
125149855Sbostic break;
125249855Sbostic case XK_KP_9:
125349855Sbostic NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );
125449855Sbostic NekoMoveDy = -NekoMoveDx;
125549855Sbostic break;
125649855Sbostic }
125749855Sbostic }
125849855Sbostic #endif
125949855Sbostic
126049855Sbostic return( ReturnState );
126149855Sbostic }
126249855Sbostic
126349855Sbostic
126449855Sbostic /*--------------------------------------------------------------
126549855Sbostic *
126649855Sbostic * G-0LCVD4@0
126749855Sbostic *
126849855Sbostic *--------------------------------------------------------------*/
126949855Sbostic
127049855Sbostic void
NekoAdjust()127149855Sbostic NekoAdjust()
127249855Sbostic {
127349855Sbostic if ( NekoX < 0 ) {
127449855Sbostic NekoX = 0;
127549855Sbostic } else if ( NekoX > WindowWidth - BITMAP_WIDTH ) {
127649855Sbostic NekoX = WindowWidth - BITMAP_WIDTH;
127749855Sbostic }
127849855Sbostic
127949855Sbostic if ( NekoY < 0 ) {
128049855Sbostic NekoY = 0;
128149855Sbostic } else if ( NekoY > WindowHeight - BITMAP_HEIGHT ) {
128249855Sbostic NekoY = WindowHeight - BITMAP_HEIGHT;
128349855Sbostic }
128449855Sbostic }
128549855Sbostic
128649855Sbostic
128749855Sbostic /*--------------------------------------------------------------
128849855Sbostic *
128949855Sbostic * %$s%H=hM}
129049855Sbostic *
129149855Sbostic *--------------------------------------------------------------*/
129249855Sbostic
129349855Sbostic Bool
ProcessEvent()129449855Sbostic ProcessEvent()
129549855Sbostic {
129649855Sbostic XEvent theEvent;
129749855Sbostic Bool ContinueState = True;
129849855Sbostic
129949855Sbostic switch ( EventState ) {
130049855Sbostic case NORMAL_STATE:
130149855Sbostic while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {
130249855Sbostic switch ( theEvent.type ) {
130349855Sbostic case ConfigureNotify:
130449855Sbostic WindowWidth = theEvent.xconfigure.width;
130549855Sbostic WindowHeight = theEvent.xconfigure.height;
130649855Sbostic WindowPointX = theEvent.xconfigure.x;
130749855Sbostic WindowPointY = theEvent.xconfigure.y;
130849855Sbostic BorderWidth = theEvent.xconfigure.border_width;
130949855Sbostic NekoAdjust();
131049855Sbostic break;
131149855Sbostic case Expose:
131249855Sbostic if ( theEvent.xexpose.count == 0 ) {
131349855Sbostic RedrawNeko();
131449855Sbostic }
131549855Sbostic break;
131649855Sbostic case MapNotify:
131749855Sbostic RedrawNeko();
131849855Sbostic break;
131949855Sbostic case KeyPress:
132049855Sbostic ContinueState = ProcessKeyPress( &theEvent.xkey );
132149855Sbostic if ( !ContinueState ) {
132249855Sbostic return( ContinueState );
132349855Sbostic }
132449855Sbostic break;
132549855Sbostic default:
132649855Sbostic /* Unknown Event */
132749855Sbostic break;
132849855Sbostic }
132949855Sbostic }
133049855Sbostic break;
133149855Sbostic #ifdef DEBUG
133249855Sbostic case DEBUG_LIST:
133349855Sbostic XNextEvent( theDisplay, &theEvent );
133449855Sbostic switch ( theEvent.type ) {
133549855Sbostic case ConfigureNotify:
133649855Sbostic WindowWidth = theEvent.xconfigure.width;
133749855Sbostic WindowHeight = theEvent.xconfigure.height;
133849855Sbostic WindowPointX = theEvent.xconfigure.x;
133949855Sbostic WindowPointY = theEvent.xconfigure.y;
134049855Sbostic BorderWidth = theEvent.xconfigure.border_width;
134149855Sbostic break;
134249855Sbostic case Expose:
134349855Sbostic if ( theEvent.xexpose.count == 0 ) {
134449855Sbostic DisplayCharacters();
134549855Sbostic }
134649855Sbostic break;
134749855Sbostic case MapNotify:
134849855Sbostic DisplayCharacters();
134949855Sbostic break;
135049855Sbostic case KeyPress:
135149855Sbostic ContinueState = ProcessKeyPress( &theEvent );
135249855Sbostic break;
135349855Sbostic default:
135449855Sbostic /* Unknown Event */
135549855Sbostic break;
135649855Sbostic }
135749855Sbostic break;
135849855Sbostic case DEBUG_MOVE:
135949855Sbostic while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {
136049855Sbostic switch ( theEvent.type ) {
136149855Sbostic case ConfigureNotify:
136249855Sbostic WindowWidth = theEvent.xconfigure.width;
136349855Sbostic WindowHeight = theEvent.xconfigure.height;
136449855Sbostic WindowPointX = theEvent.xconfigure.x;
136549855Sbostic WindowPointY = theEvent.xconfigure.y;
136649855Sbostic BorderWidth = theEvent.xconfigure.border_width;
136749855Sbostic NekoAdjust();
136849855Sbostic break;
136949855Sbostic case Expose:
137049855Sbostic if ( theEvent.xexpose.count == 0 ) {
137149855Sbostic RedrawNeko();
137249855Sbostic }
137349855Sbostic break;
137449855Sbostic case MapNotify:
137549855Sbostic RedrawNeko();
137649855Sbostic break;
137749855Sbostic case KeyPress:
137849855Sbostic ContinueState = ProcessKeyPress( &theEvent );
137949855Sbostic if ( !ContinueState ) {
138049855Sbostic return( ContinueState );
138149855Sbostic }
138249855Sbostic break;
138349855Sbostic default:
138449855Sbostic /* Unknown Event */
138549855Sbostic break;
138649855Sbostic }
138749855Sbostic }
138849855Sbostic break;
138949855Sbostic #endif
139049855Sbostic default:
139149855Sbostic /* Internal Error */
139249855Sbostic break;
139349855Sbostic }
139449855Sbostic
139549855Sbostic return( ContinueState );
139649855Sbostic }
139749855Sbostic
139849855Sbostic
139949855Sbostic /*--------------------------------------------------------------
140049855Sbostic *
140149855Sbostic * G-=hM}
140249855Sbostic *
140349855Sbostic *--------------------------------------------------------------*/
140449855Sbostic
140549855Sbostic void
ProcessNeko()140649855Sbostic ProcessNeko()
140749855Sbostic {
140849855Sbostic struct itimerval Value;
140949855Sbostic
141049855Sbostic /* 4D6-$N=i4|2= */
141149855Sbostic
141249855Sbostic EventState = NORMAL_STATE;
141349855Sbostic
141449855Sbostic /* G-$N=i4|2= */
141549855Sbostic
141649855Sbostic NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;
141749855Sbostic NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;
141849855Sbostic
141949855Sbostic NekoLastX = NekoX;
142049855Sbostic NekoLastY = NekoY;
142149855Sbostic
142249855Sbostic SetNekoState( NEKO_STOP );
142349855Sbostic
142449855Sbostic /* %?%$%^!<@_Dj */
142549855Sbostic
142649855Sbostic timerclear( &Value.it_interval );
142749855Sbostic timerclear( &Value.it_value );
142849855Sbostic
142949855Sbostic Value.it_interval.tv_usec = IntervalTime;
143049855Sbostic Value.it_value.tv_usec = IntervalTime;
143149855Sbostic
143249855Sbostic setitimer( ITIMER_REAL, &Value, 0 );
143349855Sbostic
143449855Sbostic /* %a%$%s=hM} */
143549855Sbostic
143649855Sbostic do {
143749855Sbostic NekoThinkDraw();
143849855Sbostic } while ( ProcessEvent() );
143949855Sbostic }
144049855Sbostic
144149855Sbostic
144249855Sbostic #ifdef DEBUG
144349855Sbostic
144449855Sbostic /*--------------------------------------------------------------
144549855Sbostic *
1446*60873Sbostic * G-0lMw!J05/31/93P14460MQ!K
144749855Sbostic *
144849855Sbostic *--------------------------------------------------------------*/
144949855Sbostic
145049855Sbostic void
NekoList()145149855Sbostic NekoList()
145249855Sbostic {
145349855Sbostic EventState = DEBUG_LIST;
145449855Sbostic
145549855Sbostic fprintf( stderr, "\n" );
145649855Sbostic fprintf( stderr, "G-0lMw$rI=<($7$^$9!#(Quit !D Alt-Q)\n" );
145749855Sbostic fprintf( stderr, "\n" );
145849855Sbostic
145949855Sbostic XSelectInput( theDisplay, theWindow, EVENT_MASK2 );
146049855Sbostic
146149855Sbostic while ( ProcessEvent() );
146249855Sbostic }
146349855Sbostic
146449855Sbostic
146549855Sbostic /*--------------------------------------------------------------
146649855Sbostic *
1467*60873Sbostic * G-0\F0s.xneko.c9%H!J05/31/93P14670MQ!K
146849855Sbostic *
146949855Sbostic *--------------------------------------------------------------*/
147049855Sbostic
147149855Sbostic void
NekoMoveTest()147249855Sbostic NekoMoveTest()
147349855Sbostic {
147449855Sbostic struct itimerval Value;
147549855Sbostic
147649855Sbostic /* 4D6-$N=i4|2= */
147749855Sbostic
147849855Sbostic EventState = DEBUG_MOVE;
147949855Sbostic
148049855Sbostic /* G-$N=i4|2= */
148149855Sbostic
148249855Sbostic NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;
148349855Sbostic NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;
148449855Sbostic
148549855Sbostic NekoLastX = NekoX;
148649855Sbostic NekoLastY = NekoY;
148749855Sbostic
148849855Sbostic SetNekoState( NEKO_STOP );
148949855Sbostic
149049855Sbostic /* %?%$%^!<@_Dj */
149149855Sbostic
149249855Sbostic timerclear( &Value.it_interval );
149349855Sbostic timerclear( &Value.it_value );
149449855Sbostic
149549855Sbostic Value.it_interval.tv_usec = IntervalTime;
149649855Sbostic Value.it_value.tv_usec = IntervalTime;
149749855Sbostic
149849855Sbostic setitimer( ITIMER_REAL, &Value, 0 );
149949855Sbostic
150049855Sbostic /* %a%$%s=hM} */
150149855Sbostic
150249855Sbostic fprintf( stderr, "\n" );
150349855Sbostic fprintf( stderr, "G-$N0\F0s.xneko.c9%H$r9T$$$^$9!#(Quit !D Alt-Q)\n" );
150449855Sbostic fprintf( stderr, "\n" );
150549855Sbostic fprintf( stderr, "\t%-!<C%I>e$Ns.xneko.cs%-!<$GG-$r0\F0$5$;$F2<$5$$!#\n" );
150649855Sbostic fprintf( stderr, "\t(M-8z$J%-!<$O#1!A#9$G$9!#)\n" );
150749855Sbostic fprintf( stderr, "\n" );
150849855Sbostic
150949855Sbostic do {
151049855Sbostic NekoThinkDraw();
151149855Sbostic } while ( ProcessEvent() );
151249855Sbostic }
151349855Sbostic
151449855Sbostic
151549855Sbostic /*--------------------------------------------------------------
151649855Sbostic *
1517*60873Sbostic * %a%K%e!<=hM}!J05/31/93P15170MQ!K
151849855Sbostic *
151949855Sbostic *--------------------------------------------------------------*/
152049855Sbostic
152149855Sbostic void
ProcessDebugMenu()152249855Sbostic ProcessDebugMenu()
152349855Sbostic {
152449855Sbostic int UserSelectNo = 0;
152549855Sbostic char UserAnswer[ BUFSIZ ];
152649855Sbostic
152749855Sbostic fprintf( stderr, "\n" );
1528*60873Sbostic fprintf( stderr, "!Zxneko 05/31/93P15280%a%K%e!<![\n" );
152949855Sbostic
153049855Sbostic while ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {
153149855Sbostic fprintf( stderr, "\n" );
153249855Sbostic fprintf( stderr, "\t1)!!G-%-%c%i%/%?!<0lMwI=<(\n" );
153349855Sbostic fprintf( stderr, "\t2)!!G-0\F0s.xneko.c9%H\n" );
153449855Sbostic fprintf( stderr, "\n" );
153549855Sbostic fprintf( stderr, "Select: " );
153649855Sbostic
153749855Sbostic fgets( UserAnswer, sizeof( UserAnswer ), stdin );
153849855Sbostic
153949855Sbostic UserSelectNo = atoi( UserAnswer );
154049855Sbostic
154149855Sbostic if ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {
154249855Sbostic fprintf( stderr, "\n" );
154349855Sbostic fprintf( stderr, "@5$7$$HV9f$rA*Br$7$F2<$5$$!#\n" );
154449855Sbostic }
154549855Sbostic }
154649855Sbostic
154749855Sbostic switch ( UserSelectNo ) {
154849855Sbostic case 1:
154949855Sbostic /* G-%-%c%i%/%?!<0lMwI=<( */
155049855Sbostic NekoList();
155149855Sbostic break;
155249855Sbostic case 2:
155349855Sbostic /* G-0\F0s.xneko.c9%H */
155449855Sbostic NekoMoveTest();
155549855Sbostic break;
155649855Sbostic default:
155749855Sbostic /* Internal Error */
155849855Sbostic break;
155949855Sbostic }
156049855Sbostic
156149855Sbostic fprintf( stderr, "s.xneko.c9%H=*N;!#\n" );
156249855Sbostic fprintf( stderr, "\n" );
156349855Sbostic }
156449855Sbostic
156549855Sbostic #endif /* DEBUG */
156649855Sbostic
156749855Sbostic
156849855Sbostic /*--------------------------------------------------------------
156949855Sbostic *
157049855Sbostic * SIGALRM %7%0%J%k=hM}
157149855Sbostic *
157249855Sbostic *--------------------------------------------------------------*/
157349855Sbostic
157449855Sbostic void
NullFunction()157549855Sbostic NullFunction()
157649855Sbostic {
157749855Sbostic /* No Operation */
157849855Sbostic }
157949855Sbostic
158049855Sbostic
158149855Sbostic /*--------------------------------------------------------------
158249855Sbostic *
158349855Sbostic * Usage
158449855Sbostic *
158549855Sbostic *--------------------------------------------------------------*/
158649855Sbostic
158749855Sbostic void
Usage()158849855Sbostic Usage()
158949855Sbostic {
159049855Sbostic fprintf( stderr,
159149855Sbostic "Usage: %s [-display <display>] [-geometry <geometry>] \\\n",
159249855Sbostic ProgramName );
159349855Sbostic fprintf( stderr, " [-title <title>] [-name <title>] [-iconic] \\\n" );
159449855Sbostic fprintf( stderr, " [-speed <speed>] [-time <time>] [-help]\n" );
159549855Sbostic }
159649855Sbostic
159749855Sbostic
159849855Sbostic /*--------------------------------------------------------------
159949855Sbostic *
160049855Sbostic * #Xi%a!<%?I>2A
160149855Sbostic *
160249855Sbostic *--------------------------------------------------------------*/
160349855Sbostic
160449855Sbostic Bool
GetArguments(argc,argv,theDisplayName,theGeometry,theTitle,NekoSpeed,IntervalTime)160549855Sbostic GetArguments( argc, argv, theDisplayName, theGeometry, theTitle,
160649855Sbostic NekoSpeed, IntervalTime )
160749855Sbostic int argc;
160849855Sbostic char *argv[];
160949855Sbostic char *theDisplayName;
161049855Sbostic char *theGeometry;
161149855Sbostic char *theTitle;
161249855Sbostic double *NekoSpeed;
161349855Sbostic long *IntervalTime;
161449855Sbostic {
161549855Sbostic int ArgCounter;
161649855Sbostic Bool iconicState;
161749855Sbostic
161849855Sbostic theDisplayName[ 0 ] = '\0';
161949855Sbostic theGeometry[ 0 ] = '\0';
162049855Sbostic theTitle[ 0 ] = '\0';
162149855Sbostic
162249855Sbostic iconicState = False;
162349855Sbostic
162449855Sbostic for ( ArgCounter = 0; ArgCounter < argc; ArgCounter++ ) {
162549855Sbostic
162649855Sbostic if ( strncmp( argv[ ArgCounter ], "-h", 2 ) == 0 ) {
162749855Sbostic Usage();
162849855Sbostic exit( 0 );
162949855Sbostic } else if ( strcmp( argv[ ArgCounter ], "-display" ) == 0 ) {
163049855Sbostic ArgCounter++;
163149855Sbostic if ( ArgCounter < argc ) {
163249855Sbostic strcpy( theDisplayName, argv[ ArgCounter ] );
163349855Sbostic } else {
163449855Sbostic fprintf( stderr, "%s: -display option error.\n", ProgramName );
163549855Sbostic exit( 1 );
163649855Sbostic }
163749855Sbostic } else if ( strncmp( argv[ ArgCounter ], "-geom", 5 ) == 0 ) {
163849855Sbostic ArgCounter++;
163949855Sbostic if ( ArgCounter < argc ) {
164049855Sbostic strcpy( theGeometry, argv[ ArgCounter ] );
164149855Sbostic } else {
164249855Sbostic fprintf( stderr,
164349855Sbostic "%s: -geometry option error.\n", ProgramName );
164449855Sbostic exit( 1 );
164549855Sbostic }
164649855Sbostic } else if ( ( strcmp( argv[ ArgCounter ], "-title" ) == 0 )
164749855Sbostic || ( strcmp( argv[ ArgCounter ], "-name" ) == 0 ) ) {
164849855Sbostic ArgCounter++;
164949855Sbostic if ( ArgCounter < argc ) {
165049855Sbostic strcpy( theTitle, argv[ ArgCounter ] );
165149855Sbostic } else {
165249855Sbostic fprintf( stderr, "%s: -title option error.\n", ProgramName );
165349855Sbostic exit( 1 );
165449855Sbostic }
165549855Sbostic } else if ( strcmp( argv[ ArgCounter ], "-iconic" ) == 0 ) {
165649855Sbostic iconicState = True;
165749855Sbostic } else if ( strcmp( argv[ ArgCounter ], "-speed" ) == 0 ) {
165849855Sbostic ArgCounter++;
165949855Sbostic if ( ArgCounter < argc ) {
166049855Sbostic *NekoSpeed = atof( argv[ ArgCounter ] );
166149855Sbostic } else {
166249855Sbostic fprintf( stderr, "%s: -speed option error.\n", ProgramName );
166349855Sbostic exit( 1 );
166449855Sbostic }
166549855Sbostic } else if ( strcmp( argv[ ArgCounter ], "-time" ) == 0 ) {
166649855Sbostic ArgCounter++;
166749855Sbostic if ( ArgCounter < argc ) {
166849855Sbostic *IntervalTime = atol( argv[ ArgCounter ] );
166949855Sbostic } else {
167049855Sbostic fprintf( stderr, "%s: -time option error.\n", ProgramName );
167149855Sbostic exit( 1 );
167249855Sbostic }
167349855Sbostic } else {
167449855Sbostic fprintf( stderr,
167549855Sbostic "%s: Unknown option \"%s\".\n", ProgramName,
167649855Sbostic argv[ ArgCounter ] );
167749855Sbostic Usage();
167849855Sbostic exit( 1 );
167949855Sbostic }
168049855Sbostic }
168149855Sbostic
168249855Sbostic if ( strlen( theDisplayName ) < 1 ) {
168349855Sbostic theDisplayName = NULL;
168449855Sbostic }
168549855Sbostic
168649855Sbostic if ( strlen( theGeometry ) < 1 ) {
168749855Sbostic theGeometry = NULL;
168849855Sbostic }
168949855Sbostic
169049855Sbostic return( iconicState );
169149855Sbostic }
169249855Sbostic
169349855Sbostic
169449855Sbostic /*--------------------------------------------------------------
169549855Sbostic *
169649855Sbostic * %a%$%s4X?t
169749855Sbostic *
169849855Sbostic *--------------------------------------------------------------*/
169949855Sbostic
170049855Sbostic int
main(argc,argv)170149855Sbostic main( argc, argv )
170249855Sbostic int argc;
170349855Sbostic char *argv[];
170449855Sbostic {
170549855Sbostic Bool iconicState;
170649855Sbostic char theDisplayName[ DIRNAMELEN ];
170749855Sbostic char theGeometry[ DIRNAMELEN ];
170849855Sbostic char theTitle[ DIRNAMELEN ];
170949855Sbostic
171049855Sbostic ProgramName = argv[ 0 ];
171149855Sbostic
171249855Sbostic argc--;
171349855Sbostic argv++;
171449855Sbostic
171549855Sbostic iconicState = GetArguments( argc, argv,
171649855Sbostic theDisplayName,
171749855Sbostic theGeometry,
171849855Sbostic theTitle,
171949855Sbostic &NekoSpeed,
172049855Sbostic &IntervalTime );
172149855Sbostic
172249855Sbostic InitScreen( theDisplayName, theGeometry, theTitle, iconicState );
172349855Sbostic
172449855Sbostic signal( SIGALRM, NullFunction );
172549855Sbostic
172649855Sbostic SinPiPer8Times3 = sin( PI_PER8 * (double)3 );
172749855Sbostic SinPiPer8 = sin( PI_PER8 );
172849855Sbostic
172949855Sbostic #ifndef DEBUG
173049855Sbostic ProcessNeko();
173149855Sbostic #else
173249855Sbostic ProcessDebugMenu();
173349855Sbostic #endif
173449855Sbostic
173549855Sbostic exit( 0 );
173649855Sbostic }
1737