User prompt
yes please
User prompt
can you then make it moveable with arrow keys
Code edit (1 edits merged)
Please save this source code
User prompt
Glitched Berry Forest
Initial prompt
can you make a cute game where a fox collects berries but one berry is glitched out and when you collect that it turns scary(some details later)
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Fox = Container.expand(function () {
var self = Container.call(this);
var foxGraphics = self.attachAsset('fox', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var GlitchedBerry = Container.expand(function () {
var self = Container.call(this);
var berryGraphics = self.attachAsset('glitchedBerry', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Erratic glitching movement
berryGraphics.rotation += 0.2;
berryGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.3) * 0.3;
berryGraphics.scaleY = 1 + Math.cos(LK.ticks * 0.3) * 0.3;
if (LK.ticks % 10 === 0) {
self.x += (Math.random() - 0.5) * 20;
self.y += (Math.random() - 0.5) * 20;
}
};
return self;
});
var NormalBerry = Container.expand(function () {
var self = Container.call(this);
var berryGraphics = self.attachAsset('normalBerry', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Gentle floating animation
self.y += Math.sin(LK.ticks * 0.1 + self.x * 0.01) * 0.5;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228b22
});
/****
* Game Code
****/
// Game state variables
var fox;
var normalBerries = [];
var glitchedBerry;
var dragNode = null;
var isGlitched = false;
var berrySpawnTimer = 0;
var glitchedBerrySpawned = false;
// Add forest background
var background = game.attachAsset('forestBackground', {
x: 0,
y: 0
});
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize fox
fox = game.addChild(new Fox());
fox.x = 1024;
fox.y = 1366;
// Spawn normal berry function
function spawnNormalBerry() {
var berry = new NormalBerry();
berry.x = Math.random() * (2048 - 120) + 60;
berry.y = Math.random() * (2732 - 120) + 60;
normalBerries.push(berry);
game.addChild(berry);
}
// Spawn glitched berry function
function spawnGlitchedBerry() {
if (!glitchedBerrySpawned) {
glitchedBerry = new GlitchedBerry();
glitchedBerry.x = Math.random() * (2048 - 120) + 60;
glitchedBerry.y = Math.random() * (2732 - 120) + 60;
game.addChild(glitchedBerry);
glitchedBerrySpawned = true;
}
}
// Transform game to scary mode
function triggerGlitchMode() {
isGlitched = true;
// Change background to dark scary color
game.setBackgroundColor(0x1a0d1a);
// Flash screen red
LK.effects.flashScreen(0xff0000, 2000);
// Play scary sound
LK.getSound('glitchSound').play();
// Make fox look scared by changing color to darker
tween(fox, {
tint: 0x666666
}, {
duration: 1000
});
// Make all remaining berries look corrupted
for (var i = 0; i < normalBerries.length; i++) {
tween(normalBerries[i], {
tint: 0x4d0033,
rotation: Math.PI
}, {
duration: 1500
});
}
// Show game over after a scary delay
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
}
// Keyboard state tracking
var keys = {
left: false,
right: false,
up: false,
down: false
};
// Handle keyboard events
LK.on('keydown', function (e) {
if (e.keyCode === 37) keys.left = true; // Left arrow
if (e.keyCode === 39) keys.right = true; // Right arrow
if (e.keyCode === 38) keys.up = true; // Up arrow
if (e.keyCode === 40) keys.down = true; // Down arrow
});
LK.on('keyup', function (e) {
if (e.keyCode === 37) keys.left = false; // Left arrow
if (e.keyCode === 39) keys.right = false; // Right arrow
if (e.keyCode === 38) keys.up = false; // Up arrow
if (e.keyCode === 40) keys.down = false; // Down arrow
});
// Handle mouse/touch move
function handleMove(x, y, obj) {
if (dragNode && !isGlitched) {
dragNode.x = x;
dragNode.y = y;
// Keep fox within bounds
if (dragNode.x < 60) dragNode.x = 60;
if (dragNode.x > 1988) dragNode.x = 1988;
if (dragNode.y < 60) dragNode.y = 60;
if (dragNode.y > 2672) dragNode.y = 2672;
}
}
// Handle keyboard movement
function handleKeyboardMovement() {
if (isGlitched) return;
var speed = 8;
if (keys.left && fox.x > 60) {
fox.x -= speed;
}
if (keys.right && fox.x < 1988) {
fox.x += speed;
}
if (keys.up && fox.y > 60) {
fox.y -= speed;
}
if (keys.down && fox.y < 2672) {
fox.y += speed;
}
}
// Mouse/touch events
game.move = handleMove;
game.down = function (x, y, obj) {
if (!isGlitched) {
dragNode = fox;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Initial berry spawning
spawnNormalBerry();
spawnNormalBerry();
spawnNormalBerry();
// Main game update loop
game.update = function () {
if (isGlitched) return;
// Handle keyboard movement
handleKeyboardMovement();
// Spawn berries over time
berrySpawnTimer++;
if (berrySpawnTimer >= 180) {
// Every 3 seconds
spawnNormalBerry();
berrySpawnTimer = 0;
}
// Spawn glitched berry after some normal berries collected
if (LK.getScore() >= 3 && !glitchedBerrySpawned) {
spawnGlitchedBerry();
}
// Check collisions with normal berries
for (var i = normalBerries.length - 1; i >= 0; i--) {
var berry = normalBerries[i];
if (fox.intersects(berry)) {
// Collect berry
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('berryCollect').play();
// Add collection effect
tween(berry, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
berry.destroy();
}
});
normalBerries.splice(i, 1);
}
}
// Check collision with glitched berry
if (glitchedBerry && fox.intersects(glitchedBerry)) {
triggerGlitchMode();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -125,8 +125,28 @@
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
}
+// Keyboard state tracking
+var keys = {
+ left: false,
+ right: false,
+ up: false,
+ down: false
+};
+// Handle keyboard events
+LK.on('keydown', function (e) {
+ if (e.keyCode === 37) keys.left = true; // Left arrow
+ if (e.keyCode === 39) keys.right = true; // Right arrow
+ if (e.keyCode === 38) keys.up = true; // Up arrow
+ if (e.keyCode === 40) keys.down = true; // Down arrow
+});
+LK.on('keyup', function (e) {
+ if (e.keyCode === 37) keys.left = false; // Left arrow
+ if (e.keyCode === 39) keys.right = false; // Right arrow
+ if (e.keyCode === 38) keys.up = false; // Up arrow
+ if (e.keyCode === 40) keys.down = false; // Down arrow
+});
// Handle mouse/touch move
function handleMove(x, y, obj) {
if (dragNode && !isGlitched) {
dragNode.x = x;
@@ -137,8 +157,25 @@
if (dragNode.y < 60) dragNode.y = 60;
if (dragNode.y > 2672) dragNode.y = 2672;
}
}
+// Handle keyboard movement
+function handleKeyboardMovement() {
+ if (isGlitched) return;
+ var speed = 8;
+ if (keys.left && fox.x > 60) {
+ fox.x -= speed;
+ }
+ if (keys.right && fox.x < 1988) {
+ fox.x += speed;
+ }
+ if (keys.up && fox.y > 60) {
+ fox.y -= speed;
+ }
+ if (keys.down && fox.y < 2672) {
+ fox.y += speed;
+ }
+}
// Mouse/touch events
game.move = handleMove;
game.down = function (x, y, obj) {
if (!isGlitched) {
@@ -155,8 +192,10 @@
spawnNormalBerry();
// Main game update loop
game.update = function () {
if (isGlitched) return;
+ // Handle keyboard movement
+ handleKeyboardMovement();
// Spawn berries over time
berrySpawnTimer++;
if (berrySpawnTimer >= 180) {
// Every 3 seconds
a cute fox with a basket. In-Game asset. 2d. High contrast. No shadows
a berry bush with a phew yummy berries on it. In-Game asset. 2d. High contrast. No shadows
a top view of a grass field with a cabin and some trees. In-Game asset. 2d. High contrast. No shadows
a cute little bunny. In-Game asset. 2d. High contrast. No shadows
cabin. In-Game asset. 2d. High contrast. No shadows
a angry wolve thats in 2d. In-Game asset. 2d. High contrast. No shadows
a cute cat with a bow. In-Game asset. 2d. High contrast. No shadows
a cute dear with an axe. In-Game asset. 2d. High contrast. No shadows
a dog cute dog with a hat and a shotgun. In-Game asset. 2d. High contrast. No shadows
a cute mouse with a hoodie on. In-Game asset. 2d. High contrast. No shadows
a cute fennec fox with a backbag. In-Game asset. 2d. High contrast. No shadows
a cute squirrel with a gutair. In-Game asset. 2d. High contrast. No shadows
a campfire. In-Game asset. 2d. High contrast. No shadows
sticks. In-Game asset. 2d. High contrast. No shadows
zombie duck. In-Game asset. 2d. High contrast. No shadows
cultists animal. In-Game asset. 2d. High contrast. No shadows
cultist girrafe. In-Game asset. 2d. High contrast. No shadows
cute nice bat cultist. In-Game asset. 2d. High contrast. No shadows
glitchSound
Sound effect
berryCollect
Sound effect
wendigoGrowl
Sound effect
wolfRoar
Sound effect
howl
Sound effect
dayMusic
Music
nightMusic
Music
bloodMoonMusic
Music
chaseTheme
Music
bunnyTouch
Sound effect
bunnyKill
Sound effect
catTouch
Sound effect
catKill
Sound effect
deerTouch
Sound effect
deerKill
Sound effect
dogTouch
Sound effect
dogKill
Sound effect
fennecTouch
Sound effect
fennecKill
Sound effect
mouseTouch
Sound effect
mouseKill
Sound effect
squirrelTouch
Sound effect
squirrelKill
Sound effect
peacefulNightAmbience
Music
twistedBloodMoonTheme
Music
wendigoChaseTheme
Music
zombieChaseTheme
Music
woodCollect
Sound effect
vampireJumpscare
Sound effect
dogStun
Sound effect
catWoodCollect
Sound effect
foxTwistedWoodCollect
Sound effect
batTouch
Sound effect
batKill
Sound effect