Skip to content

Instantly share code, notes, and snippets.

@incompl
Last active December 10, 2015 11:39
Show Gist options
  • Save incompl/4429002 to your computer and use it in GitHub Desktop.
Save incompl/4429002 to your computer and use it in GitHub Desktop.
Code for my Box2d screencast on Bocoup.com
var canvasElem = document.getElementById("game");
var world = boxbox.createWorld(canvasElem);
world.createEntity({
name: "player",
shape: "circle",
radius: 1,
image: "pig.png",
imageStretchToFit: true,
density: 4,
x: 2,
onKeyDown: function(e) {
this.applyImpulse(200, 60);
}
});
world.createEntity({
name: "ground",
shape: "square",
type: "static",
color: "rgb(0,100,0)",
width: 20,
height: .5,
y: 12
});
var block = {
name: "block",
shape: "square",
color: "brown",
width: .5,
height: 4,
onImpact: function(entity, force) {
if (entity.name() === "player") {
this.color("black");
}
}
};
world.createEntity(block, {
x: 15
});
world.createEntity(block, {
x: 17
});
world.createEntity(block, {
x: 16,
y: 1,
width: 4,
height: .5
});
<!doctype html>
<html>
<head>
<title>Happy Guinea Pigs</title>
<script src="Box2dWeb-2.1.a.3.min.js"></script>
<script src="boxbox.min.js"></script>
</head>
<body>
<canvas id="game" width=640 height=380>
Text that you see if you don't support Canvas :(
</canvas>
<script src="game.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment