1
0
mirror of https://github.com/abakh/nbsdgames.git synced 2025-02-02 15:07:27 -05:00

improved gameplay

This commit is contained in:
me 2022-02-02 01:55:52 +03:30
parent 747f1e35b1
commit 773cfd4394

View File

@ -24,6 +24,10 @@ You should have received a copy of the CC0 Public Domain Dedication along with t
#define MAXLEN 24 #define MAXLEN 24
#define MINWID 40 #define MINWID 40
#define MAXWID 80 #define MAXWID 80
#define FLIGHT_TIME 16
#define NOTRAIL_TIME 30
#define BOMB_RANGE 8
enum {UP=1,RIGHT,DOWN,LEFT,FLIGHT,NOTRAIL,BOMB,SPAWN,STOP,SUPERFOOD,TRAIL}; enum {UP=1,RIGHT,DOWN,LEFT,FLIGHT,NOTRAIL,BOMB,SPAWN,STOP,SUPERFOOD,TRAIL};
/* The Plan9 compiler can not handle VLAs and usleep is a POSIX function */ /* The Plan9 compiler can not handle VLAs and usleep is a POSIX function */
@ -165,9 +169,9 @@ void put_stuff(byte board[len][wid],byte num){
do{ do{
y=rand()%len; y=rand()%len;
x=rand()%wid; x=rand()%wid;
}while(y==py&&x==px); }while((y==py&&x==px)||board[y][x]==TRAIL);
board[y][x]=STOP; board[y][x]=STOP;
if(!rand()) if(!(rand()%40))
board[y][x]=SUPERFOOD; board[y][x]=SUPERFOOD;
else if(!(rand()%20)) else if(!(rand()%20))
board[y][x]=SPAWN; board[y][x]=SPAWN;
@ -179,6 +183,16 @@ void put_stuff(byte board[len][wid],byte num){
board[y][x]=FLIGHT; board[y][x]=FLIGHT;
} }
} }
void put_trail(byte board[len][wid],byte num){
byte y,x;
for(byte n=0;n<num;++n){
do{
y=rand()%len;
x=rand()%wid;
}while(y>py-5 && y<py+5 && x>px-10 && x<px+10);
board[y][x]=TRAIL;
}
}
void rectangle(void){ void rectangle(void){
for(int y=0;y<=len;++y){ for(int y=0;y<=len;++y){
mvaddch(3+y,0,ACS_VLINE); mvaddch(3+y,0,ACS_VLINE);
@ -240,10 +254,10 @@ void draw(byte board[len][wid]){
} }
void explode(byte board[len][wid],int by,int bx){ void explode(byte board[len][wid],int by,int bx){
board[by][bx]=0;//prevent endless recursion board[by][bx]=0;//prevent endless recursion
int sy=by-2; int sy=by-BOMB_RANGE/2;
int sx=bx-4; int sx=bx-BOMB_RANGE;
int ey=by+2; int ey=by+BOMB_RANGE/2;
int ex=bx+4; int ex=bx+BOMB_RANGE;
if(ey>=len) if(ey>=len)
ey-=len; ey-=len;
if(ex>=wid) if(ex>=wid)
@ -409,9 +423,9 @@ int main(int argc,char** argv){
else if(board[py][px]==SUPERFOOD) else if(board[py][px]==SUPERFOOD)
immunity+=len+wid; immunity+=len+wid;
else if(board[py][px]==FLIGHT) else if(board[py][px]==FLIGHT)
flight+=8; flight+=FLIGHT_TIME;
else if(board[py][px]==NOTRAIL) else if(board[py][px]==NOTRAIL)
notrail+=15; notrail+=NOTRAIL_TIME;
else else
goto NoFeatures; goto NoFeatures;
board[py][px]=0;//if one of conditions is true, it executes! keep nagging about goto being redundant! board[py][px]=0;//if one of conditions is true, it executes! keep nagging about goto being redundant!
@ -480,8 +494,10 @@ int main(int argc,char** argv){
px=0; px=0;
} }
++score; ++score;
if(!(score%100)) if(!(score%100)){
put_stuff(board,5); put_stuff(board,5);
put_trail(board,20);
}
if(immunity) if(immunity)
--immunity; --immunity;
else if(flight) else if(flight)