/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Particle = Container.expand(function (startX, startY) {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = startX;
self.y = startY;
self.velocityX = (Math.random() - 0.5) * 10;
self.velocityY = (Math.random() - 0.5) * 10 - 5;
self.life = 1.0;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.5; // gravity
self.life -= 0.03;
self.alpha = self.life;
if (self.life <= 0) {
self.destroy();
particles.splice(particles.indexOf(self), 1);
}
};
return self;
});
var Tile = Container.expand(function (column, color) {
var self = Container.call(this);
var assetName = 'tile_' + color;
var tileGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.column = column;
self.color = color;
self.speed = tileSpeed;
self.hasBeenHit = false;
self.lastY = 0;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
self.hit = function () {
if (self.hasBeenHit) return false;
self.hasBeenHit = true;
// Play sound based on column
var sounds = ['note_c', 'note_d', 'note_e', 'note_f'];
LK.getSound(sounds[self.column]).play();
// Visual feedback
LK.effects.flashObject(self, 0xffffff, 300);
tween(self, {
alpha: 0,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
// Create particles
createParticles(self.x, self.y);
return true;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x111111
});
/****
* Game Code
****/
// Game variables
var columns = [];
var tiles = [];
var particles = [];
var columnWidth = 450;
var columnSpacing = 62;
var tileSpeed = 4;
var spawnRate = 120;
var ticksSinceLastSpawn = 0;
var combo = 0;
var speedIncreaseInterval = 10;
var hitCount = 0;
var strikeZoneY = 2732 - 250;
// Create column backgrounds and strike zones
for (var i = 0; i < 4; i++) {
var columnX = 250 + i * (columnWidth + columnSpacing);
// Column background
var columnBg = game.attachAsset('column_bg', {
anchorX: 0.5,
anchorY: 0,
x: columnX,
y: 0
});
// Strike zone
var strikeZone = game.attachAsset('strike_zone', {
anchorX: 0.5,
anchorY: 0.5,
x: columnX,
y: strikeZoneY,
alpha: 0.3
});
columns.push({
x: columnX,
strikeZone: strikeZone
});
}
// UI Elements
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var comboTxt = new Text2('', {
size: 80,
fill: 0xFFFF00
});
comboTxt.anchor.set(0.5, 0);
comboTxt.y = 150;
LK.gui.top.addChild(comboTxt);
// Functions
function spawnTile() {
var columnIndex = Math.floor(Math.random() * 4);
var colors = ['red', 'blue', 'green', 'yellow'];
var color = colors[Math.floor(Math.random() * colors.length)];
var tile = new Tile(columnIndex, color);
tile.x = columns[columnIndex].x;
tile.y = -75;
tiles.push(tile);
game.addChild(tile);
}
function createParticles(x, y) {
for (var i = 0; i < 8; i++) {
var particle = new Particle(x, y);
particles.push(particle);
game.addChild(particle);
}
}
function checkTileHit(x, y) {
var hitTile = null;
var minDistance = Infinity;
for (var i = 0; i < tiles.length; i++) {
var tile = tiles[i];
if (tile.hasBeenHit) continue;
// Check if click is in tile's column
var columnX = columns[tile.column].x;
if (Math.abs(x - columnX) < columnWidth / 2) {
// Check if tile is in strike zone
if (tile.y >= strikeZoneY - 100 && tile.y <= strikeZoneY + 100) {
var distance = Math.abs(tile.y - strikeZoneY);
if (distance < minDistance) {
minDistance = distance;
hitTile = tile;
}
}
}
}
return hitTile;
}
function gameOver() {
LK.getSound('miss').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
function updateScore() {
scoreTxt.setText(LK.getScore());
if (combo > 1) {
comboTxt.setText('COMBO x' + combo);
comboTxt.alpha = 1;
} else {
comboTxt.alpha = 0;
}
}
// Game events
game.down = function (x, y, obj) {
var hitTile = checkTileHit(x, y);
if (hitTile) {
if (hitTile.hit()) {
hitCount++;
combo++;
// Score based on combo
var points = combo >= 5 ? 5 : combo;
LK.setScore(LK.getScore() + points);
// Speed increase every 10 hits
if (hitCount % speedIncreaseInterval === 0) {
tileSpeed += 0.5;
spawnRate = Math.max(60, spawnRate - 5);
}
// Remove tile from array
var index = tiles.indexOf(hitTile);
if (index > -1) {
tiles.splice(index, 1);
}
updateScore();
}
} else {
// Missed - game over
combo = 0;
gameOver();
}
};
// Main game loop
game.update = function () {
// Spawn tiles
ticksSinceLastSpawn++;
if (ticksSinceLastSpawn >= spawnRate) {
spawnTile();
ticksSinceLastSpawn = 0;
}
// Update tiles
for (var i = tiles.length - 1; i >= 0; i--) {
var tile = tiles[i];
// Check if tile passed strike zone without being hit
if (!tile.hasBeenHit && tile.lastY < strikeZoneY + 150 && tile.y >= strikeZoneY + 150) {
combo = 0;
gameOver();
return;
}
// Remove tiles that are off screen
if (tile.y > 2800) {
if (!tile.hasBeenHit) {
tile.destroy();
tiles.splice(i, 1);
}
}
}
// Update particles
for (var i = particles.length - 1; i >= 0; i--) {
var particle = particles[i];
if (particle.life <= 0) {
particles.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,247 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Particle = Container.expand(function (startX, startY) {
+ var self = Container.call(this);
+ var particleGraphics = self.attachAsset('particle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = startX;
+ self.y = startY;
+ self.velocityX = (Math.random() - 0.5) * 10;
+ self.velocityY = (Math.random() - 0.5) * 10 - 5;
+ self.life = 1.0;
+ self.update = function () {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityY += 0.5; // gravity
+ self.life -= 0.03;
+ self.alpha = self.life;
+ if (self.life <= 0) {
+ self.destroy();
+ particles.splice(particles.indexOf(self), 1);
+ }
+ };
+ return self;
+});
+var Tile = Container.expand(function (column, color) {
+ var self = Container.call(this);
+ var assetName = 'tile_' + color;
+ var tileGraphics = self.attachAsset(assetName, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.column = column;
+ self.color = color;
+ self.speed = tileSpeed;
+ self.hasBeenHit = false;
+ self.lastY = 0;
+ self.update = function () {
+ self.lastY = self.y;
+ self.y += self.speed;
+ };
+ self.hit = function () {
+ if (self.hasBeenHit) return false;
+ self.hasBeenHit = true;
+ // Play sound based on column
+ var sounds = ['note_c', 'note_d', 'note_e', 'note_f'];
+ LK.getSound(sounds[self.column]).play();
+ // Visual feedback
+ LK.effects.flashObject(self, 0xffffff, 300);
+ tween(self, {
+ alpha: 0,
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ // Create particles
+ createParticles(self.x, self.y);
+ return true;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x111111
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var columns = [];
+var tiles = [];
+var particles = [];
+var columnWidth = 450;
+var columnSpacing = 62;
+var tileSpeed = 4;
+var spawnRate = 120;
+var ticksSinceLastSpawn = 0;
+var combo = 0;
+var speedIncreaseInterval = 10;
+var hitCount = 0;
+var strikeZoneY = 2732 - 250;
+// Create column backgrounds and strike zones
+for (var i = 0; i < 4; i++) {
+ var columnX = 250 + i * (columnWidth + columnSpacing);
+ // Column background
+ var columnBg = game.attachAsset('column_bg', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: columnX,
+ y: 0
+ });
+ // Strike zone
+ var strikeZone = game.attachAsset('strike_zone', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: columnX,
+ y: strikeZoneY,
+ alpha: 0.3
+ });
+ columns.push({
+ x: columnX,
+ strikeZone: strikeZone
+ });
+}
+// UI Elements
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var comboTxt = new Text2('', {
+ size: 80,
+ fill: 0xFFFF00
+});
+comboTxt.anchor.set(0.5, 0);
+comboTxt.y = 150;
+LK.gui.top.addChild(comboTxt);
+// Functions
+function spawnTile() {
+ var columnIndex = Math.floor(Math.random() * 4);
+ var colors = ['red', 'blue', 'green', 'yellow'];
+ var color = colors[Math.floor(Math.random() * colors.length)];
+ var tile = new Tile(columnIndex, color);
+ tile.x = columns[columnIndex].x;
+ tile.y = -75;
+ tiles.push(tile);
+ game.addChild(tile);
+}
+function createParticles(x, y) {
+ for (var i = 0; i < 8; i++) {
+ var particle = new Particle(x, y);
+ particles.push(particle);
+ game.addChild(particle);
+ }
+}
+function checkTileHit(x, y) {
+ var hitTile = null;
+ var minDistance = Infinity;
+ for (var i = 0; i < tiles.length; i++) {
+ var tile = tiles[i];
+ if (tile.hasBeenHit) continue;
+ // Check if click is in tile's column
+ var columnX = columns[tile.column].x;
+ if (Math.abs(x - columnX) < columnWidth / 2) {
+ // Check if tile is in strike zone
+ if (tile.y >= strikeZoneY - 100 && tile.y <= strikeZoneY + 100) {
+ var distance = Math.abs(tile.y - strikeZoneY);
+ if (distance < minDistance) {
+ minDistance = distance;
+ hitTile = tile;
+ }
+ }
+ }
+ }
+ return hitTile;
+}
+function gameOver() {
+ LK.getSound('miss').play();
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+}
+function updateScore() {
+ scoreTxt.setText(LK.getScore());
+ if (combo > 1) {
+ comboTxt.setText('COMBO x' + combo);
+ comboTxt.alpha = 1;
+ } else {
+ comboTxt.alpha = 0;
+ }
+}
+// Game events
+game.down = function (x, y, obj) {
+ var hitTile = checkTileHit(x, y);
+ if (hitTile) {
+ if (hitTile.hit()) {
+ hitCount++;
+ combo++;
+ // Score based on combo
+ var points = combo >= 5 ? 5 : combo;
+ LK.setScore(LK.getScore() + points);
+ // Speed increase every 10 hits
+ if (hitCount % speedIncreaseInterval === 0) {
+ tileSpeed += 0.5;
+ spawnRate = Math.max(60, spawnRate - 5);
+ }
+ // Remove tile from array
+ var index = tiles.indexOf(hitTile);
+ if (index > -1) {
+ tiles.splice(index, 1);
+ }
+ updateScore();
+ }
+ } else {
+ // Missed - game over
+ combo = 0;
+ gameOver();
+ }
+};
+// Main game loop
+game.update = function () {
+ // Spawn tiles
+ ticksSinceLastSpawn++;
+ if (ticksSinceLastSpawn >= spawnRate) {
+ spawnTile();
+ ticksSinceLastSpawn = 0;
+ }
+ // Update tiles
+ for (var i = tiles.length - 1; i >= 0; i--) {
+ var tile = tiles[i];
+ // Check if tile passed strike zone without being hit
+ if (!tile.hasBeenHit && tile.lastY < strikeZoneY + 150 && tile.y >= strikeZoneY + 150) {
+ combo = 0;
+ gameOver();
+ return;
+ }
+ // Remove tiles that are off screen
+ if (tile.y > 2800) {
+ if (!tile.hasBeenHit) {
+ tile.destroy();
+ tiles.splice(i, 1);
+ }
+ }
+ }
+ // Update particles
+ for (var i = particles.length - 1; i >= 0; i--) {
+ var particle = particles[i];
+ if (particle.life <= 0) {
+ particles.splice(i, 1);
+ }
+ }
+};
\ No newline at end of file