1
0
vt100-games/MazezaM/mazezam.c

584 lines
12 KiB
C
Raw Normal View History

2020-06-26 13:19:23 +02:00
/*
MazezaM
Copyright (C) 2002
Malcolm Tyrrell
tyrrelmr@cs.tcd.ie
CP/M version (C) 2004-2008
Ventzislav Tzvetkov
http://drhirudo.hit.bg
z88dk version by Stefano Bodrato (www.z88dk.org)
VT100 version by Anna Christina Naß <acn@acn.wtf>
Build:
zcc +cpm -lndos -O3 -o MAZEZAM.COM mazezam.c
2020-06-26 13:19:23 +02:00
This code may be used and distributed under
the terms of the GNU General Public Licence.
*/
#pragma output REGISTER_SP = 0xa000
2020-06-26 13:19:23 +02:00
#pragma output hrgpage = 36096
#include <stdio.h> // We use printf(); putchar();
#include <string.h> // strlen for the Level name centering.
#define LEVELS 12 // Number of Levels
#define TRUE 1
#define FALSE 0
#define PLAYER "P" // player symbol
#define BRICK ":" // brick symbol
#define COLWAY 15 // color of entrance and exit
#define COLDOOR 15 // color of entrance door
#define COLPLAYER 14 // color of player
#define COLBRICK 8 // color of bricks
unsigned int uLives,uWidth,uHeight, i, j, l, t, r, rx, lx, bCloseFlag=FALSE, Column;
/* Global miscellaneous variables - i,j for loops and Player coordinates,
t,r,rx,lx - for the Level build. */
char *MazeLine[12], // Text pointer to the Level (Max 12 lines)
Mazezam[200], // Storage of the level.
PressedKey; // Which key is pressed.
static char *ARGH[]={
"ARGH!",
"OUCH!",
"GRRR!",
"NOOU!",
"NAAH!",
"UUUF!",
"AAAH!",
"OUUF!",
"PUFF!"
};
/* We use escape control combinations for handling of the display */
ClearScreen()
{
printf("\033[2J\033[H");
}
InverseOn()
{
printf("\033[7m");
}
InverseOff()
{
printf("\033[0m");
}
ResetAttr()
{
printf("\033[0m");
}
FgCol(color)
int color;
{
if(color<8)
printf("\033[3%dm", color);
if(color>=8)
printf("\033[3%d;1m", color-8); // bright colors begin at 8
}
BgCol(color)
int color;
{
char str[6];
printf("\033[4%dm", color);
}
PrintPlayer()
{
FgCol(COLPLAYER);
printf(PLAYER);
ResetAttr();
}
ColorLine(line)
int line;
{
FgCol(line);
}
void PrintEnter()
{
printf("\n");
}
void FillRow()
{
FgCol(COLBRICK);
for (Column=0;Column<80;Column++) printf(BRICK);
ResetAttr();
PrintEnter();
}
void FillWall()
{
FgCol(COLBRICK);
for (l=0;l<26;l++) printf(BRICK);
ResetAttr();
}
void FillSpace()
{
for (l=0;l<28;l++) printf(" ");
}
void gotogxy(int x,int y)
{
printf("\033[%d;%dH",y+1,x+1); // Console sequence for setting cursor to X,Y position.
}
void Level(int MazeNumber)
{
int k;
char *LevelName; // Pointer to the Level name string.
ClearScreen();
switch (MazeNumber)
{
case 1:
LevelName="Humble Origins";uWidth=7;uHeight=2;lx=rx=1;
MazeLine[1]=" # # ";
MazeLine[2]=" # ## ";
break;
case 2:
LevelName="Easy Does It";uWidth=8;uHeight=lx=3;rx=2;
MazeLine[1]=" # ###";
MazeLine[2]=" # # # ";
MazeLine[3]=" # # # ";
break;
case 3:
LevelName="Up, Up and Away";uWidth=5;uHeight=lx=11;rx=1;
MazeLine[1]= " # ";
MazeLine[2]= " # ##";
MazeLine[3]= " ## ";
MazeLine[4]= "# # ";
MazeLine[5]= " # # ";
MazeLine[6]= " ### ";
MazeLine[7]= "# # ";
MazeLine[8]= " # # ";
MazeLine[9]= " # # ";
MazeLine[10]="# ## ";
MazeLine[11]=" # ";
break;
case 4:
LevelName="Little Harder";uWidth=5;uHeight=4;lx=2;rx=1;
MazeLine[1]=" # # ";
MazeLine[2]=" # #";
MazeLine[3]=" # ";
MazeLine[4]=" ## #";
break;
case 5:
LevelName="To and Fro";uWidth=13;uHeight=6;lx=rx=1;
MazeLine[1]=" ##### ";
MazeLine[2]="# ##### ### ";
MazeLine[3]=" # ### #### ";
MazeLine[4]="# # ####### ";
MazeLine[5]=" ### # ## ";
MazeLine[6]="# # # ## # ";
break;
case 6:
LevelName="Loop-de-Loop";uWidth=14;uHeight=4;lx=2;rx=4;
MazeLine[1]=" ##### ## ## ";
MazeLine[2]=" ## ## ## ";
MazeLine[3]="## # ## ### ";
MazeLine[4]=" ######## #";
break;
case 7:
LevelName="Somehow Easy";uWidth=5;uHeight=rx=3;lx=1;
MazeLine[1]=" ## ";
MazeLine[2]=" # ";
MazeLine[3]=" # ##";
break;
case 8:
LevelName="Be Prepared";uWidth=7;uHeight=6;lx=5;rx=3;
MazeLine[1]=" # ";
MazeLine[2]=" #### ";
MazeLine[3]=" ### ##";
MazeLine[4]=" # # # ";
MazeLine[5]=" # ## ";
MazeLine[6]="# ## ";
break;
case 9:
LevelName="Two Front Doors";uWidth=16;uHeight=rx=7;lx=1;
MazeLine[1]=" ####### ";
MazeLine[2]=" #### #### # # ";
MazeLine[3]="## ## ###### # #";
MazeLine[4]="## # # ";
MazeLine[5]=" ############# ";
MazeLine[6]=" # ## # ### ";
MazeLine[7]=" # ### ##";
break;
case 10:
LevelName="Through, through";uWidth=15;uHeight=4;lx=3;rx=1;
MazeLine[1]=" #### #### ##";
MazeLine[2]=" # ## ## # ## ";
MazeLine[3]=" # ## #### ## ";
MazeLine[4]=" # ## #### # ";
break;
case 11:
LevelName="Double Cross";uWidth=9;uHeight=lx=7;rx=3;
MazeLine[1]=" # #### ";
MazeLine[2]=" # # ## ";
MazeLine[3]=" # #### #";
MazeLine[4]="# ## # ";
MazeLine[5]=" # ###";
MazeLine[6]=" ###### ";
MazeLine[7]=" # ";
break;
case 12:
LevelName="Inside Out";uWidth=14;uHeight=10;lx=8;rx=1;
MazeLine[1]= " # ";
MazeLine[2]= " ########## #";
MazeLine[3]= " ### ## ";
MazeLine[4]= " # ######## # ";
MazeLine[5]= " ### ### ### ";
MazeLine[6]= " ### # ### ";
MazeLine[7]= " # ####### ## ";
MazeLine[8]= " # # # ### ";
MazeLine[9]= " ############ ";
MazeLine[10]=" ";
break;
default:
ClearScreen();
gotogxy(9,7);
printf("Congratulations!");
gotogxy(2,8);
printf("You've completed the MazezaM");
gotogxy(12,10);
InverseOn();
printf("Well Done!");
InverseOff();
bCloseFlag=TRUE;
getkey();
break;
}
if (bCloseFlag) return;
for (i=1;i<uHeight+1;i++) strcpy(&Mazezam[i*uWidth],MazeLine[i]); // Copy the Level Data.
l=((80-uWidth)/2);
t=((22-uHeight)/2);
r=80-l-uWidth;
FgCol(COLBRICK); printf(BRICK); printf(BRICK);printf(BRICK); ResetAttr();
printf(" Level ");
if (MazeNumber<10) printf("0%d ",MazeNumber);
else printf("%d ",MazeNumber);
FgCol(COLBRICK); for (i=0;i<50;i++) printf(BRICK); ResetAttr();
printf(" Lives ");
if (uLives<10) printf("0%d",uLives);
else printf("%d",uLives);
FgCol(COLBRICK); printf(" "); printf(BRICK); printf(BRICK); printf(BRICK); PrintEnter(); ResetAttr();
for (i=1;i!=t+1;i++) FillRow();
for (i=1;i!=uHeight+1;i++)
{
if (i==lx) for (k=0;k!=l;k++) { FgCol(COLWAY); printf("_"); ResetAttr(); }
if (i!=lx) for (k=0;k!=l;k++) { FgCol(COLBRICK); printf(BRICK); ResetAttr(); }
ColorLine(i); printf(MazeLine[i]); ResetAttr(); // Print the Level line.
if (i==rx) for (k=0;k!=r;k++) { FgCol(COLWAY); printf("_"); ResetAttr(); }
if (i!=rx) for (k=0;k!=r;k++) { FgCol(COLBRICK); printf(BRICK); ResetAttr(); }
PrintEnter();
}
FgCol(COLBRICK); for (i=t+uHeight+1;i!=22;i++) FillRow(); ResetAttr();
j=strlen(LevelName);
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(BRICK); ResetAttr();
printf(" ");
printf(LevelName);
printf(" ");
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(BRICK); ResetAttr();
PrintEnter();
for (i=0;i!=l;i++)
{
gotogxy(i+1,t+lx);
PrintPlayer(); //Start animation
gotogxy(i,t+lx);
FgCol(COLWAY);
printf("_"); // Fill after
}
gotogxy(l-1,t+lx);
FgCol(COLDOOR); printf("O");
PrintPlayer();
i=lx;
j=1;
}
void Title()
{
ClearScreen();
gotogxy(0,2);
FillRow();
FillWall(); BgCol(7); FgCol(13);
printf(" M"); FgCol(10); printf(" a"); FgCol(11); printf(" z");
FgCol(12); printf(" e"); FgCol(11); printf(" z"); FgCol(10); printf(" a");
FgCol(13); printf(" M "); ResetAttr();
FillWall(); PrintEnter();
FillRow();
FillWall(); FillSpace(); FillWall(); PrintEnter();
FillWall(); printf(" CPM version (C) 2004-08 by "); FillWall(); PrintEnter();
FillWall(); printf(" Ventzislav Tzvetkov "); FillWall(); PrintEnter();
FillWall(); printf(" VT100 color (C) 2020 by "); FillWall(); PrintEnter();
FillWall(); printf(" Anna Christina Nass "); FillWall(); PrintEnter();
FillWall(); FillSpace(); FillWall(); PrintEnter();
FillWall(); FillSpace(); FillWall(); PrintEnter();
FillRow();
PrintEnter();
PrintEnter();
printf(" Keys: 8 ^ r - retry level\n");
printf(" | q - quit\n");
printf(" 4 <--+--> 6 \n");
printf(" |\n");
printf(" v 2 Press SPACE to start\n");
printf(" (or use WASD keys)\n");
uLives=3;
Column=40;
for (;;)
{
gotogxy(Column,11);
PrintPlayer();
PressedKey=getkey();
if (PressedKey==' ') break;
if (PressedKey=='Q' || PressedKey=='q')
{
bCloseFlag=TRUE;
break;
}
if (PressedKey=='6')
{
gotogxy(Column,11);
Column+=(Column<53);
printf(" ");
}
if (PressedKey=='4')
{
gotogxy(Column,11);
Column-=(Column>26);
printf(" ");
}
}
}
int main()
{
int Mazeno,Loop,rand;
printf("\033[?25l"); // Hide Cursor escape sequence
for (;;)
{
Title();
Mazeno=1;
if (bCloseFlag) break;
Level(Mazeno);
for(;;)
{
PressedKey=getkey();
// restart level
if (PressedKey=='R' || PressedKey=='r')
{
uLives--;
if (uLives<1) PressedKey='q';
else
{
gotogxy(l+j-3,t+i-1);
InverseOn();
printf(ARGH[rand%9]);
InverseOff();
getkey();
Level(Mazeno);
}
}
// quit
if (PressedKey=='Q' || PressedKey=='q')
{
//gotogxy(l+j-3,t+i-1);
//InverseOn();
//printf(ARGH[rand%9]);
//InverseOff();
//getkey();
gotogxy(35,10);
InverseOn();
printf("GAME OVER!");
InverseOff();
getkey();
bCloseFlag=TRUE;
break;
}
// right - level cleared
if ((PressedKey=='6' || PressedKey=='D' || PressedKey=='d') && (i==rx && j==uWidth))
{
gotogxy(l+j-1,t+i);
printf(" ");
for (i=l+uWidth;i!=80;i++)
{
gotogxy(i,t+rx);
PrintPlayer();
gotogxy(i,t+rx);
FgCol(COLWAY); printf("_"); ResetAttr();
}
InverseOn();
i=t+rx;
switch (rand%6)
{
case 0:
gotogxy(13,i);
printf("Hurray!");
break;
case 1:
gotogxy(13,i);
printf("Hurrah!");
break;
case 2:
gotogxy(16,i);
printf("Yes!");
break;
case 3:
gotogxy(14,i);
printf("Great!");
break;
case 4:
gotogxy(12,i);
printf("Yee-hah!");
break;
default:
gotogxy(16,i);
printf("Yay!");
}
InverseOff();
getkey();
uLives++;
Level(++Mazeno);
PressedKey=0;
}
// right
if ((PressedKey=='6' || PressedKey=='D' || PressedKey=='d') && j<uWidth)
if ((Mazezam[i*uWidth+j])==' ')
{
gotogxy(l+j-1,t+i);
printf(" ");
j++;
gotogxy(l+j-1,t+i);
PrintPlayer();
}
else
if (Mazezam[(i*uWidth)+uWidth-1]==' ')
{
j++;
for (Loop=uWidth-1;Loop>0;Loop--)
Mazezam[(i*uWidth)+Loop]=Mazezam[(i*uWidth)+Loop-1];
Mazezam[i*uWidth]=' ';
gotogxy(l,t+i);
for (Loop=0;Loop<uWidth;Loop++)
{
ColorLine(i);
putchar(Mazezam[i*uWidth+Loop]);
ResetAttr();
}
gotogxy(l+j-1,t+i);
PrintPlayer();
}
// left
if ((PressedKey=='4' || PressedKey=='A' || PressedKey=='a') && j>1)
if (Mazezam[(i*uWidth)+j-2]==' ')
{
gotogxy(l+j-1,t+i);
printf(" ");
j--;
gotogxy(l+j-1,t+i);
PrintPlayer();
}
else
if (Mazezam[i*uWidth]==' ')
{
j--;
for (Loop=1;Loop!=uWidth;Loop++)
Mazezam[(i*uWidth)+Loop-1]=Mazezam[(i*uWidth)+Loop];
Mazezam[(i*uWidth)+uWidth-1]=' ';
gotogxy(l,t+i);
for (Loop=0;Loop<uWidth;Loop++)
{
ColorLine(i);
putchar(Mazezam[i*uWidth+Loop]);
ResetAttr();
}
gotogxy(l+j-1,t+i);
PrintPlayer();
}
// down
if ((PressedKey=='2' || PressedKey=='S' || PressedKey=='s') && i<uHeight)
if (Mazezam[((i+1)*uWidth)+j-1]==' ')
{
gotogxy(l+j-1,t+i);
printf(" ");
i++;
gotogxy(l+j-1,t+i);
PrintPlayer();
}
// up
if ((PressedKey=='8' || PressedKey=='W' || PressedKey=='w') && i>1)
if (Mazezam[((i-1)*uWidth)+j-1]==' ')
{
gotogxy(l+j-1,t+i);
printf(" ");
i--;
gotogxy(l+j-1,t+i);
PrintPlayer();
}
PressedKey=0;
if (bCloseFlag) break;
rand++;
}
if (bCloseFlag) break;
}
ClearScreen();
printf("\033[?25h"); // Show Cursor escape sequence
return 0;
}