home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume13
/
thricken
/
part01
/
screen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-03
|
3KB
|
131 lines
#include <signal.h>
#include <fcntl.h>
#include <curses.h>
#include "extern.h"
#include "thricken.h"
WINDOW *gw,*sw,*lw;
char *init_file = "screen";
void myerror(char *error);
void stop();
void refresh3();
void cleanup() {
nocbreak();
echo();
endwin();
write_score();
exit(0);
}
void init_display() {
int i,j;
char *ptr,s;
FILE *fp;
initscr();
signal(SIGTSTP,stop);
signal(SIGINT,cleanup);
clear();
noecho();
cbreak();
gw = newwin(HEIGHT, WIDTH, 0,0);
lw = newwin(9, 79-WIDTH, 0, WIDTH+1);
sw = newwin(14, 79-WIDTH, 10, WIDTH+1);
if ((fp = fopen(init_file,"r")) == NULL) {
myerror(init_file);
}
for (i=0; i<24; i++) {
mvwaddstr(gw,i,0,readline(fp));
}
for (i=0; i<9; i++) {
mvwaddstr(lw,i,0,readline(fp));
}
for (i=0; i<14; i++) {
mvwaddstr(sw,i,0,readline(fp));
}
fclose(fp);
}
void myerror(char *e) {
nocbreak();
echo();
endwin();
perror(e);
sleep(2);
exit(1);
}
draw_sprite(WINDOW *w, int y, int x, char spr) {
int i,j;
for (j=0; j<SPRHEIGHT; j++)
for (i=0; i<SPRWIDTH; i++)
mvwaddch(w,y+j,x+i,sprite[spr][j][i]);
}
draw_map(int y, int x) {
int i,j;
for (i=0; i<SCRWIDTH; i++)
for (j=0; j<SCRHEIGHT; j++) {
draw_sprite(gw, j*SPRHEIGHT, i*SPRWIDTH,
map[(y+j+rows)%rows][(x+i+cols)%cols]);
}
}
void draw_you(char y, char x, char c) {
draw_sprite(gw, y, x, c);
}
void draw_stats(char level) {
char buf[75-WIDTH];
char tmp;
mvwprintw(sw,3,8,"%06d",level);
draw_sprite(sw,3,20,'d');
strncpy(buf,lname,74-WIDTH);
if ((tmp=strlen(lname)) < 74-WIDTH)
strncpy(buf+tmp," \0",74-WIDTH-tmp);
buf[26]='\0';
mvwprintw(sw,1,3,"%s",buf);
strncpy(buf,author,74-WIDTH);
if ((tmp=strlen(author)) < 74-WIDTH)
strncpy(buf+tmp," \0",74-WIDTH-tmp);
buf[25]='\0';
mvwprintw(sw,11,4,"%s",buf);
strncpy(buf,dname,74-WIDTH);
if ((tmp=strlen(dname)) < 74-WIDTH)
strncpy(buf+tmp,": \0",74-WIDTH-tmp);
buf[11]='\0';
mvwprintw(sw,7,17,"%s",buf);
}
void update_wins() {
mvwprintw(sw,5,8,"%06d",score);
mvwprintw(sw,7,8,"%06d",moves);
mvwprintw(sw,8,19,"%06d",diamonds);
refresh3();
}
void refresh3() {
wrefresh(gw);
wrefresh(sw);
wrefresh(lw);
}
void refresh_all() {
clearok(curscr,TRUE);
wrefresh(curscr);
}
void stop() {
nocbreak();
echo();
kill(getpid(),SIGSTOP);
noecho();
cbreak();
refresh_all();
}