Processing Forum
- "void boundries()
- {
- noFill();
- noStroke();
- rectMode(CORNER);
- if (inside(x1, y1, x2, y2))
- {
- // println("Inside!");
- }
- else {
- //println("Outside!");
- }
- noFill();
- noStroke();
- rect(x1, y1, x2, y2);
- }
- // a simple boolean function that will return true if the mouse is inside the two points
- boolean inside(int x1, int y1, int x2, int y2)
- {
- // This is broken up for speed.
- // instead of doing four checks and then getting a false we check each one and can get a faster fail
- if (px > x1)
- {
- if ( px < x2)
- {
- if ( py > y1)
- {
- if ( py < y2)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
the second issue I'm having is in regards to resetting my snake after finishing the game. My teacher has told me to use append and shorten in order to achieve this, but I can only seem to shorten the array by 1 through using shorten. My snake starts off at 6 in length, and for every rupee it consumes the snake body grows one. When the game ends (say I have 10 rupees) and the body length is 16, when I reset the game my snake starts at 15 rather then 6.
my line for append is-
- snakePosX = append(snakePosX, snakePosX[snakePosX.length-1]+1);
- snakePosY = append(snakePosY, snakePosY[snakePosY.length-1]+1);
and for shorten it is -
- snakePosX =shorten(snakePosX);
- snakePosY =shorten(snakePosY);
I realise shorten would have to be elaborated somehow, but I seem to be getting a multitude of issues whenever I try to involve the array in any form or even mention .length.
I'd post the full code, but I'm a little paranoid of people in my degree finding it while searching for help like I am now, haha! Any help would be super appreciated though.