===================================================================
--- original.js
+++ change.js
@@ -1,44 +1,46 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
// Dart class
var Dart = Container.expand(function () {
- var self = Container.call(this);
- var dartGraphics = self.attachAsset('dart', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = -10;
- self.update = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var dartGraphics = self.attachAsset('dart', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -10;
+ self.gravity = 0.5;
+ self.update = function () {
+ self.speed += self.gravity;
+ self.y += self.speed;
+ };
});
// Target class
var Target = Container.expand(function () {
- var self = Container.call(this);
- var targetGraphics = self.attachAsset('target', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var self = Container.call(this);
+ var targetGraphics = self.attachAsset('target', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize score
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize target
@@ -48,25 +50,25 @@
// Initialize darts array
var darts = [];
// Mouse or touch down on the game
game.down = function (x, y, obj) {
- var newDart = new Dart();
- newDart.x = x;
- newDart.y = 2732 - 100; // Start from the bottom of the screen
- darts.push(newDart);
- game.addChild(newDart);
+ var newDart = new Dart();
+ newDart.x = x;
+ newDart.y = 2732 - 100; // Start from the bottom of the screen
+ darts.push(newDart);
+ game.addChild(newDart);
};
// Update game every tick
game.update = function () {
- for (var i = darts.length - 1; i >= 0; i--) {
- if (darts[i].intersects(target)) {
- // Update score
- score += 1;
- scoreTxt.setText(score);
- darts[i].destroy();
- darts.splice(i, 1);
- } else if (darts[i].y < -50) {
- darts[i].destroy();
- darts.splice(i, 1);
- }
- }
+ for (var i = darts.length - 1; i >= 0; i--) {
+ if (darts[i].intersects(target)) {
+ // Update score
+ score += 1;
+ scoreTxt.setText(score);
+ darts[i].destroy();
+ darts.splice(i, 1);
+ } else if (darts[i].y < -50) {
+ darts[i].destroy();
+ darts.splice(i, 1);
+ }
+ }
};
\ No newline at end of file