/**** * 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 (type) { var self = Container.call(this); var fishGraphics = self.attachAsset(type, { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 2 + 1; self.direction = Math.random() < 0.5 ? 1 : -1; self.hits = type === 'fish1' ? 1 : type === 'fish2' ? 2 : 3; // High score fish require more hits 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 type = 'fish' + (i % 3 + 1); var fish = new Fish(type); fish.x = Math.random() * 2048; fish.y = Math.random() * 2732; fish.score = (i % 3 + 1) * 10; 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)) { fish.hits--; if (fish.hits <= 0) { // Increase score score += fish.score; scoreTxt.setText('Score: ' + score); // Remove fish fish.destroy(); fishes.splice(index, 1); // Add a new fish var type = 'fish' + (Math.floor(Math.random() * 3) + 1); var newFish = new Fish(type); newFish.x = Math.random() * 2048; newFish.y = Math.random() * 2732; newFish.score = (type === 'fish1' ? 1 : type === 'fish2' ? 2 : 3) * 10; game.addChild(newFish); fishes.push(newFish); } } }); }); // Game tick LK.on('tick', function () { // Move fishes fishes.forEach(function (fish) { fish.move(); }); });
===================================================================
--- original.js
+++ change.js
@@ -14,16 +14,17 @@
};
});
// Assets will be automatically created based on usage in the code.
// Fish class
-var Fish = Container.expand(function () {
+var Fish = Container.expand(function (type) {
var self = Container.call(this);
var fishGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1;
self.direction = Math.random() < 0.5 ? 1 : -1;
+ self.hits = type === 'fish1' ? 1 : type === 'fish2' ? 2 : 3; // High score fish require more hits
self.move = function () {
self.x += self.speed * self.direction;
if (self.x > 2048 || self.x < 0) {
self.direction *= -1;
@@ -68,20 +69,25 @@
blade.updatePosition(pos.x, pos.y);
// Check for collisions with fishes
fishes.forEach(function (fish, index) {
if (blade.intersects(fish)) {
- // Increase score
- score += fish.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);
+ fish.hits--;
+ if (fish.hits <= 0) {
+ // Increase score
+ score += fish.score;
+ scoreTxt.setText('Score: ' + score);
+ // Remove fish
+ fish.destroy();
+ fishes.splice(index, 1);
+ // Add a new fish
+ var type = 'fish' + (Math.floor(Math.random() * 3) + 1);
+ var newFish = new Fish(type);
+ newFish.x = Math.random() * 2048;
+ newFish.y = Math.random() * 2732;
+ newFish.score = (type === 'fish1' ? 1 : type === 'fish2' ? 2 : 3) * 10;
+ game.addChild(newFish);
+ fishes.push(newFish);
+ }
}
});
});
// Game tick
日本の包丁. 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.