Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2012 08:30
Show Gist options
  • Save anonymous/3633315 to your computer and use it in GitHub Desktop.
Save anonymous/3633315 to your computer and use it in GitHub Desktop.
//set main namespace
goog.provide('hello');
//get requirements
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.Layer');
goog.require('lime.Circle');
goog.require('lime.Label');
goog.require('lime.animation.Spawn');
goog.require('lime.animation.FadeTo');
goog.require('lime.animation.ScaleTo');
goog.require('lime.animation.MoveTo');
goog.require('lime.transitions.Dissolve');
goog.require('lime.audio.Audio');
hello.W = 1024;
hello.H = 768;
// entrypoint
hello.start = function(){
lime.scheduleManager.setDisplayRate(1000 / 60); // 60 FPS
hello.director = new lime.Director(document.body, hello.W, hello.H);
hello.director.setDisplayFPS(false);
hello.scene1();
hello.director.makeMobileWebAppCapable();
}
hello.scene1 = function(){
var scene = new lime.Scene();
var layer = new lime.Layer().setPosition(0,0).setAnchorPoint(0,0);
var bg = new lime.Sprite().setFill('assets/wood.jpg').setPosition(0,0).setAnchorPoint(0,0);
var title = new lime.Label().setText('').setPosition(900,50).setFontColor('#fff').setFontSize(26)
layer.appendChild(bg);
layer.appendChild(title);
scene.appendChild(layer);
var snd = new lime.audio.Audio('assets/pick.mp3');
goog.events.listen(snd.baseElement,"ended",function(){
snd.stop();
});
var score = 0;
function addStar(){
var x = Math.random()*hello.W;
var y = Math.random()*hello.H;
var star = new lime.Sprite().setSize(101,85).setFill('assets/star.gif').setPosition(x,y);
goog.events.listen(star, ['mouseover','touchstart'], function(e){
if (star.toBeDeleted) return;
star.toBeDeleted = true;
var zoomout = new lime.animation.Spawn(
new lime.animation.ScaleTo(5),
new lime.animation.FadeTo(0)
).setDuration(1.5).enableOptimizations();
star.runAction(zoomout);
snd.play();
score++;
title.setText('Score: '+score);
if (score>9)
hello.scene2();
});
layer.appendChild(star);
}
for (var k = 0; k < 10; ++k)
addStar();
hello.director.replaceScene(scene, lime.transitions.Dissolve);
};
hello.scene2 = function(){
var scene = new lime.Scene();
var layer = new lime.Layer().setPosition(0,0).setAnchorPoint(0,0);
var bg = new lime.Sprite().setFill('#FFF').setPosition(0,0).setAnchorPoint(0,0);
var title = new lime.Label().setText('Game Over').setPosition(hello.W/2,hello.H/2).setFontColor('#000').setFontSize(64)
layer.appendChild(bg);
layer.appendChild(title);
scene.appendChild(layer);
hello.director.replaceScene(scene, lime.transitions.Dissolve);
};
goog.exportSymbol('hello.start', hello.start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment