1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: tarass |
---|
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 | |
---|
23 | #include <stdlib.h> |
---|
24 | |
---|
25 | #include "common.h" |
---|
26 | |
---|
27 | int init_graphics( void ) |
---|
28 | { |
---|
29 | #ifdef USE_SLANG |
---|
30 | /* Initialize slang library */ |
---|
31 | SLsig_block_signals(); |
---|
32 | SLtt_get_terminfo(); |
---|
33 | |
---|
34 | if( SLkp_init() == -1 ) |
---|
35 | { |
---|
36 | SLsig_unblock_signals(); |
---|
37 | return 1; |
---|
38 | } |
---|
39 | |
---|
40 | SLang_init_tty (-1, 0, 1); |
---|
41 | |
---|
42 | if( SLsmg_init_smg() == -1 ) |
---|
43 | { |
---|
44 | SLsig_unblock_signals(); |
---|
45 | return 1; |
---|
46 | } |
---|
47 | |
---|
48 | SLsig_unblock_signals(); |
---|
49 | |
---|
50 | SLsmg_cls(); |
---|
51 | SLsmg_refresh(); |
---|
52 | #else |
---|
53 | /* Initialize ncurses library */ |
---|
54 | initscr(); |
---|
55 | keypad(stdscr, TRUE); |
---|
56 | nonl(); |
---|
57 | cbreak(); |
---|
58 | noecho(); |
---|
59 | nodelay(stdscr, TRUE); |
---|
60 | #endif |
---|
61 | |
---|
62 | return 0; |
---|
63 | } |
---|
64 | |
---|
65 | void init_game( game *g ) |
---|
66 | { |
---|
67 | #ifdef USE_SLANG |
---|
68 | static char * const colors[] = |
---|
69 | { |
---|
70 | "black", "green", "yellow", "white", |
---|
71 | "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL |
---|
72 | }; |
---|
73 | |
---|
74 | int i; |
---|
75 | |
---|
76 | for( i = 0; colors[i] ; i++ ) |
---|
77 | { |
---|
78 | SLtt_set_color( i+1, NULL, colors[i], "black" ); |
---|
79 | } |
---|
80 | |
---|
81 | g->w = SLtt_Screen_Cols; |
---|
82 | g->h = SLtt_Screen_Rows; |
---|
83 | #else |
---|
84 | start_color(); |
---|
85 | |
---|
86 | init_pair( BLACK, COLOR_BLACK, COLOR_BLACK ); |
---|
87 | init_pair( GREEN, COLOR_GREEN, COLOR_BLACK ); |
---|
88 | init_pair( YELLOW, COLOR_YELLOW, COLOR_BLACK ); |
---|
89 | init_pair( WHITE, COLOR_WHITE, COLOR_BLACK ); |
---|
90 | init_pair( RED, COLOR_RED, COLOR_BLACK ); |
---|
91 | init_pair( GRAY, COLOR_WHITE, COLOR_BLACK ); // XXX |
---|
92 | init_pair( LIGHTGRAY, COLOR_WHITE, COLOR_BLACK ); // XXX |
---|
93 | init_pair( BLUE, COLOR_BLUE, COLOR_BLACK ); |
---|
94 | init_pair( CYAN, COLOR_CYAN, COLOR_BLACK ); |
---|
95 | init_pair( MAGENTA, COLOR_MAGENTA, COLOR_BLACK ); |
---|
96 | |
---|
97 | g->w = COLS; |
---|
98 | g->h = LINES; |
---|
99 | #endif |
---|
100 | } |
---|
101 | |
---|
102 | char get_key( void ) |
---|
103 | { |
---|
104 | #ifdef USE_SLANG |
---|
105 | if( SLang_input_pending (0) ) |
---|
106 | { |
---|
107 | return SLang_getkey(); |
---|
108 | } |
---|
109 | #else |
---|
110 | char key; |
---|
111 | |
---|
112 | if( ( key = getch() ) != ERR ) |
---|
113 | { |
---|
114 | return key; |
---|
115 | } |
---|
116 | #endif |
---|
117 | |
---|
118 | return 0; |
---|
119 | } |
---|
120 | |
---|
121 | void clear_graphics( void ) |
---|
122 | { |
---|
123 | #ifdef USE_SLANG |
---|
124 | SLsmg_cls(); |
---|
125 | #else |
---|
126 | clear(); |
---|
127 | #endif |
---|
128 | } |
---|
129 | |
---|
130 | void refresh_graphics( void ) |
---|
131 | { |
---|
132 | gfx_goto( 0, 0 ); |
---|
133 | #ifdef USE_SLANG |
---|
134 | SLsmg_refresh(); |
---|
135 | #else |
---|
136 | refresh(); |
---|
137 | #endif |
---|
138 | } |
---|
139 | |
---|
140 | void end_graphics( void ) |
---|
141 | { |
---|
142 | #ifdef USE_SLANG |
---|
143 | SLang_reset_tty(); |
---|
144 | SLsmg_reset_smg(); |
---|
145 | #else |
---|
146 | endwin(); |
---|
147 | #endif |
---|
148 | } |
---|
149 | |
---|
150 | |
---|