User prompt
remove shop background
User prompt
make shop not pause the game
User prompt
enemies arent spawning
User prompt
i dont see the shop button
User prompt
button that opens shop
User prompt
add a ui on the top right called shop
User prompt
add a shop that pauses the background and opens a shop with upgrades for example timestop duration upgrade and lower enemy spawn rate
User prompt
make bullet fly for 100 miliseconds in the timestop and then stop and unfreeze when timestop ends
User prompt
make right click stop time
User prompt
add damaging moves
Initial prompt
jojo timestop game
/**** * Classes ****/ // HeroBullet class representing the hero's projectiles var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet', 0.5, 0.5); self.speed = -10; self.move = function () { if (!hero.isTimestopped || self.timestopActive) { self.y += self.speed; } }; self.timestopActive = false; self.activateTimestop = function () { self.timestopActive = true; LK.setTimeout(function () { self.timestopActive = false; }, 100); }; self.isOffScreen = function () { return self.y < -self.height; }; }); // Hero class representing the main character var Hero = Container.expand(function () { var self = Container.call(this); self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - self.height / 2; game.addChild(bullet); return bullet; }; var heroGraphics = self.createAsset('jojoHero', 'Main Hero', 0.5, 0.5); self.speed = 5; self.isTimestopped = false; self.timestopDuration = 3000; // Initial timestop duration self.move = function (direction) { if (self.isTimestopped) { return; } if (direction === 'left') { self.x -= self.speed; } if (direction === 'right') { self.x += self.speed; } if (direction === 'up') { self.y -= self.speed; } if (direction === 'down') { self.y += self.speed; } }; self.timestop = function () { self.isTimestopped = true; heroBullets.forEach(function (bullet) { bullet.activateTimestop(); }); LK.setTimeout(function () { self.isTimestopped = false; }, self.timestopDuration); }; }); // Enemy class representing the adversaries var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('jojoEnemy', 'Enemy Character', 0.5, 0.5); self.speed = 2; self.move = function () { if (hero.isTimestopped) { return; } self.y += self.speed; }; }); var Shop = Container.expand(function () { var self = Container.call(this); var shopGraphics = self.createAsset('shopBackground', 'Shop Background', 0.5, 0.5); self.visible = false; self.upgrades = { timestopDuration: { cost: 100, effect: function effect() { hero.timestopDuration += 1000; } }, enemySpawnRate: { cost: 100, effect: function effect() { game.enemySpawnRate += 30; } } }; self.show = function () { self.visible = true; game.paused = true; }; self.hide = function () { self.visible = false; game.paused = false; }; self.purchaseUpgrade = function (upgrade) { if (score >= self.upgrades[upgrade].cost) { updateScore(-self.upgrades[upgrade].cost); self.upgrades[upgrade].effect(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000, // Init game with black background paused: false, enemySpawnRate: 120 // Initial spawn rate }); /**** * Game Code ****/ var shop = game.addChild(new Shop()); // Initialize hero var hero = game.addChild(new Hero()); hero.x = game.width / 2; hero.y = game.height - 100; // Initialize enemies array var enemies = []; // Initialize hero bullets array var heroBullets = []; // Initialize score var score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Function to update score function updateScore(value) { score += value; scoreTxt.setText(score.toString()); } // Function to spawn enemies function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * (game.width - enemy.width) + enemy.width / 2; enemy.y = -enemy.height; enemies.push(enemy); game.addChild(enemy); } // Event listener for touch events on the hero hero.on('down', function (obj) { var bullet = hero.shoot(); heroBullets.push(bullet); }); // Event listener for right-click events on the game area to trigger timestop game.on('rightdown', function (obj) { hero.timestop(); }); // Event listener for two-finger tap events on the game area to open the shop // Note: LK does not have a 'tap' event, so we simulate it with 'down' and 'up' events var touchCount = 0; game.on('down', function (obj) { touchCount++; if (touchCount === 2) { shop.show(); } }); game.on('up', function (obj) { touchCount = 0; }); // Event listener for touch move events on the game area game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); hero.x = pos.x; hero.y = pos.y; }); // Main game loop LK.on('tick', function () { if (game.paused) { return; } // Move hero based on touch input (handled by event listeners) // Move enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].move(); // Check for collision with hero if (enemies[i].intersects(hero)) { LK.effects.flashScreen(0xff0000, 500); LK.showGameOver(); return; } // Remove enemies that are off-screen if (enemies[i].y > game.height + enemies[i].height) { enemies[i].destroy(); enemies.splice(i, 1); updateScore(-1); } } // Move hero bullets for (var b = heroBullets.length - 1; b >= 0; b--) { heroBullets[b].move(); // Check for collision with enemies for (var e = enemies.length - 1; e >= 0; e--) { if (heroBullets[b].intersects(enemies[e])) { enemies[e].destroy(); enemies.splice(e, 1); updateScore(1); } } // Remove bullets that are off-screen if (heroBullets[b].isOffScreen()) { heroBullets[b].destroy(); heroBullets.splice(b, 1); } } // Spawn enemies at random intervals if (LK.ticks % game.enemySpawnRate === 0) { spawnEnemy(); } });
===================================================================
--- original.js
+++ change.js
@@ -34,8 +34,9 @@
};
var heroGraphics = self.createAsset('jojoHero', 'Main Hero', 0.5, 0.5);
self.speed = 5;
self.isTimestopped = false;
+ self.timestopDuration = 3000; // Initial timestop duration
self.move = function (direction) {
if (self.isTimestopped) {
return;
}
@@ -58,9 +59,9 @@
bullet.activateTimestop();
});
LK.setTimeout(function () {
self.isTimestopped = false;
- }, 3000); // Timestop effect lasts for 3 seconds
+ }, self.timestopDuration);
};
});
// Enemy class representing the adversaries
var Enemy = Container.expand(function () {
@@ -73,19 +74,57 @@
}
self.y += self.speed;
};
});
+var Shop = Container.expand(function () {
+ var self = Container.call(this);
+ var shopGraphics = self.createAsset('shopBackground', 'Shop Background', 0.5, 0.5);
+ self.visible = false;
+ self.upgrades = {
+ timestopDuration: {
+ cost: 100,
+ effect: function effect() {
+ hero.timestopDuration += 1000;
+ }
+ },
+ enemySpawnRate: {
+ cost: 100,
+ effect: function effect() {
+ game.enemySpawnRate += 30;
+ }
+ }
+ };
+ self.show = function () {
+ self.visible = true;
+ game.paused = true;
+ };
+ self.hide = function () {
+ self.visible = false;
+ game.paused = false;
+ };
+ self.purchaseUpgrade = function (upgrade) {
+ if (score >= self.upgrades[upgrade].cost) {
+ updateScore(-self.upgrades[upgrade].cost);
+ self.upgrades[upgrade].effect();
+ }
+ };
+});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000,
+ // Init game with black background
+ paused: false,
+ enemySpawnRate: 120 // Initial spawn rate
});
/****
* Game Code
****/
+var shop = game.addChild(new Shop());
+
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = game.width / 2;
hero.y = game.height - 100;
@@ -127,9 +166,20 @@
// Event listener for right-click events on the game area to trigger timestop
game.on('rightdown', function (obj) {
hero.timestop();
+}); // Event listener for two-finger tap events on the game area to open the shop
+// Note: LK does not have a 'tap' event, so we simulate it with 'down' and 'up' events
+var touchCount = 0;
+game.on('down', function (obj) {
+ touchCount++;
+ if (touchCount === 2) {
+ shop.show();
+ }
});
+game.on('up', function (obj) {
+ touchCount = 0;
+});
// Event listener for touch move events on the game area
game.on('move', function (obj) {
var pos = obj.event.getLocalPosition(game);
@@ -138,8 +188,11 @@
});
// Main game loop
LK.on('tick', function () {
+ if (game.paused) {
+ return;
+ }
// Move hero based on touch input (handled by event listeners)
// Move enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].move();
@@ -174,9 +227,8 @@
}
}
// Spawn enemies at random intervals
- if (LK.ticks % 120 === 0) {
- // Every 2 seconds
+ if (LK.ticks % game.enemySpawnRate === 0) {
spawnEnemy();
}
});
\ No newline at end of file