User prompt
increase the alpha of all assets that start with scope
User prompt
make the not viewed areas color #060606
User prompt
reduce it a litte
User prompt
increase it more an do it the same as not viewed areas alpha
User prompt
increase the alpha of scope ring asset
User prompt
make the scoep circular shaped
User prompt
little bit more
User prompt
little bit more
User prompt
a little bit more
User prompt
yes it is working now. can you do it a little bit more
User prompt
it doesnt work. can you please darken the not viewed area and do not change the viewed area.
User prompt
viewed areas alpha will stay. darken just the not viewed ara
User prompt
more
User prompt
it gotten worse can you do the opposite of what you are doing
User prompt
it is too dark and seeing the targets is not possible at the moment. can yo fix it
User prompt
the scopes vision is very dark. can you fix it
User prompt
do not add a yellow tint just increase the brightness of it
User prompt
make the viewed part brighter
User prompt
Please fix the bug: 'LK.effects.maskCircle is not a function' in or related to this line: 'scopeMaskOverlay = LK.effects.maskCircle({' Line Number: 211
User prompt
make the scope view circular not rectangular
User prompt
The areas outside the circle seen by the scope should be black and the aiming effect should be given.
User prompt
Do not show any other places on the screen other than the scope.
User prompt
the weapon is not shooting whe the button is pressed. can you fix it
User prompt
make the gun shoot when red fire button is pressed
User prompt
shoot when shoot button is pressed
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Fire Button class var FireButton = Container.expand(function () { var self = Container.call(this); var btn = self.attachAsset('fire_btn', { anchorX: 0.5, anchorY: 0.5 }); var txt = new Text2('FIRE', { size: 60, fill: "#fff" }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = 0; self.addChild(txt); // For press effect self.flash = function () { tween(btn, { alpha: 0.5 }, { duration: 80, onFinish: function onFinish() { tween(btn, { alpha: 1 }, { duration: 80 }); } }); }; return self; }); // Sniper Scope class var Scope = Container.expand(function () { var self = Container.call(this); // Scope ring var ring = self.attachAsset('scope_ring', { anchorX: 0.5, anchorY: 0.5, alpha: 0.25 }); // Crosshairs var crossV = self.attachAsset('scope_crosshair_v', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5 }); var crossH = self.attachAsset('scope_crosshair_h', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5 }); // For shot flash self.flash = function () { var flash = self.attachAsset('shot_flash', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 }); tween(flash, { alpha: 0 }, { duration: 200, onFinish: function onFinish() { flash.destroy(); } }); }; return self; }); // Stickman class (base for all stickmen) var Stickman = Container.expand(function () { var self = Container.call(this); // Default: civilian self.isTarget = false; self.isAlive = true; // Set up body and head var body = null; var head = null; self.setType = function (type) { // Remove previous if (body) body.destroy(); if (head) head.destroy(); if (type === 'target') { body = self.attachAsset('stickman_target_body', { anchorX: 0.5, anchorY: 0 }); head = self.attachAsset('stickman_target_head', { anchorX: 0.5, anchorY: 0.5, y: 0 }); head.y = -30; self.isTarget = true; } else if (type === 'civilian') { body = self.attachAsset('stickman_civilian_body', { anchorX: 0.5, anchorY: 0 }); head = self.attachAsset('stickman_civilian_head', { anchorX: 0.5, anchorY: 0.5, y: 0 }); head.y = -30; self.isTarget = false; } else { body = self.attachAsset('stickman_body', { anchorX: 0.5, anchorY: 0 }); head = self.attachAsset('stickman_head', { anchorX: 0.5, anchorY: 0.5, y: 0 }); head.y = -30; self.isTarget = false; } }; // For hit detection, we use the head and body rectangles self.getHitRects = function () { // Returns array of rectangles in game coordinates var rects = []; if (!body || !head) return rects; // Body rects.push(new Rectangle(self.x - body.width / 2, self.y, body.width, body.height)); // Head rects.push(new Rectangle(self.x - head.width / 2, self.y - 30 - head.height / 2, head.width, head.height)); return rects; }; // Animate death self.die = function () { if (!self.isAlive) return; self.isAlive = false; // Fade out and fall tween(self, { rotation: Math.PI / 2, alpha: 0 }, { duration: 700, easing: tween.cubicOut, onFinish: function onFinish() { self.visible = false; } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Music // Sound effects // Shot effect // Fire button // Sniper scope // Stickman body (used for both targets and civilians, colored differently) // --- Level Data --- var levels = [ // Each level: {targets: [positions], civilians: [positions], time: seconds, story: string} { targets: [{ x: 600, y: 1200 }], civilians: [{ x: 900, y: 1200 }, { x: 1400, y: 1200 }], time: 15, story: "Eliminate the red stickman. Avoid civilians!" }, { targets: [{ x: 400, y: 1000 }, { x: 1600, y: 1300 }], civilians: [{ x: 900, y: 1200 }, { x: 1200, y: 1400 }, { x: 700, y: 1500 }], time: 18, story: "Two targets this time. Don't miss!" }, { targets: [{ x: 500, y: 900 }, { x: 1550, y: 1100 }, { x: 1000, y: 1700 }], civilians: [{ x: 800, y: 1200 }, { x: 1200, y: 1300 }, { x: 1700, y: 1500 }, { x: 600, y: 1600 }], time: 20, story: "Three targets. Watch out for blue civilians!" } // More levels can be added here ]; // --- Game State --- var currentLevel = 0; var stickmen = []; var targetsLeft = 0; var timeLeft = 0; var timerInterval = null; var gameActive = false; var score = 0; var shotsFired = 0; var shotsHit = 0; var levelStartTime = 0; // --- UI Elements --- var scope = null; var fireBtn = null; var timerTxt = null; var scoreTxt = null; var storyTxt = null; // --- Setup UI --- function setupUI() { // Remove previous UI if any if (timerTxt) timerTxt.destroy(); if (scoreTxt) scoreTxt.destroy(); if (storyTxt) storyTxt.destroy(); // Timer (top right) timerTxt = new Text2('00', { size: 90, fill: "#fff" }); timerTxt.anchor.set(1, 0); LK.gui.topRight.addChild(timerTxt); // Score (top center) scoreTxt = new Text2('Score: 0', { size: 90, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Story (top, below score) storyTxt = new Text2('', { size: 60, fill: "#fff" }); storyTxt.anchor.set(0.5, 0); storyTxt.y = 100; LK.gui.top.addChild(storyTxt); } // --- Start Level --- function startLevel(levelIdx) { // Clean up previous for (var i = 0; i < stickmen.length; ++i) { stickmen[i].destroy(); } stickmen = []; targetsLeft = 0; timeLeft = 0; gameActive = false; shotsFired = 0; shotsHit = 0; setupUI(); // Level data var level = levels[levelIdx]; if (!level) { // No more levels: show win LK.showYouWin(); return; } // Show story storyTxt.setText(level.story); // Place stickmen // Targets for (var i = 0; i < level.targets.length; ++i) { var t = new Stickman(); t.setType('target'); t.x = level.targets[i].x; t.y = level.targets[i].y; game.addChild(t); stickmen.push(t); targetsLeft++; } // Civilians for (var i = 0; i < level.civilians.length; ++i) { var c = new Stickman(); c.setType('civilian'); c.x = level.civilians[i].x; c.y = level.civilians[i].y; game.addChild(c); stickmen.push(c); } // Reset scope position to center if (scope) scope.destroy(); scope = new Scope(); scope.x = 2048 / 2; scope.y = 2732 / 2; game.addChild(scope); // Fire button (bottom right, but offset diagonally up left) if (fireBtn) fireBtn.destroy(); fireBtn = new FireButton(); // Offset the button up and left from the bottom right corner fireBtn.x = -180; fireBtn.y = -180; LK.gui.bottomRight.addChild(fireBtn); // Timer timeLeft = level.time; timerTxt.setText(timeLeft.toFixed(1)); scoreTxt.setText('Score: ' + score); // Start timer if (timerInterval) LK.clearInterval(timerInterval); timerInterval = LK.setInterval(function () { if (!gameActive) return; timeLeft -= 0.1; if (timeLeft < 0) timeLeft = 0; timerTxt.setText(timeLeft.toFixed(1)); if (timeLeft <= 0) { failLevel("Time's up!"); } }, 100); // Enable game gameActive = true; levelStartTime = Date.now(); } // --- Fire Shot --- function fireShot() { if (!gameActive) return; fireBtn.flash(); scope.flash(); LK.getSound('shot').play(); shotsFired++; // Check if any stickman is under the scope center var hit = false; var hitTarget = null; var hitCivilian = null; for (var i = 0; i < stickmen.length; ++i) { var s = stickmen[i]; if (!s.isAlive) continue; var rects = s.getHitRects(); for (var j = 0; j < rects.length; ++j) { var r = rects[j]; // Scope center is (scope.x, scope.y) if (scope.x >= r.x && scope.x <= r.x + r.width && scope.y >= r.y && scope.y <= r.y + r.height) { hit = true; if (s.isTarget) hitTarget = s;else hitCivilian = s; break; } } if (hit) break; } if (hitTarget) { // Success: kill target hitTarget.die(); targetsLeft--; shotsHit++; score += 100 + Math.max(0, Math.floor(50 * (timeLeft / levels[currentLevel].time))); scoreTxt.setText('Score: ' + score); LK.getSound('success').play(); if (targetsLeft <= 0) { // Level complete gameActive = false; LK.setTimeout(function () { currentLevel++; startLevel(currentLevel); }, 1200); } } else if (hitCivilian) { // Fail: hit civilian hitCivilian.die(); failLevel("You shot a civilian!"); } else { // Missed shot failLevel("You missed!"); } } // --- Fail Level --- function failLevel(msg) { if (!gameActive) return; gameActive = false; LK.getSound('fail').play(); LK.effects.flashScreen(0xff0000, 800); // Show game over after a short delay LK.setTimeout(function () { LK.showGameOver(); }, 900); } // --- Game Move/Drag Handling --- var draggingScope = false; var dragOffsetX = 0; var dragOffsetY = 0; // Only allow dragging scope, not fire button game.down = function (x, y, obj) { // If touch is inside fireBtn, don't drag scope var local = LK.gui.bottomRight.toLocal({ x: x, y: y }); if (fireBtn && fireBtn.containsPoint && fireBtn.containsPoint(local)) { // Do nothing, handled by fireBtn return; } // If touch is inside scope, start dragging var dx = x - scope.x; var dy = y - scope.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 200) { // inside scope ring draggingScope = true; dragOffsetX = dx; dragOffsetY = dy; } }; game.move = function (x, y, obj) { if (draggingScope && gameActive) { // Clamp scope inside game area var nx = x - dragOffsetX; var ny = y - dragOffsetY; // Keep scope inside screen if (nx < 200) nx = 200; if (nx > 2048 - 200) nx = 2048 - 200; if (ny < 200) ny = 200; if (ny > 2732 - 200) ny = 2732 - 200; scope.x = nx; scope.y = ny; } }; game.up = function (x, y, obj) { draggingScope = false; }; // Fire button press fireBtn = null; // Will be created in startLevel // Add a shoot button to the game UI and handle its press to fire // We need to handle fireBtn presses LK.gui.bottomRight.down = function (x, y, obj) { // Convert to fireBtn local if (!fireBtn || !gameActive) return; var local = fireBtn.toLocal({ x: x, y: y }); // Check if inside button if (local.x >= -110 && local.x <= 110 && local.y >= -60 && local.y <= 60) { fireShot(); } }; // --- Game Update --- game.update = function () { // No per-frame logic needed for now }; // --- Start Game --- currentLevel = 0; score = 0; setupUI(); startLevel(currentLevel); // --- Play music --- LK.playMusic('sniper_bg');
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Fire Button class
var FireButton = Container.expand(function () {
var self = Container.call(this);
var btn = self.attachAsset('fire_btn', {
anchorX: 0.5,
anchorY: 0.5
});
var txt = new Text2('FIRE', {
size: 60,
fill: "#fff"
});
txt.anchor.set(0.5, 0.5);
txt.x = 0;
txt.y = 0;
self.addChild(txt);
// For press effect
self.flash = function () {
tween(btn, {
alpha: 0.5
}, {
duration: 80,
onFinish: function onFinish() {
tween(btn, {
alpha: 1
}, {
duration: 80
});
}
});
};
return self;
});
// Sniper Scope class
var Scope = Container.expand(function () {
var self = Container.call(this);
// Scope ring
var ring = self.attachAsset('scope_ring', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.25
});
// Crosshairs
var crossV = self.attachAsset('scope_crosshair_v', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
var crossH = self.attachAsset('scope_crosshair_h', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
// For shot flash
self.flash = function () {
var flash = self.attachAsset('shot_flash', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
tween(flash, {
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
flash.destroy();
}
});
};
return self;
});
// Stickman class (base for all stickmen)
var Stickman = Container.expand(function () {
var self = Container.call(this);
// Default: civilian
self.isTarget = false;
self.isAlive = true;
// Set up body and head
var body = null;
var head = null;
self.setType = function (type) {
// Remove previous
if (body) body.destroy();
if (head) head.destroy();
if (type === 'target') {
body = self.attachAsset('stickman_target_body', {
anchorX: 0.5,
anchorY: 0
});
head = self.attachAsset('stickman_target_head', {
anchorX: 0.5,
anchorY: 0.5,
y: 0
});
head.y = -30;
self.isTarget = true;
} else if (type === 'civilian') {
body = self.attachAsset('stickman_civilian_body', {
anchorX: 0.5,
anchorY: 0
});
head = self.attachAsset('stickman_civilian_head', {
anchorX: 0.5,
anchorY: 0.5,
y: 0
});
head.y = -30;
self.isTarget = false;
} else {
body = self.attachAsset('stickman_body', {
anchorX: 0.5,
anchorY: 0
});
head = self.attachAsset('stickman_head', {
anchorX: 0.5,
anchorY: 0.5,
y: 0
});
head.y = -30;
self.isTarget = false;
}
};
// For hit detection, we use the head and body rectangles
self.getHitRects = function () {
// Returns array of rectangles in game coordinates
var rects = [];
if (!body || !head) return rects;
// Body
rects.push(new Rectangle(self.x - body.width / 2, self.y, body.width, body.height));
// Head
rects.push(new Rectangle(self.x - head.width / 2, self.y - 30 - head.height / 2, head.width, head.height));
return rects;
};
// Animate death
self.die = function () {
if (!self.isAlive) return;
self.isAlive = false;
// Fade out and fall
tween(self, {
rotation: Math.PI / 2,
alpha: 0
}, {
duration: 700,
easing: tween.cubicOut,
onFinish: function onFinish() {
self.visible = false;
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Music
// Sound effects
// Shot effect
// Fire button
// Sniper scope
// Stickman body (used for both targets and civilians, colored differently)
// --- Level Data ---
var levels = [
// Each level: {targets: [positions], civilians: [positions], time: seconds, story: string}
{
targets: [{
x: 600,
y: 1200
}],
civilians: [{
x: 900,
y: 1200
}, {
x: 1400,
y: 1200
}],
time: 15,
story: "Eliminate the red stickman. Avoid civilians!"
}, {
targets: [{
x: 400,
y: 1000
}, {
x: 1600,
y: 1300
}],
civilians: [{
x: 900,
y: 1200
}, {
x: 1200,
y: 1400
}, {
x: 700,
y: 1500
}],
time: 18,
story: "Two targets this time. Don't miss!"
}, {
targets: [{
x: 500,
y: 900
}, {
x: 1550,
y: 1100
}, {
x: 1000,
y: 1700
}],
civilians: [{
x: 800,
y: 1200
}, {
x: 1200,
y: 1300
}, {
x: 1700,
y: 1500
}, {
x: 600,
y: 1600
}],
time: 20,
story: "Three targets. Watch out for blue civilians!"
}
// More levels can be added here
];
// --- Game State ---
var currentLevel = 0;
var stickmen = [];
var targetsLeft = 0;
var timeLeft = 0;
var timerInterval = null;
var gameActive = false;
var score = 0;
var shotsFired = 0;
var shotsHit = 0;
var levelStartTime = 0;
// --- UI Elements ---
var scope = null;
var fireBtn = null;
var timerTxt = null;
var scoreTxt = null;
var storyTxt = null;
// --- Setup UI ---
function setupUI() {
// Remove previous UI if any
if (timerTxt) timerTxt.destroy();
if (scoreTxt) scoreTxt.destroy();
if (storyTxt) storyTxt.destroy();
// Timer (top right)
timerTxt = new Text2('00', {
size: 90,
fill: "#fff"
});
timerTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timerTxt);
// Score (top center)
scoreTxt = new Text2('Score: 0', {
size: 90,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Story (top, below score)
storyTxt = new Text2('', {
size: 60,
fill: "#fff"
});
storyTxt.anchor.set(0.5, 0);
storyTxt.y = 100;
LK.gui.top.addChild(storyTxt);
}
// --- Start Level ---
function startLevel(levelIdx) {
// Clean up previous
for (var i = 0; i < stickmen.length; ++i) {
stickmen[i].destroy();
}
stickmen = [];
targetsLeft = 0;
timeLeft = 0;
gameActive = false;
shotsFired = 0;
shotsHit = 0;
setupUI();
// Level data
var level = levels[levelIdx];
if (!level) {
// No more levels: show win
LK.showYouWin();
return;
}
// Show story
storyTxt.setText(level.story);
// Place stickmen
// Targets
for (var i = 0; i < level.targets.length; ++i) {
var t = new Stickman();
t.setType('target');
t.x = level.targets[i].x;
t.y = level.targets[i].y;
game.addChild(t);
stickmen.push(t);
targetsLeft++;
}
// Civilians
for (var i = 0; i < level.civilians.length; ++i) {
var c = new Stickman();
c.setType('civilian');
c.x = level.civilians[i].x;
c.y = level.civilians[i].y;
game.addChild(c);
stickmen.push(c);
}
// Reset scope position to center
if (scope) scope.destroy();
scope = new Scope();
scope.x = 2048 / 2;
scope.y = 2732 / 2;
game.addChild(scope);
// Fire button (bottom right, but offset diagonally up left)
if (fireBtn) fireBtn.destroy();
fireBtn = new FireButton();
// Offset the button up and left from the bottom right corner
fireBtn.x = -180;
fireBtn.y = -180;
LK.gui.bottomRight.addChild(fireBtn);
// Timer
timeLeft = level.time;
timerTxt.setText(timeLeft.toFixed(1));
scoreTxt.setText('Score: ' + score);
// Start timer
if (timerInterval) LK.clearInterval(timerInterval);
timerInterval = LK.setInterval(function () {
if (!gameActive) return;
timeLeft -= 0.1;
if (timeLeft < 0) timeLeft = 0;
timerTxt.setText(timeLeft.toFixed(1));
if (timeLeft <= 0) {
failLevel("Time's up!");
}
}, 100);
// Enable game
gameActive = true;
levelStartTime = Date.now();
}
// --- Fire Shot ---
function fireShot() {
if (!gameActive) return;
fireBtn.flash();
scope.flash();
LK.getSound('shot').play();
shotsFired++;
// Check if any stickman is under the scope center
var hit = false;
var hitTarget = null;
var hitCivilian = null;
for (var i = 0; i < stickmen.length; ++i) {
var s = stickmen[i];
if (!s.isAlive) continue;
var rects = s.getHitRects();
for (var j = 0; j < rects.length; ++j) {
var r = rects[j];
// Scope center is (scope.x, scope.y)
if (scope.x >= r.x && scope.x <= r.x + r.width && scope.y >= r.y && scope.y <= r.y + r.height) {
hit = true;
if (s.isTarget) hitTarget = s;else hitCivilian = s;
break;
}
}
if (hit) break;
}
if (hitTarget) {
// Success: kill target
hitTarget.die();
targetsLeft--;
shotsHit++;
score += 100 + Math.max(0, Math.floor(50 * (timeLeft / levels[currentLevel].time)));
scoreTxt.setText('Score: ' + score);
LK.getSound('success').play();
if (targetsLeft <= 0) {
// Level complete
gameActive = false;
LK.setTimeout(function () {
currentLevel++;
startLevel(currentLevel);
}, 1200);
}
} else if (hitCivilian) {
// Fail: hit civilian
hitCivilian.die();
failLevel("You shot a civilian!");
} else {
// Missed shot
failLevel("You missed!");
}
}
// --- Fail Level ---
function failLevel(msg) {
if (!gameActive) return;
gameActive = false;
LK.getSound('fail').play();
LK.effects.flashScreen(0xff0000, 800);
// Show game over after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 900);
}
// --- Game Move/Drag Handling ---
var draggingScope = false;
var dragOffsetX = 0;
var dragOffsetY = 0;
// Only allow dragging scope, not fire button
game.down = function (x, y, obj) {
// If touch is inside fireBtn, don't drag scope
var local = LK.gui.bottomRight.toLocal({
x: x,
y: y
});
if (fireBtn && fireBtn.containsPoint && fireBtn.containsPoint(local)) {
// Do nothing, handled by fireBtn
return;
}
// If touch is inside scope, start dragging
var dx = x - scope.x;
var dy = y - scope.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 200) {
// inside scope ring
draggingScope = true;
dragOffsetX = dx;
dragOffsetY = dy;
}
};
game.move = function (x, y, obj) {
if (draggingScope && gameActive) {
// Clamp scope inside game area
var nx = x - dragOffsetX;
var ny = y - dragOffsetY;
// Keep scope inside screen
if (nx < 200) nx = 200;
if (nx > 2048 - 200) nx = 2048 - 200;
if (ny < 200) ny = 200;
if (ny > 2732 - 200) ny = 2732 - 200;
scope.x = nx;
scope.y = ny;
}
};
game.up = function (x, y, obj) {
draggingScope = false;
};
// Fire button press
fireBtn = null; // Will be created in startLevel
// Add a shoot button to the game UI and handle its press to fire
// We need to handle fireBtn presses
LK.gui.bottomRight.down = function (x, y, obj) {
// Convert to fireBtn local
if (!fireBtn || !gameActive) return;
var local = fireBtn.toLocal({
x: x,
y: y
});
// Check if inside button
if (local.x >= -110 && local.x <= 110 && local.y >= -60 && local.y <= 60) {
fireShot();
}
};
// --- Game Update ---
game.update = function () {
// No per-frame logic needed for now
};
// --- Start Game ---
currentLevel = 0;
score = 0;
setupUI();
startLevel(currentLevel);
// --- Play music ---
LK.playMusic('sniper_bg');