Skip to main content

Posts

Showing posts with the label increment

(VII) Movement: arrow keys, and, +=, -=, variable coordinates

Howdy everybody! Take a look at the new code of the day: In this code we have defined new keyboard scan codes for the arrow keys, see it in the DECLARATIONS as constants and declare variables to control if the keys are pressed or not, like we did it with key escape. Here x and y that are the coordinates of the white square will turn into variables because we will move this square then the value of the coordinates will be variable. When we DO UPDATE this time we will check also the four possible arrow keys and checking not to go with our white square outside our screen, otherwise the square will hide, you can prove it. Notice that the condition is multiple, using and to check that both conditions are true at the same time to change the value of the corresponding variable. We increment or decrement x or y with 1 (1 pixel), to go up y-1, right x+1, down y+1 or left x-1. This way: To increment we use the form variable+=amount of increment, for exemple x+=1 To de...