Skip to content

Commit

Permalink
lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Poincare committed Apr 8, 2012
1 parent 56e3903 commit c18a73b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/clickr/clickr.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<script src="../../hydroxide.js"></script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script src="game.js"></script>

<body>
<canvas id="cnv" width="600" height="600">Canvas not supported. Go get a new browser.</canvas>
</body>
</html>
102 changes: 102 additions & 0 deletions examples/clickr/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
function createClass() {
/* inherit from the main OHGameObj class, provided by Hydroxide */
var GameObj = Object.create(OHGameObj);

GameObj.xspeed = 1;
GameObj.yspeed = 1;

GameObj.x = 0;
GameObj.y = 0;

GameObj.centerx = 150;
GameObj.centery = 0;

GameObj.radius = 15;

GameObj.width = 50;
GameObj.height = 50;

GameObj.toDraw = true;

GameObj.draw = function(context) {
if(!this.toDraw) {
return;
}

context.beginPath();
context.arc(this.centerx, this.centery, 15, 0, 2 * Math.PI, false);
context.fillStyle = "#8ED6FF";
context.fill();
context.closePath();
//context.fillRect(this.x, this.y, this.width, this.height);

this.centerToCoor();
};

GameObj.centerToCoor = function() {
this.x = this.centerx - this.radius;
this.y = this.centery - this.radius;
}

GameObj.update = function() {
this.centery += this.yspeed;
this.centerToCoor();
};

GameObj.type = "circle";

GameObj.onEdgeY = function () {
this.toDraw = false;
};

GameObj.onEdgeX = function() {
this.toDraw = false;
};

//change color of the rectangles
GameObj.screenClicked = function(posX, posY, inMe) {
if(inMe) {
this.toDraw = false;
obj = Hydroxide.getDataObject("gameStats");

obj["points"]++;

Hydroxide.updateDataObject("gameStats", obj);
}
console.log("Screen clicked!");
}

return GameObj;
}

function addObject() {
var GameObj = createClass();
var g = Object.create(GameObj);

g.centerx = Math.floor(Math.random() * parseInt($("#cnv").attr("width")));
g.centery = g.radius;

g.yspeed = Math.random() * 2;
Hydroxide.registerObject(g);
}

function init() {
var c = $("#cnv")[0];
var context = c.getContext("2d");

var GameObj = createClass();

$("#cnv").click(Hydroxide.mouseClick);

setInterval("addObject()", 600);

var gameStats = {"points":0}

Hydroxide.registerObject(GameObj);
Hydroxide.registerDataObject("gameStats", gameStats);

Hydroxide.start("cnv", context, 20, 20, 600, 600);
}

$(document).ready(init);

0 comments on commit c18a73b

Please sign in to comment.