window.onload = function() { // You can copy-and-paste the code from any of the examples at http://examples.phaser.io here. // You will need to change the fourth parameter to "new Phaser.Game()" from // 'phaser-example' to an empty string ''. // The assets (and code) can be found at: https://github.com/photonstorm/phaser/tree/master/examples/assets // You will need to change the paths you pass to "game.load.image()" or any other // loading functions to reflect where you are putting the assets. // All loading functions will typically all be found inside "preload()". "use strict"; var game = new Phaser.Game(1000, 800, Phaser.AUTO, 'phaser-example', { preload: preload, create: create}); var p; var trophy; var score = 0; var counter= 1; var temp; var text; var music; function preload() { game.load.image('diamond', '/games/6dsq/imgs/green_ball.png'); game.load.image('poison', '/games/6dsq/imgs/blue_ball.png'); game.load.audio('fish','/games/6dsq/imgs/fish.ogg'); } function create() { game.stage.backgroundColor = '#00000000'; trophy = game.add.sprite(calcXLocation(), calcYLocation(),'poison'); p = game.add.emitter(game.world.centerX, game.world.centerY, 1000); p.gravity = 0; p.makeParticles('diamond'); trophy.inputEnabled = true; trophy.input.pixelPerfect = true; trophy.input.useHandCursor = true; trophy.events.onInputOver.add(overSprite,this); trophy.events.onInputOut.add(outSprite, this); p.start(false, 5000, 10, 100000); game.time.events.loop(Phaser.Timer.SECOND, move, this); text = game.add.text(25, 730, 'DogCoin: 0', { font: "18px Arial", fill: "#ffffff", align: "center" }); music = game.add.audio('fish',1,true); music.play('',0,1,true); } function overSprite() { console.log('over'); trophy.x = calcXLocation(); trophy.y = calcYLocation(); } function outSprite() { console.log('out'); counter += 1; score += 10 * counter ; text.content = 'DogCoins: ' + score; } function move() { trophy.x = calcXLocation(); trophy.y = calcYLocation(); } function calcXLocation(){ temp =Math.floor((Math.random()*777)+1); while (10 > temp >987) temp = Math.floor((Math.random()*777)+1) ; return temp; } function calcYLocation(){ temp =Math.floor((Math.random()*555)); while (10 > temp >765) temp = Math.floor((Math.random()*555)) ; return temp; } function render() { game.debug.renderSpriteCorners(trophy,false,false); game.debug.renderSpriteInfo(trophy, 20, 32); } };