Lines and Dots
by Robodude
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v5.0.1.min.js"></script>
<div id="container"></div>
CSS
body {
margin: 0px;
padding: 0px;
}
JavaScript
var game;
function extend(Child, Parent) {
var F = function () { };
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.uber = Parent.prototype;
}
function Game() {
this.width = 800;
this.height = 600;
this.targetId = "container"
this.level = 0;
this.levels = [
Level1()
]
this.players = [];
this.playerTurn = 0;
for (var n in arguments[0]) {
this[n] = arguments[0][n];
}
this.players.push(new Player({ name: "John", color: "rgba(255,0,0,.8)" }));
this.players.push(new Player({ name: "Tom", color: "rgba(0,0,255,.8)" }));
this.stage = new Kinetic.Stage({
container: this.targetId,
width: this.width,
height: this.height
});
this.stage.scale({ x: 2, y: 2 });
this.loadedLevel = new Level({
data: this.levels[this.level],
parent: this
});
this.stage.draw();
}
Game.prototype.switchPlayer = function () {
this.playerTurn++;
if (this.playerTurn > this.players.length - 1) {
this.playerTurn = 0;
}
}
Game.prototype.getCurrentPlayer = function () {
return this.players[this.playerTurn];
}
Game.prototype.getGame = function () {
return this;
}
function Level() {
this.name = "Level 1";
this.data = [];
this.level = [];
this.parent = null;
for (var n in arguments[0]) {
this[n] = arguments[0][n];
}
this.layer = new Kinetic.Layer({
x: 20,
y: 20
...