Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit c712e3692b0c4ac9eda933a88f0832ef838a2b96 Rob committed Feb 11, 2010
@@ -0,0 +1 @@
+**/*.swp
1 README
@@ -0,0 +1 @@
+Jarm is a little game where you wander around trying to find seeds to plant.
0 bsp.js
No changes.
@@ -0,0 +1,12 @@
+function PlantingDialog(){
+ game.state = "paused";
+ this.dlg = $("#planting-dlg");
+
+ this.dlg
+ .show();
+}
+
+PlantingDialog.prototype.close = function(){
+ game.state = "playing";
+ this.dlg.hide();
+}
@@ -0,0 +1,122 @@
+function scrollBackground(dx, dy){
+ var pos = this.position();
+ var x = dx - pos.left;
+ var y = dy - pos.top;
+
+ var playground = $.playground();
+ if (x < 0)
+ x = 0;
+ else if (x + playground.width() >= this.width())
+ x = this.width() - playground.width();
+
+ if (y < 0)
+ y = 0;
+ else if (y + playground.height() >= this.height())
+ y = this.height() - playground.height();
+
+ var offset = this.offset();
+ var position = this.position();
+ this.offset({left: offset.left - position.left - x, top: offset.top - position.top - y});
+ return this;
+}
+
+function setBackground(elem, options){
+ // backgrounds repeat
+ var background = $(elem);
+
+ $.extend({
+ width: background.width(),
+ height: background.height()
+ }, options);
+
+ background.css(
+ {
+ backgroundRepeat: "repeat",
+ backgroundPosition: "0px 0px",
+ backgroundImage: "url(" + options.imageURL + ")",
+ width: options.width + "px",
+ height: options.height + "px"
+ }
+ );
+
+ // add some handy methods
+ background.scrollBackground = scrollBackground;
+
+ return background;
+}
+
+function rectOverlap(x1, y1, w1, h1, x2, y2, w2, h2){
+ if ((x1 + w1 >= x2) &&
+ (y1 + h1 >= y2) &&
+ (x1 <= x2 + w2) &&
+ (y1 <= y2 + h2))
+ return true;
+ return false;
+}
+
+function dist_sq(pos1, pos2){
+ return (pos1.top - pos2.top) * (pos1.top - pos2.top) +
+ (pos1.left - pos2.left) * (pos1.left - pos2.left);
+}
+
+function near(obj1, obj2, radius){
+ var centre1 = obj1.position();
+ centre1.left += obj1.width() / 2;
+ centre1.top += obj1.height() / 2;
+ var centre2 = obj2.position();
+ centre2.left += obj2.width() / 2;
+ centre2.top += obj2.height() / 2;
+
+ return dist_sq(centre1, centre2) <= radius * radius;
+}
+
+function keyDown(what){
+ return $.gameQuery.keyTracker[$.keycodes[what]];
+}
+
+$.keycodes = {
+ backspace: 8,
+ tab: 9,
+ enter: 13,
+ shift: 16,
+ ctrl: 17,
+ alt: 18,
+ pause: 19,
+ caps: 20,
+ escape: 27,
+ space: 32,
+ pageup: 33,
+ pagedown: 34,
+ end: 35,
+ home: 36,
+ left: 37,
+ up: 38,
+ right: 39,
+ down: 40,
+ insert: 45,
+ del: 46
+}
+
+for (var i = 48; i <= 57; i++){
+ $.keycodes[String.fromCharCode(i)] = i;
+}
+for (var i = 65; i <= 90; i++){
+ $.keycodes[String.fromCharCode(i)] = i;
+}
+for (var i = 0; i <= 9; i++){
+ $.keycodes["num" + i] = i + 96;
+}
+for (var i = 1; i <= 12; i++){
+ $.keycodes["f" + i] = i + 111;
+}
+
+function getTimeElapsed(){
+ if (getTimeElapsed.lastFrame === undefined)
+ getTimeElapsed.lastFrame = new Date();
+
+ var currentTime = new Date();
+ var gap = new Date();
+ gap.setTime(currentTime.getTime() - getTimeElapsed.lastFrame.getTime());
+ getTimeElapsed.lastFrame = currentTime;
+ return gap.getMilliseconds();
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,25 @@
+<html>
+ <head>
+ <title>Farming</title>
+ <link rel = "stylesheet" type = "text/css" href = "style.css" />
+ </head>
+ <body>
+ <div id = "playground"></div>
+ <div id = "msg"></div>
+ <div id = "sidebar">
+ Inventory:
+ <div id = "inventory"></div>
+ </div>
+ <div class = "dialog" id = "planting-dlg">
+ <div class = "close-button" onclick = "game.dialog.close()">X</div>
+ </div>
+ <script type = "text/javascript" src = "jquery-1.4.min.js"></script>
+ <script type = "text/javascript" src = "jquery.gamequery-0.4.0.js"></script>
+ <script type = "text/javascript" src = "bsp.js"></script>
+ <script type = "text/javascript" src = "helpers.js"></script>
+ <script type = "text/javascript" src = "initialize.js"></script>
+ <script type = "text/javascript" src = "dialog.js"></script>
+ <script type = "text/javascript" src = "plants.js"></script>
+ <script type = "text/javascript" src = "jarm.js"></script>
+ </body>
+</html>
@@ -0,0 +1,54 @@
+function loadPlants(){
+ var tree = new Animation({imageURL: "images/tree.png"});
+ for (var i = 0; i < 10; i++){
+ var x = Math.floor(Math.random() * (game.worldSize - 38));
+ var y = Math.floor(Math.random() * (game.worldSize - 38));
+ game.playground.addSprite("tree" + i, {animation: tree, width: 45, height: 38,
+ posx: x, posy: y});
+ $("#tree" + i).addClass("collideable");
+ game.objects.add($("#tree" + i), x, y);
+ }
+
+ var bush = new Animation({imageURL: "images/bush.png"});
+ for (var i = 0; i < 30; i++){
+ var x = Math.floor(Math.random() * (game.worldSize - 28));
+ var y = Math.floor(Math.random() * (game.worldSize - 28));
+ game.playground.addSprite("bush" + i, {animation: bush, width: 40, height: 28,
+ posx: x, posy: y});
+ $("#bush" + i).addClass("collideable");
+ game.objects.add($("#bush" + i), x, y);
+ }
+}
+
+function loadObjects(){
+ animations.plot = new Animation({imageURL: "images/plot.png"});
+
+ game.playground
+ .addSprite("plot1", {animation: animations.plot,
+ width: 30, height: 30, posx: 340, posy: 300});
+ game.objects.add($("#plot1"), 340, 300);
+}
+
+function loadWalkingAnim(){
+ animations.walkingAnim.idle = new Animation({imageURL: "images/farmer.png"});
+ animations.walkingAnim.west = new Animation({imageURL: "images/walking-west.png",
+ numberOfFrame: 2, type: $.gameQuery.ANIMATION_HORIZONTAL, rate: game.frameRate * 10, delta: 16});
+ animations.walkingAnim.east = new Animation({imageURL: "images/walking-east.png",
+ numberOfFrame: 2, type: $.gameQuery.ANIMATION_HORIZONTAL, rate: game.frameRate * 10, delta: 16});
+ animations.walkingAnim.north = new Animation({imageURL: "images/walking-north.png",
+ numberOfFrame: 2, type: $.gameQuery.ANIMATION_HORIZONTAL, rate: game.frameRate * 10, delta: 16});
+ animations.walkingAnim.south = new Animation({imageURL: "images/walking-south.png",
+ numberOfFrame: 2, type: $.gameQuery.ANIMATION_HORIZONTAL, rate: game.frameRate * 10, delta: 16});
+}
+
+function registerCallbacks(){
+ $(document).keypress(onKeyPress);
+}
+
+function initializeFarmer(){
+ game.playground
+ .addSprite("farmer", {animation: animations.walkingAnim.idle,
+ width: 16, height: 16, posx: 400, posy: 300});
+ game.farmer = $("#farmer");
+ game.farmer.inventory = [];
+}
Oops, something went wrong.

0 comments on commit c712e36

Please sign in to comment.