Exemplo n.º 1
0
		.bind('Moved', function(from) {
			// var walls = this.hit('Wall');
			// if (walls) { 
			// 	console.log("hit wall");
			// 	this.attr({
			// 		x: from.x,
			// 		y: from.y
			// 	});
			// 	return;
			// }
			
			var doors = this.hit('Door');
			if (doors) {
				console.log("Hit door(s)");
				console.log(doors);
				var door = doors[0];
				Crafty.scene(door.obj.destination);
				return;
			}
			if (this.hit('Shape') || this.hit('Wall') || this.isOutOfBounds()) {
				console.log("hit shape, wall or boundary");
				this.attr({
					x: from.x,
					y: from.y
				});
			}
		})
Exemplo n.º 2
0
Crafty.scene("introScene", function() {
  Crafty.e("2D, DOM, Text")
  .attr({ y: 100, w: gameWidth })
  .css({ "text-align": "center" })
  .text("Space Invaders")
  .textColor("white")
  .textFont({ size: "30px" });

  Crafty.e("2D, DOM, Text")
  .attr({ y: 270, w: gameWidth })
  .css({ "text-align": "center" })
  .text("Controls")
  .textColor("white")
  .textFont({ size: "20px" });

  Crafty.e("2D, DOM, Text")
  .attr({ y: 300, w: gameWidth })
  .css({ "text-align": "center" })
  .text("[Left/Right] - Move<br>[Space] - Fire")
  .textColor("white")
  .textFont({ size: "16px" });

  Crafty.e("2D, DOM, Text")
  .attr({ y: 500, w: gameWidth })
  .css({ "text-align": "center" })
  .text("Press any key to start")
  .textColor("white")
  .textFont({ size: "30px" });

  Crafty.bind("KeyDown", function() {
    Crafty.enterScene("gameScene");
  });
}, function() {
  Crafty.unbind("KeyDown");
});