User prompt
You can add score system right corner
User prompt
Add score system add menü
User prompt
Add score
User prompt
Point system
User prompt
Target move up and right and left and down
User prompt
Target move up and down
User prompt
Target move right and left
User prompt
Background black
Code edit (1 edits merged)
Please save this source code
User prompt
Hı
Initial prompt
Hı
/**** * Classes ****/ // No plugins needed for MVP // HiCharacter: draggable by the player var HiCharacter = Container.expand(function () { var self = Container.call(this); var charAsset = self.attachAsset('hiCharacter', { anchorX: 0.5, anchorY: 0.5 }); // For possible future use: down/up events self.down = function (x, y, obj) {}; self.up = function (x, y, obj) {}; return self; }); // HiDot: collectible, spawns at random positions var HiDot = Container.expand(function () { var self = Container.call(this); var dotAsset = self.attachAsset('hiDot', { anchorX: 0.5, anchorY: 0.5 }); return self; }); // HiTarget: the goal area var HiTarget = Container.expand(function () { var self = Container.call(this); var targetAsset = self.attachAsset('hiTarget', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Center positions // "Hi" themed assets: a character, a target, and a collectible "dot". // Character: red box, Target: green ellipse, Dot: yellow ellipse. var centerX = 2048 / 2; var centerY = 2732 / 2; // --- MENU SYSTEM --- var menuOverlay = new Container(); menuOverlay.zIndex = 1000; // ensure on top // Menu background (semi-transparent) var menuBg = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, scaleX: 10, scaleY: 6, x: centerX, y: centerY }); menuBg.alpha = 0.92; menuOverlay.addChild(menuBg); // Menu title var menuTitle = new Text2('Hi Game', { size: 180, fill: 0xD83318 }); menuTitle.anchor.set(0.5, 0.5); menuTitle.x = centerX; menuTitle.y = centerY - 250; menuOverlay.addChild(menuTitle); // Start button var startBtn = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.5, scaleY: 1.2, x: centerX, y: centerY + 100 }); startBtn.alpha = 0.98; menuOverlay.addChild(startBtn); var startTxt = new Text2('Start Game', { size: 120, fill: 0xFFFFFF }); startTxt.anchor.set(0.5, 0.5); startTxt.x = centerX; startTxt.y = centerY + 100; menuOverlay.addChild(startTxt); // Add menu to GUI overlay LK.gui.center.addChild(menuOverlay); // Hide gameplay UI until game starts var scoreTxt = new Text2('0', { size: 140, fill: 0x222222 }); scoreTxt.anchor.set(1, 0); // anchor to right edge, top scoreTxt.x = LK.gui.top.width; // position at right edge of gui.top scoreTxt.visible = false; LK.gui.top.addChild(scoreTxt); // "Hı!" greeting text at the top center, below the score var hiTxt = new Text2('Hı!', { size: 120, fill: 0xD83318 }); hiTxt.anchor.set(0.5, 0); hiTxt.y = 160; hiTxt.visible = false; LK.gui.top.addChild(hiTxt); // Menu state var gameStarted = false; // Start button interaction startBtn.interactive = true; startBtn.down = function (x, y, obj) { if (gameStarted) return; gameStarted = true; menuOverlay.visible = false; scoreTxt.visible = true; hiTxt.visible = true; // Reset score LK.setScore(0); scoreTxt.setText('0'); }; startTxt.interactive = true; startTxt.down = startBtn.down; // Create and position the target near the bottom center var hiTarget = new HiTarget(); hiTarget.x = centerX; hiTarget.y = 2732 - 350; game.addChild(hiTarget); // Target movement variables (up/down and left/right) var targetSpeedY = 8; // px per frame (vertical) var targetDirY = 1; // 1 = down, -1 = up var targetMinY = 2732 - 700 + hiTarget.height / 2; var targetMaxY = 2732 - 200 - hiTarget.height / 2; var targetSpeedX = 10; // px per frame (horizontal) var targetDirX = 1; // 1 = right, -1 = left var targetMinX = 200 + hiTarget.width / 2; var targetMaxX = 2048 - 200 - hiTarget.width / 2; // Create and position the character near the top center var hiCharacter = new HiCharacter(); hiCharacter.x = centerX; hiCharacter.y = 500; game.addChild(hiCharacter); // Dots array var hiDots = []; // Dragging logic var dragNode = null; // For intersection state tracking var lastTargetIntersecting = false; // Helper: spawn a dot at a random position (not overlapping with target or character) function spawnDot() { var dot = new HiDot(); // Avoid top 200px and bottom 400px, and avoid left/right 100px var minX = 100 + dot.width / 2; var maxX = 2048 - 100 - dot.width / 2; var minY = 300 + dot.height / 2; var maxY = 2732 - 400 - dot.height / 2; // Try up to 10 times to avoid spawning on character or target for (var i = 0; i < 10; i++) { dot.x = minX + Math.random() * (maxX - minX); dot.y = minY + Math.random() * (maxY - minY); // Check overlap with character or target if (!dot.intersects(hiCharacter) && !dot.intersects(hiTarget)) break; } hiDots.push(dot); game.addChild(dot); } // Initial dot spawnDot(); // Move handler: drag character, check for dot/target intersections function handleMove(x, y, obj) { if (dragNode) { // Clamp to game area (avoid top left 100x100) var newX = Math.max(hiCharacter.width / 2 + 20, Math.min(2048 - hiCharacter.width / 2 - 20, x)); var newY = Math.max(hiCharacter.height / 2 + 120, Math.min(2732 - hiCharacter.height / 2 - 20, y)); dragNode.x = newX; dragNode.y = newY; } // Check for dot collection for (var i = hiDots.length - 1; i >= 0; i--) { var dot = hiDots[i]; if (hiCharacter.intersects(dot)) { // Collect dot dot.destroy(); hiDots.splice(i, 1); // Update score LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore().toString()); // Spawn a new dot spawnDot(); } } // Check for reaching the target (win condition: must have at least 5 points) var nowIntersecting = hiCharacter.intersects(hiTarget); if (!lastTargetIntersecting && nowIntersecting && LK.getScore() >= 5) { LK.effects.flashScreen(0x83de44, 800); LK.showYouWin(); } lastTargetIntersecting = nowIntersecting; } // Touch/mouse events game.down = function (x, y, obj) { // Only start drag if touch is on character var local = hiCharacter.toLocal(game.toGlobal({ x: x, y: y })); if (local.x >= -hiCharacter.width / 2 && local.x <= hiCharacter.width / 2 && local.y >= -hiCharacter.height / 2 && local.y <= hiCharacter.height / 2) { dragNode = hiCharacter; handleMove(x, y, obj); } }; game.move = handleMove; game.up = function (x, y, obj) { dragNode = null; }; // Game update: not needed for MVP, but required for intersection state tracking game.update = function () { // Move the target up and down hiTarget.y += targetSpeedY * targetDirY; if (hiTarget.y >= targetMaxY && targetDirY === 1) { hiTarget.y = targetMaxY; targetDirY = -1; } if (hiTarget.y <= targetMinY && targetDirY === -1) { hiTarget.y = targetMinY; targetDirY = 1; } // Move the target left and right hiTarget.x += targetSpeedX * targetDirX; if (hiTarget.x >= targetMaxX && targetDirX === 1) { hiTarget.x = targetMaxX; targetDirX = -1; } if (hiTarget.x <= targetMinX && targetDirX === -1) { hiTarget.x = targetMinX; targetDirX = 1; } // No per-frame logic needed except for intersection state tracking var nowIntersecting = hiCharacter.intersects(hiTarget); lastTargetIntersecting = nowIntersecting; };
===================================================================
--- original.js
+++ change.js
@@ -96,9 +96,10 @@
var scoreTxt = new Text2('0', {
size: 140,
fill: 0x222222
});
-scoreTxt.anchor.set(0.5, 0);
+scoreTxt.anchor.set(1, 0); // anchor to right edge, top
+scoreTxt.x = LK.gui.top.width; // position at right edge of gui.top
scoreTxt.visible = false;
LK.gui.top.addChild(scoreTxt);
// "Hı!" greeting text at the top center, below the score
var hiTxt = new Text2('Hı!', {
Man. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Witch. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Beatuful yellow Hair woman. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat