Using the Arrow Keys
Using the Arrow Keys
Today was the third time being at my internship. Exciting right!! I continued on the same project that I have been working on from last week. Last week I worked on making a little giph walk north, east, south, and west, through the use of some functions. I would essentially call a function that I had already created. For instance, if I called walkNorth(). This is telling the console that I have called this variable, and that the computer is going to find this walkNorth() variable and run what this variable is assigned to do. In this case, I assigned this variable to walk north. How I did that is a little more complicated, so for now, all you need to know is that this giph walks north when the variable walkNorth() is called. I also made different variables called walkEast(), walkSouth(), and walkWest, and assigned them to walk in there specific direction. Calling these variables one by one is kind of inconvenient because I would have to input these commands everytime I wanted the giph to do something. Now we get on to what I worked on today.
I worked on assigning the arrow keys to one of these functions. Essentially what I wrote in the code, was when the top arrow key was pressed, walkNorth(). I did this with all of the other variables as well. This made it much easier to move this giph around. A simple thing that was done in this process was finding out the keycode of a certain keyboard key. For example, the keycode for the up arrow key is "38." I would then make an if statement that would say, if this keycode is pressed, walkNorth(). This was all very interesting. Soon it was time to go back to school. I am very excited to go next week.
Comments
Post a Comment