<<< Back to main page

Javascript Project

Code

In this project, you will make a javascript browser game. I have some basic code attached - why don't you take a look here.

Directions

There are three sections in game.html:

Most of the cool stuff will happen in the javascript.  There are two functions: the 
$(document).keypress
function, and the
everyTick
function. The
$(document).keypress
function is automatically called every time you press a keyboard key. Right now, it detects whether you used the wasd keys, and moves the player block around. The
everyTick
function is automatically called 30x a second. Right now, it bounces a block around the screen. You can use the code in these functions as an example for how to write your own.

If you're not familiar with javascript, you can find examples of most of the basic syntax in the provided code. Here's some more info to get you started:

When you make a variable, you don't need to specify its type. (In fact, you can't specify the type of a variable at all.) This is perfectly fine: 
x = 5;

This code uses jQuery to move objects around. A quick jQuery primer:

You can do whatever you want from here on. Here are some ideas for stuff to implement, if you don't have a good idea already:

  1. Make it so that the player can't move off the screen. You can do this by adding some if statements in either the keypress or the everyTick function.
  2. Figure out how to spawn a new div whenever the player hits a certain key. Hint:
    $('body').append('some text')
    adds text to the end of the body. Use this to add more divs.
  3. Turn the new divs into bullets. Make them move automatically. You will get a sticker for making it this far. Call us over for a check-off.
  4. Detect when the bullets hit the green block. Make the green block disappear, or something.
  5. Spawn enemies automatically... you are most of the way to making a video game now. The rest is up to you!

Proceed to Code