User prompt
Add a moving by arrow keys and add a hacker menu to visit hacked cameras and use hack commands in park and add a asset of Player in Hack Menu ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add a hack abilities to hack cameras and add a hack effect by canadian goose ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Park Patrol Mayhem
Initial prompt
make a game with canadian goose as player destroying cameras in park locations with security room and hack security cameras in park
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Camera = Container.expand(function () {
var self = Container.call(this);
var cameraGraphics = self.attachAsset('camera', {
anchorX: 0.5,
anchorY: 0.5
});
self.isDestroyed = false;
self.isHacked = false;
self.destroy = function () {
if (!self.isDestroyed) {
self.isDestroyed = true;
cameraGraphics.alpha = 0.3;
LK.getSound('cameraDestroy').play();
LK.setScore(LK.getScore() + 10);
camerasDestroyed++;
updateScoreDisplay();
}
};
self.hack = function () {
if (!self.isHacked && !self.isDestroyed) {
self.isHacked = true;
// Create hack effect - green tint and pulse
tween(cameraGraphics, {
tint: 0x00ff00
}, {
duration: 300,
easing: tween.easeIn
});
tween(cameraGraphics, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut
});
tween(cameraGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
// Camera is now hacked - disable it
cameraGraphics.alpha = 0.5;
cameraGraphics.tint = 0x00ff00;
}
});
LK.setScore(LK.getScore() + 15); // More points for hacking
camerasDestroyed++;
updateScoreDisplay();
}
};
return self;
});
var Goose = Container.expand(function () {
var self = Container.call(this);
var gooseGraphics = self.attachAsset('goose', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.isHidden = false;
self.hasKey = false;
self.hackRange = 150;
self.isHacking = false;
self.update = function () {
// Arrow key movement
if (LK.keys.ArrowLeft || LK.keys.KeyA) {
self.x -= self.speed;
}
if (LK.keys.ArrowRight || LK.keys.KeyD) {
self.x += self.speed;
}
if (LK.keys.ArrowUp || LK.keys.KeyW) {
self.y -= self.speed;
}
if (LK.keys.ArrowDown || LK.keys.KeyS) {
self.y += self.speed;
}
// Keep goose within bounds
if (self.x < 40) self.x = 40;
if (self.x > 2008) self.x = 2008;
if (self.y < 40) self.y = 40;
if (self.y > 2692) self.y = 2692;
// Check if hiding behind objects
self.checkHiding();
};
self.hackNearbyCamera = function () {
if (self.isHacking) return;
// Find closest camera within hack range
var closestCamera = null;
var closestDistance = self.hackRange;
for (var i = 0; i < cameras.length; i++) {
var camera = cameras[i];
if (!camera.isDestroyed && !camera.isHacked) {
var distance = Math.sqrt(Math.pow(self.x - camera.x, 2) + Math.pow(self.y - camera.y, 2));
if (distance <= closestDistance) {
closestCamera = camera;
closestDistance = distance;
}
}
}
if (closestCamera) {
self.isHacking = true;
closestCamera.hack();
// Create hack effect on goose
tween(gooseGraphics, {
tint: 0x00ff00
}, {
duration: 500,
easing: tween.easeInOut
});
tween(gooseGraphics, {
tint: 0xffffff
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isHacking = false;
}
});
}
};
self.checkHiding = function () {
self.isHidden = false;
for (var i = 0; i < hideSpots.length; i++) {
if (self.intersects(hideSpots[i])) {
self.isHidden = true;
break;
}
}
// Visual feedback for hiding
gooseGraphics.alpha = self.isHidden ? 0.6 : 1.0;
};
return self;
});
var Guard = Container.expand(function () {
var self = Container.call(this);
var guardGraphics = self.attachAsset('guard', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.direction = Math.random() * Math.PI * 2;
self.patrolTimer = 0;
self.detectionRadius = 80;
self.update = function () {
// Simple patrol behavior
self.patrolTimer++;
if (self.patrolTimer > 120) {
// Change direction every 2 seconds
self.direction = Math.random() * Math.PI * 2;
self.patrolTimer = 0;
}
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Keep guards within bounds
if (self.x < 50 || self.x > 1998) self.direction = Math.PI - self.direction;
if (self.y < 50 || self.y > 2682) self.direction = -self.direction;
// Check for goose detection
var distToGoose = Math.sqrt(Math.pow(self.x - goose.x, 2) + Math.pow(self.y - goose.y, 2));
if (distToGoose < self.detectionRadius && !goose.isHidden) {
// Game over - caught by guard
LK.getSound('gameOver').play();
LK.showGameOver();
}
};
return self;
});
var HackerMenu = Container.expand(function () {
var self = Container.call(this);
var menuBackground = self.attachAsset('securityRoom', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 8,
scaleY: 6
});
menuBackground.tint = 0x001100;
menuBackground.alpha = 0.9;
var playerAvatar = self.attachAsset('goose', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
playerAvatar.x = -800;
playerAvatar.y = -400;
playerAvatar.tint = 0x00ff00;
var titleText = new Text2('HACKER MENU - CAMERAS ACCESSED', {
size: 80,
fill: 0x00ff00
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 0;
titleText.y = -500;
self.addChild(titleText);
var commandsText = new Text2('COMMANDS:\n[1] Disable All Guards\n[2] Override Security\n[3] Access Camera Feed\n[ESC] Exit Menu', {
size: 60,
fill: 0x00ff00
});
commandsText.anchor.set(0.5, 0.5);
commandsText.x = 0;
commandsText.y = 0;
self.addChild(commandsText);
var hackedCamerasText = new Text2('HACKED CAMERAS: 0', {
size: 50,
fill: 0x00ff00
});
hackedCamerasText.anchor.set(0.5, 0.5);
hackedCamerasText.x = 0;
hackedCamerasText.y = 300;
self.addChild(hackedCamerasText);
self.isActive = false;
self.alpha = 0;
self.show = function () {
self.isActive = true;
var hackedCount = 0;
for (var i = 0; i < cameras.length; i++) {
if (cameras[i].isHacked) hackedCount++;
}
hackedCamerasText.setText('HACKED CAMERAS: ' + hackedCount);
tween(self, {
alpha: 1
}, {
duration: 300,
easing: tween.easeOut
});
};
self.hide = function () {
self.isActive = false;
tween(self, {
alpha: 0
}, {
duration: 300,
easing: tween.easeIn
});
};
self.executeCommand = function (command) {
switch (command) {
case '1':
// Disable all guards
for (var i = 0; i < guards.length; i++) {
guards[i].speed = 0;
guards[i].alpha = 0.3;
}
commandsText.setText('GUARDS DISABLED!\nPress [ESC] to exit');
break;
case '2':
// Override security - disable remaining cameras
for (var i = 0; i < cameras.length; i++) {
if (!cameras[i].isDestroyed && !cameras[i].isHacked) {
cameras[i].hack();
}
}
commandsText.setText('SECURITY OVERRIDDEN!\nPress [ESC] to exit');
break;
case '3':
commandsText.setText('CAMERA FEED ACCESSED!\nAll movements tracked.\nPress [ESC] to exit');
break;
}
};
return self;
});
var HideSpot = Container.expand(function (assetType) {
var self = Container.call(this);
var spotGraphics = self.attachAsset(assetType, {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Key = Container.expand(function () {
var self = Container.call(this);
var keyGraphics = self.attachAsset('key', {
anchorX: 0.5,
anchorY: 0.5
});
self.isCollected = false;
self.update = function () {
if (!self.isCollected && self.intersects(goose)) {
self.isCollected = true;
goose.hasKey = true;
keyGraphics.alpha = 0;
LK.getSound('keyCollect').play();
}
};
return self;
});
var SecurityRoom = Container.expand(function () {
var self = Container.call(this);
var roomGraphics = self.attachAsset('securityRoom', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (goose.hasKey && self.intersects(goose)) {
// Win condition - reached security room with key
LK.getSound('win').play();
LK.showYouWin();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228b22
});
/****
* Game Code
****/
// Game variables
var camerasDestroyed = 0;
var totalCameras = 8;
var dragTarget = null;
var cameras = [];
var guards = [];
var hideSpots = [];
// Create UI elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 120;
scoreTxt.y = 50;
LK.gui.topLeft.addChild(scoreTxt);
var cameraTxt = new Text2('Cameras: 0/8', {
size: 50,
fill: 0xFFFFFF
});
cameraTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(cameraTxt);
var instructionTxt = new Text2('Arrow keys to move, hack cameras, press H for hacker menu!', {
size: 40,
fill: 0xFFFF00
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 80;
LK.gui.top.addChild(instructionTxt);
// Create goose
var goose = game.addChild(new Goose());
goose.x = 200;
goose.y = 300;
// Create cameras scattered around the park
var cameraPositions = [{
x: 400,
y: 200
}, {
x: 800,
y: 300
}, {
x: 1200,
y: 400
}, {
x: 1600,
y: 250
}, {
x: 300,
y: 800
}, {
x: 700,
y: 1000
}, {
x: 1400,
y: 900
}, {
x: 1800,
y: 1200
}];
for (var i = 0; i < cameraPositions.length; i++) {
var camera = game.addChild(new Camera());
camera.x = cameraPositions[i].x;
camera.y = cameraPositions[i].y;
cameras.push(camera);
}
// Create guards
for (var g = 0; g < 3; g++) {
var guard = game.addChild(new Guard());
guard.x = 500 + g * 600;
guard.y = 600 + g * 400;
guards.push(guard);
}
// Create hiding spots (trees and benches)
var hideSpotPositions = [{
type: 'tree',
x: 350,
y: 500
}, {
type: 'bench',
x: 600,
y: 700
}, {
type: 'tree',
x: 1000,
y: 600
}, {
type: 'bench',
x: 1300,
y: 800
}, {
type: 'tree',
x: 1500,
y: 500
}, {
type: 'bench',
x: 200,
y: 1200
}];
for (var h = 0; h < hideSpotPositions.length; h++) {
var hideSpot = game.addChild(new HideSpot(hideSpotPositions[h].type));
hideSpot.x = hideSpotPositions[h].x;
hideSpot.y = hideSpotPositions[h].y;
hideSpots.push(hideSpot);
}
// Create key
var key = game.addChild(new Key());
key.x = 1600;
key.y = 1500;
// Create security room
var securityRoom = game.addChild(new SecurityRoom());
securityRoom.x = 1800;
securityRoom.y = 2200;
// Create hacker menu
var hackerMenu = game.addChild(new HackerMenu());
hackerMenu.x = 1024;
hackerMenu.y = 1366;
function updateScoreDisplay() {
scoreTxt.setText('Score: ' + LK.getScore());
cameraTxt.setText('Cameras: ' + camerasDestroyed + '/' + totalCameras);
if (camerasDestroyed >= totalCameras) {
instructionTxt.setText('All cameras destroyed! Find the security room!');
}
}
// Touch/mouse controls
game.down = function (x, y, obj) {
dragTarget = goose;
};
game.move = function (x, y, obj) {
if (dragTarget) {
dragTarget.x = x;
dragTarget.y = y;
}
};
game.up = function (x, y, obj) {
dragTarget = null;
// Double tap detection for hack ability
if (goose.intersects({
x: x,
y: y,
width: 100,
height: 100
}) || Math.abs(goose.x - x) < 50 && Math.abs(goose.y - y) < 50) {
goose.hackNearbyCamera();
}
};
// Main game loop
game.update = function () {
// Keyboard controls for hacker menu
if (LK.keys.KeyH && !hackerMenu.isActive) {
// Check if player has hacked at least one camera
var hasHackedCamera = false;
for (var i = 0; i < cameras.length; i++) {
if (cameras[i].isHacked) {
hasHackedCamera = true;
break;
}
}
if (hasHackedCamera) {
hackerMenu.show();
}
}
if (LK.keys.Escape && hackerMenu.isActive) {
hackerMenu.hide();
}
// Command execution in hacker menu
if (hackerMenu.isActive) {
if (LK.keys.Digit1) {
hackerMenu.executeCommand('1');
}
if (LK.keys.Digit2) {
hackerMenu.executeCommand('2');
}
if (LK.keys.Digit3) {
hackerMenu.executeCommand('3');
}
}
// Check for camera collisions
for (var c = 0; c < cameras.length; c++) {
var camera = cameras[c];
if (!camera.isDestroyed && !camera.isHacked && camera.intersects(goose)) {
camera.destroy();
}
}
// Win condition check - all cameras destroyed and in security room
if (camerasDestroyed >= totalCameras && goose.hasKey) {
instructionTxt.setText('Enter the security room to hack the system!');
}
}; ===================================================================
--- original.js
+++ change.js
@@ -71,8 +71,21 @@
self.hasKey = false;
self.hackRange = 150;
self.isHacking = false;
self.update = function () {
+ // Arrow key movement
+ if (LK.keys.ArrowLeft || LK.keys.KeyA) {
+ self.x -= self.speed;
+ }
+ if (LK.keys.ArrowRight || LK.keys.KeyD) {
+ self.x += self.speed;
+ }
+ if (LK.keys.ArrowUp || LK.keys.KeyW) {
+ self.y -= self.speed;
+ }
+ if (LK.keys.ArrowDown || LK.keys.KeyS) {
+ self.y += self.speed;
+ }
// Keep goose within bounds
if (self.x < 40) self.x = 40;
if (self.x > 2008) self.x = 2008;
if (self.y < 40) self.y = 40;
@@ -161,8 +174,102 @@
}
};
return self;
});
+var HackerMenu = Container.expand(function () {
+ var self = Container.call(this);
+ var menuBackground = self.attachAsset('securityRoom', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 8,
+ scaleY: 6
+ });
+ menuBackground.tint = 0x001100;
+ menuBackground.alpha = 0.9;
+ var playerAvatar = self.attachAsset('goose', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 2,
+ scaleY: 2
+ });
+ playerAvatar.x = -800;
+ playerAvatar.y = -400;
+ playerAvatar.tint = 0x00ff00;
+ var titleText = new Text2('HACKER MENU - CAMERAS ACCESSED', {
+ size: 80,
+ fill: 0x00ff00
+ });
+ titleText.anchor.set(0.5, 0.5);
+ titleText.x = 0;
+ titleText.y = -500;
+ self.addChild(titleText);
+ var commandsText = new Text2('COMMANDS:\n[1] Disable All Guards\n[2] Override Security\n[3] Access Camera Feed\n[ESC] Exit Menu', {
+ size: 60,
+ fill: 0x00ff00
+ });
+ commandsText.anchor.set(0.5, 0.5);
+ commandsText.x = 0;
+ commandsText.y = 0;
+ self.addChild(commandsText);
+ var hackedCamerasText = new Text2('HACKED CAMERAS: 0', {
+ size: 50,
+ fill: 0x00ff00
+ });
+ hackedCamerasText.anchor.set(0.5, 0.5);
+ hackedCamerasText.x = 0;
+ hackedCamerasText.y = 300;
+ self.addChild(hackedCamerasText);
+ self.isActive = false;
+ self.alpha = 0;
+ self.show = function () {
+ self.isActive = true;
+ var hackedCount = 0;
+ for (var i = 0; i < cameras.length; i++) {
+ if (cameras[i].isHacked) hackedCount++;
+ }
+ hackedCamerasText.setText('HACKED CAMERAS: ' + hackedCount);
+ tween(self, {
+ alpha: 1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ };
+ self.hide = function () {
+ self.isActive = false;
+ tween(self, {
+ alpha: 0
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ };
+ self.executeCommand = function (command) {
+ switch (command) {
+ case '1':
+ // Disable all guards
+ for (var i = 0; i < guards.length; i++) {
+ guards[i].speed = 0;
+ guards[i].alpha = 0.3;
+ }
+ commandsText.setText('GUARDS DISABLED!\nPress [ESC] to exit');
+ break;
+ case '2':
+ // Override security - disable remaining cameras
+ for (var i = 0; i < cameras.length; i++) {
+ if (!cameras[i].isDestroyed && !cameras[i].isHacked) {
+ cameras[i].hack();
+ }
+ }
+ commandsText.setText('SECURITY OVERRIDDEN!\nPress [ESC] to exit');
+ break;
+ case '3':
+ commandsText.setText('CAMERA FEED ACCESSED!\nAll movements tracked.\nPress [ESC] to exit');
+ break;
+ }
+ };
+ return self;
+});
var HideSpot = Container.expand(function (assetType) {
var self = Container.call(this);
var spotGraphics = self.attachAsset(assetType, {
anchorX: 0.5,
@@ -234,9 +341,9 @@
fill: 0xFFFFFF
});
cameraTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(cameraTxt);
-var instructionTxt = new Text2('Destroy cameras, avoid guards, find the key!', {
+var instructionTxt = new Text2('Arrow keys to move, hack cameras, press H for hacker menu!', {
size: 40,
fill: 0xFFFF00
});
instructionTxt.anchor.set(0.5, 0);
@@ -324,8 +431,12 @@
// Create security room
var securityRoom = game.addChild(new SecurityRoom());
securityRoom.x = 1800;
securityRoom.y = 2200;
+// Create hacker menu
+var hackerMenu = game.addChild(new HackerMenu());
+hackerMenu.x = 1024;
+hackerMenu.y = 1366;
function updateScoreDisplay() {
scoreTxt.setText('Score: ' + LK.getScore());
cameraTxt.setText('Cameras: ' + camerasDestroyed + '/' + totalCameras);
if (camerasDestroyed >= totalCameras) {
@@ -355,8 +466,37 @@
}
};
// Main game loop
game.update = function () {
+ // Keyboard controls for hacker menu
+ if (LK.keys.KeyH && !hackerMenu.isActive) {
+ // Check if player has hacked at least one camera
+ var hasHackedCamera = false;
+ for (var i = 0; i < cameras.length; i++) {
+ if (cameras[i].isHacked) {
+ hasHackedCamera = true;
+ break;
+ }
+ }
+ if (hasHackedCamera) {
+ hackerMenu.show();
+ }
+ }
+ if (LK.keys.Escape && hackerMenu.isActive) {
+ hackerMenu.hide();
+ }
+ // Command execution in hacker menu
+ if (hackerMenu.isActive) {
+ if (LK.keys.Digit1) {
+ hackerMenu.executeCommand('1');
+ }
+ if (LK.keys.Digit2) {
+ hackerMenu.executeCommand('2');
+ }
+ if (LK.keys.Digit3) {
+ hackerMenu.executeCommand('3');
+ }
+ }
// Check for camera collisions
for (var c = 0; c < cameras.length; c++) {
var camera = cameras[c];
if (!camera.isDestroyed && !camera.isHacked && camera.intersects(goose)) {