Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define POSITION_BOXES
- #ifdef POSITION_BOXES
- #include <stdio.h>
- #include <fcntl.h>
- struct
- {
- int x,y,xdim,ydim;
- unsigned char text;
- }boxes[100];
- signed int boxptr=0;
- int main(void)
- {
- enum
- {
- up,down,left,right,grewx,grewy
- }LASTSTEP;
- unsigned char screen[60][40],collide[60][40];
- int x,y;
- int n=0;
- y=0;
- while ( y<40 )
- {
- x=0;
- while ( x<60 ) screen[x][y]=collide[x][y]=0,x++; y++;
- }
- boxes[n].x=boxes[n].y=boxes[n].xdim=boxes[n].ydim=0;
- while (1)
- {
- if ( kbhit())
- {
- switch(getch())
- {
- case 'x': if ( boxes[boxptr].xdim<15)
- boxes[boxptr].xdim++; LASTSTEP=grewx; break;
- case 'y':if ( boxes[boxptr].ydim<15)
- boxes[boxptr].ydim++; LASTSTEP=grewy;break;
- case 's': if ( boxes[boxptr].xdim>0)
- boxes[boxptr].xdim--; break;
- case 'a': if ( boxes[boxptr].ydim>0)
- boxes[boxptr].ydim--; break;
- case 'u': if ( boxes[boxptr].y>0)
- boxes[boxptr].y--; LASTSTEP=up;break;
- case 'j': if ( boxes[boxptr].y+boxes[boxptr].ydim<39)
- boxes[boxptr].y++;LASTSTEP=down; break;
- case 'h': if ( boxes[boxptr].x>0)
- boxes[boxptr].x--; LASTSTEP=left;break;
- case 'k': if ( boxes[boxptr].x+boxes[boxptr].xdim<59)
- boxes[boxptr].x++; LASTSTEP=right;break;
- case 'n': boxptr++; boxes[n].x=boxes[n].y=boxes [n].xdim=boxes[n].ydim=0; break;
- case 'q': goto writeout;
- }
- }
- y=0;
- while ( y<40 )
- {
- x=0;
- while ( x<60 ) screen[x][y]=' ',collide[x][y]=255,x++;
- y++;
- }
- n=0;
- while ( n < boxptr+1)
- {
- int dimc_x,dimc_y;
- dimc_y=boxes[n].ydim;
- while ( dimc_y>=0)
- {
- dimc_x=boxes[n].xdim;
- while ( dimc_x >= 0 )
- {
- if ( collide[boxes[n].x+dimc_x][boxes[n].y+dimc_y]==255||collide[boxes[n].x+dimc_x][boxes[n].y+dimc_y]==n)
- screen[boxes[n].x+dimc_x][boxes[n].y+dimc_y]=177,
- collide[boxes[n].x+dimc_x][boxes[n].y+dimc_y]=n;
- else
- {
- printf("\a");
- switch(LASTSTEP)
- {
- case up: boxes[n].y++;break;
- case down:boxes[n].y--;break;
- case left:boxes[n].x++;break;
- case right:boxes[n].x--;break;
- case grewx: boxes[n].xdim--; break;
- case grewy: boxes[n].ydim--; break;
- }
- dimc_x=0;
- dimc_y=boxes[n].ydim+1;
- goto repeat;
- }
- dimc_x--;
- }
- repeat:
- dimc_y--;
- }
- n++;
- }
- system("cls");
- y=0;
- while ( y < 40)
- {
- x=0;
- while ( x<60) printf("%c%c%c%c",screen[x][y],screen[x+1][y],screen[x+2][y],screen[x+3][y]),x+=4;
- printf("\n");
- y++;
- }
- }
- writeout:
- (0);
- FILE *output=fopen("posdata","wb");
- fwrite(&boxptr,sizeof(signed int),1,output);
- fwrite(boxes, sizeof(boxes),1,output);
- fclose(output);
- }
- //#Else
- #else
- #include <stdio.h>
- #include <fcntl.h>
- #define XSPACING 10
- #define YSPACING 10
- struct
- {
- int x,y,xdim,ydim;
- unsigned char text;
- }boxes[100],swap;
- signed int boxc=0;
- void sort_boxes(int num)
- {
- int n=0,n2=0;
- n=1;
- while ( n<num-1)
- {
- n2=n;
- while ( n2>n)
- {
- if ( boxes[n2].x+boxes[n2].y*60 < boxes[n2-1].x+boxes[n2-1].y*60 )
- swap=boxes[n2];
- boxes[n2]=boxes[n2-1];
- boxes[n2-1]=swap;
- n2--;
- }
- n++;
- }
- }
- int main(void)
- {
- int x_off=0,y_off=0;
- int old_x=0,old_y=0;
- FILE *input=fopen("posdata","rb");
- fread(&boxc,sizeof(signed int),1,input);
- fread(boxes, sizeof(boxes[0]),boxc,input);
- fclose(input);
- int n=0;
- sort_boxes(boxc);
- while ( n < boxc)
- {
- int x=0,y=0;
- while (y<40)
- {
- x=0;
- while(x<60)
- {
- if ( x==boxes[n].x&& y==boxes[n].y)
- {
- while ( (x+x_off-old_x)/XSPACING >0)old_x+=XSPACING,printf("%d nach rechts\n",XSPACING);
- while ( (y+y_off-old_y)/XSPACING >0)old_y+=YSPACING;printf("%d nach unten\n",YSPACING);
- printf("Kiste mit der Groesse %d %d\n",boxes[n].xdim,boxes[n].ydim);
- old_x=boxes[n].x,old_y=boxes[n].y;
- x_off+=x-old_x-boxes[n].xdim%XSPACING;
- y_off+=x-old_y-boxes[n].ydim%YSPACING;
- }
- x++;
- }
- y++;
- }
- n++;
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment