===================================================================
--- original.js
+++ change.js
@@ -1,107 +1,145 @@
-var SpeechBubble = Container.expand(function (text) {
- var self = Container.call(this);
- var bubbleGraphics = self.createAsset('speechBubble', 'Speech Bubble', .5, .5);
- var bubbleText = new Text2(text, {
- size: 50,
- fill: '#000000'
- });
- bubbleText.anchor.set(.5, .5);
- self.addChild(bubbleText);
-});
-var Customer = Container.expand(function () {
- var self = Container.call(this);
- var customerGraphics = self.createAsset('customer', 'Customer', .5, .5);
- self.speechBubble = self.addChild(new SpeechBubble(''));
- self.speechBubble.y = -self.speechBubble.height - 30;
-});
+/****
+* Classes
+****/
var BubbleTea = Container.expand(function () {
var self = Container.call(this);
- var teaGraphics = self.createAsset('bubbleTea', 'Bubble Tea', .5, .5);
+ var teaGraphics = self.attachAsset('bubbleTea', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.ingredients = [];
self.speed = 10;
- self.catch = function (ingredient) {
+ self["catch"] = function (ingredient) {
self.ingredients.push(ingredient);
};
- self.move = function (direction) {
+ self._move_migrated = function (direction) {
self.x += self.speed * direction;
- if (self.x < teaGraphics.width / 2) self.x = teaGraphics.width / 2;
- if (self.x > 2048 - teaGraphics.width / 2) self.x = 2048 - teaGraphics.width / 2;
- if (self.y < teaGraphics.height / 2) self.y = teaGraphics.height / 2;
- if (self.y > 2732 - teaGraphics.height / 2) self.y = 2732 - teaGraphics.height / 2;
+ if (self.x < teaGraphics.width / 2) {
+ self.x = teaGraphics.width / 2;
+ }
+ if (self.x > 2048 - teaGraphics.width / 2) {
+ self.x = 2048 - teaGraphics.width / 2;
+ }
+ if (self.y < teaGraphics.height / 2) {
+ self.y = teaGraphics.height / 2;
+ }
+ if (self.y > 2732 - teaGraphics.height / 2) {
+ self.y = 2732 - teaGraphics.height / 2;
+ }
};
});
+var Customer = Container.expand(function () {
+ var self = Container.call(this);
+ var customerGraphics = self.attachAsset('customer', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speechBubble = self.addChild(new SpeechBubble(''));
+ self.speechBubble.y = -self.speechBubble.height - 30;
+});
var Ingredient = Container.expand(function (id) {
var self = Container.call(this);
self.id = id;
self.speed = Math.random() * 10 + 6;
- var ingredientGraphics = self.createAsset('ingredient' + id, 'Ingredient', .5, .5);
- self.move = function () {
+ var ingredientGraphics = self.createAsset('ingredient' + id, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 2732;
}
- if (self.x < ingredientGraphics.width / 2) self.x = ingredientGraphics.width / 2;
- if (self.x > 2048 - ingredientGraphics.width / 2) self.x = 2048 - ingredientGraphics.width / 2;
+ if (self.x < ingredientGraphics.width / 2) {
+ self.x = ingredientGraphics.width / 2;
+ }
+ if (self.x > 2048 - ingredientGraphics.width / 2) {
+ self.x = 2048 - ingredientGraphics.width / 2;
+ }
};
self.add = function () {};
});
-var Game = Container.expand(function () {
+var SpeechBubble = Container.expand(function (text) {
var self = Container.call(this);
- var score = 0;
- var scoreTxt = new Text2(score.toString(), {
- size: 100,
- fill: '#FFA500'
+ var bubbleGraphics = self.attachAsset('speechBubble', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- scoreTxt.anchor.set(0.5, 0.5);
- var scoreBox = LK.getAsset('scoreBox', 'Score Box', 0, 0);
- scoreBox.width = 200;
- scoreBox.height = 100;
- scoreBox.x = 2048 - scoreBox.width / 2;
- scoreBox.y = 2732 - scoreBox.height / 2;
- self.addChild(scoreBox);
- scoreBox.addChild(scoreTxt);
- scoreTxt.x = scoreBox.width / 2;
- scoreTxt.y = scoreBox.height / 2;
- self.updateScore = function (newScore) {
- score = newScore;
- scoreTxt.setText(score.toString());
- };
- var background = self.createAsset('background', 'Game Background', 0.5, 0.5);
- self.addChild(background);
- background.width = 2048;
- background.height = 2732;
- background.x = 2048 / 2;
- background.y = 2732 / 2;
- var ingredients = [];
- var customer = self.addChild(new Customer());
- customer.x = 500;
- customer.y = 2732 - customer.height / 2 + 300;
- var bubbleTea = self.addChild(new BubbleTea());
- bubbleTea.x = 2048 / 2;
- bubbleTea.y = 2732 - bubbleTea.height / 2;
- stage.on('move', function (obj) {
- var event = obj.event;
- var pos = event.getLocalPosition(self);
- bubbleTea.x = pos.x;
+ var bubbleText = new Text2(text, {
+ size: 50,
+ fill: '#000000'
});
- LK.on('tick', function () {
- for (var a = ingredients.length - 1; a >= 0; a--) {
- ingredients[a].move();
- if (ingredients[a].y >= 2732) {
- LK.showGameOver();
- } else if (bubbleTea.intersects(ingredients[a])) {
- bubbleTea.catch(ingredients[a]);
- ingredients[a].destroy();
- ingredients.splice(a, 1);
- self.updateScore(score + ingredients[a].speed);
- }
- }
- if (LK.ticks % 60 == 0) {
- var newIngredient = new Ingredient(Math.floor(Math.random() * 5));
- newIngredient.x = Math.random() * 2048;
- newIngredient.y = -newIngredient.height;
- ingredients.push(newIngredient);
- self.addChild(newIngredient);
- }
- });
+ bubbleText.anchor.set(.5, .5);
+ self.addChild(bubbleText);
});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var score = 0;
+var scoreTxt = new Text2(score.toString(), {
+ size: 100,
+ fill: '#FFA500'
+});
+scoreTxt.anchor.set(0.5, 0.5);
+var scoreBox = LK.getAsset('scoreBox', {});
+scoreBox.width = 200;
+scoreBox.height = 100;
+scoreBox.x = 2048 - scoreBox.width / 2;
+scoreBox.y = 2732 - scoreBox.height / 2;
+game.addChild(scoreBox);
+scoreBox.addChild(scoreTxt);
+scoreTxt.x = scoreBox.width / 2;
+scoreTxt.y = scoreBox.height / 2;
+game.updateScore = function (newScore) {
+ score = newScore;
+ scoreTxt.setText(score.toString());
+};
+var background = game.attachAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+game.addChild(background);
+background.width = 2048;
+background.height = 2732;
+background.x = 2048 / 2;
+background.y = 2732 / 2;
+var ingredients = [];
+var customer = game.addChild(new Customer());
+customer.x = 500;
+customer.y = 2732 - customer.height / 2 + 300;
+var bubbleTea = game.addChild(new BubbleTea());
+bubbleTea.x = 2048 / 2;
+bubbleTea.y = 2732 - bubbleTea.height / 2;
+game.on('move', function (x, y, obj) {
+ var event = obj;
+ var pos = game.toLocal(event.global);
+ bubbleTea.x = pos.x;
+});
+LK.on('tick', function () {
+ for (var a = ingredients.length - 1; a >= 0; a--) {
+ ingredients[a]._move_migrated();
+ if (ingredients[a].y >= 2732) {
+ LK.showGameOver();
+ } else if (bubbleTea.intersects(ingredients[a])) {
+ bubbleTea["catch"](ingredients[a]);
+ ingredients[a].destroy();
+ ingredients.splice(a, 1);
+ game.updateScore(score + ingredients[a].speed);
+ }
+ }
+ if (LK.ticks % 60 == 0) {
+ var newIngredient = new Ingredient(Math.floor(Math.random() * 5));
+ newIngredient.x = Math.random() * 2048;
+ newIngredient.y = -newIngredient.height;
+ ingredients.push(newIngredient);
+ game.addChild(newIngredient);
+ }
+});
\ No newline at end of file
Fruit jelly boba pearls, no cup Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pile of Fruit jelly boba pearls, no cup Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
kawaii harajuku customer, mask, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
fruit shiny anime, no face Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
boba pearls, pile, no cup, shiny anime Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red bean, shiny anime, pile no cup Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
shiny plastic cup, no lid, anime, empty Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
whipped milk foam, creamy fluff, anime, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
flan pudding, shiny, anime Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
anime angry lines, red cross Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
boba tea shop logo, kawaii anime, circular logo Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Tea shop interior, anime cafe Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Speech bubble 💬, "don't drop!" Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
UI point box, white square Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.