In this project, you will make a javascript browser game. I have some basic code attached - why don't you take a look here.
There are three sections in game.html:
<script>tags) is the actual game logic.
<style>tag) defines how your game objects look - color, size, and stuff.
<body>tag) simply lists out your game objects. Right now, there are two objects: the player and a random block.
$(document).keypressfunction, and the
everyTickfunction. The
$(document).keypressfunction 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
everyTickfunction 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:
$('#object-id')finds an HTML tag with the given id. You can also use
$('.object-class')to select every object in a class.
object.css(property)returns the CSS style of the property.
object.css(property, value)sets property to value. We set the 'top' and 'left' properties of some divs to simulate movement. You can also set anything else you'd like: 'background-color', 'width', etc.
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:
$('body').append('some text')adds text to the end of the body. Use this to add more divs.