Add: God's next chocoball
This commit is contained in:
@@ -3,9 +3,6 @@ Chocoball.constructor = Chocoball;
|
|||||||
|
|
||||||
function Chocoball(index, onClickHandler) {
|
function Chocoball(index, onClickHandler) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.row = Math.floor(index / 5);
|
|
||||||
this.col = index % 5;
|
|
||||||
|
|
||||||
this.onClickHandler = onClickHandler;
|
this.onClickHandler = onClickHandler;
|
||||||
|
|
||||||
this.initVariables();
|
this.initVariables();
|
||||||
@@ -17,6 +14,14 @@ function Chocoball(index, onClickHandler) {
|
|||||||
Chocoball.prototype.initVariables = function(textContent) {
|
Chocoball.prototype.initVariables = function(textContent) {
|
||||||
this.isActivated = false;
|
this.isActivated = false;
|
||||||
this.number = 0;
|
this.number = 0;
|
||||||
|
|
||||||
|
if(this.index == 100) {
|
||||||
|
this.col = 6.4;
|
||||||
|
this.row = 1;
|
||||||
|
} else {
|
||||||
|
this.row = Math.floor(this.index / 5);
|
||||||
|
this.col = this.index % 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Chocoball.prototype.drawChocoball = function() {
|
Chocoball.prototype.drawChocoball = function() {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ var Game = {
|
|||||||
|
|
||||||
// init game elements
|
// init game elements
|
||||||
this.initVariables();
|
this.initVariables();
|
||||||
|
this.drawObjects();
|
||||||
|
|
||||||
|
|
||||||
// bottom ui
|
// bottom ui
|
||||||
@@ -46,9 +47,13 @@ var Game = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
initVariables: function() {
|
initVariables: function() {
|
||||||
|
this.nextNumber = 1;
|
||||||
|
|
||||||
this.firstChocoballArray = this.makeChocoballArray(1, 25);
|
this.firstChocoballArray = this.makeChocoballArray(1, 25);
|
||||||
this.secondChocoballArray = this.makeChocoballArray(26, 50);
|
this.secondChocoballArray = this.makeChocoballArray(26, 50);
|
||||||
|
},
|
||||||
|
|
||||||
|
drawObjects: function() {
|
||||||
this.chocoballs = new Array();
|
this.chocoballs = new Array();
|
||||||
for(var i = 0; i < 25; i++) {
|
for(var i = 0; i < 25; i++) {
|
||||||
var chocoball = new Chocoball(
|
var chocoball = new Chocoball(
|
||||||
@@ -59,9 +64,39 @@ var Game = {
|
|||||||
this.chocoballs.push(chocoball);
|
this.chocoballs.push(chocoball);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.god = new God(game.world.width - 120, Game.GOD_POSITION_Y + 100, this);
|
var graphics = game.add.graphics(0, 0);
|
||||||
|
var triangleStartX = God.POSITION_X;
|
||||||
|
var triangleStartY = God.POSITION_Y - 220;
|
||||||
|
var triangleHalfWidth = 20;
|
||||||
|
var triangleHeight = 40;
|
||||||
|
graphics.beginFill(0xFFFFFF);
|
||||||
|
graphics.lineStyle(20, 0x000000);
|
||||||
|
graphics.moveTo(triangleStartX, triangleStartY);
|
||||||
|
graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - triangleHeight);
|
||||||
|
graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - triangleHeight);
|
||||||
|
graphics.lineTo(triangleStartX, triangleStartY);
|
||||||
|
graphics.endFill();
|
||||||
|
|
||||||
this.nextNumber = 1;
|
graphics.lineStyle(10, 0x000000);
|
||||||
|
graphics.beginFill(0xFFFFFF);
|
||||||
|
graphics.drawCircle(God.POSITION_X, God.POSITION_Y - 340, 200);
|
||||||
|
graphics.endFill();
|
||||||
|
|
||||||
|
graphics.beginFill(0xFFFFFF);
|
||||||
|
graphics.lineStyle(0);
|
||||||
|
graphics.moveTo(triangleStartX, triangleStartY);
|
||||||
|
graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - triangleHeight);
|
||||||
|
graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - triangleHeight);
|
||||||
|
graphics.lineTo(triangleStartX, triangleStartY);
|
||||||
|
graphics.endFill();
|
||||||
|
|
||||||
|
this.nextChocoball = new Chocoball(
|
||||||
|
100,
|
||||||
|
(function(chocoball) { console.log("no event") }).bind(this)
|
||||||
|
);
|
||||||
|
this.nextChocoball.setNumber(this.nextNumber);
|
||||||
|
|
||||||
|
this.god = new God(God.POSITION_X, God.POSITION_Y, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
makeChocoballArray(firstNumber, lastNumber) {
|
makeChocoballArray(firstNumber, lastNumber) {
|
||||||
@@ -87,17 +122,21 @@ var Game = {
|
|||||||
if(chocoball.number == 1)
|
if(chocoball.number == 1)
|
||||||
this.stopWatch.start();
|
this.stopWatch.start();
|
||||||
|
|
||||||
if(chocoball.number != this.nextNumber) {
|
if(chocoball.number == this.nextNumber) {
|
||||||
console.log("wrong");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
this.nextNumber++;
|
this.nextNumber++;
|
||||||
|
this.god.animateHappy();
|
||||||
|
} else {
|
||||||
|
console.log("wrong");
|
||||||
|
this.god.animateAngry();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chocoball.number < 25)
|
if(chocoball.number < 25) {
|
||||||
chocoball.setNumber(this.secondChocoballArray[chocoball.index]);
|
chocoball.setNumber(this.secondChocoballArray[chocoball.index]);
|
||||||
else
|
this.nextChocoball.setNumber(this.nextNumber);
|
||||||
|
} else {
|
||||||
chocoball.setActive(false);
|
chocoball.setActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
if(chocoball.number == 50) {
|
if(chocoball.number == 50) {
|
||||||
console.log("game clear");
|
console.log("game clear");
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ God = function(x, y, mainGame) {
|
|||||||
this.isActivated = true;
|
this.isActivated = true;
|
||||||
|
|
||||||
Phaser.Sprite.call(this, game, x, y, 'god_angry');
|
Phaser.Sprite.call(this, game, x, y, 'god_angry');
|
||||||
|
// this.anchor.setTo(0.5, 1);
|
||||||
this.anchor.setTo(0.5, 1);
|
this.anchor.setTo(0.5, 1);
|
||||||
this.scale.set(0.5);
|
this.scale.set(0.5);
|
||||||
|
|
||||||
@@ -11,6 +12,8 @@ God = function(x, y, mainGame) {
|
|||||||
// this.events.onInputDown.add(this.onDown, this);
|
// this.events.onInputDown.add(this.onDown, this);
|
||||||
|
|
||||||
game.add.existing(this);
|
game.add.existing(this);
|
||||||
|
|
||||||
|
this.smileAgain();
|
||||||
}
|
}
|
||||||
|
|
||||||
God.prototype = Object.create(Phaser.Sprite.prototype);
|
God.prototype = Object.create(Phaser.Sprite.prototype);
|
||||||
@@ -40,10 +43,10 @@ God.prototype.setScale = function(size) {
|
|||||||
|
|
||||||
God.prototype.animateHappy = function(type) {
|
God.prototype.animateHappy = function(type) {
|
||||||
this.loadTexture('god_happy');
|
this.loadTexture('god_happy');
|
||||||
this.mainGame.speechBubble.showSpeechBubble(type);
|
// this.mainGame.speechBubble.showSpeechBubble(type);
|
||||||
|
|
||||||
var tween = game.add.tween(this.scale);
|
var tween = game.add.tween(this.scale);
|
||||||
tween.to({x:0.7, y:0.7}, 500, Phaser.Easing.Quadratic.Out, true, 0);
|
tween.to({x:0.6, y:0.6}, 500, Phaser.Easing.Quadratic.Out, true, 0);
|
||||||
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true);
|
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true);
|
||||||
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0);
|
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0);
|
||||||
tween.onComplete.add(this.smileAgain, this);
|
tween.onComplete.add(this.smileAgain, this);
|
||||||
@@ -52,10 +55,12 @@ God.prototype.animateHappy = function(type) {
|
|||||||
|
|
||||||
God.prototype.animateAngry = function(type) {
|
God.prototype.animateAngry = function(type) {
|
||||||
this.loadTexture('god_angry');
|
this.loadTexture('god_angry');
|
||||||
this.mainGame.speechBubble.showSpeechBubble(type);
|
// this.mainGame.speechBubble.showSpeechBubble(type);
|
||||||
|
|
||||||
var tween = game.add.tween(this.scale);
|
var tween = game.add.tween(this.scale);
|
||||||
tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Bounce.Out, true, 0);
|
// tween.to({x:0.7}, 1000, Phaser.Easing.Quadratic.In, true, 0);
|
||||||
|
tween.to({x:0.6}, 1000, Phaser.Easing.Bounce.Out, true, 0);
|
||||||
|
|
||||||
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true);
|
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true);
|
||||||
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0);
|
// tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0);
|
||||||
tween.onComplete.add(this.smileAgain, this);
|
tween.onComplete.add(this.smileAgain, this);
|
||||||
@@ -65,4 +70,15 @@ God.prototype.animateAngry = function(type) {
|
|||||||
God.prototype.smileAgain = function() {
|
God.prototype.smileAgain = function() {
|
||||||
this.scale.set(0.5);
|
this.scale.set(0.5);
|
||||||
this.loadTexture('god_smile');
|
this.loadTexture('god_smile');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
God.loadResources = function() {
|
||||||
|
game.load.image('god_angry', '../../../resources/image/character/god/god_hungry.png');
|
||||||
|
game.load.image('god_smile', '../../../resources/image/character/god/god_smile.png');
|
||||||
|
game.load.image('god_happy', '../../../resources/image/character/god/god_happy.png');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
God.POSITION_X = 840;
|
||||||
|
God.POSITION_Y = 640;
|
||||||
@@ -35,6 +35,7 @@ var Loading = {
|
|||||||
game.load.image('card_edge', '../../../resources/image/ui/card_selected.png');
|
game.load.image('card_edge', '../../../resources/image/ui/card_selected.png');
|
||||||
|
|
||||||
Chocoball.loadResources();
|
Chocoball.loadResources();
|
||||||
|
God.loadResources();
|
||||||
|
|
||||||
// game.load.image('a', '../../../resources/image/icon/fullscreen_white.png');
|
// game.load.image('a', '../../../resources/image/icon/fullscreen_white.png');
|
||||||
// game.load.image('b', '../../../resources/image/icon/fullscreen_white.png');
|
// game.load.image('b', '../../../resources/image/icon/fullscreen_white.png');
|
||||||
|
|||||||
Reference in New Issue
Block a user