mirror of
https://github.com/PoetryInCode/matrix.git
synced 2026-08-13 11:24:40 -04:00
reformatted the more confusing part of the code. added pause functionality
This commit is contained in:
parent
3ca6fc88ad
commit
3b174eb92d
BIN
bin/matrix
BIN
bin/matrix
Binary file not shown.
106
src/main.c
106
src/main.c
@ -8,6 +8,14 @@
|
|||||||
#define UP (1)
|
#define UP (1)
|
||||||
#define DOWN (2)
|
#define DOWN (2)
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FALSE
|
||||||
|
#define FALSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
WINDOW term = *initscr();
|
WINDOW term = *initscr();
|
||||||
start_color();
|
start_color();
|
||||||
@ -60,86 +68,106 @@ int main(int argc, char **argv) {
|
|||||||
int get = getch();
|
int get = getch();
|
||||||
while(get!='q') {
|
while(get!='q') {
|
||||||
if(get=='s') {
|
if(get=='s') {
|
||||||
pause=1;
|
pause=TRUE;
|
||||||
}
|
}
|
||||||
int xPos = rand()%maxX;//get random x position for the stream
|
int xPos = rand()%maxX;//get random x position for the stream
|
||||||
if(cascade[xPos]==ERR) {//make sure the stream is set to active
|
if(cascade[xPos]==ERR) {//make sure the stream is set to active
|
||||||
cascade[xPos]=0;
|
cascade[xPos]=0;
|
||||||
}
|
}
|
||||||
for(int i=0; i<maxX; i++) {//move the streams down
|
//---------swich to weird format-----------
|
||||||
if(cascade[i]!=ERR) {
|
for(int i=0; i<maxX; i++)
|
||||||
tail[i] = cascade[i]-tailLen[i];
|
{//move the streams up/down
|
||||||
if(cascade[i]==maxY) {//check if the position is at the bottom of the screen
|
if(!pause)
|
||||||
cascade[i]=ERR;//set the position to ERR if it is at the bottom
|
{
|
||||||
} else {
|
if(cascade[i]!=ERR)
|
||||||
if(rand()%10==1) {//check if the stream will jump
|
{
|
||||||
if(!(jmpTail[i]<=maxY)) {
|
tail[i] = cascade[i]-tailLen[i];
|
||||||
if(dir==DOWN) {
|
if(cascade[i]==maxY)
|
||||||
cascade[i]=cascade[i]+rand()%8;
|
{//check if the position is at the bottom of the screen
|
||||||
jmpTail[i]=cascade[i]-tailLen[i];
|
cascade[i]=ERR;//set the position to ERR if it is at the bottom
|
||||||
} else {
|
}
|
||||||
cascade[i]=cascade[i]-rand()%8;
|
else
|
||||||
jmpTail[i]=cascade[i]+tailLen[i];
|
{
|
||||||
|
if(rand()%10==1)
|
||||||
|
{//check if the stream will jump
|
||||||
|
if(!(jmpTail[i]<=maxY))
|
||||||
|
{
|
||||||
|
if(dir==DOWN)
|
||||||
|
{
|
||||||
|
cascade[i]=cascade[i]+rand()%8;
|
||||||
|
jmpTail[i]=cascade[i]-tailLen[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cascade[i]=cascade[i]-rand()%8;
|
||||||
|
jmpTail[i]=cascade[i]+tailLen[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
else
|
||||||
if(!pause) {
|
{
|
||||||
if(dir==DOWN) {
|
if(dir==DOWN)
|
||||||
|
{
|
||||||
cascade[i]++;//increase the position
|
cascade[i]++;//increase the position
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
cascade[i]--;
|
cascade[i]--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//-------Back to normal format-------
|
||||||
if(tail[i]!=maxY) {//keep increasing the tail untill it is at the bottom
|
if(tail[i]!=maxY) {//keep increasing the tail untill it is at the bottom
|
||||||
if(!pause) {
|
if(dir==DOWN) {
|
||||||
if(dir==DOWN) {
|
tail[i]++;
|
||||||
tail[i]++;
|
} else {
|
||||||
} else {
|
tail[i]--;
|
||||||
tail[i]--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(jmpTail[i]==maxY || jmpTail==0) {
|
if(jmpTail[i]==maxY || jmpTail==0) {
|
||||||
jmpTail[i]=OK;
|
jmpTail[i]=OK;
|
||||||
} else {
|
} else {
|
||||||
if(!pause) {
|
if(dir==DOWN) {
|
||||||
if(dir==DOWN) {
|
jmpTail[i]++;
|
||||||
jmpTail[i]++;
|
} else {
|
||||||
} else {
|
jmpTail[i]--;
|
||||||
jmpTail[i]--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mvaddch(jmpTail[i],i,' ');
|
mvaddch(jmpTail[i],i,' ');
|
||||||
mvaddch(tail[i],i,' ');
|
mvaddch(tail[i],i,' ');
|
||||||
mvaddch(cascade[i],i,(rand()%/*57*/57)+65);
|
mvaddch(cascade[i],i,(rand()%60)+65);
|
||||||
}
|
}
|
||||||
refresh();
|
refresh();
|
||||||
if(!pause) {
|
if(!pause) {
|
||||||
get=getch();
|
timeout(time);
|
||||||
} else {
|
} else {
|
||||||
timeout(-1);
|
timeout(-1);
|
||||||
switch (getch()) {
|
get=getch();
|
||||||
|
switch (get) {
|
||||||
case 's':
|
case 's':
|
||||||
pause=!pause;
|
pause=!pause;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
pause=1;
|
pause=FALSE;
|
||||||
if(dir=DOWN) {
|
if(dir=DOWN) {
|
||||||
dir=UP;
|
dir=UP;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(dir=UP) {
|
if(dir=UP) {
|
||||||
dir=DOWN;
|
dir=DOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
get='q';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
timeout(time);
|
timeout(time);
|
||||||
}
|
}
|
||||||
|
if(get!='q') {
|
||||||
|
get=getch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
endwin();
|
endwin();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user