User prompt
Add green platforms that make you go faster if you touch them for 20 seconds ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add turrets that shoot that shoot you with homing missiles and if the missile touches the floor or a platform it explodes ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add drones that shoot red cubes to attack you in the sky ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add Saws
User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 529
User prompt
Make the blue cube has facial expressions on the eyes ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add particles when the blue cube moves ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add moveable boxes
User prompt
Add sprinting
User prompt
Add spinning obstacles ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add lasers
User prompt
Add the obstacle wall
User prompt
Remove the big red cube
User prompt
Make a new enemies that is a big red cube that jumps toward you to attack
User prompt
Make the blue cube be able to dash ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make it so that the blue cube can double jump
User prompt
Make the platforms collidable
Code edit (1 edits merged)
Please save this source code
User prompt
Junkyard Journey
Initial prompt
Make a platformer game about a blue cube with eyes exploring the junkyard with enemies trying to kill the blue cube, the blue cube must get to the blue circle at the other side of the junkyard
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyBody = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 2;
self.direction = 1;
self.startX = 0;
self.patrolDistance = 300;
self.update = function () {
self.x += self.speed * self.direction;
if (Math.abs(self.x - self.startX) > self.patrolDistance) {
self.direction *= -1;
}
// Ground collision for enemies
if (self.y >= groundLevel) {
self.y = groundLevel;
}
// Platform collision for enemies
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.intersects(platform) && self.y - 40 < platform.y - 20) {
self.y = platform.y - 20;
}
}
};
return self;
});
var JunkPile = Container.expand(function () {
var self = Container.call(this);
var junkBody = self.attachAsset('junkPile', {
anchorX: 0.5,
anchorY: 1.0
});
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformBody = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerBody = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
var leftEye = self.attachAsset('playerEye', {
anchorX: 0.5,
anchorY: 0.5,
x: -20,
y: -50
});
var rightEye = self.attachAsset('playerEye', {
anchorX: 0.5,
anchorY: 0.5,
x: 20,
y: -50
});
var leftPupil = self.attachAsset('playerPupil', {
anchorX: 0.5,
anchorY: 0.5,
x: -20,
y: -50
});
var rightPupil = self.attachAsset('playerPupil', {
anchorX: 0.5,
anchorY: 0.5,
x: 20,
y: -50
});
self.velocityX = 0;
self.velocityY = 0;
self.onGround = false;
self.jumpPower = -15;
self.gravity = 0.8;
self.maxSpeed = 8;
self.friction = 0.85;
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
// Apply friction
self.velocityX *= self.friction;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Ground collision
if (self.y >= groundLevel) {
self.y = groundLevel;
self.velocityY = 0;
self.onGround = true;
} else {
self.onGround = false;
}
// Platform collision
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.velocityY > 0 && self.intersects(platform) && self.y - 80 < platform.y - 20) {
self.y = platform.y - 20;
self.velocityY = 0;
self.onGround = true;
}
}
// Boundary checking
if (self.x < 40) {
self.x = 40;
}
if (self.x > levelWidth - 40) {
self.x = levelWidth - 40;
}
};
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
LK.getSound('jump').play();
}
};
self.moveLeft = function () {
self.velocityX = Math.max(self.velocityX - 1.5, -self.maxSpeed);
};
self.moveRight = function () {
self.velocityX = Math.min(self.velocityX + 1.5, self.maxSpeed);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
var player;
var enemies = [];
var platforms = [];
var junkPiles = [];
var goal;
var camera;
var groundLevel = 2600;
var levelWidth = 4000;
var gameWon = false;
// Create camera object for following player
camera = {
x: 0,
y: 0,
targetX: 0,
targetY: 0,
smoothing: 0.1
};
// Create player
player = game.addChild(new Player());
player.x = 200;
player.y = groundLevel;
// Create platforms
var platformPositions = [{
x: 500,
y: 2400
}, {
x: 800,
y: 2200
}, {
x: 1200,
y: 2300
}, {
x: 1600,
y: 2100
}, {
x: 2000,
y: 2000
}, {
x: 2400,
y: 2200
}, {
x: 2800,
y: 2400
}, {
x: 3200,
y: 2300
}, {
x: 3600,
y: 2500
}];
for (var i = 0; i < platformPositions.length; i++) {
var platform = game.addChild(new Platform());
platform.x = platformPositions[i].x;
platform.y = platformPositions[i].y;
platforms.push(platform);
}
// Create enemies
var enemyPositions = [{
x: 600,
y: groundLevel
}, {
x: 1000,
y: 2200
}, {
x: 1400,
y: groundLevel
}, {
x: 1800,
y: 2000
}, {
x: 2200,
y: groundLevel
}, {
x: 2600,
y: 2200
}, {
x: 3000,
y: groundLevel
}, {
x: 3400,
y: 2300
}];
for (var i = 0; i < enemyPositions.length; i++) {
var enemy = game.addChild(new Enemy());
enemy.x = enemyPositions[i].x;
enemy.y = enemyPositions[i].y;
enemy.startX = enemy.x;
enemies.push(enemy);
}
// Create junk piles for decoration
var junkPositions = [{
x: 300,
y: groundLevel
}, {
x: 700,
y: groundLevel
}, {
x: 1100,
y: groundLevel
}, {
x: 1500,
y: groundLevel
}, {
x: 1900,
y: groundLevel
}, {
x: 2300,
y: groundLevel
}, {
x: 2700,
y: groundLevel
}, {
x: 3100,
y: groundLevel
}, {
x: 3500,
y: groundLevel
}];
for (var i = 0; i < junkPositions.length; i++) {
var junk = game.addChild(new JunkPile());
junk.x = junkPositions[i].x;
junk.y = junkPositions[i].y;
junkPiles.push(junk);
}
// Create goal
goal = game.addChild(LK.getAsset('goal', {
anchorX: 0.5,
anchorY: 0.5
}));
goal.x = levelWidth - 200;
goal.y = groundLevel - 50;
// Touch controls
var touchStartX = 0;
var touchStartY = 0;
var isDragging = false;
game.down = function (x, y, obj) {
touchStartX = x;
touchStartY = y;
isDragging = true;
// Jump on tap
player.jump();
};
game.move = function (x, y, obj) {
if (isDragging) {
var deltaX = x - touchStartX;
if (deltaX < -20) {
player.moveLeft();
} else if (deltaX > 20) {
player.moveRight();
}
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
// Game update loop
game.update = function () {
if (gameWon) return;
// Update camera to follow player
camera.targetX = player.x - 1024;
camera.targetY = player.y - 1366;
camera.x += (camera.targetX - camera.x) * camera.smoothing;
camera.y += (camera.targetY - camera.y) * camera.smoothing;
// Keep camera within level bounds
if (camera.x < 0) camera.x = 0;
if (camera.x > levelWidth - 2048) camera.x = levelWidth - 2048;
if (camera.y < -500) camera.y = -500;
if (camera.y > 0) camera.y = 0;
// Apply camera offset to game
game.x = -camera.x;
game.y = -camera.y;
// Check collision with enemies
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (player.intersects(enemy)) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
return;
}
}
// Check if player reached goal
if (player.intersects(goal)) {
gameWon = true;
LK.effects.flashScreen(0x00FF00, 1000);
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
return;
}
// Check if player fell off the level
if (player.y > groundLevel + 500) {
LK.effects.flashScreen(0xFF0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
return;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,350 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Enemy = Container.expand(function () {
+ var self = Container.call(this);
+ var enemyBody = self.attachAsset('enemy', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.speed = 2;
+ self.direction = 1;
+ self.startX = 0;
+ self.patrolDistance = 300;
+ self.update = function () {
+ self.x += self.speed * self.direction;
+ if (Math.abs(self.x - self.startX) > self.patrolDistance) {
+ self.direction *= -1;
+ }
+ // Ground collision for enemies
+ if (self.y >= groundLevel) {
+ self.y = groundLevel;
+ }
+ // Platform collision for enemies
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ if (self.intersects(platform) && self.y - 40 < platform.y - 20) {
+ self.y = platform.y - 20;
+ }
+ }
+ };
+ return self;
+});
+var JunkPile = Container.expand(function () {
+ var self = Container.call(this);
+ var junkBody = self.attachAsset('junkPile', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ return self;
+});
+var Platform = Container.expand(function () {
+ var self = Container.call(this);
+ var platformBody = self.attachAsset('platform', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerBody = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ var leftEye = self.attachAsset('playerEye', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -20,
+ y: -50
+ });
+ var rightEye = self.attachAsset('playerEye', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 20,
+ y: -50
+ });
+ var leftPupil = self.attachAsset('playerPupil', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -20,
+ y: -50
+ });
+ var rightPupil = self.attachAsset('playerPupil', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 20,
+ y: -50
+ });
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.onGround = false;
+ self.jumpPower = -15;
+ self.gravity = 0.8;
+ self.maxSpeed = 8;
+ self.friction = 0.85;
+ self.update = function () {
+ // Apply gravity
+ self.velocityY += self.gravity;
+ // Apply friction
+ self.velocityX *= self.friction;
+ // Update position
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Ground collision
+ if (self.y >= groundLevel) {
+ self.y = groundLevel;
+ self.velocityY = 0;
+ self.onGround = true;
+ } else {
+ self.onGround = false;
+ }
+ // Platform collision
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ if (self.velocityY > 0 && self.intersects(platform) && self.y - 80 < platform.y - 20) {
+ self.y = platform.y - 20;
+ self.velocityY = 0;
+ self.onGround = true;
+ }
+ }
+ // Boundary checking
+ if (self.x < 40) {
+ self.x = 40;
+ }
+ if (self.x > levelWidth - 40) {
+ self.x = levelWidth - 40;
+ }
+ };
+ self.jump = function () {
+ if (self.onGround) {
+ self.velocityY = self.jumpPower;
+ self.onGround = false;
+ LK.getSound('jump').play();
+ }
+ };
+ self.moveLeft = function () {
+ self.velocityX = Math.max(self.velocityX - 1.5, -self.maxSpeed);
+ };
+ self.moveRight = function () {
+ self.velocityX = Math.min(self.velocityX + 1.5, self.maxSpeed);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2C3E50
+});
+
+/****
+* Game Code
+****/
+var player;
+var enemies = [];
+var platforms = [];
+var junkPiles = [];
+var goal;
+var camera;
+var groundLevel = 2600;
+var levelWidth = 4000;
+var gameWon = false;
+// Create camera object for following player
+camera = {
+ x: 0,
+ y: 0,
+ targetX: 0,
+ targetY: 0,
+ smoothing: 0.1
+};
+// Create player
+player = game.addChild(new Player());
+player.x = 200;
+player.y = groundLevel;
+// Create platforms
+var platformPositions = [{
+ x: 500,
+ y: 2400
+}, {
+ x: 800,
+ y: 2200
+}, {
+ x: 1200,
+ y: 2300
+}, {
+ x: 1600,
+ y: 2100
+}, {
+ x: 2000,
+ y: 2000
+}, {
+ x: 2400,
+ y: 2200
+}, {
+ x: 2800,
+ y: 2400
+}, {
+ x: 3200,
+ y: 2300
+}, {
+ x: 3600,
+ y: 2500
+}];
+for (var i = 0; i < platformPositions.length; i++) {
+ var platform = game.addChild(new Platform());
+ platform.x = platformPositions[i].x;
+ platform.y = platformPositions[i].y;
+ platforms.push(platform);
+}
+// Create enemies
+var enemyPositions = [{
+ x: 600,
+ y: groundLevel
+}, {
+ x: 1000,
+ y: 2200
+}, {
+ x: 1400,
+ y: groundLevel
+}, {
+ x: 1800,
+ y: 2000
+}, {
+ x: 2200,
+ y: groundLevel
+}, {
+ x: 2600,
+ y: 2200
+}, {
+ x: 3000,
+ y: groundLevel
+}, {
+ x: 3400,
+ y: 2300
+}];
+for (var i = 0; i < enemyPositions.length; i++) {
+ var enemy = game.addChild(new Enemy());
+ enemy.x = enemyPositions[i].x;
+ enemy.y = enemyPositions[i].y;
+ enemy.startX = enemy.x;
+ enemies.push(enemy);
+}
+// Create junk piles for decoration
+var junkPositions = [{
+ x: 300,
+ y: groundLevel
+}, {
+ x: 700,
+ y: groundLevel
+}, {
+ x: 1100,
+ y: groundLevel
+}, {
+ x: 1500,
+ y: groundLevel
+}, {
+ x: 1900,
+ y: groundLevel
+}, {
+ x: 2300,
+ y: groundLevel
+}, {
+ x: 2700,
+ y: groundLevel
+}, {
+ x: 3100,
+ y: groundLevel
+}, {
+ x: 3500,
+ y: groundLevel
+}];
+for (var i = 0; i < junkPositions.length; i++) {
+ var junk = game.addChild(new JunkPile());
+ junk.x = junkPositions[i].x;
+ junk.y = junkPositions[i].y;
+ junkPiles.push(junk);
+}
+// Create goal
+goal = game.addChild(LK.getAsset('goal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+goal.x = levelWidth - 200;
+goal.y = groundLevel - 50;
+// Touch controls
+var touchStartX = 0;
+var touchStartY = 0;
+var isDragging = false;
+game.down = function (x, y, obj) {
+ touchStartX = x;
+ touchStartY = y;
+ isDragging = true;
+ // Jump on tap
+ player.jump();
+};
+game.move = function (x, y, obj) {
+ if (isDragging) {
+ var deltaX = x - touchStartX;
+ if (deltaX < -20) {
+ player.moveLeft();
+ } else if (deltaX > 20) {
+ player.moveRight();
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ isDragging = false;
+};
+// Game update loop
+game.update = function () {
+ if (gameWon) return;
+ // Update camera to follow player
+ camera.targetX = player.x - 1024;
+ camera.targetY = player.y - 1366;
+ camera.x += (camera.targetX - camera.x) * camera.smoothing;
+ camera.y += (camera.targetY - camera.y) * camera.smoothing;
+ // Keep camera within level bounds
+ if (camera.x < 0) camera.x = 0;
+ if (camera.x > levelWidth - 2048) camera.x = levelWidth - 2048;
+ if (camera.y < -500) camera.y = -500;
+ if (camera.y > 0) camera.y = 0;
+ // Apply camera offset to game
+ game.x = -camera.x;
+ game.y = -camera.y;
+ // Check collision with enemies
+ for (var i = 0; i < enemies.length; i++) {
+ var enemy = enemies[i];
+ if (player.intersects(enemy)) {
+ LK.getSound('hit').play();
+ LK.effects.flashScreen(0xFF0000, 500);
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 500);
+ return;
+ }
+ }
+ // Check if player reached goal
+ if (player.intersects(goal)) {
+ gameWon = true;
+ LK.effects.flashScreen(0x00FF00, 1000);
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 1000);
+ return;
+ }
+ // Check if player fell off the level
+ if (player.y > groundLevel + 500) {
+ LK.effects.flashScreen(0xFF0000, 500);
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 500);
+ return;
+ }
+};
\ No newline at end of file