Skip to content
Browse files

Merge branch 'choico'

  • Loading branch information...
2 parents ecded42 + 139feb1 commit 85d00e62aba4a4b6a473ec887b82eebf702a5aaa @tonistiigi tonistiigi committed Sep 21, 2011
View
BIN lime/demos/pong/assets/applause.mp3
Binary file not shown.
View
BIN lime/demos/pong/assets/applause.wav
Binary file not shown.
View
BIN lime/demos/pong/assets/bounce.mp3
Binary file not shown.
View
BIN lime/demos/pong/assets/bounce.wav
Binary file not shown.
View
40 lime/demos/pong/game.js
@@ -8,6 +8,7 @@ goog.require('lime.animation.FadeTo');
goog.require('lime.fill.LinearGradient');
goog.require('pong.Notice');
goog.require('pong.Player');
+goog.require('lime.audio.Audio');
pong.Game = function(mode) {
lime.Sprite.call(this);
@@ -17,6 +18,7 @@ pong.Game = function(mode) {
this.WIDTH = 300;
this.HEIGHT = 360;
this.mode = mode;
+ this.winning_score = 10;
this.setAnchorPoint(0, 0);
this.setSize(320, 460);
@@ -45,8 +47,11 @@ pong.Game = function(mode) {
this.world.appendChild(this.ball);
this.placeball();
- this.notice = new pong.Notice().setPosition(160, 200).setHidden(true);
+ this.notice = new pong.Notice().setPosition(160, 200).setHidden(false);
this.appendChild(this.notice);
+
+ this.endRoundSound = new lime.audio.Audio('assets/applause.wav');
+ this.bounceSound = new lime.audio.Audio('assets/bounce.wav');
};
goog.inherits(pong.Game, lime.Sprite);
@@ -71,38 +76,50 @@ pong.Game.prototype.step_ = function(dt) {
pos.y += this.v.y * dt * this.SPEED;
if (pos.x < this.RADIUS) {
+ // bounce off left wall
this.v.x *= -1;
pos.x = this.RADIUS;
+ this.bounceSound.stop();
+ this.bounceSound.play();
}
else if (pos.x > size.width - this.RADIUS) {
+ // bounce off right wall
this.v.x *= -1;
pos.x = size.width - this.RADIUS;
+ this.bounceSound.stop();
+ this.bounceSound.play();
}
var pp, pwidth = this.p1.getSize().width / 2 + this.RADIUS;
if (pos.y < this.RADIUS) {
pp = this.p2.getPosition();
var diff = pos.x - pp.x;
if (Math.abs(diff) < pwidth) {
+ // bounce off of top paddle
this.v.x += diff / pwidth;
this.v.y *= -1;
if (this.v.x > 1) this.v.x = 1;
if (this.v.x < -1) this.v.x = -1;
this.v.normalize();
pos.y = this.RADIUS;
+ this.bounceSound.stop();
+ this.bounceSound.play();
}
else this.endRound(this.p1);
}
else if (pos.y > size.height - this.RADIUS) {
pp = this.p1.getPosition();
var diff = pos.x - pp.x;
if (Math.abs(diff) < pwidth) {
+ // bounce off of bottom paddle
this.v.x += diff / pwidth;
this.v.y *= -1;
if (this.v.x > 1) this.v.x = 1;
if (this.v.x < -1) this.v.x = -1;
this.v.normalize();
pos.y = size.height - this.RADIUS;
+ this.bounceSound.stop();
+ this.bounceSound.play();
}
else this.endRound(this.p2);
}
@@ -115,17 +132,31 @@ pong.Game.prototype.step_ = function(dt) {
};
pong.Game.prototype.placeball = function() {
this.ball.setPosition(this.WIDTH / 2, this.HEIGHT - this.RADIUS);
- goog.events.listenOnce(this.ball, ['touchstart', 'mousedown'], this.start, false, this);
+ goog.events.listenOnce(this.world, ['touchstart', 'mousedown'], this.start, false, this);
this.p1.setPosition(this.WIDTH / 2, this.HEIGHT);
this.p2.setPosition(this.WIDTH / 2, 0);
};
+pong.Game.prototype.endGame = function() {
+ this.notice.title.setText(this.p1.score > this.p2.score ? 'You won!' : 'You lost.');
+ this.notice.score.setText(this.p1.score + ' : ' + this.p2.score);
+ this.notice.setOpacity(0).setHidden(false);
+ var show = new lime.animation.FadeTo(1);
+ this.notice.runAction(show);
+ goog.events.listenOnce(this.notice, ['touchstart', 'mousedown'], pong.newgame, false, this);
+}
+
pong.Game.prototype.endRound = function(winner) {
winner.score++;
lime.scheduleManager.unschedule(this.step_, this);
- this.notice.title.setText(winner == this.p1 ? 'You scored' : 'You lost');
+ if(winner.score >= this.winning_score) {
+ this.endGame();
+ return;
+ }
+
+ this.notice.title.setText(winner == this.p1 ? 'You scored' : 'Opponent scored');
this.notice.score.setText(this.p1.score + ' : ' + this.p2.score);
this.notice.setOpacity(0).setHidden(false);
@@ -134,4 +165,7 @@ pong.Game.prototype.endRound = function(winner) {
this.placeball();
},false, this);
this.notice.runAction(show);
+
+ this.endRoundSound.stop();
+ this.endRoundSound.play();
};
View
5 lime/demos/pong/notice.js
@@ -11,9 +11,10 @@ pong.Notice = function() {
this.setSize(150, 100).setFill(back).setAnchorPoint(.5, 0);
- this.title = new lime.Label().setText('title').setPosition(0, 20);
+ this.title = new lime.Label().setText('Click to begin!').setPosition(0, 20);
this.appendChild(this.title);
- this.score = new lime.Label().setText('3 : 2').setPosition(0, 60).setFontSize(34);
+
+ this.score = new lime.Label().setText('').setPosition(0, 60).setFontSize(34);
this.appendChild(this.score);
};
goog.inherits(pong.Notice, lime.RoundedRect);
View
7 lime/demos/pong/player.js
@@ -12,7 +12,12 @@ pong.Player = function(is_down) {
this.setAnchorPoint(.5, 0);
- this.inner = new lime.RoundedRect().setSize(80, 15).setFill(100, 100, 0).setAnchorPoint(.5, 0);
+ var front_color = '#000';
+ var back_color = '#DDD';
+ var grad = new lime.fill.LinearGradient().
+ addColorStop(0, is_down ? front_color : back_color).
+ addColorStop(1, is_down ? back_color : front_color);
+ this.inner = new lime.RoundedRect().setSize(80, 15).setFill(grad).setAnchorPoint(.5, 0);
this.appendChild(this.inner);
View
27 lime/demos/pong/pong.js
@@ -12,24 +12,24 @@ goog.require('pong.Game');
// entrypoint
pong.start = function() {
- lime.scheduleManager.setDisplayRate(1000 / 60);
+ lime.scheduleManager.setDisplayRate(1000 / 60);
pong.director = new lime.Director(document.body, 320, 460);
var scene = new lime.Scene(),
layer = new lime.Layer();
- var btn = new lime.GlossyButton('SINGLE').setSize(100, 40).setPosition(150, 100);
- goog.events.listen(btn, 'click', function() {
- pong.newgame(1);
- });
- layer.appendChild(btn);
+ var btn = new lime.GlossyButton('SINGLE').setSize(100, 40).setPosition(150, 100);
+ goog.events.listen(btn, 'click', function() {
+ pong.newgame(1);
+ });
+ layer.appendChild(btn);
- btn = new lime.GlossyButton('MULTI').setSize(100, 40).setPosition(150, 200);
- goog.events.listen(btn, 'click', function() {
- pong.newgame(2);
- });
- layer.appendChild(btn);
+ btn = new lime.GlossyButton('VS').setSize(100, 40).setPosition(150, 200);
+ goog.events.listen(btn, 'click', function() {
+ pong.newgame(2);
+ });
+ layer.appendChild(btn);
scene.appendChild(layer);
@@ -40,13 +40,14 @@ pong.start = function() {
};
pong.newgame = function(mode) {
- var scene = new lime.Scene(),
- layer = new lime.Layer();
+ var scene = new lime.Scene(),
+ layer = new lime.Layer();
scene.appendChild(layer);
var game = new pong.Game(mode);
layer.appendChild(game);
+
pong.director.replaceScene(scene);
};
View
2 lime/demos/tests/box2d.js
@@ -120,4 +120,4 @@ test.start = function() {
};
-goog.exportSymbol('test.start', test.start);
+goog.exportSymbol('test.start', test.start);
View
2 lime/demos/zlizer/bubble.js
@@ -13,7 +13,7 @@ zlizer.Bubble = function(value) {
this.lbl = new lime.Label().setText(value).setFontSize(34).setFontColor('#fff').setFontWeight(700).setFontFamily('Impact');
this.appendChild(this.lbl);
- this.GRAVITY = 5;
+ this.GRAVITY = 2.5;
this.setAnchorPoint(0, 0);
this.setScale(1.2);
View
676 lime/demos/zlizer/compiled/zlizer.js
538 additions, 138 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 lime/demos/zlizer/game.js
@@ -417,7 +417,7 @@ zlizer.Game.prototype.removeBubble = function(b) {
zlizer.Game.prototype.checkDeletions = function() {
var i = this.bubbles.length;
while (--i >= 0) {
- if (this.bubbles[i].getPosition().y > 840) {
+ if (this.bubbles[i].getPosition().y > 840 || this.bubbles[i].getPosition().x < 0 || this.bubbles[i].getPosition().x > 768) {
this.removeBubble(this.bubbles[i]);
}
}
View
14 lime/demos/zlizer/zlizer.js
@@ -81,18 +81,26 @@ zlizer.loadMenuScene = function(opt_transition) {
var btns_layer = new lime.Layer().setPosition(-250, 110);
levels.appendChild(btns_layer);
-
- for (var r = 0; r < 4; r++) {
+
+ var r = 0;
+ for (r = 0; r < 4; r++) {
for (var c = 0; c < 5; c++) {
var num = (c + 1) + (r * 5);
- var btn = new zlizer.Button('' + num).setSize(100, 100).setPosition(c * 125, r * 125);
+ var btn = new zlizer.Button('' + num).setSize(80, 80).setPosition(c * 125, r * 90);
btns_layer.appendChild(btn);
goog.events.listen(btn, lime.Button.Event.CLICK, function() {
zlizer.loadGame(this);
},false, num);
}
}
+ //Creates a button to go back to the main menu
+ var btn_main = new zlizer.Button('Back to Menu').setSize(400, 80).setPosition(250, r * 90);
+ btns_layer.appendChild(btn_main);
+ goog.events.listen(btn_main, lime.Button.Event.CLICK, function() {
+ contents.runAction(new lime.animation.MoveTo(0, 280).enableOptimizations());
+ },false, num);
+
};
View
16 lime/src/helper/style.js
@@ -42,7 +42,7 @@ lime.style.getCSSproperty = function(name) {
})();
/**
- * Set border radisu of a DOM element
+ * Set border radius of a DOM element
* @param {Element} el Element to change.
* @param {Array.<number>} values Radius values.
* @param {Array.<number>=} opt_vertical Vertical radius values.
@@ -83,7 +83,7 @@ lime.style.Transform = function(opt_precision) {
* Scale current transform object
* @param {number} sx X-axis scale factor.
* @param {number} sy y-axis scale factor.
- * @return {lime.style.Transform} obejct itself.
+ * @return {lime.style.Transform} object itself.
*/
lime.style.Transform.prototype.scale = function(sx, sy) {
//if(sx!=1 && sy!=1)
@@ -94,8 +94,8 @@ lime.style.Transform.prototype.scale = function(sx, sy) {
/**
* Rotate current transform object
* @param {number} angle Angle to rotate.
- * @param {string=} opt_unit Units.
- * @return {lime.style.Transform} obejct itself.
+ * @param {string=} opt_unit Units. Defaults to degrees.
+ * @return {lime.style.Transform} object itself.
*/
lime.style.Transform.prototype.rotate = function(angle, opt_unit) {
var rot_str = 'rotate(' + angle + (opt_unit ? opt_unit : 'deg') + ')';
@@ -110,7 +110,7 @@ lime.style.Transform.prototype.rotate = function(angle, opt_unit) {
* @param {number} tx Offset in x-axis.
* @param {number} ty Offset in y-axis.
* @param {number=} opt_tz Offset in z-axis.
- * @return {lime.style.Transform} obejct itself.
+ * @return {lime.style.Transform} object itself.
*/
lime.style.Transform.prototype.translate = function(tx, ty, opt_tz) {
@@ -126,9 +126,9 @@ lime.style.Transform.prototype.translate = function(tx, ty, opt_tz) {
/**
* Set the current precision of transform. This is handled as a
- * state machine so its added when called not when done.
+ * state machine so it's added when called not when done.
* @param {number} p Precision(Lowest value to make a difference).
- * @return {lime.style.Transform} obejct itself.
+ * @return {lime.style.Transform} object itself.
*/
lime.style.Transform.prototype.setPrecision = function(p) {
if (this.precision != 1) {
@@ -144,7 +144,7 @@ lime.style.Transform.prototype.setPrecision = function(p) {
};
/**
- * Return CSS transform string from the obejct
+ * Return CSS transform string from the object
* @return {string} CSS value string.
*/
lime.style.Transform.prototype.toString = function() {

0 comments on commit 85d00e6

Please sign in to comment.
Something went wrong with that request. Please try again.