This time I've read the FAQ before posting!
Alright, so I have a part in my code that looks like this:
It moves the snake's bodyparts X and Y position backwards in the matrix. Later, the new position for the head is added but I didn't include that part.Code:for (i = 0; i < size; i++) { snakepos[size - i][0] = snakepos[size - (i + 1)][0]; snakepos[size - i][1] = snakepos[size - (i + 1)][1]; }
I noticed that on slower computer (e.g. thos in my school) the game started to lag a bit as the snake got longer which I can understand.
So I wanted to optimize a bit and replace it with something and I remembered that bit shifting moves stuff backwards and forwards.
I tried replacing it with something like:
It's shifted by 16 bits because snakepos is declared as a short. I've done some mixing by excluding some of the things like snakepos[0][1] because I though snakepos[0][0]>>16 shifted the whole matrix but neither way worked.Code:snakepos[0][0]>>16; snakepos[0][1]>>16; snakepos[0][0] = snakepos[1][0]; snakepos[0][1] = snakepos[1][1];
Are there because I use plus and minus to change position and thus it would be bad if those were empty all the time (meaning that the snake would constantly be in one place the whole time)Code:snakepos[0][0] = snakepos[1][0]; snakepos[0][1] = snakepos[1][1];
So is this possible or should I stick with the for loop? Or is there some other way?