Player Movement


The first thing I did was implement player movement using the eight way movement script from prac 6. At first the player could move in 8 directions using the keys w, a, s and d. These  directions were north, south, east, west, northwest, northeast, southwest and southeast. This was done by getting the input the player gives when they press a key and adjusting the inputX and inputY variables according. InputX was the player's X positon and inputY was the player's Y position. The input from the player was checked as long as one of the input variables was not equal to zero This was because if they were both zero there would be no input. I got some people to test my game. It was mentioned to me that I may not want diagonal movement eg the player been able to move northeast, northwest, etc. I thought about it a bit and realised I did not want diagonal movement in my game as it would make it too easy. I decided to try and disable the diagonal movement by changing inputX and inputY. I changed my code from checking both to only checking one. In other words when inputX is not zero I set inputY to zero so it would not do anything. Then when inputY is not zero I set inputX to zero. This way my code would not check if the player was pressing two keys at once and would just check the key they pressed last. However, when I tested my code in the game I could only move up and down. I had somehow disabled the sideways movement. I went back to my code and changed my else statement to an if else and that fixed it. Now when I tested it the player the player could move left, right, up and down but not diagonally. 

Leave a comment

Log in with itch.io to leave a comment.