User prompt
Make the score 0
User prompt
Make the score 0 when we pause the game
User prompt
When we get out of the game make the score 0
User prompt
Put the button a little down
User prompt
Make the button a arrow your making me mad
User prompt
Make the button a arrow that is facing up not a block
User prompt
Make the jump button a arrow
User prompt
Make the jump button a arrow that is pointing upwards and put the jump button on the right side
Code edit (1 edits merged)
Please save this source code
User prompt
Jump Block!
Initial prompt
Make a game that there is a block there is a jump arrow if you press it the block will jump
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// The main block the player controls
var JumpBlock = Container.expand(function () {
var self = Container.call(this);
// Attach the block asset (a box)
var block = self.attachAsset('jumpBlock', {
anchorX: 0.5,
anchorY: 0.5
});
// Block state
self.isJumping = false;
self.jumpHeight = 500; // How high the block jumps (in px)
self.jumpDuration = 350; // ms for jump up
self.fallDuration = 400; // ms for fall down
// Store ground Y for reset
self.groundY = 0;
// Method to trigger jump
self.jump = function (_onFinish) {
if (self.isJumping) return;
self.isJumping = true;
// Animate up
tween(self, {
y: self.y - self.jumpHeight
}, {
duration: self.jumpDuration,
easing: tween.cubicOut,
onFinish: function onFinish() {
// Animate down
tween(self, {
y: self.groundY
}, {
duration: self.fallDuration,
easing: tween.bounceOut,
onFinish: function onFinish() {
self.isJumping = false;
if (_onFinish) _onFinish();
}
});
}
});
};
return self;
});
// The jump arrow button
var JumpButton = Container.expand(function () {
var self = Container.call(this);
// Attach a large ellipse as the button
var btn = self.attachAsset('jumpArrowBtn', {
anchorX: 0.5,
anchorY: 0.5
});
// Attach an up arrow (triangle)
var arrow = self.attachAsset('jumpArrow', {
anchorX: 0.5,
anchorY: 0.5
});
arrow.width = btn.width * 0.32;
arrow.height = btn.height * 0.32;
arrow.rotation = 0; // Upwards
arrow.y = 0;
// Visual feedback on press
self.flash = function () {
tween(btn, {
scaleX: 0.92,
scaleY: 0.92
}, {
duration: 60,
easing: tween.easeIn,
onFinish: function onFinish() {
tween(btn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80,
easing: tween.easeOut
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222a36
});
/****
* Game Code
****/
// Score text
// Create block asset (box)
// Create jump button asset (ellipse)
// Create arrow asset (box, will be rotated)
var scoreTxt = new Text2('0', {
size: 140,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Center block horizontally, place at bottom with margin
var block = new JumpBlock();
game.addChild(block);
block.x = 2048 / 2;
block.groundY = 2732 - 220;
block.y = block.groundY;
// Place jump button above bottom, right side
var jumpBtn = new JumpButton();
game.addChild(jumpBtn);
// Position jump button on the right side, with a margin from the edge and a bit lower above the bottom
jumpBtn.x = 2048 - 320; // 320px margin from right edge, fits button width
jumpBtn.y = 2732 - 280; // moved further down (closer to bottom)
// Score
var score = 0;
LK.setScore(0);
// Touch/click handling for jump button
var isBtnPressed = false;
// Helper: check if point (x, y) is inside jumpBtn
function isInsideJumpBtn(x, y) {
// Use ellipse hit test
var dx = x - jumpBtn.x;
var dy = y - jumpBtn.y;
var rx = jumpBtn.width / 2;
var ry = jumpBtn.height / 2;
return dx * dx / (rx * rx) + dy * dy / (ry * ry) <= 1;
}
// Main move handler
function handleMove(x, y, obj) {
// No drag needed, just visual feedback if finger is on button
if (isBtnPressed) {
if (!isInsideJumpBtn(x, y)) {
isBtnPressed = false;
}
}
}
// Down event: check if jumpBtn is pressed
game.down = function (x, y, obj) {
if (isInsideJumpBtn(x, y) && !block.isJumping) {
isBtnPressed = true;
jumpBtn.flash();
block.jump(function () {
// On landing, increment score
score += 1;
LK.setScore(score);
scoreTxt.setText(score);
});
}
};
// Up event: reset press state
game.up = function (x, y, obj) {
isBtnPressed = false;
};
// Move event: for touch feedback
game.move = handleMove;
// Game update: not needed for this simple game, but required for future expansion
game.update = function () {
// No per-frame logic needed
};
// Reset score to 0 when the game is destroyed (exited)
game.destroy = function () {
score = 0;
LK.setScore(0);
};
// Reset score to 0 when the game is paused
game.pause = function () {
score = 0;
LK.setScore(0);
}; ===================================================================
--- original.js
+++ change.js
@@ -120,8 +120,9 @@
jumpBtn.x = 2048 - 320; // 320px margin from right edge, fits button width
jumpBtn.y = 2732 - 280; // moved further down (closer to bottom)
// Score
var score = 0;
+LK.setScore(0);
// Touch/click handling for jump button
var isBtnPressed = false;
// Helper: check if point (x, y) is inside jumpBtn
function isInsideJumpBtn(x, y) {