您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

164 行
3.3 KiB

  1. /*
  2. * ttyvaders Textmode shoot'em up
  3. * Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id: graphics.c,v 1.5 2002/12/23 10:06:27 sam Exp $
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <stdlib.h>
  23. #include "common.h"
  24. int init_graphics( void )
  25. {
  26. #ifdef USE_SLANG
  27. /* Initialize slang library */
  28. SLsig_block_signals();
  29. SLtt_get_terminfo();
  30. if( SLkp_init() == -1 )
  31. {
  32. SLsig_unblock_signals();
  33. return 1;
  34. }
  35. SLang_init_tty (-1, 0, 1);
  36. if( SLsmg_init_smg() == -1 )
  37. {
  38. SLsig_unblock_signals();
  39. return 1;
  40. }
  41. SLsig_unblock_signals();
  42. SLsmg_cls();
  43. SLsmg_refresh();
  44. #elif USE_NCURSES
  45. /* Initialize ncurses library */
  46. initscr();
  47. keypad(stdscr, TRUE);
  48. nonl();
  49. cbreak();
  50. noecho();
  51. nodelay(stdscr, TRUE);
  52. #else
  53. /* Dummy driver */
  54. #endif
  55. return 0;
  56. }
  57. void init_game( game *g )
  58. {
  59. #ifdef USE_SLANG
  60. static char * const colors[] =
  61. {
  62. "black", "green", "yellow", "white",
  63. "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL
  64. };
  65. int i;
  66. for( i = 0; colors[i] ; i++ )
  67. {
  68. SLtt_set_color( i+1, NULL, colors[i], "black" );
  69. }
  70. g->w = SLtt_Screen_Cols;
  71. g->h = SLtt_Screen_Rows;
  72. #elif USE_NCURSES
  73. start_color();
  74. init_pair( BLACK, COLOR_BLACK, COLOR_BLACK );
  75. init_pair( GREEN, COLOR_GREEN, COLOR_BLACK );
  76. init_pair( YELLOW, COLOR_YELLOW, COLOR_BLACK );
  77. init_pair( WHITE, COLOR_WHITE, COLOR_BLACK );
  78. init_pair( RED, COLOR_RED, COLOR_BLACK );
  79. init_pair( GRAY, COLOR_WHITE, COLOR_BLACK ); // XXX
  80. init_pair( LIGHTGRAY, COLOR_WHITE, COLOR_BLACK ); // XXX
  81. init_pair( BLUE, COLOR_BLUE, COLOR_BLACK );
  82. init_pair( CYAN, COLOR_CYAN, COLOR_BLACK );
  83. init_pair( MAGENTA, COLOR_MAGENTA, COLOR_BLACK );
  84. g->w = COLS;
  85. g->h = LINES;
  86. #else
  87. /* Use dummy driver */
  88. g->w = 80;
  89. g->h = 25;
  90. #endif
  91. }
  92. char get_key( void )
  93. {
  94. #ifdef USE_SLANG
  95. if( SLang_input_pending (0) )
  96. {
  97. return SLang_getkey();
  98. }
  99. #elif USE_NCURSES
  100. char key;
  101. if( ( key = getch() ) != ERR )
  102. {
  103. return key;
  104. }
  105. #else
  106. /* Use dummy driver */
  107. #endif
  108. return 0;
  109. }
  110. void clear_graphics( void )
  111. {
  112. #ifdef USE_SLANG
  113. SLsmg_cls();
  114. #elif USE_NCURSES
  115. clear();
  116. #else
  117. /* Use dummy driver */
  118. #endif
  119. }
  120. void refresh_graphics( void )
  121. {
  122. gfx_goto( 0, 0 );
  123. #ifdef USE_SLANG
  124. SLsmg_refresh();
  125. #elif USE_NCURSES
  126. refresh();
  127. #else
  128. /* Use dummy driver */
  129. #endif
  130. }
  131. void end_graphics( void )
  132. {
  133. #ifdef USE_SLANG
  134. SLang_reset_tty();
  135. SLsmg_reset_smg();
  136. #elif USE_NCURSES
  137. endwin();
  138. #else
  139. /* Use dummy driver */
  140. #endif
  141. }