📄 xneko.c
字号:
unsigned long theWindowMask; Pixmap theIconPixmap; Pixmap theCursorSource; Pixmap theCursorMask; XWMHints theWMHints; Window theRoot; Colormap theColormap; XColor theWhiteColor, theBlackColor, theExactColor; if ( ( theDisplay = XOpenDisplay( DisplayName ) ) == NULL ) { fprintf( stderr, "%s: Can't open display", ProgramName ); if ( DisplayName != NULL ) { fprintf( stderr, " %s.\n", DisplayName ); } else { fprintf( stderr, ".\n" ); } exit( 1 ); } theScreen = DefaultScreen( theDisplay ); theDepth = DefaultDepth( theDisplay, theScreen ); theBlackPixel = BlackPixel( theDisplay, theScreen ); theWhitePixel = WhitePixel( theDisplay, theScreen ); GeometryStatus = XParseGeometry( theGeometry, &WindowPointX, &WindowPointY, &WindowWidth, &WindowHeight ); if ( !( GeometryStatus & XValue ) ) { WindowPointX = DEFAULT_WIN_X; } if ( !( GeometryStatus & YValue ) ) { WindowPointY = DEFAULT_WIN_Y; } if ( !( GeometryStatus & WidthValue ) ) { WindowWidth = WINDOW_WIDTH; } if ( !( GeometryStatus & HeightValue ) ) { WindowHeight = WINDOW_HEIGHT; } theCursorSource = XCreateBitmapFromData( theDisplay, RootWindow( theDisplay, theScreen ), cursor_bits, cursor_width, cursor_height ); theCursorMask = XCreateBitmapFromData( theDisplay, RootWindow( theDisplay, theScreen ), cursor_mask_bits, cursor_mask_width, cursor_mask_height ); theColormap = DefaultColormap( theDisplay, theScreen ); if ( !XAllocNamedColor( theDisplay, theColormap, "white", &theWhiteColor, &theExactColor ) ) { fprintf( stderr, "%s: Can't XAllocNamedColor( \"white\" ).\n", ProgramName ); exit( 1 ); } if ( !XAllocNamedColor( theDisplay, theColormap, "black", &theBlackColor, &theExactColor ) ) { fprintf( stderr, "%s: Can't XAllocNamedColor( \"black\" ).\n", ProgramName ); exit( 1 ); } theCursor = XCreatePixmapCursor( theDisplay, theCursorSource, theCursorMask, &theBlackColor, &theWhiteColor, cursor_x_hot, cursor_y_hot ); theWindowAttributes.border_pixel = theBlackPixel; theWindowAttributes.background_pixel = theWhitePixel; theWindowAttributes.cursor = theCursor; theWindowAttributes.override_redirect = False; theWindowMask = CWBackPixel | CWBorderPixel | CWCursor | CWOverrideRedirect; theWindow = XCreateWindow( theDisplay, RootWindow( theDisplay, theScreen ), WindowPointX, WindowPointY, WindowWidth, WindowHeight, BorderWidth, theDepth, InputOutput, CopyFromParent, theWindowMask, &theWindowAttributes ); theIconPixmap = XCreateBitmapFromData( theDisplay, theWindow, icon_bits, icon_width, icon_height ); theWMHints.icon_pixmap = theIconPixmap; if ( iconicState ) { theWMHints.initial_state = IconicState; } else { theWMHints.initial_state = NormalState; } theWMHints.flags = IconPixmapHint | StateHint; XSetWMHints( theDisplay, theWindow, &theWMHints ); theSizeHints.flags = PPosition | PSize; theSizeHints.x = WindowPointX; theSizeHints.y = WindowPointY; theSizeHints.width = WindowWidth; theSizeHints.height = WindowHeight; XSetNormalHints( theDisplay, theWindow, &theSizeHints ); if ( strlen( TitleName ) >= 1 ) { XStoreName( theDisplay, theWindow, TitleName ); XSetIconName( theDisplay, theWindow, TitleName ); } else { XStoreName( theDisplay, theWindow, ProgramName ); XSetIconName( theDisplay, theWindow, ProgramName ); } XMapWindow( theDisplay, theWindow ); XFlush( theDisplay ); XGetGeometry( theDisplay, theWindow, &theRoot, &WindowPointX, &WindowPointY, &WindowWidth, &WindowHeight, &BorderWidth, &theDepth ); InitBitmapAndGCs(); XSelectInput( theDisplay, theWindow, EVENT_MASK1 ); XFlush( theDisplay );}/*-------------------------------------------------------------- * * %$%s%?!</usr/src/games/xneko/SCCS/s.xneko.ck * * !!$3$N4X?t$r8F$V$H!"$"$k0lDj$N;~4VJV$C$F$3$J$/$J$k!#G- * $NF0:n%?%$%_%s%0D4@0$KMxMQ$9$k$3$H!# * *--------------------------------------------------------------*/voidInterval(){ pause();}/*-------------------------------------------------------------- * * SCCS/s.xneko.c#728/%+%&%s%H=hM} * *--------------------------------------------------------------*/voidTickCount(){ if ( ++NekoTickCount >= MAX_TICK ) { NekoTickCount = 0; } if ( NekoTickCount % 2 == 0 ) { if ( NekoStateCount < MAX_TICK ) { NekoStateCount++; } }}/*-------------------------------------------------------------- * * G->uBV@_Dj * *--------------------------------------------------------------*/voidSetNekoState( SetValue ) int SetValue;{ NekoTickCount = 0; NekoStateCount = 0; NekoState = SetValue;#ifdef DEBUG switch ( NekoState ) { case NEKO_STOP: case NEKO_JARE: case NEKO_KAKI: case NEKO_AKUBI: case NEKO_SLEEP: case NEKO_U_TOGI: case NEKO_D_TOGI: case NEKO_L_TOGI: case NEKO_R_TOGI: NekoMoveDx = NekoMoveDy = 0; break; default: break; }#endif}/*-------------------------------------------------------------- * * G-IA2h=hM} * *--------------------------------------------------------------*/voidDrawNeko( x, y, DrawGC ) int x; int y; GC DrawGC;{ if ( ( x != NekoLastX || y != NekoLastY ) && ( EventState != DEBUG_LIST ) ) { XFillRectangle( theDisplay, theWindow, SpaceGC, NekoLastX, NekoLastY, BITMAP_WIDTH, BITMAP_HEIGHT ); } XSetTSOrigin( theDisplay, DrawGC, x, y ); XFillRectangle( theDisplay, theWindow, DrawGC, x, y, BITMAP_WIDTH, BITMAP_HEIGHT ); XFlush( theDisplay ); NekoLastX = x; NekoLastY = y; NekoLastGC = DrawGC;}/*-------------------------------------------------------------- * * G-:FIA2h=hM} * *--------------------------------------------------------------*/voidRedrawNeko(){ XFillRectangle( theDisplay, theWindow, NekoLastGC, NekoLastX, NekoLastY, BITMAP_WIDTH, BITMAP_HEIGHT ); XFlush( theDisplay );}/*-------------------------------------------------------------- * * G-0\F0J}K!7hDj * *--------------------------------------------------------------*/voidNekoDirection(){ int NewState; double LargeX, LargeY; double Length; double SinTheta; if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) { NewState = NEKO_STOP; } else { LargeX = (double)NekoMoveDx; LargeY = (double)(-NekoMoveDy); Length = sqrt( LargeX * LargeX + LargeY * LargeY ); SinTheta = LargeY / Length; if ( NekoMoveDx > 0 ) { if ( SinTheta > SinPiPer8Times3 ) { NewState = NEKO_U_MOVE; } else if ( ( SinTheta <= SinPiPer8Times3 ) && ( SinTheta > SinPiPer8 ) ) { NewState = NEKO_UR_MOVE; } else if ( ( SinTheta <= SinPiPer8 ) && ( SinTheta > -( SinPiPer8 ) ) ) { NewState = NEKO_R_MOVE; } else if ( ( SinTheta <= -( SinPiPer8 ) ) && ( SinTheta > -( SinPiPer8Times3 ) ) ) { NewState = NEKO_DR_MOVE; } else { NewState = NEKO_D_MOVE; } } else { if ( SinTheta > SinPiPer8Times3 ) { NewState = NEKO_U_MOVE; } else if ( ( SinTheta <= SinPiPer8Times3 ) && ( SinTheta > SinPiPer8 ) ) { NewState = NEKO_UL_MOVE; } else if ( ( SinTheta <= SinPiPer8 ) && ( SinTheta > -( SinPiPer8 ) ) ) { NewState = NEKO_L_MOVE; } else if ( ( SinTheta <= -( SinPiPer8 ) ) && ( SinTheta > -( SinPiPer8Times3 ) ) ) { NewState = NEKO_DL_MOVE; } else { NewState = NEKO_D_MOVE; } } } if ( NekoState != NewState ) { SetNekoState( NewState ); }}/*-------------------------------------------------------------- * * G-JI$V$D$+$jH=Dj * *--------------------------------------------------------------*/BoolIsWindowOver(){ Bool ReturnValue = False; if ( NekoY <= 0 ) { NekoY = 0; ReturnValue = True; } else if ( NekoY >= WindowHeight - BITMAP_HEIGHT ) { NekoY = WindowHeight - BITMAP_HEIGHT; ReturnValue = True; } if ( NekoX <= 0 ) { NekoX = 0; ReturnValue = True; } else if ( NekoX >= WindowWidth - BITMAP_WIDTH ) { NekoX = WindowWidth - BITMAP_WIDTH; ReturnValue = True; } return( ReturnValue );}/*-------------------------------------------------------------- * * G-0\F0>u67H=Dj * *--------------------------------------------------------------*/BoolIsNekoDontMove(){ if ( NekoX == NekoLastX && NekoY == NekoLastY ) { return( True ); } else { return( False ); }}/*-------------------------------------------------------------- * * G-0\F03+;OH=Dj * *--------------------------------------------------------------*/BoolIsNekoMoveStart(){#ifndef DEBUG if ( ( PrevMouseX >= MouseX - IDLE_SPACE && PrevMouseX <= MouseX + IDLE_SPACE ) && ( PrevMouseY >= MouseY - IDLE_SPACE && PrevMouseY <= MouseY + IDLE_SPACE ) ) { return( False ); } else { return( True ); }#else if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) { return( False ); } else { return( True ); }#endif}/*-------------------------------------------------------------- * * G-0\F0 dx, dy 7W;; * *--------------------------------------------------------------*/voidCalcDxDy(){ Window QueryRoot, QueryChild; int AbsoluteX, AbsoluteY; int RelativeX, RelativeY; unsigned int ModKeyMask; double LargeX, LargeY; double DoubleLength, Length; XQueryPointer( theDisplay, theWindow, &QueryRoot, &QueryChild, &AbsoluteX, &AbsoluteY, &RelativeX, &RelativeY, &ModKeyMask ); PrevMouseX = MouseX; PrevMouseY = MouseY; MouseX = RelativeX; MouseY = RelativeY; LargeX = (double)( MouseX - NekoX - BITMAP_WIDTH / 2 ); LargeY = (double)( MouseY - NekoY - BITMAP_HEIGHT ); DoubleLength = LargeX * LargeX + LargeY * LargeY; if ( DoubleLength != (double)0 ) { Length = sqrt( DoubleLength ); if ( Length <= NekoSpeed ) { NekoMoveDx = (int)LargeX; NekoMoveDy = (int)LargeY; } else { NekoMoveDx = (int)( ( NekoSpeed * LargeX ) / Length ); NekoMoveDy = (int)( ( NekoSpeed * LargeY ) / Length ); } } else { NekoMoveDx = NekoMoveDy = 0; }}/*-------------------------------------------------------------- * * F0:n2r@OG-IA2h=hM} * *--------------------------------------------------------------*/voidNekoThinkDraw(){#ifndef DEBUG CalcDxDy();#endif if ( NekoState != NEKO_SLEEP ) { DrawNeko( NekoX, NekoY, NekoTickCount % 2 == 0 ? *(AnimationPattern[ NekoState ].TickEvenGCPtr) : *(AnimationPattern[ NekoState ].TickOddGCPtr) ); } else { DrawNeko( NekoX, NekoY, NekoTickCount % 8 <= 3 ? *(AnimationPattern[ NekoState ].TickEvenGCPtr) : *(AnimationPattern[ NekoState ].TickOddGCPtr) ); } TickCount(); switch ( NekoState ) { case NEKO_STOP: if ( IsNekoMoveStart() ) { SetNekoState( NEKO_AWAKE ); break; } if ( NekoStateCount < NEKO_STOP_TIME ) { break; } if ( NekoMoveDx < 0 && NekoX <= 0 ) { SetNekoState( NEKO_L_TOGI ); } else if ( NekoMoveDx > 0 && NekoX >= WindowWidth - BITMAP_WIDTH ) { SetNekoState( NEKO_R_TOGI ); } else if ( NekoMoveDy < 0 && NekoY <= 0 ) { SetNekoState( NEKO_U_TOGI ); } else if ( NekoMoveDy > 0 && NekoY >= WindowHeight - BITMAP_HEIGHT ) { SetNekoState( NEKO_D_TOGI ); } else { SetNekoState( NEKO_JARE ); } break; case NEKO_JARE: if ( IsNekoMoveStart() ) { SetNekoState( NEKO_AWAKE ); break; } if ( NekoStateCount < NEKO_JARE_TIME ) { break; } SetNekoState( NEKO_KAKI ); break; case NEKO_KAKI: if ( IsNekoMoveStart() ) { SetNekoState( NEKO_AWAKE ); break; } if ( NekoStateCount < NEKO_KAKI_TIME ) { break; } SetNekoState( NEKO_AKUBI ); break; case NEKO_AKUBI: if ( IsNekoMoveStart() ) { SetNekoState( NEKO_AWAKE ); break; } if ( NekoStateCount < NEKO_AKUBI_TIME ) { break; } SetNekoState( NEKO_SLEEP ); break; case NEKO_SLEEP: if ( IsNekoMoveStart() ) { SetNekoState( NEKO_AWAKE ); break; } break; case NEKO_AWAKE: if ( NekoStateCount < NEKO_AWAKE_TIME ) { break; } NekoDirection(); /* G-$,F0$/8~$-$r5a$a$k */ break; case NEKO_U_MOVE: case NEKO_D_MOVE: case NEKO_L_MOVE: case NEKO_R_MOVE: case NEKO_UL_MOVE: case NEKO_UR_MOVE: case NEKO_DL_MOVE: case NEKO_DR_MOVE: NekoX += NekoMoveDx; NekoY += NekoMoveDy; NekoDirection(); if ( IsWindowOver() ) { if ( IsNekoDontMove() ) { SetNekoState( NEKO_STOP ); } } break; case NEKO_U_TOGI: case NEKO_D_TOGI: case NEKO_L_TOGI: case NEKO_R_TOGI: if ( IsNekoMoveStart() ) { SetNekoState( NEKO_AWAKE ); break; } if ( NekoStateCount < NEKO_TOGI_TIME ) { break; } SetNekoState( NEKO_KAKI ); break; default: /* Internal Error */ SetNekoState( NEKO_STOP ); break; } Interval();}#ifdef DEBUG/*-------------------------------------------------------------- * * %-%c%i%/%?!<0lMwI=<(!J5/31/93P11500MQ!K
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -