Code: Select all
//#include <lib.h>
#define plot(X,Y,C) poke(0xBBA8+(X)+(Y)*40,C)
#define scrn(X,Y) peek(0xBBA8+(X)+(Y)*40)
#define ICE 'a'
#define PINGURIGHT 'b'
#define PINGULEFT 'd'
#define PINGU 'c'
#define WALL 254
#define EGG 'f'
#define MONSTER 'g'
#define MONSTERDEAD 'h'
#define FLAG 'i'
#define MX 7
#define MY 8
char rnd(char max);
void wait(unsigned int wait_cs);
void plots(char x,char y,const char *msg);
void iplot(unsigned char xx, unsigned char yy);
char redefchar[72]= //208 +24
{
30,51,33,33,33,51,30,0, //(a)glace
12,10,12,30,45,45,12,14, //(b)pingouin droite
45,45,63,18,18,30,12,30, //(c)pingouin
12,20,12,30,45,45,12,28, //(d)pingouin gauche
63,33,33,33,33,33,33,63, //(e) mur
30,51,33,45,45,33,51,30, //(f) oeuf
0,12,30,45,63,18,30,12, //(g) monstre
0,0,0,0,12,30,45,63, //(h) monstre raplapla
16,24,28,30,16,16,16,16 //(i) drapeau
};
/*
//ice2
15,24,51,38,44,40,40,40,
60,6,3,1,1,1,1,1,
40,32,32,32,32,49,24,15,
1,1,5,13,25,51,6,60,
//bear left
6,9,8,16,18,16,16,9,
12,50,2,1,9,33,33,17,
24,32,32,24,25,34,34,31,
7,9,9,7,33,3,6,60,
//pingu
3,7,13,13,7,14,23,19, //faceleft
48,56,44,44,56,28,58,50, //faceright
59,59,59,55,39,47,47,6, //leftlegdown
55,55,55,59,57,61,61,24, //rightleg down
3,7,13,13,7,14,7,31,
48,56,44,44,56,28,56,62,
63,62,62,52,44,47,47,6,
63,31,31,11,13,61,61,24,
//pingu right
3,7,15,15,15,31,25,48,
48,24,62,48,48,56,56,56,
//legs1
48,48,33,35,38,47,63,31,
56,40,40,8,24,48,62,0,
//legs2
48,48,33,35,38,47,63,1,
56,40,40,8,24,48,32,60,
//legs3/0
48,48,33,35,38,47,63,15,
56,40,40,8,24,48,32,48,
//bear
24,60,36,55,31,11,14,12,
14,31,19,55,62,52,28,12,
15,31,63,62,54,15,15,12,
60,62,63,31,27,60,60,12, */
struct pstack {unsigned char c,r;};
char x=0,y=0,level=0;
unsigned char i=0,j=0,k=0,c=0,r=0,tx=0,ty=0,u=0,z=0,celldone=0;
unsigned char sw[MX+2][MY+2];ew[MX+2][MY+2]; //south walls, est walls
unsigned char v[MX+2][MY+2]; //visited cells
struct pstack ps[MX*MY+2];
void main()
{
text(); cls(); paper(0); ink(1);
//cell = 'c';
//wall = 'w';
memcpy((unsigned char*)46856,redefchar,32);
for (x=9;x<=23;x++){
//curset(x*6+9,y*6,0);
plot(x,4,WALL);
plot(x,20,WALL);
}
for (y=5;y<=19;y++){ //0-14
plot(9,y,WALL);
plot(23,y,WALL);
}
lbl_redo:
for (x=10;x<=22;x++){ //2*13=26 (+2=28) 1-13
for (y=5;y<=19;y++){ //2*15=30 1-15
plot(x,y,ICE+128);
}
}
plots(3,1,"Initializing...");
tx=MX+1; ty=MY+1;
for(c=0;c<=tx;c++) {
for(r=0;r<=ty;r++) {
sw[c][r]=1;ew[c][r]=1;v[c][r]=0;
}
}
//SET BORDER CELLS TO VISITED
for(c=0;c<=tx;c++) {
v[c][0]=1;v[c][ty]=1;
}
for(r=0;r<=ty;r++) {
v[0][r]=1;v[tx][r]=1;
}
plots(3,1,"Building...");
c=rnd(MX)+1;
r=rnd(MY)+1;
lbl_push:
u++;ps[u].c=c;ps[u].r=r;
v[c][r]=1; plot((c<<1)+8,(r<<1)+3,' '+128);
lbl_test:
if(v[c][r+1]==1 && v[c+1][r]==1 && v[c][r-1]==1 && v[c-1][r]==1) goto lbl_pop;
lbl_explore:
z=rnd(4);
if(z==0 && v[c][r+1]==0){
sw[c][r]=0; plot((c<<1)+8,(r<<1)+3+1,' '+128);
r++;
goto lbl_push;
}
if(z==1 && v[c+1][r]==0){
ew[c][r]=0; plot((c<<1)+8+1,(r<<1)+3,' '+128);
c++;
goto lbl_push;
}
if(z==2 && v[c][r-1]==0){
sw[c][r-1]=0; plot((c<<1)+8,(r<<1)+3-1,' '+128);
r--;
goto lbl_push;
}
if(z==3 && v[c-1][r]==0){
ew[c-1][r]=0; plot((c<<1)+8-1,(r<<1)+3,' '+128);
c--;
goto lbl_push;
}
goto lbl_explore;
lbl_pop:
c=ps[u].c;r=ps[u].r;u--;
if (u>0) goto lbl_test;
get();
goto lbl_redo;
}
void wait(unsigned int wait_cs)
{
unsigned int start=deek(0x0276);
unsigned int tw=start-wait_cs;
while (tw<start) {start=deek(0x0276);};
}
void plots(char x_pos,char y_pos, const char *msg)
{
memcpy((unsigned char*)(0xBBA8+x_pos+y_pos*40),msg,strlen(msg));
}
char rnd(char max)
{
return (char) (rand()/(32768/max));
}