|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 17519 (0x446f)
Types: TextFile
Names: »mex.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/Sun/Mex/mex.c«
/* ALL code in this program may be used for personal use */
/* and this program may be distributed as long as this copyright */
/* heading is attached to each source code file. Distribution must */
/* be done FREE of charge................ */
/* Glenn Kreisel */
/* glenn@midget.towson.edu */
/* S72QKRE@TOWSONVX.BITNET */
#include "mex.h"
extern Panel_item rows_left_string;
extern ring_bell();
extern Panel_item level_num;
extern Panel_item score_string,rows_string;
extern Panel_item level_string;
extern Panel right_panel;
extern Panel_item restart_button,start_button;
extern void do_mex_look();
extern void read_in_scores();
extern void write_out_scores();
extern void insert_score();
extern void freeze_proc();
extern char **define_2d();
extern Frame frame;
extern Panel_item show_next;
Pixfont *bold, *cour;
extern Canvas game_canvas;
static short box[] = {
#include "block1.icon"
};
mpr_static(block, block_icon_width, block_icon_height, 1, box);
static short box1[] = {
#include "block2.icon"
};
mpr_static(block2, block_icon_width, block_icon_height, 1, box1);
static short box2[] = {
#include "block3.icon"
};
mpr_static(block3, block_icon_width, block_icon_height, 1, box2);
static short box3[] = {
#include "block4.icon"
};
mpr_static(block4, block_icon_width, block_icon_height, 1, box3);
static short box4[] = {
#include "block5.icon"
};
mpr_static(block5, block_icon_width, block_icon_height, 1, box4);
static short box5[] = {
#include "block6.icon"
};
mpr_static(block6, block_icon_width, block_icon_height, 1, box5);
static short box6[] = {
#include "block7.icon"
};
mpr_static(block7, block_icon_width, block_icon_height, 1, box6);
struct object_struct {
struct object_struct *next_pointer;
Pixrect *block_type;
char x[4];
char y[4];
};
#include "objects.h"
struct object_struct *objects[7] = {<red_piece, <green_piece,
&yellow_piece, &blue_piece,
&white_piece, &red_piece, &green_piece
};
struct object_struct *current_object;
int key=0;
char black[char_width * char_width];
struct xy {
int x;
int y;
};
struct xy still_blocks[22];
int num_stationary;
static short still_box[] = {
#include "still_block.icon"
};
mpr_static(still_block_type, block_icon_width, block_icon_height, 1, still_box);
#include "screens.h"
char **screen;
Pixwin *pw;
Pixwin *right_panel_pw;
int frozen=0, top_of = 0, key_up = 0, fast = 0,score=0,level=0,sound_on=0;
int c,rows_needed=0,num_rows=0,rows=0,restart=0,drop_score,DELAY,sun3_delay;
int speed,speed_add=0,something_on_screen=0;
Pixrect *black_pr;
/* /userb/shirley/icons/tetrix 64x64 */
main(argc,argv)
int argc;
char **argv;
{
int i, j;
Event event;
char num_str[5];
Rect start;
DELAY=5;
sun3_delay=0;
if(system("sparc")!=0) {sun3_delay=3; DELAY=1;}
srand((int)time(0));
if (!(bold = pf_open("/usr/lib/fonts/fixedwidthfonts/gallant.r.19")))
bold = pf_default();
if (!(cour = pf_open("/usr/lib/fonts/fixedwidthfonts/cour.r.24")))
cour = pf_default();
for (i = 0; i < char_height * char_width; i++)
black[i] = 255;
black_pr = mem_point(char_width, char_height, 1, black);
screen = define_2d(width + 2, height+1);
do_mex_look(&argc,argv);
for(i=1;i<argc;i++)
{
if(strcmp(argv[i],"-SUN3")==0 || strcmp(argv[i],"-sun3")==0) {sun3_delay=3; DELAY=1;}
if(strcmp(argv[i],"-so")==0) sound_on=1;
}
right_panel_pw=(Pixwin *)window_get(right_panel,WIN_PIXWIN);
window_set(frame,WIN_SHOW,TRUE,0);
(void) notify_dispatch();
restart=GAME_OVER;
do
{
while(restart!=GAME_OVER && restart!=EXIT_GAME)
{
restart=Do_game();
if(restart==GAME_OVER)
insert_score(score,rows);
panel_set(start_button,PANEL_SHOW_ITEM,TRUE,0);
panel_set(restart_button,PANEL_SHOW_ITEM,FALSE,0);
}
restart=GAME_OVER;
(void) notify_dispatch();
usleep(200);
} while(restart!=EXIT_GAME);
free(*screen);
free(screen);
exit(0);
}
char **
define_2d(wid, hei)
int wid, hei;
{
char *a;
int i;
char **aa;
a = (char *) calloc(wid * hei, sizeof(char));
aa = (char **) calloc(hei, sizeof(char *));
for (i = 0; i < hei; i++) {
aa[i] = a;
a += wid;
}
return (aa);
}
clear_screen()
{
Rect r;
int x, y;
for (y = 0; y < height; y++)
for (x = 0; x < width+2; x++)
screen[y][x] = 0;
for (x = 0; x < width + 2; x++)
{
screen[height][x] = 1;
screen[0][x]=1;
}
for (x = 0; x < height; x++) {
screen[x][width + 1] = 1;
screen[x][0] = 1;
}
do_split_screen();
something_on_screen=0;
top_of=255;
if(level==10) {level=0; speed_add++;}
x=level;
rows_needed=10;
speed=13;
pw_batch_on(pw);
if(x==1 && speed_add>0)
{
do_GMK();
speed=9;
rows_needed=17;
}
if(x==2 && speed_add>0)
{
do_CLW();
speed=10;
rows_needed=16;
}
if(x==3)
{
if(speed_add==0){
num_stationary=do_columns();
display_stationary_stuff();
}
else do_SMILE();
rows_needed=13;
speed=11;
}
if(x==4)
{
num_stationary=pick_random_station_pos(4);
display_stationary_stuff();
rows_needed=15;
speed=12;
}
if(x==5)
{
num_stationary=pick_random_station_pos(5);
display_stationary_stuff();
speed=10;
rows_needed=12;
}
if(x==6)
{
do_triangle();
rows_needed=11;
speed=10;
}
if(x==7)
{
do_screen10();
rows_needed=13;
speed=10;
}
if(x==8)
{
do_side_triangles();
speed=8;
}
if(x==9)
{
do_hex();
}
if(speed>speed_add) speed=(speed-(speed_add*2))+sun3_delay;
bump_level(0);
pw_batch_off(pw);
}
do_split_screen()
{
register i,x;
Rect r;
pw_get_region_rect(pw,&r);
if(something_on_screen)
{
x=r.r_width >> 1;
for(i=0;i<x;i++)
{
pw_batch_on(pw);
pw_copy(pw,0,0,x-i-1,r.r_height,PIX_SRC,pw,1,0);
pw_copy(pw,x+i+1,0,r.r_width-(x+i)-1,r.r_height,PIX_SRC,pw,x+i,0);
pw_batch_off(pw);
}
}
pw_batch_on(pw);
pw_writebackground(pw,0,0,r.r_width,r.r_height,PIX_SRC);
pw_vector(pw, 14, 0, 14, height * char_height, PIX_SRC, 3);
pw_vector(pw, (width + 1) * char_width, 0, (width + 1) * char_width, height * char_height, PIX_SRC, 3);
pw_replrop(pw, char_width, (height-1) * char_height,
(width) * char_width, char_height,
PIX_SRC , black_pr, 0, 0);
pw_batch_off(pw);
/* Clear Show Next space in right panel */
pw_writebackground(right_panel_pw,20,25,
char_width*object_width,char_height*object_height,PIX_SRC);
}
init_screen()
{
int x;
score=num_rows=level=rows=0;
speed_add=0; /* change this one now man */
level=(int)panel_get_value(level_num);
clear_screen();
bump_rows(0);
bump_score(0);
bump_level(0);
bump_rows_left();
restart=RUNNING;
}
check_rot(x, y)
int x, y;
{
int ob_x;
for (ob_x = 0; ob_x < object_width; ob_x++)
if (screen[1+y + current_object->next_pointer->y[ob_x]]
[x + current_object->next_pointer->x[ob_x]] == 1)
return (0);
return (1);
}
check_left(x, y)
int x, y;
{
int ob_x;
for (ob_x = 0; ob_x < object_width; ob_x++)
if (screen[1+y + current_object->y[ob_x]][x + current_object->x[ob_x] - 1] == 1)
return (0);
return (1);
}
check_right(x, y)
int x, y;
{
int ob_x;
for (ob_x = 0; ob_x < object_width; ob_x++)
if (screen[1+y + current_object->y[ob_x]][x + current_object->x[ob_x] + 1] == 1)
return (0);
return (1);
}
void my_directions(win,my_event)
Window win;
Event *my_event;
{
int id=event_id(my_event);
if ((id==MS_LEFT || id=='j') &&
event_is_down(my_event)) {
key = 1;
} else if ((id==MS_RIGHT || id=='l') &&
event_is_down(my_event)) {
key = 2;
} else if ((id==MS_MIDDLE || id=='k') &&
event_is_down(my_event)) {
key = 3;
} else if (id==' ' &&
event_is_down(my_event)) {
key = 4;
}
}
int
check_keys(x, y)
int x, y;
{
int key_up;
for(key_up=0;key_up<(speed)*DELAY;key_up++) (void)notify_dispatch();
if (key == 1) {
key=0;
key_up = 1;
if (check_left(x, y))
x--;
} else if (key == 2) {
key=0;
key_up = 1;
if (check_right(x, y))
x++;
} else if (key == 3) {
key=0;
key_up = 1;
if (check_rot(x, y))
current_object = current_object->next_pointer;
} else if(key==4) {
key=0;
fast=1;
drop_score=height-y;
key_up=1;
}
while(frozen)
{
notify_dispatch();
usleep(200);
}
return (x);
}
Do_game()
{
register x,y,ob_y,ob_x;
unsigned int time_up, q, hit, value;
struct object_struct *already_got;
struct pr_subregion bound;
panel_set(start_button,PANEL_SHOW_ITEM,FALSE,0);
panel_set(restart_button,PANEL_SHOW_ITEM,TRUE,0);
pw = canvas_pixwin(game_canvas);
init_screen();
srand(rand());
already_got = objects[rand() % 7];
while (1) {
fast = hit = 0;
drop_score=1;
current_object = already_got;
already_got = objects[rand() % 7];
y = 0-current_object->y[0];
x = width >> 1;
value = (int) panel_get(show_next, PANEL_TOGGLE_VALUE, 0);
if (value)
for (ob_x = 0; ob_x < object_width; ob_x++)
pw_write(right_panel_pw,
20+( already_got->x[ob_x]*char_width) ,
25 +(already_got->y[ob_x]*char_height),
block_icon_width, block_icon_height,
PIX_SRC | PIX_DST,
already_got->block_type, 0, 0);
if (!check_left(x+1, y))
break;
for (ob_x = 0; ob_x < object_width; ob_x++)
pw_write(pw,
(x + current_object->x[ob_x]) * char_width,
(y + current_object->y[ob_x]) * char_height,
block_icon_width, block_icon_height,
PIX_SRC | PIX_DST,
current_object->block_type, 0, 0);
while (!hit) {
time_up = 0;
while (time_up < MOVES_PER_ROW && !hit) {
time_up++;
if ((time_up == MOVES_PER_ROW) && (hit = yadd(x, y)))
break;
pw_batch_on(pw);
/* blink_stationary_stuff(); */
for (ob_x = 0; ob_x < object_width; ob_x++)
pw_write(pw,
(x + current_object->x[ob_x]) * char_width,
(y + current_object->y[ob_x]) * char_height,
block_icon_width, block_icon_height,
PIX_SRC ^ PIX_DST,
current_object->block_type, 0, 0);
if(restart==NEW_GAME)
return(NEW_GAME);
if(restart==EXIT_GAME)
return(EXIT_GAME);
if ((!fast) && time_up == MOVES_PER_ROW) {
y++;
}
if (fast)
y++;
else
x = check_keys(x, y);
if(fast)
time_up=MOVES_PER_ROW-1;
for (ob_x = 0; ob_x < object_width; ob_x++) {
pw_write(pw, (x + current_object->x[ob_x]) * char_width, (y + current_object->y[ob_x]) * char_height,
block_icon_width, block_icon_height,
PIX_SRC | PIX_DST, current_object->block_type, 0, 0);
}
pw_batch_off(pw);
}
}
if (top_of > y+current_object->y[0])
top_of = y+current_object->y[0];
bump_score(drop_score*5);
fill_in_pos(x, y);
if(level>6 || speed_add>0) do_maybe_on_top();
if(speed_add>0 || level>8) do_row_maybe(level);
ring_bell(50000,1);
if (value)
for (ob_x = 0; ob_x < object_width; ob_x++)
pw_write(right_panel_pw,
20+( already_got->x[ob_x]*char_width) ,
25 +(already_got->y[ob_x]*char_height),
block_icon_width, block_icon_height,
PIX_NOT(PIX_SRC) & PIX_DST, already_got->block_type, 0, 0);
}
pf_textbound(&bound,9,cour,"Game Over");
pw_writebackground(pw, 50+bound.pos.x, (height >> 1) * char_height+bound.pos.y, bound.size.x, bound.size.y,PIX_SRC);
pw_text(pw, 50, (height >> 1) * char_height, PIX_SRC, cour, "Game Over");
return(GAME_OVER);
}
yadd(x, y)
int x, y;
{
int ob_x;
for (ob_x = 0; ob_x < object_width; ob_x++)
if ((screen[2 + y + current_object->y[ob_x]][x + current_object->x[ob_x]]) == 1)
return (1);
return (0);
}
fill_in_pos(x, y)
int x, y;
{
int ob_x, i1, i;
something_on_screen=1;
for (ob_x = 0; ob_x < object_width; ob_x++) {
screen[1+y + current_object->y[ob_x]][x + current_object->x[ob_x]] = 1;
}
check_rows(y);
}
bump_rows_left()
{
char dummy[8];
sprintf(dummy,"%d",rows_needed);
panel_set_value(rows_left_string,dummy);
}
bump_score(x)
int x;
{
char dummy[8];
score+=x;
sprintf(dummy,"%d",score);
panel_set_value(score_string,dummy);
}
bump_rows(x)
int x;
{
char dummy[8];
rows+=x;
sprintf(dummy,"%d",rows);
panel_set_value(rows_string,dummy);
}
bump_level(x)
int x;
{
char dummy[8];
if(level!=MAX_LEVEL)
level+=x;
sprintf(dummy,"%d",(speed_add*10)+level+1);
panel_set_value(level_string,dummy);
}
move_block_down(where)
int where;
{
unsigned int i, i1;
char *temp;
for (i = 0; i < 14; i++) {
pw_replrop(pw, char_width, where * char_height,
(width) * char_width, char_height,
PIX_SRC ^ PIX_DST, black_pr, 0, 0);
ring_bell(15000,1);
for (i1 = 0; i1 < 15000; i1++);
}
bump_rows(1);
bump_score(100);
pw_batch_on(pw);
for (i = where; i >= top_of; i--) {
pw_copy(pw, char_width, i * char_height, (width) * char_width, char_height, PIX_SRC, pw, char_width, (i - 1) * char_height);
}
pw_batch_off(pw);
temp = screen[where+1];
for (i = where+1; i > top_of+1; i--)
screen[i] = screen[i - 1];
screen[i] = temp;
for (i1 = 0; i1 < width + 2; i1++)
screen[i][i1] = 0;
screen[i][0] = 1;
screen[i][width + 1] = 1;
top_of++;
if((--rows_needed)==0)
{
bump_rows_left();
num_rows=0;
bump_level(1);
bump_score(top_of*5);
for (i = 0; i < top_of; i++) {
pw_replrop(pw, char_width, i * char_height,
(width) * char_width, char_height,
PIX_SRC ^ PIX_DST, black_pr, 0, 0);
for (i1 = 0; i1 < 10000; i1++);
}
pw_text(pw, 1*char_width, (height >> 1) * char_height,
PIX_SRC^PIX_DST, cour, "Low Level Bonus");
sleep(2);
pw_text(pw, 1*char_width, (height >> 1) * char_height,
PIX_SRC^PIX_DST, cour, "Low Level Bonus");
for (i = top_of; i>0; i--) {
pw_replrop(pw, char_width, (i-1) * char_height,
(width) * char_width, char_height,
PIX_NOT(PIX_SRC) & PIX_DST, black_pr, 0, 0);
for (i1 = 0; i1 < 10000; i1++);
}
clear_screen();
}
bump_rows_left();
}
check_rows(y)
int y;
{
int got_one,i, x, ob_x, where;
where = 999;
got_one=0;
for (ob_x = 0; ob_x < object_width && top_of!=255; ob_x++) {
if (where != current_object->y[ob_x] + y) {
where = current_object->y[ob_x] + y;
for (x = 0; (x < width + 2) && (screen[where+1][x] == 1); x++);
if (x == width + 2)
{
move_block_down(where);
got_one++;
}
}
}
if(got_one>1) {
bump_score(got_one*20);
}
}
display_stationary_stuff()
{
int i;
something_on_screen=1;
for(i=0;i<num_stationary;i++)
{
pw_write(pw, (still_blocks[i].x) * char_width,
(still_blocks[i].y) * char_height,
block_icon_width, block_icon_height,
PIX_SRC,&still_block_type, 0, 0);
if(top_of>still_blocks[i].y) top_of=still_blocks[i].y;
screen[still_blocks[i].y+1][still_blocks[i].x]=1;
}
}
pick_random_station_pos(x)
int x;
{
int i,i1,per_row;
i1=0;
for(i=0;i<x;i++)
{
for(per_row=0;per_row<3;per_row++)
{
still_blocks[i1].x=2+((rand()>>8) % width-1);
still_blocks[i1++].y=(height-2)-i;
}
}
return(i1);
}
int do_columns()
{
int i,i1;
i1=0;
for(i=height-2;i>height-8;i--)
{
still_blocks[i1].x=1;
still_blocks[i1++].y=i;
still_blocks[i1].x=width;
still_blocks[i1++].y=i;
}
return(i1);
}
do_triangle()
{
do_read_in(screen9);
}
do_random_insert()
{
int insert_row;
char *temp;
int i,i1;
if (top_of<10 || top_of>height-3) return;
insert_row=((rand()>> 8) % ((height-1)-top_of))+top_of;
pw_batch_on(pw);
temp = screen[top_of];
for (i =top_of ; i <= insert_row; i++) {
pw_copy(pw, char_width, (i-1) * char_height, (width) * char_width, char_height, PIX_SRC, pw, char_width, (i) * char_height);
screen[i] = screen[i + 1];
}
screen[i] = temp;
pw_writebackground(pw, char_width, (i-1) * char_height, (width) * char_width, char_height,PIX_SRC) ;
pw_batch_off(pw);
for (i1 = 0; i1 < width + 2; i1++)
screen[i][i1] = 0;
screen[i][0] = 1;
screen[i][width+1]=1;
for(i=0;i<6;i++)
{
still_blocks[0].x=1+(rand() % (width-1));
still_blocks[0].y=insert_row;
num_stationary=1;
(void)display_stationary_stuff();
}
for (i = 0; i < 14; i++) {
pw_replrop(pw, char_width, insert_row * char_height,
(width) * char_width, char_height,
PIX_SRC ^ PIX_DST, black_pr, 0, 0);
ring_bell(15000,1);
for (i1 = 0; i1 < 15000; i1++);
}
top_of--;
}
do_row_maybe(x)
int x;
{
if(((rand()>> 8)%50)<(speed_add+1)*2) do_random_insert();
}
do_maybe_on_top()
{
if(((rand()>> 8)%25)<(speed_add+1)*3) do_add_on_top();
}
do_add_on_top()
{
int x,i,i1,column;
column=1+((rand()>>8)%(width-1));
i=1;
while(screen[(++i)][column]==0);
still_blocks[0].x=column;
still_blocks[0].y=i-2;
num_stationary=1;
(void)display_stationary_stuff();
for (x = 0; x < 14; x++) {
pw_replrop(pw, column*char_width, (i-2) * char_height,
char_width, char_height,
PIX_SRC ^ PIX_DST, black_pr, 0, 0);
ring_bell(15000,1);
for (i1 = 0; i1 < 23000; i1++);
}
for (x = 0; (x < width + 2) && (screen[i-1][x] == 1); x++);
if(x==width+2) move_block_down(i-2);
}
do_side_triangles()
{
do_read_in(screen4);
}
do_hex()
{
do_read_in(screen5);
}
do_screen10()
{
do_read_in(screen10);
}
do_GMK()
{
do_read_in(screen6);
}
do_CLW()
{
do_read_in(screen7);
}
do_SMILE()
{
do_read_in(screen8);
}
do_read_in(x)
char x[][width];
{
int i,y;
y=0;i=0;
while(x[y][0]!='e')
{
for(i=0;i<width;i++)
{
if(x[y][i]=='x') {
still_blocks[0].x=i+1;
still_blocks[0].y=y+(height-6);
num_stationary=1;
display_stationary_stuff();
}
}
y++;
}
}