This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

The First Task - Responding to Keystrokes [April 14, 2011, 1:44 p.m.]


This task is here to help you decide whether the material will be the right level for you or not.  Here's what I'd like you to do before joining the course:

Set up an HTML file that loads a separate Javascript file.  Write some code to detect when the user presses a key on the keyboard. Whenever the user presses one of the arrow keys, display a message on the page (e.g. display "You pressed the up arrow.").

If you already know how to do this, or if you think you can figure it out, then this course will be at the right level for you. If the task sounds too hard, then you should probably start with an introductory Javascript course before joining this group.

Doing this task will help you learn the basics of Javascript, as well as providing a basic input system that you can re-use again and again in different game projects. (After all, nearly every game involves some kind of keyboard input!)

Development Tips

One easy way, but maybe not the best way, is to attach an onkeydown or onkeyup handler to the body element of the page. (Which would you choose, onkeydown or onkeyup? Why?)

The ideal solution is one that works in all browsers, but this can be tricky.  We'll be discussing cross-browser compatibility strategies during the first week of the study group.  For now, just try to get it working in at least one or two browsers.  When you submit the task, please note which browsers you tested it in, and where it worked or didn't worked.

If you don't happen to have a webserver where you can host your HTML and JS files for this task, don't worry -- you can just develop the files on your hard drive, using "File -> Open" to load the HTML page in your web browser.

Submitting the Finished Task

Once you've got your code working to your satisfaction, send me a direct message on this site.  If you were able to host your files on the web somewhere, send me a link!  If you have working files but nowhere to host them, then let me know and I'll give you instructions for emailing your files to me directly.