/* XorGramana Copyright 2009 James W. Morris, james@jwm-art.net This file is part of XorGramana. XorGramana is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. XorGramana is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XorGramana. If not, see . */ #include "game_display.h" #include "actions.h" #include "player.h" #include "options.h" #include struct gfx_win* game_win=0; void game_win_create() { int rx=scr_win->win_brx-ICON_WIDTH; int by=scr_win->win_bry-ICON_HEIGHT; game_win=gfx_new_win(GFX_CENTER_X|GFX_CENTER_Y,0,0,rx,by,ICON_WIDTH,ICON_HEIGHT); } void game_win_destroy() { free(game_win); } void game_win_display() { xy_t ox,oy; xy_t x,y; xy_t mx,my; su_t i; SDL_Surface* icon; ox=map->view[player.player].x; oy=map->view[player.player].y; for(y=0;yblk_count_y;y++){ for(x=0;xblk_count_x;x++){ mx=ox+x; my=oy+y; if(mx>map->width||my>map->height) i=ICON_WALL; else i=map->data[my][mx]; icon=icons[i]; draw_image(icons[ICON_FLOOR], game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); if(options->show_indicators){ if(icons_with_indicators[i]) draw_image(icons_with_indicators[i], game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); else draw_image(icon, game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); } else draw_image(icon, game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); } } SDL_Flip(screen); } void game_win_update_player_info() { su_t i; gfx_set_win(scr_win); gfx_win_half_size(); set_space_icon(SPC_TRAN); for(i=1;iblk_count_x-1;i++) gfx_win_draw_image(hs_icons[ICON_LINE_B],i, scr_win->blk_count_y-1); if(options->game){ gfx_mv_cur(1,scr_win->blk_count_y-1); gfx_printf("%2d of %2d",player.masks_collected,map->mask_count); } gfx_mv_cur(scr_win->blk_count_x-6,scr_win->blk_count_y-1); gfx_printf("%c%d", (player.player?'*':'#'), map->max_moves-player.move_no); SDL_Flip(screen); #ifdef PLAYER_XY_DEBUG printf("player:x,y %d,%d\n", map->player[player.player].x, map->player[player.player].y); #endif } void game_win_get_view_for(xy_t cx, xy_t cy, xy_t* tlx, xy_t* tly) { xy_t tl_x; xy_t tl_y; xy_t tmp; if((tl_x=cx-game_win->blk_count_x/2)<0) tl_x=0; if((tl_y=cy-game_win->blk_count_y/2)<0) tl_y=0; if((tmp=tl_x+game_win->blk_count_x)>map->width) tl_x+=map->width-tmp; if((tmp=tl_y+game_win->blk_count_y)>map->width) tl_y+=map->width-tmp; *tlx=tl_x; *tly=tl_y; } void game_win_show(xy_t cx, xy_t cy) { xy_t tlx,tly; xy_t x,y,mx,my,i; SDL_Surface* icon; game_win_get_view_for(cx,cy,&tlx,&tly); for(y=0;yblk_count_y;y++){ for(x=0;xblk_count_x;x++){ mx=tlx+x; my=tly+y; if(mx>map->width||my>map->height) i=ICON_WALL; else i=map->data[my][mx]; icon=icons[i]; draw_image(icons[ICON_FLOOR], game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); if(options->show_indicators){ if(icons_with_indicators[i]) draw_image(icons_with_indicators[i], game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); else draw_image(icon, game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); } else draw_image(icon, game_win->blk_tlx+x*ICON_WIDTH, game_win->blk_tly+y*ICON_HEIGHT); } } SDL_Flip(screen); } void game_win_swap_update() { su_t p=(player.player)?0:1; if(map->player[player.player].x>map->view[p].x &&map->player[player.player].xview[p].x+game_win->blk_count_x-1) { if(map->player[player.player].y>map->view[p].y &&map->player[player.player].yview[p].y+game_win->blk_count_y-1){ map->view[player.player].x=map->view[p].x; map->view[player.player].y=map->view[p].y; } } } void game_win_move_player(struct xor_move* pmv) { xy_t vx, vy; xy_t ovx,ovy; su_t scrt=(player.replay?1:options->scroll_thresh); ovx=vx=map->view[player.player].x; ovy=vy=map->view[player.player].y; switch(pmv->dir){ case MV_LEFT: if(pmv->to_x0) vx--; break; case MV_RIGHT: if(pmv->to_x > vx+game_win->blk_count_x-1-scrt &&vxwidth-game_win->blk_count_x) vx++; break; case MV_UP: if(pmv->to_y0) vy--; break; case MV_DOWN: if(pmv->to_y > vy+game_win->blk_count_y-1-scrt &&vyheight-game_win->blk_count_y) vy++; break; default:break; } if(ovx!=vx||ovy!=vy){ map->view[player.player].x=vx; map->view[player.player].y=vy; game_win_display(map); return; } game_win_icon_display(pmv->from_x, pmv->from_y, ICON_FLOOR); game_win_icon_display(pmv->to_x, pmv->to_y, pmv->from_obj); SDL_Flip(screen); } void game_win_move_object(struct xor_move* omv) { game_win_icon_display(omv->from_x, omv->from_y, ICON_FLOOR); game_win_icon_display(omv->to_x, omv->to_y, omv->from_obj); SDL_Flip(screen); } struct xy* game_win_map_coord(xy_t x, xy_t y) { struct xy* ret=0; struct xy* pv=&map->view[player.player]; if(!(ret=malloc(sizeof(struct xy)))) return 0; if(x >= pv->x && x < pv->x+game_win->blk_count_x &&y >= pv->y && y < pv->y+game_win->blk_count_y) { ret->x=(x-pv->x)*ICON_W; ret->y=(y-pv->y)*ICON_H; return ret; } free(ret); return 0; } void game_win_icon_display(xy_t x, xy_t y, su_t icon) { xy_t xx, yy; xy_t ox,oy; SDL_Surface* surface=icons[icon]; ox=map->view[player.player].x; oy=map->view[player.player].y; if(x=ox+game_win->blk_count_x ||y=oy+game_win->blk_count_y) return; xx=x-ox; yy=y-oy; draw_image(icons[ICON_FLOOR], game_win->blk_tlx+xx*ICON_WIDTH, game_win->blk_tly+yy*ICON_HEIGHT); if(options->show_indicators){ if(icons_with_indicators[icon]) draw_image(icons_with_indicators[icon], game_win->blk_tlx+xx*ICON_WIDTH, game_win->blk_tly+yy*ICON_HEIGHT); else draw_image(surface, game_win->blk_tlx+xx*ICON_WIDTH, game_win->blk_tly+yy*ICON_HEIGHT); } else{ draw_image(surface, game_win->blk_tlx+xx*ICON_WIDTH, game_win->blk_tly+yy*ICON_HEIGHT); } } /* void game_win_icon_dump(xy_t x, xy_t y, su_t icon) { xy_t xx, yy; wattrset(game_win,COLOR_PAIR(icon)); for(yy=0;yy