/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Class for falling blocks var FallingBlock = Container.expand(function () { var self = Container.call(this); self.containsPoint = function (point) { var localPoint = self.toLocal(point); return localPoint.x >= 0 && localPoint.y >= 0 && localPoint.x <= self.width && localPoint.y <= self.height; }; var blockGraphics = self.attachAsset('block', { anchorX: 0.5, anchorY: 0.5 }); var smallBlockGraphics = self.attachAsset('smallBlock', { width: 500, height: 400, anchorX: 0.5, anchorY: 0.5 }); var smallestBlockGraphics = self.attachAsset('smallestBlock', { width: 500, height: 125, anchorX: 0.5, anchorY: 0.5 }); self.speed = 40; self.update = function () { self.y += self.speed; if (self.y > 2732 || self.x < 0 || self.x > 2048) { self.destroy(); } }; self.down = function (x, y, obj) { if (Math.abs(self.y - 2632) < 50) { LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore() + " 一般OK"); var halo = new Halo(); halo.x = self.x; halo.y = self.y; halo.color = 0x808080; // grey color game.addChild(halo); self.destroy(); } else if (Math.abs(self.y + smallBlockGraphics.height / 2 - 2632) < 50) { LK.setScore(LK.getScore() + 2); scoreTxt.setText(LK.getScore() + " 良好Good"); var halo = new Halo(); halo.x = self.x; halo.y = self.y; halo.color = 0x0000ff; // blue color game.addChild(halo); self.destroy(); } else if (Math.abs(self.y + smallestBlockGraphics.height / 2 - 2632) < 50) { LK.setScore(LK.getScore() + 3); scoreTxt.setText(LK.getScore() + " 完美Perfect"); var halo = new Halo(); halo.x = self.x; halo.y = self.y; halo.color = 0xffff00; // gold color game.addChild(halo); self.destroy(); } }; }); // Class for halo effect var Halo = Container.expand(function () { var self = Container.call(this); var haloGraphics = self.attachAsset('halo', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.alpha -= 0.01; if (self.alpha <= 0) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ LK.on('keydown', function (event) { if (event.key >= '1' && event.key <= '4') { var laneIndex = parseInt(event.key) - 1; for (var i = 0; i < blocks.length; i++) { if (blocks[i].x === lanes[laneIndex]) { blocks[i].down(blocks[i].x, blocks[i].y, { global: { x: blocks[i].x, y: blocks[i].y } }); break; } } } }); var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.setText(LK.getScore()); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var blocks = []; var lanes = [512, 1024, 1536, 2048]; var whiteLine = new Container(); var whiteLineGraphics = whiteLine.attachAsset('line', { width: 2048, height: 20, color: 0xffffff, x: 0, y: 2402 }); game.addChild(whiteLine); function spawnBlock() { var lane = Math.max(50, Math.min(1898, lanes[Math.floor(Math.random() * lanes.length)])); var newBlock = new FallingBlock(); newBlock.x = lane; newBlock.y = 0; blocks.push(newBlock); game.addChild(newBlock); } var spawnInterval = LK.setInterval(spawnBlock, Math.random() * 1400 + 600); game.update = function () { for (var i = blocks.length - 1; i >= 0; i--) { if (blocks[i].y > 2732) { LK.setScore(LK.getScore() - 1); scoreTxt.setText(LK.getScore() + " 失误Miss"); blocks[i].destroy(); blocks.splice(i, 1); } } }; game.down = function (x, y, obj) { for (var i = 0; i < blocks.length; i++) { if (blocks[i].containsPoint({ x: x, y: y })) { blocks[i].down(x, y, obj); break; } } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Class for falling blocks
var FallingBlock = Container.expand(function () {
var self = Container.call(this);
self.containsPoint = function (point) {
var localPoint = self.toLocal(point);
return localPoint.x >= 0 && localPoint.y >= 0 && localPoint.x <= self.width && localPoint.y <= self.height;
};
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
var smallBlockGraphics = self.attachAsset('smallBlock', {
width: 500,
height: 400,
anchorX: 0.5,
anchorY: 0.5
});
var smallestBlockGraphics = self.attachAsset('smallestBlock', {
width: 500,
height: 125,
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 40;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 || self.x < 0 || self.x > 2048) {
self.destroy();
}
};
self.down = function (x, y, obj) {
if (Math.abs(self.y - 2632) < 50) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore() + " 一般OK");
var halo = new Halo();
halo.x = self.x;
halo.y = self.y;
halo.color = 0x808080; // grey color
game.addChild(halo);
self.destroy();
} else if (Math.abs(self.y + smallBlockGraphics.height / 2 - 2632) < 50) {
LK.setScore(LK.getScore() + 2);
scoreTxt.setText(LK.getScore() + " 良好Good");
var halo = new Halo();
halo.x = self.x;
halo.y = self.y;
halo.color = 0x0000ff; // blue color
game.addChild(halo);
self.destroy();
} else if (Math.abs(self.y + smallestBlockGraphics.height / 2 - 2632) < 50) {
LK.setScore(LK.getScore() + 3);
scoreTxt.setText(LK.getScore() + " 完美Perfect");
var halo = new Halo();
halo.x = self.x;
halo.y = self.y;
halo.color = 0xffff00; // gold color
game.addChild(halo);
self.destroy();
}
};
});
// Class for halo effect
var Halo = Container.expand(function () {
var self = Container.call(this);
var haloGraphics = self.attachAsset('halo', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.alpha -= 0.01;
if (self.alpha <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
LK.on('keydown', function (event) {
if (event.key >= '1' && event.key <= '4') {
var laneIndex = parseInt(event.key) - 1;
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].x === lanes[laneIndex]) {
blocks[i].down(blocks[i].x, blocks[i].y, {
global: {
x: blocks[i].x,
y: blocks[i].y
}
});
break;
}
}
}
});
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.setText(LK.getScore());
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var blocks = [];
var lanes = [512, 1024, 1536, 2048];
var whiteLine = new Container();
var whiteLineGraphics = whiteLine.attachAsset('line', {
width: 2048,
height: 20,
color: 0xffffff,
x: 0,
y: 2402
});
game.addChild(whiteLine);
function spawnBlock() {
var lane = Math.max(50, Math.min(1898, lanes[Math.floor(Math.random() * lanes.length)]));
var newBlock = new FallingBlock();
newBlock.x = lane;
newBlock.y = 0;
blocks.push(newBlock);
game.addChild(newBlock);
}
var spawnInterval = LK.setInterval(spawnBlock, Math.random() * 1400 + 600);
game.update = function () {
for (var i = blocks.length - 1; i >= 0; i--) {
if (blocks[i].y > 2732) {
LK.setScore(LK.getScore() - 1);
scoreTxt.setText(LK.getScore() + " 失误Miss");
blocks[i].destroy();
blocks.splice(i, 1);
}
}
};
game.down = function (x, y, obj) {
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].containsPoint({
x: x,
y: y
})) {
blocks[i].down(x, y, obj);
break;
}
}
};