===================================================================
--- original.js
+++ change.js
@@ -1,25 +1,40 @@
-var SmokeParticle = Container.expand(function (startX, startY) {
+/****
+* Classes
+****/
+var Arrow = Container.expand(function () {
var self = Container.call(this);
- var smokeGraphics = self.createAsset('smoke', 'Smoke Graphics', .5, .5);
- self.x = startX;
- self.y = startY;
- var scale = 1;
- var scaleRate = 1 / (1 * 60);
- self.animate = function () {
- scale -= scaleRate;
- if (scale <= 0) {
- self.destroy();
- return;
- }
- self.scale.x = scale;
- self.scale.y = scale;
+ var arrowGraphics = self.attachAsset('arrow', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ arrowGraphics.rotation = -135 * (Math.PI / 180);
+ self.speed = 30 * 0.85;
+ self.gravity = 0.2 * 1.3 * 0.9 * 0.9 * 0.9 * 0.5;
+ self.velocityY = 0;
+ self._move_migrated = function () {
+ self.x += self.speed * Math.cos(self.rotation);
+ self.y += self.speed * Math.sin(self.rotation) + self.velocityY;
+ self.velocityY += self.gravity;
+ self.rotation += 0.01 * 1.5;
};
- LK.on('tick', self.animate);
});
+var Firework = Container.expand(function () {
+ var self = Container.call(this);
+ var fireworkGraphics = self.attachAsset('firework', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ LK.setTimeout(function () {
+ self.destroy();
+ }, 1000);
+});
var FireworkParticle = Container.expand(function (startX, startY) {
var self = Container.call(this);
- var fireworkGraphics = self.createAsset('firework', 'Firework Graphics', .5, .5);
+ var fireworkGraphics = self.attachAsset('firework', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.x = startX;
self.y = startY;
var endX = Math.random() * 2048;
var endY = Math.random() * (2732 - 600) + 300;
@@ -37,19 +52,11 @@
self.scale.y = 1 - progress;
};
LK.on('tick', self.animate);
});
-var Firework = Container.expand(function () {
- var self = Container.call(this);
- var fireworkGraphics = self.createAsset('firework', 'Firework Graphics', .5, .5);
- LK.setTimeout(function () {
- self.destroy();
- }, 1000);
-});
var Player = Container.expand(function () {
var self = Container.call(this);
Player.prototype.easeAndMoveVertical = function (newX, newY) {
- var self = this;
var startTime = LK.ticks;
var duration = 30;
var startX = self.x;
var startY = self.y;
@@ -68,23 +75,33 @@
easingComplete = true;
}
});
};
- var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
});
-var Arrow = Container.expand(function () {
+var SmokeParticle = Container.expand(function (startX, startY) {
var self = Container.call(this);
- var arrowGraphics = self.createAsset('arrow', 'Arrow Graphics', .5, .5);
- arrowGraphics.rotation = -135 * (Math.PI / 180);
- self.speed = 30 * 0.85;
- self.gravity = 0.2 * 1.3 * 0.9 * 0.9 * 0.9 * 0.5;
- self.velocityY = 0;
- self.move = function () {
- self.x += self.speed * Math.cos(self.rotation);
- self.y += self.speed * Math.sin(self.rotation) + self.velocityY;
- self.velocityY += self.gravity;
- self.rotation += 0.01 * 1.5;
+ var smokeGraphics = self.attachAsset('smoke', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = startX;
+ self.y = startY;
+ var scale = 1;
+ var scaleRate = 1 / (1 * 60);
+ self.animate = function () {
+ scale -= scaleRate;
+ if (scale <= 0) {
+ self.destroy();
+ return;
+ }
+ self.scale.x = scale;
+ self.scale.y = scale;
};
+ LK.on('tick', self.animate);
});
var Target = Container.expand(function () {
var self = Container.call(this);
self.easeAndMoveVertical = function (newX, newY) {
@@ -112,99 +129,110 @@
self.startVerticalMovement = function () {
self.direction = 1;
self.speed = 4;
};
- var targetGraphics = self.createAsset('target', 'Target Graphics', .5, .5);
+ var targetGraphics = self.attachAsset('target', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
targetGraphics.scale.x = -1;
self.speed = 2;
self.direction = 1;
- self.move = function () {
+ self._move_migrated = function () {
self.y += self.speed * self.direction;
if (self.y >= 2732 * .75 - self.height / 2 || self.y <= 2732 * .24 + self.height / 2) {
self.direction *= -1;
}
};
});
-var Game = Container.expand(function () {
- var self = Container.call(this);
- var bg = self.createAsset('background', 'Background Image', 0, 0);
- bg.width = 2048;
- bg.height = 2732;
- var arrows = [];
- var targets = [];
- var score = 0;
- var arrowCount = 5;
- var arrowCountTxt = new Text2('Arrows: ' + arrowCount, {
- size: 100,
- fill: "#ffffff"
- });
- arrowCountTxt.anchor.set(0.5, 0);
- LK.gui.topCenter.addChild(arrowCountTxt);
- var scoreTxt = new Text2('Score: 0', {
- size: 100,
- fill: "#ffffff"
- });
- scoreTxt.anchor.set(1, 0);
- LK.gui.topRight.addChild(scoreTxt);
- scoreTxt.y = arrowCountTxt.y;
- var player = self.addChild(new Player());
- player.x = 150;
- player.y = 2732 / 2;
- var target = self.addChild(new Target());
- target.x = 2048 - target.width / 2;
- target.y = 2732 / 2;
- var arrow;
- stage.on('move', function (obj) {
- var event = obj.event;
- var pos = event.getLocalPosition(self);
- var dx = pos.x - player.x;
- var dy = pos.y - player.y;
- var angle = Math.atan2(dy, dx);
- player.rotation = angle;
- });
- stage.on('up', function (obj) {
- if (arrowCount > 0) {
- arrow = self.addChild(new Arrow());
- arrow.x = player.x;
- arrow.y = player.y;
- arrow.rotation = player.rotation - Math.PI / 6 + 5 * (Math.PI / 180);
- arrows.push(arrow);
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var bg = game.attachAsset('background', {});
+bg.width = 2048;
+bg.height = 2732;
+var arrows = [];
+var targets = [];
+var score = 0;
+var arrowCount = 5;
+var arrowCountTxt = new Text2('Arrows: ' + arrowCount, {
+ size: 100,
+ fill: "#ffffff"
+});
+arrowCountTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(arrowCountTxt);
+var scoreTxt = new Text2('Score: 0', {
+ size: 100,
+ fill: "#ffffff"
+});
+scoreTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(scoreTxt);
+scoreTxt.y = arrowCountTxt.y;
+var player = game.addChild(new Player());
+player.x = 150;
+player.y = 2732 / 2;
+var target = game.addChild(new Target());
+target.x = 2048 - target.width / 2;
+target.y = 2732 / 2;
+var arrow;
+game.on('move', function (x, y, obj) {
+ var event = obj;
+ var pos = game.toLocal(event.global);
+ var dx = pos.x - player.x;
+ var dy = pos.y - player.y;
+ var angle = Math.atan2(dy, dx);
+ player.rotation = angle;
+});
+game.on('up', function (x, y, obj) {
+ if (arrowCount > 0) {
+ arrow = game.addChild(new Arrow());
+ arrow.x = player.x;
+ arrow.y = player.y;
+ arrow.rotation = player.rotation - Math.PI / 6 + 5 * (Math.PI / 180);
+ arrows.push(arrow);
+ }
+});
+LK.on('tick', function () {
+ target._move_migrated();
+ for (var a = arrows.length - 1; a >= 0; a--) {
+ var smoke = new SmokeParticle(arrows[a].x, arrows[a].y);
+ game.addChildAt(smoke, game.getChildIndex(arrows[a]));
+ arrows[a]._move_migrated();
+ if (arrows[a].x > 2048) {
+ arrowCount--;
+ arrows[a].destroy();
+ arrows.splice(a, 1);
+ arrowCountTxt.setText('Arrows: ' + arrowCount);
+ if (arrowCount == 0) {
+ LK.showGameOver();
+ }
}
- });
- LK.on('tick', function () {
- target.move();
- for (var a = arrows.length - 1; a >= 0; a--) {
- var smoke = new SmokeParticle(arrows[a].x, arrows[a].y);
- self.addChildAt(smoke, self.getChildIndex(arrows[a]));
- arrows[a].move();
- if (arrows[a].x > 2048) {
- arrowCount--;
- arrows[a].destroy();
- arrows.splice(a, 1);
- arrowCountTxt.setText('Arrows: ' + arrowCount);
- if (arrowCount == 0) {
- LK.showGameOver();
- }
+ if (arrows[a] && arrows[a].intersects(target) && arrows[a].y > target.y - target.height / 4 && arrows[a].y < target.y + target.height / 4) {
+ score++;
+ scoreTxt.setText('Score: ' + score);
+ if (target.width > 50 && target.height > 50) {
+ target.scale.x *= 0.95;
+ target.scale.y *= 0.95;
}
- if (arrows[a] && arrows[a].intersects(target) && arrows[a].y > target.y - target.height / 4 && arrows[a].y < target.y + target.height / 4) {
- score++;
- scoreTxt.setText('Score: ' + score);
- if (target.width > 50 && target.height > 50) {
- target.scale.x *= 0.95;
- target.scale.y *= 0.95;
- }
- target.speed *= 1.2;
- var newX = Math.random() * (2048 * 0.2) + 2048 * 0.7;
- var newY = Math.random() * (2732 / 2 + 300 - (2732 / 2 - 300)) + 2732 / 2 - 300;
- target.easeAndMoveVertical(newX, newY);
- for (var i = 0; i < 10; i++) {
- self.addChild(new FireworkParticle(arrows[a].x, arrows[a].y));
- }
- arrows[a].destroy();
- arrows.splice(a, 1);
- var newPlayerX = Math.random() * (400 - 100) + 100;
- var newPlayerY = Math.random() * (2732 / 2 + 300 - (2732 / 2 - 300)) + 2732 / 2 - 300;
- player.easeAndMoveVertical(newPlayerX, newPlayerY);
+ target.speed *= 1.2;
+ var newX = Math.random() * (2048 * 0.2) + 2048 * 0.7;
+ var newY = Math.random() * (2732 / 2 + 300 - (2732 / 2 - 300)) + 2732 / 2 - 300;
+ target.easeAndMoveVertical(newX, newY);
+ for (var i = 0; i < 10; i++) {
+ game.addChild(new FireworkParticle(arrows[a].x, arrows[a].y));
}
+ arrows[a].destroy();
+ arrows.splice(a, 1);
+ var newPlayerX = Math.random() * (400 - 100) + 100;
+ var newPlayerY = Math.random() * (2732 / 2 + 300 - (2732 / 2 - 300)) + 2732 / 2 - 300;
+ player.easeAndMoveVertical(newPlayerX, newPlayerY);
}
- });
-});
+ }
+});
\ No newline at end of file
plain gold star, no outline Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
tasty burger. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
small figure of one funny and fat angry man, with brown beard and open mouth, 2d game character. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
star in colors of russian flag, 2d game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Yerevan road from top view, 2d
funny and stupid cock in suit, old, bold head, russian flag, 2d game character. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.