User prompt
Make the shield texture an asset named shield
User prompt
hey bro The code is not working properly and we want to at least have an asset (new) effect on it.
Code edit (4 edits merged)
Please save this source code
User prompt
When we start the game, we cannot move, use our abilities and take damage for the first 1.5 seconds, we have a shield effect on us. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
HEYYYY??????!!!!.?There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.There is an asset called bullet, use it on the texture of the bullet fired by the player, and there is another asset called button, use it on the small texture inside the buttons.
Code edit (1 edits merged)
Please save this source code
User prompt
When time slows down, enemies move as well, but at 0.25x speed. It doesn't damage enemies. When you damage them, enemies move and others come. And make it harder to get the purple thing to win the game
User prompt
They do not redirect when you click on the buttons
User prompt
Add 4 buttons that direct right, left, up and down instead of joystick
User prompt
Move the joystick correctly so that we can use it left, right, up and down.
User prompt
The joystick should be bigger and when you use the joystick, the game should not get a bug and time should not slow down. Also, time should not stop but slow down to 0.25x speed, meaning the player's bullets and the enemy bullets should slow down only
User prompt
Let's have a gun so we can move, let's shoot a bullet every 1.5 seconds, let the enemies shoot bullets at 2-second intervals and there will be a movement joystick on the screen to move the character and the screen When we click, time will slow down instead of stopping, our bullets, enemies and bullets will slow down. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Time Freeze
Initial prompt
Pause the game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
level: 1,
highScore: 0
});
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('collectible', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
sprite.tint = 0x00ffff; // Cyan for player bullets
self.speed = 15;
self.direction = {
x: 0,
y: -1
}; // Default moving upward
self.isEnemyBullet = false;
self.lastPosition = {
x: 0,
y: 0
};
self.setDirection = function (dirX, dirY) {
var length = Math.sqrt(dirX * dirX + dirY * dirY);
if (length > 0) {
self.direction.x = dirX / length;
self.direction.y = dirY / length;
}
};
self.setEnemyBullet = function (isEnemy) {
self.isEnemyBullet = isEnemy;
if (isEnemy) {
sprite.tint = 0xff0000; // Red for enemy bullets
}
};
self.update = function () {
self.lastPosition.x = self.x;
self.lastPosition.y = self.y;
// Apply time slowing effect
var actualSpeed = timeIsFrozen ? self.speed * 0.3 : self.speed;
self.x += self.direction.x * actualSpeed;
self.y += self.direction.y * actualSpeed;
// Remove if out of bounds
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.shouldRemove = true;
}
};
return self;
});
var Collectible = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('collectible', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 1;
self.type = "standard"; // can be "standard" or "timeRecharge"
self.setValue = function (value) {
self.value = value;
};
self.setType = function (type) {
self.type = type;
if (type === "timeRecharge") {
sprite.tint = 0x3498db; // Blue for time recharge
}
};
self.update = function () {
// Animate collectible
if (!timeIsFrozen) {
sprite.rotation += 0.02;
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.target = null;
self.movementPattern = "chase"; // can be "chase", "patrol", or "random"
self.patrolPoints = [];
self.currentPatrolIndex = 0;
self.randomMoveCounter = 0;
self.setTarget = function (target) {
self.target = target;
};
self.setPatrolPoints = function (points) {
self.patrolPoints = points;
};
self.setMovementPattern = function (pattern) {
self.movementPattern = pattern;
};
self.update = function () {
if (!timeIsFrozen) {
if (self.movementPattern === "chase" && self.target) {
// Chase player
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 0) {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
} else if (self.movementPattern === "patrol" && self.patrolPoints.length > 0) {
// Patrol between points
var targetPoint = self.patrolPoints[self.currentPatrolIndex];
var dx = targetPoint.x - self.x;
var dy = targetPoint.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 10) {
// Reached the point, move to next patrol point
self.currentPatrolIndex = (self.currentPatrolIndex + 1) % self.patrolPoints.length;
} else {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
} else if (self.movementPattern === "random") {
// Random movement
self.randomMoveCounter--;
if (self.randomMoveCounter <= 0) {
self.vx = Math.random() * self.speed * 2 - self.speed;
self.vy = Math.random() * self.speed * 2 - self.speed;
self.randomMoveCounter = Math.floor(Math.random() * 60) + 30;
}
self.x += self.vx;
self.y += self.vy;
// Bounce off walls
if (self.x <= sprite.width / 2 || self.x >= 2048 - sprite.width / 2) {
self.vx *= -1;
}
if (self.y <= sprite.height / 2 || self.y >= 2732 - sprite.height / 2) {
self.vy *= -1;
}
}
}
};
return self;
});
var Joystick = Container.expand(function () {
var self = Container.call(this);
// Background circle
var background = self.attachAsset('pauseBarBackground', {
anchorX: 0.5,
anchorY: 0.5
});
background.width = 200;
background.height = 200;
background.alpha = 0.5;
// Stick
var stick = LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
stick.alpha = 0.8;
self.addChild(stick);
self.active = false;
self.value = {
x: 0,
y: 0
};
self.maxDistance = 80;
self.down = function (x, y, obj) {
self.active = true;
self.updateStick(x, y);
};
self.move = function (x, y, obj) {
if (self.active) {
self.updateStick(x, y);
}
};
self.up = function (x, y, obj) {
self.active = false;
stick.x = 0;
stick.y = 0;
self.value.x = 0;
self.value.y = 0;
};
self.updateStick = function (x, y) {
// Convert to local coords
var localPos = {
x: x - self.x,
y: y - self.y
};
var distance = Math.sqrt(localPos.x * localPos.x + localPos.y * localPos.y);
if (distance > self.maxDistance) {
// Normalize and scale to maxDistance
localPos.x = localPos.x / distance * self.maxDistance;
localPos.y = localPos.y / distance * self.maxDistance;
}
stick.x = localPos.x;
stick.y = localPos.y;
// Normalize values to -1 to 1
self.value.x = stick.x / self.maxDistance;
self.value.y = stick.y / self.maxDistance;
};
return self;
});
var LevelEnd = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('levelEnd', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Animate the level end gate
if (!timeIsFrozen) {
sprite.rotation += 0.01;
}
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = 0;
self.vy = 0;
self.update = function () {
if (!timeIsFrozen) {
self.x += self.vx;
self.y += self.vy;
// Bounce off walls
if (self.x <= sprite.width / 2 || self.x >= 2048 - sprite.width / 2) {
self.vx *= -1;
}
if (self.y <= sprite.height / 2 || self.y >= 2732 - sprite.height / 2) {
self.vy *= -1;
}
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.isDragging = false;
self.lastPosition = {
x: 0,
y: 0
};
self.setDragging = function (isDragging) {
self.isDragging = isDragging;
};
self.move = function (x, y) {
if (self.isDragging && !timeIsFrozen) {
self.x = x;
self.y = y;
}
};
self.update = function () {
// Store last position
self.lastPosition.x = self.x;
self.lastPosition.y = self.y;
// Use joystick for movement if it exists and game is not fully frozen
if (joystick && !timeIsFrozen) {
self.x += joystick.value.x * self.speed;
self.y += joystick.value.y * self.speed;
} else if (joystick && timeIsFrozen) {
// Slower movement when time is slowed
self.x += joystick.value.x * self.speed * 0.7;
self.y += joystick.value.y * self.speed * 0.7;
}
// Constrain player to game boundaries
if (self.x < sprite.width / 2) self.x = sprite.width / 2;
if (self.x > 2048 - sprite.width / 2) self.x = 2048 - sprite.width / 2;
if (self.y < sprite.height / 2) self.y = sprite.height / 2;
if (self.y > 2732 - sprite.height / 2) self.y = 2732 - sprite.height / 2;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x34495e
});
/****
* Game Code
****/
// Game state variables
var currentLevel = storage.level || 1;
var score = 0;
var timeIsFrozen = false;
var pauseEnergy = 100;
var pauseEnergyMax = 100;
var pauseEnergyDrainRate = 0.5;
var levelComplete = false;
var player;
var obstacles = [];
var enemies = [];
var collectibles = [];
var bullets = [];
var enemyBullets = [];
var levelEnd;
var freezeEffect;
var joystick;
var shootingTimer = 0;
var enemyShootingTimer = {};
// UI elements
var scoreTxt;
var levelTxt;
var pauseBarBg;
var pauseBar;
var instructionsTxt;
function initGame() {
// Clear existing objects if any
obstacles = [];
enemies = [];
collectibles = [];
bullets = [];
enemyBullets = [];
// Reset game state
pauseEnergy = pauseEnergyMax;
timeIsFrozen = false;
levelComplete = false;
score = LK.getScore();
shootingTimer = 0;
enemyShootingTimer = {};
// Create UI
createUI();
// Create player
player = new Player();
player.x = 1024; // Center of screen
player.y = 2200; // Near bottom
game.addChild(player);
// Create freeze effect (initially invisible)
freezeEffect = LK.getAsset('freezeEffect', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
freezeEffect.x = 2048 / 2;
freezeEffect.y = 2732 / 2;
game.addChild(freezeEffect);
// Create joystick
joystick = new Joystick();
joystick.x = 250;
joystick.y = 2500;
game.addChild(joystick);
// Create level based on current level
createLevel(currentLevel);
// Start background music
LK.playMusic('bgmusic');
}
function createUI() {
// Score text
scoreTxt = new Text2('Score: 0', {
size: 70,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 120;
scoreTxt.y = 30;
LK.gui.addChild(scoreTxt);
// Level text
levelTxt = new Text2('Level: ' + currentLevel, {
size: 70,
fill: 0xFFFFFF
});
levelTxt.anchor.set(1, 0);
levelTxt.x = 2048 - 120;
levelTxt.y = 30;
LK.gui.addChild(levelTxt);
// Pause energy bar background
pauseBarBg = LK.getAsset('pauseBarBackground', {
anchorX: 0.5,
anchorY: 0.5
});
pauseBarBg.x = 2048 / 2;
pauseBarBg.y = 100;
LK.gui.addChild(pauseBarBg);
// Pause energy bar
pauseBar = LK.getAsset('pauseBar', {
anchorX: 0,
anchorY: 0.5
});
pauseBar.x = pauseBarBg.x - pauseBarBg.width / 2;
pauseBar.y = pauseBarBg.y;
pauseBar.width = pauseBarBg.width * (pauseEnergy / pauseEnergyMax);
LK.gui.addChild(pauseBar);
// Instructions
instructionsTxt = new Text2('Use joystick to move. Tap screen to slow time.\nShoot automatically every 1.5 seconds. Enemies shoot every 2 seconds.', {
size: 50,
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0);
instructionsTxt.x = 2048 / 2;
instructionsTxt.y = 150;
LK.gui.addChild(instructionsTxt);
// Auto-hide instructions after 5 seconds
LK.setTimeout(function () {
tween(instructionsTxt, {
alpha: 0
}, {
duration: 1000
});
}, 5000);
}
function createLevel(level) {
// Each level has a different configuration
switch (level) {
case 1:
// Level 1: Simple introduction
createObstacle(600, 500, 3, 0);
createObstacle(1200, 800, -2, 2);
createObstacle(1600, 1200, 0, 4);
createCollectible(800, 600);
createCollectible(1400, 1000);
createCollectible(1700, 1800);
createCollectible(500, 1500, "timeRecharge");
// Level end
levelEnd = new LevelEnd();
levelEnd.x = 1800;
levelEnd.y = 2400;
game.addChild(levelEnd);
break;
case 2:
// Level 2: Introduce enemies
createObstacle(600, 500, 4, 0);
createObstacle(1200, 800, -3, 3);
createObstacle(1600, 1200, 0, 5);
createObstacle(900, 1600, 4, -2);
var enemy = createEnemy(1000, 1000, "chase");
enemy.setTarget(player);
createCollectible(800, 600);
createCollectible(1400, 1000);
createCollectible(1700, 1800);
createCollectible(500, 1500);
createCollectible(1200, 2200, "timeRecharge");
// Level end
levelEnd = new LevelEnd();
levelEnd.x = 1800;
levelEnd.y = 2400;
game.addChild(levelEnd);
break;
case 3:
// Level 3: More complex with patrol enemies
createObstacle(600, 500, 5, 0);
createObstacle(1200, 800, -4, 3);
createObstacle(1600, 1200, 0, 6);
createObstacle(900, 1600, 5, -3);
createObstacle(1400, 2000, -3, -3);
var enemy1 = createEnemy(1000, 1000, "chase");
enemy1.setTarget(player);
var enemy2 = createEnemy(1500, 1500, "patrol");
enemy2.setPatrolPoints([{
x: 1500,
y: 1500
}, {
x: 1500,
y: 2000
}, {
x: 1000,
y: 2000
}, {
x: 1000,
y: 1500
}]);
createCollectible(800, 600);
createCollectible(1400, 1000);
createCollectible(1700, 1800);
createCollectible(500, 1500);
createCollectible(1200, 2200);
createCollectible(1800, 1300, "timeRecharge");
// Level end
levelEnd = new LevelEnd();
levelEnd.x = 1800;
levelEnd.y = 2400;
game.addChild(levelEnd);
break;
default:
// Higher levels: Procedurally generate increasingly difficult layouts
var obstacleCount = 3 + Math.min(level, 7);
var enemyCount = 1 + Math.min(level - 2, 5);
var collectibleCount = 4 + Math.min(level, 6);
// Create obstacles
for (var i = 0; i < obstacleCount; i++) {
var x = 400 + Math.random() * 1600;
var y = 400 + Math.random() * 1800;
var vx = (Math.random() * 6 + 2) * (Math.random() > 0.5 ? 1 : -1);
var vy = (Math.random() * 6 + 2) * (Math.random() > 0.5 ? 1 : -1);
createObstacle(x, y, vx, vy);
}
// Create enemies
for (var i = 0; i < enemyCount; i++) {
var x = 400 + Math.random() * 1600;
var y = 400 + Math.random() * 1800;
var patternType = Math.random();
if (patternType < 0.4) {
var enemy = createEnemy(x, y, "chase");
enemy.setTarget(player);
} else if (patternType < 0.7) {
var enemy = createEnemy(x, y, "patrol");
var patrolRadius = 300 + Math.random() * 300;
var patrolPoints = [];
var patrolPointCount = 3 + Math.floor(Math.random() * 3);
for (var j = 0; j < patrolPointCount; j++) {
var angle = j / patrolPointCount * Math.PI * 2;
patrolPoints.push({
x: x + Math.cos(angle) * patrolRadius,
y: y + Math.sin(angle) * patrolRadius
});
}
enemy.setPatrolPoints(patrolPoints);
} else {
createEnemy(x, y, "random");
}
}
// Create collectibles
for (var i = 0; i < collectibleCount; i++) {
var x = 300 + Math.random() * 1700;
var y = 300 + Math.random() * 2000;
if (i === collectibleCount - 1) {
createCollectible(x, y, "timeRecharge");
} else {
createCollectible(x, y);
}
}
// Level end
levelEnd = new LevelEnd();
levelEnd.x = 1700 + Math.random() * 200;
levelEnd.y = 2200 + Math.random() * 300;
game.addChild(levelEnd);
break;
}
}
function createObstacle(x, y, vx, vy) {
var obstacle = new Obstacle();
obstacle.x = x;
obstacle.y = y;
obstacle.vx = vx;
obstacle.vy = vy;
obstacles.push(obstacle);
game.addChild(obstacle);
return obstacle;
}
function createEnemy(x, y, movementPattern) {
var enemy = new Enemy();
enemy.x = x;
enemy.y = y;
enemy.setMovementPattern(movementPattern);
enemies.push(enemy);
game.addChild(enemy);
return enemy;
}
function createCollectible(x, y, type) {
var collectible = new Collectible();
collectible.x = x;
collectible.y = y;
if (type === "timeRecharge") {
collectible.setType("timeRecharge");
}
collectibles.push(collectible);
game.addChild(collectible);
return collectible;
}
function createPlayerBullet() {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y - 30;
bullet.setDirection(0, -1); // Shoot upward
bullets.push(bullet);
game.addChild(bullet);
return bullet;
}
function createEnemyBullet(enemy) {
var bullet = new Bullet();
bullet.x = enemy.x;
bullet.y = enemy.y + 30;
// Direction toward player
var dx = player.x - enemy.x;
var dy = player.y - enemy.y;
bullet.setDirection(dx, dy);
bullet.setEnemyBullet(true);
enemyBullets.push(bullet);
game.addChild(bullet);
return bullet;
}
function toggleFreezeTime() {
if (pauseEnergy <= 0 && timeIsFrozen) {
// Can't stay frozen with no energy
unfreezeTime();
return;
}
if (!timeIsFrozen && pauseEnergy > 0) {
// Slow time (not completely freeze)
timeIsFrozen = true;
tween(freezeEffect, {
alpha: 0.2
}, {
duration: 300
});
LK.getSound('freeze').play();
} else if (timeIsFrozen) {
// Unfreeze time
unfreezeTime();
}
}
function unfreezeTime() {
timeIsFrozen = false;
tween(freezeEffect, {
alpha: 0
}, {
duration: 300
});
LK.getSound('unfreeze').play();
}
function updatePauseEnergyBar() {
pauseBar.width = pauseBarBg.width * (pauseEnergy / pauseEnergyMax);
}
function checkCollisions() {
// Check player-obstacle collisions
for (var i = 0; i < obstacles.length; i++) {
if (player.intersects(obstacles[i])) {
handlePlayerHit();
return;
}
}
// Check player-enemy collisions
for (var i = 0; i < enemies.length; i++) {
if (player.intersects(enemies[i])) {
handlePlayerHit();
return;
}
}
// Check player-collectible collisions
for (var i = collectibles.length - 1; i >= 0; i--) {
if (player.intersects(collectibles[i])) {
// Collect the item
if (collectibles[i].type === "timeRecharge") {
pauseEnergy = Math.min(pauseEnergyMax, pauseEnergy + 50);
updatePauseEnergyBar();
} else {
score += collectibles[i].value;
LK.setScore(score);
scoreTxt.setText('Score: ' + score);
}
LK.getSound('collect').play();
collectibles[i].destroy();
collectibles.splice(i, 1);
}
}
// Check if player reached the level end
if (levelEnd && player.intersects(levelEnd)) {
completeLevel();
}
}
function handlePlayerHit() {
if (!timeIsFrozen) {
// Flash the screen red
LK.effects.flashScreen(0xff0000, 500);
LK.getSound('hit').play();
// Show game over
LK.showGameOver();
}
}
function completeLevel() {
if (!levelComplete) {
levelComplete = true;
// Save progress
currentLevel++;
storage.level = currentLevel;
// Save high score
if (score > storage.highScore) {
storage.highScore = score;
}
// Play win sound
LK.getSound('win').play();
// Show level complete
LK.showYouWin();
}
}
// Game event handlers
game.down = function (x, y, obj) {
// Check if joystick was clicked
if (joystick.getBounds().contains(x, y)) {
joystick.down(x - joystick.x, y - joystick.y, obj);
} else if (!timeIsFrozen && pauseEnergy > 0) {
// Slow time when clicking anywhere else (if we have energy)
toggleFreezeTime();
} else if (timeIsFrozen) {
// Unfreeze time when clicking anywhere else if already frozen
toggleFreezeTime();
}
};
game.up = function (x, y, obj) {
joystick.up(x - joystick.x, y - joystick.y, obj);
};
game.move = function (x, y, obj) {
joystick.move(x - joystick.x, y - joystick.y, obj);
};
// Game update loop
game.update = function () {
// Check if game is initialized
if (!player) {
initGame();
return;
}
// Drain pause energy when time is frozen
if (timeIsFrozen) {
pauseEnergy = Math.max(0, pauseEnergy - pauseEnergyDrainRate);
updatePauseEnergyBar();
// Automatically unfreeze when energy is depleted
if (pauseEnergy <= 0) {
unfreezeTime();
}
} else if (pauseEnergy < pauseEnergyMax) {
// Slowly recharge when not frozen
pauseEnergy = Math.min(pauseEnergyMax, pauseEnergy + 0.1);
updatePauseEnergyBar();
}
// Handle player shooting (every 1.5 seconds)
shootingTimer++;
var shootingInterval = timeIsFrozen ? 90 * 1.5 : 90; // 90 ticks = 1.5 seconds, slower when time is frozen
if (shootingTimer >= shootingInterval) {
createPlayerBullet();
shootingTimer = 0;
}
// Handle enemy shooting (every 2 seconds)
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (!enemyShootingTimer[i]) {
enemyShootingTimer[i] = 0;
}
enemyShootingTimer[i]++;
var enemyShootInterval = timeIsFrozen ? 120 * 1.5 : 120; // 120 ticks = 2 seconds, slower when time is frozen
if (enemyShootingTimer[i] >= enemyShootInterval) {
createEnemyBullet(enemy);
enemyShootingTimer[i] = 0;
}
}
// Update game objects
player.update();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
if (bullets[i].shouldRemove) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Update enemy bullets
for (var i = enemyBullets.length - 1; i >= 0; i--) {
enemyBullets[i].update();
if (enemyBullets[i].shouldRemove) {
enemyBullets[i].destroy();
enemyBullets.splice(i, 1);
}
}
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
}
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
}
for (var i = 0; i < collectibles.length; i++) {
collectibles[i].update();
}
if (levelEnd) {
levelEnd.update();
}
// Check for collisions
checkCollisions();
// Check bullet collisions with enemies
for (var i = bullets.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (bullets[i] && bullets[i].intersects(enemies[j])) {
// Enemy hit by player bullet
enemies[j].destroy();
enemies.splice(j, 1);
bullets[i].destroy();
bullets.splice(i, 1);
// Update score
score += 10;
LK.setScore(score);
scoreTxt.setText('Score: ' + score);
break;
}
}
}
// Check enemy bullet collisions with player
for (var i = enemyBullets.length - 1; i >= 0; i--) {
if (enemyBullets[i] && player.intersects(enemyBullets[i])) {
// Player hit by enemy bullet
if (!timeIsFrozen) {
handlePlayerHit();
} else {
// Just destroy the bullet if time is frozen (player gets a break)
enemyBullets[i].destroy();
enemyBullets.splice(i, 1);
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -9,8 +9,54 @@
/****
* Classes
****/
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var sprite = self.attachAsset('collectible', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.5,
+ scaleY: 0.5
+ });
+ sprite.tint = 0x00ffff; // Cyan for player bullets
+ self.speed = 15;
+ self.direction = {
+ x: 0,
+ y: -1
+ }; // Default moving upward
+ self.isEnemyBullet = false;
+ self.lastPosition = {
+ x: 0,
+ y: 0
+ };
+ self.setDirection = function (dirX, dirY) {
+ var length = Math.sqrt(dirX * dirX + dirY * dirY);
+ if (length > 0) {
+ self.direction.x = dirX / length;
+ self.direction.y = dirY / length;
+ }
+ };
+ self.setEnemyBullet = function (isEnemy) {
+ self.isEnemyBullet = isEnemy;
+ if (isEnemy) {
+ sprite.tint = 0xff0000; // Red for enemy bullets
+ }
+ };
+ self.update = function () {
+ self.lastPosition.x = self.x;
+ self.lastPosition.y = self.y;
+ // Apply time slowing effect
+ var actualSpeed = timeIsFrozen ? self.speed * 0.3 : self.speed;
+ self.x += self.direction.x * actualSpeed;
+ self.y += self.direction.y * actualSpeed;
+ // Remove if out of bounds
+ if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
var Collectible = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('collectible', {
anchorX: 0.5,
@@ -101,8 +147,69 @@
}
};
return self;
});
+var Joystick = Container.expand(function () {
+ var self = Container.call(this);
+ // Background circle
+ var background = self.attachAsset('pauseBarBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ background.width = 200;
+ background.height = 200;
+ background.alpha = 0.5;
+ // Stick
+ var stick = LK.getAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.5,
+ scaleY: 0.5
+ });
+ stick.alpha = 0.8;
+ self.addChild(stick);
+ self.active = false;
+ self.value = {
+ x: 0,
+ y: 0
+ };
+ self.maxDistance = 80;
+ self.down = function (x, y, obj) {
+ self.active = true;
+ self.updateStick(x, y);
+ };
+ self.move = function (x, y, obj) {
+ if (self.active) {
+ self.updateStick(x, y);
+ }
+ };
+ self.up = function (x, y, obj) {
+ self.active = false;
+ stick.x = 0;
+ stick.y = 0;
+ self.value.x = 0;
+ self.value.y = 0;
+ };
+ self.updateStick = function (x, y) {
+ // Convert to local coords
+ var localPos = {
+ x: x - self.x,
+ y: y - self.y
+ };
+ var distance = Math.sqrt(localPos.x * localPos.x + localPos.y * localPos.y);
+ if (distance > self.maxDistance) {
+ // Normalize and scale to maxDistance
+ localPos.x = localPos.x / distance * self.maxDistance;
+ localPos.y = localPos.y / distance * self.maxDistance;
+ }
+ stick.x = localPos.x;
+ stick.y = localPos.y;
+ // Normalize values to -1 to 1
+ self.value.x = stick.x / self.maxDistance;
+ self.value.y = stick.y / self.maxDistance;
+ };
+ return self;
+});
var LevelEnd = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('levelEnd', {
anchorX: 0.5,
@@ -160,16 +267,25 @@
self.y = y;
}
};
self.update = function () {
+ // Store last position
+ self.lastPosition.x = self.x;
+ self.lastPosition.y = self.y;
+ // Use joystick for movement if it exists and game is not fully frozen
+ if (joystick && !timeIsFrozen) {
+ self.x += joystick.value.x * self.speed;
+ self.y += joystick.value.y * self.speed;
+ } else if (joystick && timeIsFrozen) {
+ // Slower movement when time is slowed
+ self.x += joystick.value.x * self.speed * 0.7;
+ self.y += joystick.value.y * self.speed * 0.7;
+ }
// Constrain player to game boundaries
if (self.x < sprite.width / 2) self.x = sprite.width / 2;
if (self.x > 2048 - sprite.width / 2) self.x = 2048 - sprite.width / 2;
if (self.y < sprite.height / 2) self.y = sprite.height / 2;
if (self.y > 2732 - sprite.height / 2) self.y = 2732 - sprite.height / 2;
- // Store last position
- self.lastPosition.x = self.x;
- self.lastPosition.y = self.y;
};
return self;
});
@@ -194,10 +310,15 @@
var player;
var obstacles = [];
var enemies = [];
var collectibles = [];
+var bullets = [];
+var enemyBullets = [];
var levelEnd;
var freezeEffect;
+var joystick;
+var shootingTimer = 0;
+var enemyShootingTimer = {};
// UI elements
var scoreTxt;
var levelTxt;
var pauseBarBg;
@@ -207,19 +328,23 @@
// Clear existing objects if any
obstacles = [];
enemies = [];
collectibles = [];
+ bullets = [];
+ enemyBullets = [];
// Reset game state
pauseEnergy = pauseEnergyMax;
timeIsFrozen = false;
levelComplete = false;
score = LK.getScore();
+ shootingTimer = 0;
+ enemyShootingTimer = {};
// Create UI
createUI();
// Create player
player = new Player();
- player.x = 200;
- player.y = 300;
+ player.x = 1024; // Center of screen
+ player.y = 2200; // Near bottom
game.addChild(player);
// Create freeze effect (initially invisible)
freezeEffect = LK.getAsset('freezeEffect', {
anchorX: 0.5,
@@ -228,8 +353,13 @@
});
freezeEffect.x = 2048 / 2;
freezeEffect.y = 2732 / 2;
game.addChild(freezeEffect);
+ // Create joystick
+ joystick = new Joystick();
+ joystick.x = 250;
+ joystick.y = 2500;
+ game.addChild(joystick);
// Create level based on current level
createLevel(currentLevel);
// Start background music
LK.playMusic('bgmusic');
@@ -270,9 +400,9 @@
pauseBar.y = pauseBarBg.y;
pauseBar.width = pauseBarBg.width * (pauseEnergy / pauseEnergyMax);
LK.gui.addChild(pauseBar);
// Instructions
- instructionsTxt = new Text2('Tap and hold player to move. Tap anywhere else to freeze time.\nFreeze time to avoid obstacles and enemies!', {
+ instructionsTxt = new Text2('Use joystick to move. Tap screen to slow time.\nShoot automatically every 1.5 seconds. Enemies shoot every 2 seconds.', {
size: 50,
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0);
@@ -445,19 +575,41 @@
collectibles.push(collectible);
game.addChild(collectible);
return collectible;
}
+function createPlayerBullet() {
+ var bullet = new Bullet();
+ bullet.x = player.x;
+ bullet.y = player.y - 30;
+ bullet.setDirection(0, -1); // Shoot upward
+ bullets.push(bullet);
+ game.addChild(bullet);
+ return bullet;
+}
+function createEnemyBullet(enemy) {
+ var bullet = new Bullet();
+ bullet.x = enemy.x;
+ bullet.y = enemy.y + 30;
+ // Direction toward player
+ var dx = player.x - enemy.x;
+ var dy = player.y - enemy.y;
+ bullet.setDirection(dx, dy);
+ bullet.setEnemyBullet(true);
+ enemyBullets.push(bullet);
+ game.addChild(bullet);
+ return bullet;
+}
function toggleFreezeTime() {
if (pauseEnergy <= 0 && timeIsFrozen) {
// Can't stay frozen with no energy
unfreezeTime();
return;
}
if (!timeIsFrozen && pauseEnergy > 0) {
- // Freeze time
+ // Slow time (not completely freeze)
timeIsFrozen = true;
tween(freezeEffect, {
- alpha: 0.3
+ alpha: 0.2
}, {
duration: 300
});
LK.getSound('freeze').play();
@@ -541,24 +693,24 @@
}
}
// Game event handlers
game.down = function (x, y, obj) {
- // Check if player was clicked
- if (player.getBounds().contains(x, y)) {
- player.setDragging(true);
+ // Check if joystick was clicked
+ if (joystick.getBounds().contains(x, y)) {
+ joystick.down(x - joystick.x, y - joystick.y, obj);
} else if (!timeIsFrozen && pauseEnergy > 0) {
- // Freeze time when clicking anywhere else (if we have energy)
+ // Slow time when clicking anywhere else (if we have energy)
toggleFreezeTime();
} else if (timeIsFrozen) {
// Unfreeze time when clicking anywhere else if already frozen
toggleFreezeTime();
}
};
game.up = function (x, y, obj) {
- player.setDragging(false);
+ joystick.up(x - joystick.x, y - joystick.y, obj);
};
game.move = function (x, y, obj) {
- player.move(x, y);
+ joystick.move(x - joystick.x, y - joystick.y, obj);
};
// Game update loop
game.update = function () {
// Check if game is initialized
@@ -578,10 +730,46 @@
// Slowly recharge when not frozen
pauseEnergy = Math.min(pauseEnergyMax, pauseEnergy + 0.1);
updatePauseEnergyBar();
}
+ // Handle player shooting (every 1.5 seconds)
+ shootingTimer++;
+ var shootingInterval = timeIsFrozen ? 90 * 1.5 : 90; // 90 ticks = 1.5 seconds, slower when time is frozen
+ if (shootingTimer >= shootingInterval) {
+ createPlayerBullet();
+ shootingTimer = 0;
+ }
+ // Handle enemy shooting (every 2 seconds)
+ for (var i = 0; i < enemies.length; i++) {
+ var enemy = enemies[i];
+ if (!enemyShootingTimer[i]) {
+ enemyShootingTimer[i] = 0;
+ }
+ enemyShootingTimer[i]++;
+ var enemyShootInterval = timeIsFrozen ? 120 * 1.5 : 120; // 120 ticks = 2 seconds, slower when time is frozen
+ if (enemyShootingTimer[i] >= enemyShootInterval) {
+ createEnemyBullet(enemy);
+ enemyShootingTimer[i] = 0;
+ }
+ }
// Update game objects
player.update();
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].update();
+ if (bullets[i].shouldRemove) {
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ }
+ }
+ // Update enemy bullets
+ for (var i = enemyBullets.length - 1; i >= 0; i--) {
+ enemyBullets[i].update();
+ if (enemyBullets[i].shouldRemove) {
+ enemyBullets[i].destroy();
+ enemyBullets.splice(i, 1);
+ }
+ }
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
}
for (var i = 0; i < enemies.length; i++) {
@@ -594,5 +782,35 @@
levelEnd.update();
}
// Check for collisions
checkCollisions();
+ // Check bullet collisions with enemies
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ for (var j = enemies.length - 1; j >= 0; j--) {
+ if (bullets[i] && bullets[i].intersects(enemies[j])) {
+ // Enemy hit by player bullet
+ enemies[j].destroy();
+ enemies.splice(j, 1);
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ // Update score
+ score += 10;
+ LK.setScore(score);
+ scoreTxt.setText('Score: ' + score);
+ break;
+ }
+ }
+ }
+ // Check enemy bullet collisions with player
+ for (var i = enemyBullets.length - 1; i >= 0; i--) {
+ if (enemyBullets[i] && player.intersects(enemyBullets[i])) {
+ // Player hit by enemy bullet
+ if (!timeIsFrozen) {
+ handlePlayerHit();
+ } else {
+ // Just destroy the bullet if time is frozen (player gets a break)
+ enemyBullets[i].destroy();
+ enemyBullets.splice(i, 1);
+ }
+ }
+ }
};
\ No newline at end of file
Modern App Store icon, high definition, square with rounded corners, for a game titled "Time Freeze" and with the description "A puzzle-action game where pausing is a superpower. Strategically freeze time to navigate hazards, avoid enemies, and collect items while managing your limited pause energy. Plan your moves carefully in this time-bending adventure where stopping the clock is your greatest tool for success.". No text on icon!
Monster 2d
A big red flag with the word end on it. In-Game asset. 2d. High contrast. No shadows
2d electronic visible coin. In-Game asset. 2d. High contrast. No shadows
2d dangerous robot bomb. In-Game asset. 2d. High contrast. No shadows
2d beam bullet. In-Game asset. 2d. High contrast. No shadows
2d shield magic. In-Game asset. 2d. High contrast. No shadows