MazezaM: maze line colors are now chosen randomly plus some speed improvements
This commit is contained in:
parent
8e930e442b
commit
ca01ada15c
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
z88dk version by Stefano Bodrato (www.z88dk.org)
|
z88dk version by Stefano Bodrato (www.z88dk.org)
|
||||||
|
|
||||||
VT100 version with 42 levels by Anna Christina Naß <acn@acn.wtf>
|
Color VT100 version with 42 levels by Anna Christina Naß <acn@acn.wtf>
|
||||||
|
|
||||||
Build:
|
Build:
|
||||||
|
|
||||||
@ -21,20 +21,22 @@
|
|||||||
the terms of the GNU General Public Licence.
|
the terms of the GNU General Public Licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// the following assures that this games works when using Z3PLUS etc.
|
||||||
#pragma output REGISTER_SP = 0xa000
|
#pragma output REGISTER_SP = 0xa000
|
||||||
#pragma output hrgpage = 36096
|
#pragma output hrgpage = 36096
|
||||||
|
|
||||||
#include <stdio.h> // We use printf(); putchar();
|
#include <stdio.h> // We use printf(); putchar();
|
||||||
#include <string.h> // strlen for the Level name centering.
|
#include <string.h> // strlen for the Level name centering.
|
||||||
|
#include <stdlib.h> // We use rand(); srand();
|
||||||
|
#include <conio.h> // We use kbhit();
|
||||||
|
|
||||||
#define LEVELS 42 // Number of Levels
|
#define LEVELS 42 // Number of Levels
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
#define PLAYER "P" // player symbol
|
#define PLAYER "P" // player symbol
|
||||||
#define BRICK ":" // brick symbol
|
|
||||||
#define COLWAY 15 // color of entrance and exit
|
#define COLWAY 15 // color of entrance and exit
|
||||||
#define COLDOOR 15 // color of entrance door
|
#define COLDOOR 11 // color of entrance door
|
||||||
#define COLPLAYER 14 // color of player
|
#define COLPLAYER 14 // color of player
|
||||||
#define COLBRICK 8 // color of bricks
|
#define COLBRICK 8 // color of bricks
|
||||||
|
|
||||||
@ -57,6 +59,9 @@ static char *ARGH[]={
|
|||||||
"PUFF!"
|
"PUFF!"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* we need 12 colors as the "biggest" maze has 12 lines */
|
||||||
|
static int LineColors[]={ 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13 };
|
||||||
|
|
||||||
/* We use escape control combinations for handling of the display */
|
/* We use escape control combinations for handling of the display */
|
||||||
|
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
@ -95,6 +100,18 @@ int color;
|
|||||||
printf("\033[4%dm", color);
|
printf("\033[4%dm", color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShuffleColors()
|
||||||
|
{
|
||||||
|
int n = sizeof(LineColors) / sizeof(LineColors[0]);
|
||||||
|
for (int i = 0; i < n - 1; i++)
|
||||||
|
{
|
||||||
|
int j = i + (rand()%n) / (n / (n - i) + 1);
|
||||||
|
int t = LineColors[j];
|
||||||
|
LineColors[j] = LineColors[i];
|
||||||
|
LineColors[i] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PrintPlayer()
|
PrintPlayer()
|
||||||
{
|
{
|
||||||
FgCol(COLPLAYER);
|
FgCol(COLPLAYER);
|
||||||
@ -105,7 +122,7 @@ PrintPlayer()
|
|||||||
ColorLine(line)
|
ColorLine(line)
|
||||||
int line;
|
int line;
|
||||||
{
|
{
|
||||||
FgCol(line);
|
FgCol(LineColors[line-1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintEnter()
|
void PrintEnter()
|
||||||
@ -116,7 +133,7 @@ void PrintEnter()
|
|||||||
void FillRow()
|
void FillRow()
|
||||||
{
|
{
|
||||||
FgCol(COLBRICK);
|
FgCol(COLBRICK);
|
||||||
for (Column=0;Column<80;Column++) printf(BRICK);
|
printf("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
|
||||||
ResetAttr();
|
ResetAttr();
|
||||||
PrintEnter();
|
PrintEnter();
|
||||||
}
|
}
|
||||||
@ -124,13 +141,13 @@ void FillRow()
|
|||||||
void FillWall()
|
void FillWall()
|
||||||
{
|
{
|
||||||
FgCol(COLBRICK);
|
FgCol(COLBRICK);
|
||||||
for (l=0;l<26;l++) printf(BRICK);
|
printf("::::::::::::::::::::::::::");
|
||||||
ResetAttr();
|
ResetAttr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FillSpace()
|
void FillSpace()
|
||||||
{
|
{
|
||||||
for (l=0;l<28;l++) printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void gotogxy(int x,int y)
|
void gotogxy(int x,int y)
|
||||||
@ -143,24 +160,26 @@ void Level(int MazeNumber)
|
|||||||
int k;
|
int k;
|
||||||
char *LevelName; // Pointer to the Level name string.
|
char *LevelName; // Pointer to the Level name string.
|
||||||
|
|
||||||
|
ShuffleColors();
|
||||||
|
|
||||||
ClearScreen();
|
ClearScreen();
|
||||||
switch (MazeNumber)
|
switch (MazeNumber)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
LevelName="Humble Origins";uWidth=7;uHeight=2;lx=1;rx=1;
|
LevelName="Humble Origins";uWidth=7;uHeight=2;lx=rx=1;
|
||||||
MazeLine[1]=" # # ";
|
MazeLine[1]=" # # ";
|
||||||
MazeLine[2]=" # ## ";
|
MazeLine[2]=" # ## ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
LevelName="Easy Does It";uWidth=8;uHeight=3;lx=3;rx=2;
|
LevelName="Easy Does It";uWidth=8;uHeight=lx=3;rx=2;
|
||||||
MazeLine[1]=" # ###";
|
MazeLine[1]=" # ###";
|
||||||
MazeLine[2]=" # # # ";
|
MazeLine[2]=" # # # ";
|
||||||
MazeLine[3]=" # # # ";
|
MazeLine[3]=" # # # ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
LevelName="Up, Up and Away";uWidth=5;uHeight=11;lx=11;rx=1;
|
LevelName="Up, Up and Away";uWidth=5;uHeight=lx=11;rx=1;
|
||||||
MazeLine[1]= " # ";
|
MazeLine[1]= " # ";
|
||||||
MazeLine[2]= " # ##";
|
MazeLine[2]= " # ##";
|
||||||
MazeLine[3]= " ## ";
|
MazeLine[3]= " ## ";
|
||||||
@ -183,7 +202,7 @@ void Level(int MazeNumber)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
LevelName="To and Fro";uWidth=13;uHeight=6;lx=1;rx=1;
|
LevelName="To and Fro";uWidth=13;uHeight=6;lx=rx=1;
|
||||||
MazeLine[1]=" ##### ";
|
MazeLine[1]=" ##### ";
|
||||||
MazeLine[2]="# ##### ### ";
|
MazeLine[2]="# ##### ### ";
|
||||||
MazeLine[3]=" # ### #### ";
|
MazeLine[3]=" # ### #### ";
|
||||||
@ -218,7 +237,7 @@ void Level(int MazeNumber)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 9:
|
case 9:
|
||||||
LevelName="Two Front Doors";uWidth=16;uHeight=7;lx=1;rx=7;
|
LevelName="Two Front Doors";uWidth=16;uHeight=rx=7;lx=1;
|
||||||
MazeLine[1]=" ####### ";
|
MazeLine[1]=" ####### ";
|
||||||
MazeLine[2]=" #### #### # # ";
|
MazeLine[2]=" #### #### # # ";
|
||||||
MazeLine[3]="## ## ###### # #";
|
MazeLine[3]="## ## ###### # #";
|
||||||
@ -237,7 +256,7 @@ void Level(int MazeNumber)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 11:
|
case 11:
|
||||||
LevelName="Double Cross";uWidth=9;uHeight=7;lx=7;rx=3;
|
LevelName="Double Cross";uWidth=9;uHeight=lx=7;rx=3;
|
||||||
MazeLine[1]=" # #### ";
|
MazeLine[1]=" # #### ";
|
||||||
MazeLine[2]=" # # ## ";
|
MazeLine[2]=" # # ## ";
|
||||||
MazeLine[3]=" # #### #";
|
MazeLine[3]=" # #### #";
|
||||||
@ -574,15 +593,15 @@ void Level(int MazeNumber)
|
|||||||
l=((80-uWidth)/2);
|
l=((80-uWidth)/2);
|
||||||
t=((22-uHeight)/2);
|
t=((22-uHeight)/2);
|
||||||
r=80-l-uWidth;
|
r=80-l-uWidth;
|
||||||
FgCol(COLBRICK); printf(BRICK); printf(BRICK);printf(BRICK); ResetAttr();
|
FgCol(COLBRICK); printf(":::"); ResetAttr();
|
||||||
printf(" Level ");
|
printf(" Level ");
|
||||||
if (MazeNumber<10) printf("0%d ",MazeNumber);
|
if (MazeNumber<10) printf("0%d ",MazeNumber);
|
||||||
else printf("%d ",MazeNumber);
|
else printf("%d ",MazeNumber);
|
||||||
FgCol(COLBRICK); for (i=0;i<50;i++) printf(BRICK); ResetAttr();
|
FgCol(COLBRICK); printf("::::::::::::::::::::::::::::::::::::::::::::::::::"); ResetAttr();
|
||||||
printf(" Lives ");
|
printf(" Lives ");
|
||||||
if (uLives<10) printf("0%d",uLives);
|
if (uLives<10) printf("0%d",uLives);
|
||||||
else printf("%d",uLives);
|
else printf("%d",uLives);
|
||||||
FgCol(COLBRICK); printf(" "); printf(BRICK); printf(BRICK); printf(BRICK); PrintEnter(); ResetAttr();
|
FgCol(COLBRICK); printf(" "); printf(":::"); PrintEnter(); ResetAttr();
|
||||||
|
|
||||||
|
|
||||||
for (i=1;i!=t+1;i++) FillRow();
|
for (i=1;i!=t+1;i++) FillRow();
|
||||||
@ -590,20 +609,20 @@ void Level(int MazeNumber)
|
|||||||
for (i=1;i!=uHeight+1;i++)
|
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(COLWAY); printf("_"); ResetAttr(); }
|
||||||
if (i!=lx) for (k=0;k!=l;k++) { FgCol(COLBRICK); printf(BRICK); ResetAttr(); }
|
if (i!=lx) for (k=0;k!=l;k++) { FgCol(COLBRICK); printf(":"); ResetAttr(); }
|
||||||
ColorLine(i); printf(MazeLine[i]); ResetAttr(); // Print the Level line.
|
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(COLWAY); printf("_"); ResetAttr(); }
|
||||||
if (i!=rx) for (k=0;k!=r;k++) { FgCol(COLBRICK); printf(BRICK); ResetAttr(); }
|
if (i!=rx) for (k=0;k!=r;k++) { FgCol(COLBRICK); printf(":"); ResetAttr(); }
|
||||||
PrintEnter();
|
PrintEnter();
|
||||||
}
|
}
|
||||||
|
|
||||||
FgCol(COLBRICK); for (i=t+uHeight+1;i!=22;i++) FillRow(); ResetAttr();
|
FgCol(COLBRICK); for (i=t+uHeight+1;i!=22;i++) FillRow(); ResetAttr();
|
||||||
j=strlen(LevelName);
|
j=strlen(LevelName);
|
||||||
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(BRICK); ResetAttr();
|
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(":"); ResetAttr();
|
||||||
printf(" ");
|
InverseOn();
|
||||||
printf(LevelName);
|
printf(" "); printf(LevelName); printf(" ");
|
||||||
printf(" ");
|
InverseOff();
|
||||||
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(BRICK); ResetAttr();
|
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(":"); ResetAttr();
|
||||||
PrintEnter();
|
PrintEnter();
|
||||||
|
|
||||||
for (i=0;i!=l;i++)
|
for (i=0;i!=l;i++)
|
||||||
@ -624,12 +643,14 @@ void Level(int MazeNumber)
|
|||||||
|
|
||||||
void Title()
|
void Title()
|
||||||
{
|
{
|
||||||
|
int seed; // for random seed initialization
|
||||||
|
|
||||||
ClearScreen();
|
ClearScreen();
|
||||||
gotogxy(0,2);
|
gotogxy(0,2);
|
||||||
FillRow();
|
FillRow();
|
||||||
FillWall(); BgCol(7); FgCol(13);
|
FillWall(); BgCol(4); FgCol(13);
|
||||||
printf(" M"); FgCol(10); printf(" a"); FgCol(11); printf(" z");
|
printf(" M"); FgCol(10); printf(" a"); FgCol(11); printf(" z");
|
||||||
FgCol(12); printf(" e"); FgCol(11); printf(" z"); FgCol(10); printf(" a");
|
FgCol(9); printf(" e"); FgCol(11); printf(" z"); FgCol(10); printf(" a");
|
||||||
FgCol(13); printf(" M "); ResetAttr();
|
FgCol(13); printf(" M "); ResetAttr();
|
||||||
FillWall(); PrintEnter();
|
FillWall(); PrintEnter();
|
||||||
FillRow();
|
FillRow();
|
||||||
@ -656,7 +677,8 @@ void Title()
|
|||||||
{
|
{
|
||||||
gotogxy(Column,11);
|
gotogxy(Column,11);
|
||||||
PrintPlayer();
|
PrintPlayer();
|
||||||
PressedKey=getkey();
|
PressedKey=getk();
|
||||||
|
seed++;
|
||||||
|
|
||||||
if (PressedKey==' ') break;
|
if (PressedKey==' ') break;
|
||||||
if (PressedKey=='Q' || PressedKey=='q')
|
if (PressedKey=='Q' || PressedKey=='q')
|
||||||
@ -664,19 +686,20 @@ void Title()
|
|||||||
bCloseFlag=TRUE;
|
bCloseFlag=TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (PressedKey=='6')
|
if (PressedKey=='6' || PressedKey=='d' || PressedKey=='D')
|
||||||
{
|
{
|
||||||
gotogxy(Column,11);
|
gotogxy(Column,11);
|
||||||
Column+=(Column<53);
|
Column+=(Column<53);
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
if (PressedKey=='4')
|
if (PressedKey=='4' || PressedKey=='a' || PressedKey=='A')
|
||||||
{
|
{
|
||||||
gotogxy(Column,11);
|
gotogxy(Column,11);
|
||||||
Column-=(Column>26);
|
Column-=(Column>26);
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
srand(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -716,11 +739,6 @@ int main()
|
|||||||
// quit
|
// quit
|
||||||
if (PressedKey=='Q' || PressedKey=='q')
|
if (PressedKey=='Q' || PressedKey=='q')
|
||||||
{
|
{
|
||||||
//gotogxy(l+j-3,t+i-1);
|
|
||||||
//InverseOn();
|
|
||||||
//printf(ARGH[rand%9]);
|
|
||||||
//InverseOff();
|
|
||||||
//getkey();
|
|
||||||
gotogxy(35,10);
|
gotogxy(35,10);
|
||||||
InverseOn();
|
InverseOn();
|
||||||
printf("GAME OVER!");
|
printf("GAME OVER!");
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user