1 /*
2 XorGramana Copyright 2009 James W. Morris, james@jwm-art.net
3
4 This file is part of XorGramana.
5
6 XorGramana is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 XorGramana is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with XorGramana. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "game_display.h"
20 #include "actions.h"
21 #include "player.h"
22 #include "options.h"
23 #include <unistd.h>
24
25 struct gfx_win* game_win=0;
26
game_win_create()27 void game_win_create()
28 {
29 int rx=scr_win->win_brx-ICON_WIDTH;
30 int by=scr_win->win_bry-ICON_HEIGHT;
31 game_win=gfx_new_win(GFX_CENTER_X|GFX_CENTER_Y,0,0,rx,by,ICON_WIDTH,ICON_HEIGHT);
32 }
33
game_win_destroy()34 void game_win_destroy()
35 {
36 free(game_win);
37 }
38
game_win_display()39 void game_win_display()
40 {
41 xy_t ox,oy;
42 xy_t x,y;
43 xy_t mx,my;
44 su_t i;
45 SDL_Surface* icon;
46 ox=map->view[player.player].x;
47 oy=map->view[player.player].y;
48 for(y=0;y<game_win->blk_count_y;y++){
49 for(x=0;x<game_win->blk_count_x;x++){
50 mx=ox+x;
51 my=oy+y;
52 if(mx>map->width||my>map->height)
53 i=ICON_WALL;
54 else
55 i=map->data[my][mx];
56 icon=icons[i];
57 draw_image(icons[ICON_FLOOR],
58 game_win->blk_tlx+x*ICON_WIDTH,
59 game_win->blk_tly+y*ICON_HEIGHT);
60 if(options->show_indicators){
61 if(icons_with_indicators[i])
62 draw_image(icons_with_indicators[i],
63 game_win->blk_tlx+x*ICON_WIDTH,
64 game_win->blk_tly+y*ICON_HEIGHT);
65 else
66 draw_image(icon,
67 game_win->blk_tlx+x*ICON_WIDTH,
68 game_win->blk_tly+y*ICON_HEIGHT);
69 }
70 else
71 draw_image(icon,
72 game_win->blk_tlx+x*ICON_WIDTH,
73 game_win->blk_tly+y*ICON_HEIGHT);
74 }
75 }
76 SDL_Flip(screen);
77 }
78
game_win_update_player_info()79 void game_win_update_player_info()
80 {
81 su_t i;
82 gfx_set_win(scr_win);
83 gfx_win_half_size();
84 set_space_icon(SPC_TRAN);
85 for(i=1;i<scr_win->blk_count_x-1;i++)
86 gfx_win_draw_image(hs_icons[ICON_LINE_B],i, scr_win->blk_count_y-1);
87 if(options->game){
88 gfx_mv_cur(1,scr_win->blk_count_y-1);
89 gfx_printf("%2d of %2d",player.masks_collected,map->mask_count);
90 }
91 gfx_mv_cur(scr_win->blk_count_x-6,scr_win->blk_count_y-1);
92 gfx_printf("%c%d",
93 (player.player?'*':'#'),
94 map->max_moves-player.move_no);
95 SDL_Flip(screen);
96 #ifdef PLAYER_XY_DEBUG
97 printf("player:x,y %d,%d\n",
98 map->player[player.player].x,
99 map->player[player.player].y);
100 #endif
101 }
102
game_win_get_view_for(xy_t cx,xy_t cy,xy_t * tlx,xy_t * tly)103 void game_win_get_view_for(xy_t cx, xy_t cy, xy_t* tlx, xy_t* tly)
104 {
105 xy_t tl_x;
106 xy_t tl_y;
107 xy_t tmp;
108 if((tl_x=cx-game_win->blk_count_x/2)<0)
109 tl_x=0;
110 if((tl_y=cy-game_win->blk_count_y/2)<0)
111 tl_y=0;
112 if((tmp=tl_x+game_win->blk_count_x)>map->width)
113 tl_x+=map->width-tmp;
114 if((tmp=tl_y+game_win->blk_count_y)>map->width)
115 tl_y+=map->width-tmp;
116 *tlx=tl_x;
117 *tly=tl_y;
118 }
119
game_win_show(xy_t cx,xy_t cy)120 void game_win_show(xy_t cx, xy_t cy)
121 {
122 xy_t tlx,tly;
123 xy_t x,y,mx,my,i;
124 SDL_Surface* icon;
125 game_win_get_view_for(cx,cy,&tlx,&tly);
126 for(y=0;y<game_win->blk_count_y;y++){
127 for(x=0;x<game_win->blk_count_x;x++){
128 mx=tlx+x;
129 my=tly+y;
130 if(mx>map->width||my>map->height)
131 i=ICON_WALL;
132 else
133 i=map->data[my][mx];
134 icon=icons[i];
135 draw_image(icons[ICON_FLOOR],
136 game_win->blk_tlx+x*ICON_WIDTH,
137 game_win->blk_tly+y*ICON_HEIGHT);
138 if(options->show_indicators){
139 if(icons_with_indicators[i])
140 draw_image(icons_with_indicators[i],
141 game_win->blk_tlx+x*ICON_WIDTH,
142 game_win->blk_tly+y*ICON_HEIGHT);
143 else
144 draw_image(icon,
145 game_win->blk_tlx+x*ICON_WIDTH,
146 game_win->blk_tly+y*ICON_HEIGHT);
147 }
148 else
149 draw_image(icon,
150 game_win->blk_tlx+x*ICON_WIDTH,
151 game_win->blk_tly+y*ICON_HEIGHT);
152 }
153 }
154 SDL_Flip(screen);
155 }
156
game_win_swap_update()157 void game_win_swap_update()
158 {
159 su_t p=(player.player)?0:1;
160 if(map->player[player.player].x>map->view[p].x
161 &&map->player[player.player].x<map->view[p].x+game_win->blk_count_x-1)
162 {
163 if(map->player[player.player].y>map->view[p].y
164 &&map->player[player.player].y<map->view[p].y+game_win->blk_count_y-1){
165 map->view[player.player].x=map->view[p].x;
166 map->view[player.player].y=map->view[p].y;
167 }
168 }
169 }
170
game_win_move_player(struct xor_move * pmv)171 void game_win_move_player(struct xor_move* pmv)
172 {
173 xy_t vx, vy;
174 xy_t ovx,ovy;
175 su_t scrt=(player.replay?1:options->scroll_thresh);
176 ovx=vx=map->view[player.player].x;
177 ovy=vy=map->view[player.player].y;
178 switch(pmv->dir){
179 case MV_LEFT:
180 if(pmv->to_x<vx+scrt&&vx>0)
181 vx--;
182 break;
183 case MV_RIGHT:
184 if(pmv->to_x > vx+game_win->blk_count_x-1-scrt
185 &&vx<map->width-game_win->blk_count_x)
186 vx++;
187 break;
188 case MV_UP:
189 if(pmv->to_y<vy+scrt&&vy>0)
190 vy--;
191 break;
192 case MV_DOWN:
193 if(pmv->to_y > vy+game_win->blk_count_y-1-scrt
194 &&vy<map->height-game_win->blk_count_y)
195 vy++;
196 break;
197 default:break;
198 }
199 if(ovx!=vx||ovy!=vy){
200 map->view[player.player].x=vx;
201 map->view[player.player].y=vy;
202 game_win_display(map);
203 return;
204 }
205 game_win_icon_display(pmv->from_x, pmv->from_y, ICON_FLOOR);
206 game_win_icon_display(pmv->to_x, pmv->to_y, pmv->from_obj);
207 SDL_Flip(screen);
208 }
209
game_win_move_object(struct xor_move * omv)210 void game_win_move_object(struct xor_move* omv)
211 {
212 game_win_icon_display(omv->from_x, omv->from_y, ICON_FLOOR);
213 game_win_icon_display(omv->to_x, omv->to_y, omv->from_obj);
214 SDL_Flip(screen);
215 }
216
game_win_map_coord(xy_t x,xy_t y)217 struct xy* game_win_map_coord(xy_t x, xy_t y)
218 {
219 struct xy* ret=0;
220 struct xy* pv=&map->view[player.player];
221 if(!(ret=malloc(sizeof(struct xy))))
222 return 0;
223 if(x >= pv->x && x < pv->x+game_win->blk_count_x
224 &&y >= pv->y && y < pv->y+game_win->blk_count_y)
225 {
226 ret->x=(x-pv->x)*ICON_W;
227 ret->y=(y-pv->y)*ICON_H;
228 return ret;
229 }
230 free(ret);
231 return 0;
232 }
233
game_win_icon_display(xy_t x,xy_t y,su_t icon)234 void game_win_icon_display(xy_t x, xy_t y, su_t icon)
235 {
236 xy_t xx, yy;
237 xy_t ox,oy;
238 SDL_Surface* surface=icons[icon];
239 ox=map->view[player.player].x;
240 oy=map->view[player.player].y;
241 if(x<ox||x>=ox+game_win->blk_count_x
242 ||y<oy||y>=oy+game_win->blk_count_y)
243 return;
244 xx=x-ox;
245 yy=y-oy;
246 draw_image(icons[ICON_FLOOR],
247 game_win->blk_tlx+xx*ICON_WIDTH,
248 game_win->blk_tly+yy*ICON_HEIGHT);
249 if(options->show_indicators){
250 if(icons_with_indicators[icon])
251 draw_image(icons_with_indicators[icon],
252 game_win->blk_tlx+xx*ICON_WIDTH,
253 game_win->blk_tly+yy*ICON_HEIGHT);
254 else
255 draw_image(surface,
256 game_win->blk_tlx+xx*ICON_WIDTH,
257 game_win->blk_tly+yy*ICON_HEIGHT);
258 }
259 else{
260 draw_image(surface,
261 game_win->blk_tlx+xx*ICON_WIDTH,
262 game_win->blk_tly+yy*ICON_HEIGHT);
263 }
264 }
265
266 /*
267
268 void game_win_icon_dump(xy_t x, xy_t y, su_t icon)
269 {
270 xy_t xx, yy;
271 wattrset(game_win,COLOR_PAIR(icon));
272 for(yy=0;yy<ICON_H;yy++)
273 for(xx=0;xx<ICON_W;xx++)
274 mvwaddch(game_win,y+yy,x+xx,icons[icon].chrs[yy][xx]);
275 }
276 */
277
278
279