/**** * Classes ****/ // Blade class var Blade = Container.expand(function () { var self = Container.call(this); var bladeGraphics = self.attachAsset('blade', { anchorX: 0.5, anchorY: 0.5 }); self.updatePosition = function (x, y) { self.x = x; self.y = y; }; }); // Assets will be automatically created based on usage in the code. // Fish class var Fish = Container.expand(function () { var self = Container.call(this); var fishGraphics = self.attachAsset('fish', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 2 + 1; self.direction = Math.random() < 0.5 ? 1 : -1; self.move = function () { self.x += self.speed * self.direction; if (self.x > 2048 || self.x < 0) { self.direction *= -1; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to represent water }); /**** * Game Code ****/ var fishes = []; var blade; var score = 0; var scoreTxt = new Text2('Score: 0', { size: 100, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); // Create fishes for (var i = 0; i < 10; i++) { var fish = new Fish(); fish.x = Math.random() * 2048; fish.y = Math.random() * 2732; game.addChild(fish); fishes.push(fish); } // Create blade blade = new Blade(); game.addChild(blade); // Handle touch move game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); blade.updatePosition(pos.x, pos.y); // Check for collisions with fishes fishes.forEach(function (fish, index) { if (blade.intersects(fish)) { // Increase score score++; scoreTxt.setText('Score: ' + score); // Remove fish fish.destroy(); fishes.splice(index, 1); // Add a new fish var newFish = new Fish(); newFish.x = Math.random() * 2048; newFish.y = Math.random() * 2732; game.addChild(newFish); fishes.push(newFish); } }); }); // Game tick LK.on('tick', function () { // Move fishes fishes.forEach(function (fish) { fish.move(); }); });
/****
* Classes
****/
// Blade class
var Blade = Container.expand(function () {
var self = Container.call(this);
var bladeGraphics = self.attachAsset('blade', {
anchorX: 0.5,
anchorY: 0.5
});
self.updatePosition = function (x, y) {
self.x = x;
self.y = y;
};
});
// Assets will be automatically created based on usage in the code.
// Fish class
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1;
self.direction = Math.random() < 0.5 ? 1 : -1;
self.move = function () {
self.x += self.speed * self.direction;
if (self.x > 2048 || self.x < 0) {
self.direction *= -1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent water
});
/****
* Game Code
****/
var fishes = [];
var blade;
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Create fishes
for (var i = 0; i < 10; i++) {
var fish = new Fish();
fish.x = Math.random() * 2048;
fish.y = Math.random() * 2732;
game.addChild(fish);
fishes.push(fish);
}
// Create blade
blade = new Blade();
game.addChild(blade);
// Handle touch move
game.on('move', function (obj) {
var pos = obj.event.getLocalPosition(game);
blade.updatePosition(pos.x, pos.y);
// Check for collisions with fishes
fishes.forEach(function (fish, index) {
if (blade.intersects(fish)) {
// Increase score
score++;
scoreTxt.setText('Score: ' + score);
// Remove fish
fish.destroy();
fishes.splice(index, 1);
// Add a new fish
var newFish = new Fish();
newFish.x = Math.random() * 2048;
newFish.y = Math.random() * 2732;
game.addChild(newFish);
fishes.push(newFish);
}
});
});
// Game tick
LK.on('tick', function () {
// Move fishes
fishes.forEach(function (fish) {
fish.move();
});
});
日本の包丁. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
忍者鰯. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
侍蛸. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
殿様鯨. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆弾クラーケン. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.