Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "zcommon.acs"
- function int wall (int move, int width, int height)
- {
- if (move > height * (width-1) && move != height * (width-1) +1 && move != height * width)
- {
- return 1;
- //print(s:"wallhug =",d:wall);
- }
- if (move%45 == 0 && move != height * width && move != width)
- {
- return 2;
- //print(s:"wallhug =",d:wall);
- }
- if (move<width && move != 1)
- {
- return 3;
- //print(s:"wallhug =",d:wall);
- }
- if (move%45 == 1 && move != 1 && move != height * (width-1)+1)
- {
- return 4;
- //print(s:"wallhug =",d:wall);
- }
- if (move == 1)
- {
- return 5;
- //print(s:"wallhug =",d:wall);
- }
- if (move == width)
- {
- return 6;
- //print(s:"wallhug =",d:wall);
- }
- if (move == height * (width-1)+1)
- {
- return 7;
- //print(s:"wallhug =",d:wall);
- }
- if (move == height * width)
- {
- return 8;
- //print(s:"wallhug =",d:wall);
- }
- return 0;
- }
- //wallhug
- //if we are at the wall of the maze, the new direction cannot go into the direction of the maze.
- //We will define this similarly to moving
- //0 we are not at a wall
- //1 we are at the top wall
- //2 we are at the right wall
- //3 we are the bottom wall
- //4 we are at the left wall
- //5 bottom left
- //6 bottom right
- //7 top left
- //8 top right
- script 1 OPEN
- {
- int height = 45;
- int width = 45;
- int spawnxy[2] = {0,0};
- int exitxy[2] = {0,0};
- //Calculation from x,y to sector tag:
- // tag = roomx+(roomy-1)*height
- while (spawnxy[0]%2 == 0) // check if spawnx is on the odd grid
- {
- spawnxy[0] = random(1,width);
- delay(1);
- //print(s:"spawn x =", i:spawnxy[0]);
- }
- while (spawnxy[1]%2 == 0) // check if spawny is on the odd grid
- {
- spawnxy[1] = random(1,height);
- delay(1);
- //print(s:"spawn y =", i:spawnxy[1]);
- }
- while(exitxy[0]%2 == 0 || exitxy[0] == spawnxy[0]) // check if exit x is on the odd grid and not in same room as end
- {
- exitxy[0] = random(1,width);
- delay(1);
- //print(s:"exit x =", i:exitxy[0]);
- }
- while(exitxy[1]%2 == 0 || exitxy[1] == spawnxy[1]) // check if y is on the odd grid and not in same room as end
- {
- exitxy[1] = random(1,height);
- delay(1);
- //print(s:"exit y =", i:exitxy[1]);
- }
- int spawntag = spawnxy[0] + (spawnxy[1]-1) * height;
- int exittag = exitxy[0] + (exitxy[1]-1)* height;
- spawntag = 1193;
- exittag = 45;
- Ceiling_MoveToValue(spawntag, 128, 128, 0);
- Ceiling_MoveToValue(exittag, 128, 128,0);
- //we define moving with random switch
- //1 as up: +height*2
- //2 as right: +2
- //3 as down: -height*2
- //4 as left: -2
- //If we are at an edge, we cannot move in that direction, we cannot move back in the direction we came
- int move = spawntag;
- int directionold = 0;
- int directionnew = 0;
- int wallhug = wall(move, width, height);
- while (move != exittag)
- {
- print(s:"while move != exittag begins");
- delay(1);
- directionold = directionnew;
- switch(directionold) //We apply the move
- {
- case 0:
- break;
- case 1:
- Ceiling_MoveToValue(move+height, 128, 128, 0);
- Ceiling_MoveToValue(move+height*2, 128, 128, 0);
- move = move+height*2;
- break;
- case 2:
- Ceiling_MoveToValue(move+1, 128, 128, 0);
- Ceiling_MoveToValue(move+2, 128, 128, 0);
- move = move+2;
- break;
- case 3:
- Ceiling_MoveToValue(move-height, 128, 128, 0);
- Ceiling_MoveToValue(move-height*2, 128, 128, 0);
- move = move-height*2;
- break;
- case 4:
- Ceiling_MoveToValue(move-1, 128, 128, 0);
- Ceiling_MoveToValue(move-2, 128, 128, 0);
- move = move-2;
- break;
- }
- //int movexy[2] = {move%width, ceil(move/height)};
- //Delay(50);
- //print(s:"move is now at ", i:movexy[0], s:", ", i:movexy[1]);
- wallhug = wall(move, width, height);
- directionnew = random(1,4);
- while (directionnew == 1 && directionold == 3) //no moving back, no moving through the wall
- {
- print(s:"we are now in directionnew loop");
- while (wallhug == 1 && directionnew == 1)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 2 && directionnew == 2)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 3 && directionnew == 3)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 4 && directionnew == 4)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 5 && (directionnew == 3 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 6 && (directionnew == 2 || 3))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 7 && (directionnew == 1 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 8 && (directionnew == 1 || 2))
- {
- directionnew = random(1,4);
- }
- }
- while (directionnew == 2 && directionold == 4) //no moving back, no moving through the wall
- {
- while (wallhug == 1 && directionnew == 1)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 2 && directionnew == 2)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 3 && directionnew == 3)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 4 && directionnew == 4)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 5 && (directionnew == 3 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 6 && (directionnew == 2 || 3))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 7 && (directionnew == 1 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 8 && (directionnew == 1 || 2))
- {
- directionnew = random(1,4);
- }
- }
- while (directionnew == 3 && directionold == 1) //no moving back, no moving through the wall
- {
- while (wallhug == 1 && directionnew == 1)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 2 && directionnew == 2)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 3 && directionnew == 3)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 4 && directionnew == 4)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 5 && (directionnew == 3 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 6 && (directionnew == 2 || 3))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 7 && (directionnew == 1 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 8 && (directionnew == 1 || 2))
- {
- directionnew = random(1,4);
- }
- }
- while (directionnew == 4 && directionold == 2) //no moving back, no moving through the wall
- {
- while (wallhug == 1 && directionnew == 1)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 2 && directionnew == 2)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 3 && directionnew == 3)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 4 && directionnew == 4)
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 5 && (directionnew == 3 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 6 && (directionnew == 2 || 3))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 7 && (directionnew == 1 || 4))
- {
- directionnew = random(1,4);
- }
- directionnew = random(1,4);
- while (wallhug == 8 && (directionnew == 1 || 2))
- {
- directionnew = random(1,4);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement