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 decrement we use the form variable-=amount of decrement, for exemple x-=1
Remember the structure:
- DESCRIPTION
- DECLARATIONS
- INITIALIZATIONS
- GAME LOOP
- INPUT
- DO UPDATE
- DRAW
- screensync
- screenlock
- cls
- ...
- screenunlock
- FREE UP CPU TIME
- sleep 1,1
- ENDING
Contact me for any question and tell me your feedback, see you!
Go to the next entry
Go to the previous entry
Go to the first entry
Comments
Post a Comment