Skip to content

Commit

Permalink
new example0.html which tries to get something working with as little…
Browse files Browse the repository at this point in the history
… code as possible
  • Loading branch information
ippa committed Sep 4, 2011
1 parent 2c4170d commit b25cea9
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/example0.html
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<script src="../jaws.js"></script>
<link type="text/css" rel="stylesheet" href="style.css" />
<title>Jaws Example #12 - As minimalistic as JawsJS can get</title>
</head>
<body>
<div id="info">
As minimalistic a Jaws-game can get, have jaws.start() autocreate a canvas.
Also skip wrapping setup, update &amp; draw in a function or object.
This makes Jaws look for them in the global window-object.
</div>

<script>
function setup() {
player = new jaws.Sprite({image: "plane.png", x: jaws.width/2, y:jaws.height/2, anchor: "center"})
jaws.preventDefaultKeys(["up", "down", "left", "right"])
}

function update() {
if(jaws.pressed("left")) { player.x -= 2 }
if(jaws.pressed("right")) { player.x += 2 }
if(jaws.pressed("up")) { player.y -= 2 }
if(jaws.pressed("down")) { player.y += 2 }
}

function draw() {
jaws.clear()
player.draw()
}

// Looks for <canvas> or <div id="canvas"> to draw on. Creates <canvas> if niether is found.
// Then load predined-assets, call setup(), then loop update() and draw() in 60 FPS.
jaws.start()
</script>

</body>
</html>

0 comments on commit b25cea9

Please sign in to comment.