home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume13 / thricken / part01 / screen.c < prev    next >
C/C++ Source or Header  |  1992-08-03  |  3KB  |  131 lines

  1. #include <signal.h>
  2. #include <fcntl.h>
  3. #include <curses.h>
  4. #include "extern.h"
  5. #include "thricken.h"
  6.  
  7. WINDOW *gw,*sw,*lw;
  8. char *init_file = "screen";
  9.  
  10. void myerror(char *error);
  11. void stop();
  12. void refresh3();
  13.  
  14. void cleanup() {
  15.     nocbreak();
  16.     echo();
  17.     endwin();
  18.     write_score();
  19.     exit(0);
  20. }
  21.  
  22. void init_display() {
  23.     int i,j;
  24.     char *ptr,s;
  25.     FILE *fp;
  26.     initscr();
  27.     signal(SIGTSTP,stop);
  28.     signal(SIGINT,cleanup);
  29.     clear();
  30.     noecho();
  31.     cbreak();
  32.     gw = newwin(HEIGHT, WIDTH, 0,0);
  33.     lw = newwin(9, 79-WIDTH, 0, WIDTH+1); 
  34.     sw = newwin(14, 79-WIDTH, 10, WIDTH+1); 
  35.     
  36.     if ((fp = fopen(init_file,"r")) == NULL) {
  37.     myerror(init_file);
  38.     }
  39.     for (i=0; i<24; i++) {
  40.     mvwaddstr(gw,i,0,readline(fp));
  41.     }
  42.     for (i=0; i<9; i++) {
  43.     mvwaddstr(lw,i,0,readline(fp));
  44.     }
  45.     for (i=0; i<14; i++) {
  46.     mvwaddstr(sw,i,0,readline(fp));
  47.     }
  48.     fclose(fp);
  49. }
  50.  
  51. void myerror(char *e) {
  52.     nocbreak();
  53.     echo();
  54.     endwin();
  55.     perror(e);
  56.     sleep(2);
  57.     exit(1);
  58. }
  59.  
  60. draw_sprite(WINDOW *w, int y, int x, char spr) {
  61.     int i,j;
  62.  
  63.     for (j=0; j<SPRHEIGHT; j++)
  64.     for (i=0; i<SPRWIDTH; i++)
  65.         mvwaddch(w,y+j,x+i,sprite[spr][j][i]);
  66. }
  67.  
  68. draw_map(int y, int x) {
  69.     int i,j;
  70.  
  71.     for (i=0; i<SCRWIDTH; i++)
  72.     for (j=0; j<SCRHEIGHT; j++) {
  73.         draw_sprite(gw, j*SPRHEIGHT, i*SPRWIDTH,
  74.             map[(y+j+rows)%rows][(x+i+cols)%cols]);
  75.     }
  76. }
  77.  
  78. void draw_you(char y, char x, char c) {
  79.     draw_sprite(gw, y, x, c);
  80. }
  81.  
  82. void draw_stats(char level) {
  83.     char buf[75-WIDTH];
  84.     char tmp;
  85.     
  86.     mvwprintw(sw,3,8,"%06d",level);
  87.     draw_sprite(sw,3,20,'d');
  88.     strncpy(buf,lname,74-WIDTH);
  89.     if ((tmp=strlen(lname)) < 74-WIDTH)
  90.     strncpy(buf+tmp,"                        \0",74-WIDTH-tmp);
  91.     buf[26]='\0';
  92.     mvwprintw(sw,1,3,"%s",buf);
  93.     strncpy(buf,author,74-WIDTH);
  94.     if ((tmp=strlen(author)) < 74-WIDTH)
  95.     strncpy(buf+tmp,"                        \0",74-WIDTH-tmp);
  96.     buf[25]='\0';
  97.     mvwprintw(sw,11,4,"%s",buf);
  98.     strncpy(buf,dname,74-WIDTH);
  99.     if ((tmp=strlen(dname)) < 74-WIDTH)
  100.     strncpy(buf+tmp,":                       \0",74-WIDTH-tmp);
  101.     buf[11]='\0';
  102.     mvwprintw(sw,7,17,"%s",buf);
  103. }
  104.  
  105. void update_wins() {
  106.     mvwprintw(sw,5,8,"%06d",score);
  107.     mvwprintw(sw,7,8,"%06d",moves);
  108.     mvwprintw(sw,8,19,"%06d",diamonds);
  109.     refresh3();
  110. }
  111.  
  112. void refresh3() {
  113.     wrefresh(gw);
  114.     wrefresh(sw);
  115.     wrefresh(lw);
  116. }
  117.  
  118. void refresh_all() {
  119.     clearok(curscr,TRUE);
  120.     wrefresh(curscr);
  121. }
  122.     
  123. void stop() {
  124.     nocbreak();
  125.     echo();
  126.     kill(getpid(),SIGSTOP);
  127.     noecho();
  128.     cbreak();
  129.     refresh_all();
  130. }
  131.