User prompt
move the coins to x 1024 and y 50
User prompt
fix it
User prompt
move the coins towards the score when they are pressed
User prompt
move the coins to the player when they are pressed
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'console.log("Player initial position: (".concat(player.x, ", ").concat(player.y, ")"));' Line Number: 65
User prompt
Log your coin’s (x, y), the player’s (x, y), and the velocity each frame. If the velocity sign is backward, flip your direction calculation. Double‐check that (1024, 2482) is truly where the engine thinks the play
Code edit (1 edits merged)
Please save this source code
User prompt
make the coins fly here: the `player_idle` position is centered horizontally at **x = 1024** and positioned vertically at **y = 2482**.
User prompt
make the coins fly there
User prompt
the tween animation is good, but the player is not created at that position
User prompt
add a press event for the coins, when pressed, they tween pop animation towards the current player position ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
The coins are “flying off” because the coin’s velocity isn’t being properly initialized at the right time. The nested definition of coin.update means that the coin.down function (responsible for setting the movement vector) is defined but never executed. When it eventually gets (mis)triggered, it applies a high-speed impulse (multiplied by 10) that sends the coins racing past the player and off the visible screen. By restructuring the code to call coin.down immediately upon coin creation—and by possibly lowering the speed—you should achieve a more controlled coin attraction effect.
User prompt
FLY TOWARDS THE FREAKING PLAYER POSITION NOT OFF THE SCREEN LMAO
User prompt
it still doesn't work, fix it
User prompt
fix ti
User prompt
when pressing these coins, they fly towards the player and on collision, add the score and destroy themselves
User prompt
when an enemy is killed, it has a 50% chance to drop a silver_coin that is worth 5 points to the score when picked up and 10% chance to drop a gold_coin that is worth 10 points to the score when picked up, and a 40% chance to drop no coins, do it
User prompt
coins move too fast, i can't see them fix it
Code edit (1 edits merged)
Please save this source code
User prompt
coins should fly towards the player and collide, not fall off the map
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'down')' in or related to this line: 'coin.down = function () {' Line Number: 688
User prompt
Chance Logic: A random value is generated for each enemy defeat. If the random value is less than 0.5, a silver coin is dropped. If it is between 0.5 and 0.6, a gold coin is dropped. Otherwise, nothing is dropped.
Code edit (2 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Basic Shape class (so "Shape" is defined) var Shape = Container.expand(function (options) { var self = Container.call(this); self.attachAsset('shape', { width: options.width, height: options.height, anchorX: options.anchorX || 0, anchorY: options.anchorY || 0, color: options.color || 0x66ff00, alpha: typeof options.alpha === 'number' ? options.alpha : 0 // invisible shape }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ function spawnCoin(coinType, x, y, scoreValue) { var coin = new Container(); coin.attachAsset(coinType, { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); coin.update = function () { if (player.intersects(coin)) { score += scoreValue; updateScoreDisplay(); coin.destroy(); } }; coin.down = function (x, y, obj) { tween(coin, { x: player.x, y: player.y }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { if (player.intersects(coin)) { score += scoreValue; updateScoreDisplay(); coin.destroy(); } } }); }; game.addChild(coin); } // For the jump collider /**** * Global Variables ****/ var jumpColGlobal = null; // For projectile input tracking var isPressHeld = false; var pressHoldStartTime = 0; var pressDownX = 0; // track where the press started (X) var pressDownY = 0; // track where the press started (Y) /**** * Score Setup ****/ var score = 0; var scoreTxt; // container for the score text function updateScoreDisplay() { // Remove the old scoreTxt from the game game.removeChild(scoreTxt); // Create a new score container with the updated score scoreTxt = createScoreText(score); scoreTxt.scaleX = 1.0; scoreTxt.scaleY = 1.0; game.addChild(scoreTxt); // Add tween animation to score display tween(scoreTxt, { scaleX: 1.5, scaleY: 1.5 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(scoreTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); } function incrementScore() { score++; updateScoreDisplay(); } function createScoreText(value) { var shadow = new Text2(String(value), { size: 600, fill: 0x000000, fontFamily: "Arial" }); shadow.name = "shadow"; shadow.anchor.set(0.5, 0); shadow.x = 4; shadow.y = 4; var main = new Text2(String(value), { size: 600, fill: 0xFF69B4, fontFamily: "Arial" }); main.name = "main"; main.anchor.set(0.5, 0); var container = new Container(); container.name = "scoreTxt"; container.x = 1024; container.y = 50; container.addChild(shadow); container.addChild(main); return container; } // build the score text container once scoreTxt = createScoreText(score); scoreTxt.scaleX = 1.0; scoreTxt.scaleY = 1.0; LK.playMusic('bgm', { loop: true }); var bg01 = LK.getAsset('bg01', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 }); game.addChild(bg01); game.addChild(scoreTxt); /**** * Petals ****/ var petals = []; for (var i = 0; i < 50; i++) { var petal = new Container(); petal.attachAsset('petals', { anchorX: 0.5, anchorY: 0.5, rotation: Math.random() * Math.PI * 2 }); petal.x = Math.random() * 2048; petal.y = Math.random() * 2732; petal.speedY = Math.random() * 2 + 1; petal.speedX = Math.random() * 2 - 1; petal.update = function () { this.y += this.speedY; this.x += this.speedX; if (this.y > 2732) { this.y = -50; this.x = Math.random() * 2048; } }; petals.push(petal); game.addChild(petal); } /**** * Player Setup ****/ var player = new Container(); var visualContainer = new Container(); visualContainer.name = 'visual'; var playerSprite = visualContainer.attachAsset('player_idle', { anchorX: 0.5, anchorY: 0.5 }); player.addChild(visualContainer); player.x = 1024; player.y = 2732 - 250; game.addChild(player); /**** * Idle animations ****/ function startBreathingAnimation() { tween(player, { scaleX: 1.05, scaleY: 1.05 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(player, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: startBreathingAnimation }); } }); } function startTiltAnimation() { tween(player, { rotation: Math.PI / 32 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(player, { rotation: -Math.PI / 32 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(player, { rotation: 0 }, { duration: 500, easing: tween.easeInOut, onFinish: startTiltAnimation }); } }); } }); } startBreathingAnimation(); startTiltAnimation(); /**** * Attack collider ****/ var attackCol = LK.getAsset('attackcol', { anchorX: 0.5, anchorY: 0.5, alpha: 0.75 }); game.addChild(attackCol); attackCol.visible = false; attackCol.alpha = 0; /**** * Swap player sprite ****/ function swapPlayerVisual(newVisualId, x, y) { var flip = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; var onDone = arguments.length > 4 ? arguments[4] : undefined; var visualContainer = player.findChildByName('visual'); if (!visualContainer) { visualContainer = new Container(); visualContainer.name = 'visual'; player.addChild(visualContainer); } else { visualContainer.removeChildAt(0); } playerSprite = visualContainer.attachAsset(newVisualId, { anchorX: 0.5, anchorY: 0.5 }); visualContainer.scaleX = flip; player.x = x; player.y = y; if (newVisualId === 'player_jump') { flip = Math.random() < 0.5 ? -1 : 1; visualContainer.scaleX = flip; jumpColGlobal = LK.getAsset('jumpcol', { anchorX: 0.5, anchorY: 0.5, x: x, y: y + player.height / 2, alpha: 0 }); game.addChild(jumpColGlobal); tween(jumpColGlobal, { y: jumpColGlobal.y - 600 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(jumpColGlobal, { y: 2732 - 250 + player.height / 2 }, { duration: 300, easing: tween.bounceOut, onFinish: function onFinish() { jumpColGlobal.destroy(); jumpColGlobal = null; } }); } }); } if (typeof onDone === 'function') { if (newVisualId === 'player_idle') { startBreathingAnimation(); startTiltAnimation(); } onDone(); } } /**** * Input logic ****/ var isSequenceRunning = false; var isJumping = false; var playerState = 'idle'; game.down = function (x, y) { if (isSequenceRunning) { return; } isPressHeld = true; pressHoldStartTime = Date.now(); pressDownX = x; // remember where the press happened pressDownY = y; // remember where the press happened // Jump if tapped in top 2/3 if (y < 2732 * 2.5 / 3 && !isJumping) { isJumping = true; LK.getSound('hup').play(); swapPlayerVisual('player_jump', player.x, player.y); // dust effect for (var i = 0; i < 10; i++) { var p = LK.getAsset('dust', { anchorX: 0.5, anchorY: 0.5, x: player.x + (Math.random() * 100 - 50), y: player.y + (Math.random() * 100 - 50) }); game.addChild(p); tween(p, { alpha: 0, x: p.x + (Math.random() * 200 - 100), y: p.y - Math.random() * 200 }, { duration: 500, onFinish: function onFinish() { p.destroy(); } }); } tween(player, { y: player.y - 600 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(player, { y: 2732 - 250 }, { duration: 300, easing: tween.bounceOut, onFinish: function onFinish() { // landing dust effect for (var j = 0; j < 10; j++) { var pp = LK.getAsset('dust', { anchorX: 0.5, anchorY: 0.5, x: player.x + (Math.random() * 100 - 50), y: player.y + (Math.random() * 100 - 50) }); game.addChild(pp); tween(pp, { alpha: 0, x: pp.x + (Math.random() * 200 - 100), y: pp.y + Math.random() * 200 }, { duration: 500, onFinish: function onFinish() { pp.destroy(); } }); } isJumping = false; swapPlayerVisual('player_idle', 1024, 2732 - 250, 1, function () { startBreathingAnimation(); startTiltAnimation(); }); var v = player.findChildByName('visual'); if (v) { var dir = v.scaleX < 0 ? -1 : 1; tween(v, { scaleX: dir * 1.3, scaleY: 1.3 }, { duration: 50, onFinish: function onFinish() { tween(v, { scaleX: dir * 1.0, scaleY: 1.0 }, { duration: 100 }); } }); } } }); } }); return; } // Attack if tapped in bottom 1/3 isSequenceRunning = true; var flip = x < 1024 ? -1 : 1; swapPlayerVisual('player_attackf01', 1024, 2732 - 250, flip); LK.getSound('retroslash').play(); var vis = player.findChildByName('visual'); if (vis) { tween(vis, { scaleX: flip * 1.3, scaleY: 1.3 }, { duration: 50, onFinish: function onFinish() { tween(vis, { scaleX: flip * 1.0, scaleY: 1.0 }, { duration: 100 }); } }); } LK.setTimeout(function () { swapPlayerVisual('player_attackf02', 1024, 2732 - 250, flip); // bigger/visible collider, offset so you see it overlapping attackCol.width = 180; attackCol.height = 180; attackCol.x = flip === -1 ? 874 : 1174; attackCol.y = 2732 - 250; attackCol.scaleX = flip; attackCol.visible = true; LK.setTimeout(function () { if (attackCol) { attackCol.visible = false; } swapPlayerVisual('player_idle', 1024, 2732 - 250, 1, function () { startBreathingAnimation(); startTiltAnimation(); }); isSequenceRunning = false; playerState = 'idle'; }, 250); }, 250); }; /**** * Enemies array + spawn ****/ var enemies = []; function spawnEnemy() { var e = new Container(); // shape child as the "hitbox" var hitbox = new Shape({ width: 200, height: 209, anchorX: 0.5, anchorY: 0.5, color: 0x00FF00, alpha: 0 }); hitbox.x = 0; hitbox.y = 0; e.addChild(hitbox); var gfx = e.attachAsset('enemy01', { anchorX: 0.5, anchorY: 0.5 }); var fromLeft = Math.random() < 0.5; e.x = fromLeft ? -gfx.width / 2 : 2048 + gfx.width / 2; e.y = 2732 - 225; e.speedX = fromLeft ? Math.random() * 4 + 2 : -(Math.random() * 4 + 2); gfx.scaleX = fromLeft ? 1 : -1; var baseY = e.y; function bounce() { tween(e, { y: baseY - 50 }, { duration: 500, easing: tween.bounceInOut, onFinish: function onFinish() { tween(e, { y: baseY }, { duration: 500, easing: tween.bounceInOut, onFinish: bounce }); } }); } bounce(); enemies.push(e); game.addChild(e); } LK.setInterval(spawnEnemy, Math.random() * 1500 + 1000); /**** * NEW CODE: Projectile Logic ****/ var projectiles = []; function spawnProjectile(targetX, targetY) { var proj = new Container(); proj.attachAsset('player_throw', { anchorX: 0.5, anchorY: 0.5 }); LK.getSound('throwsnd').play(); // Instantiate cloudsmoke at the same position as the projectile proj.x = player.x; proj.y = player.y; var cloudSmoke = LK.getAsset('cloudsmoke', { anchorX: 0.5, anchorY: 0.5, x: proj.x, y: proj.y, alpha: 0.75 }); game.addChild(cloudSmoke); // Add tween for pop and disappear effect tween(cloudSmoke, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { cloudSmoke.destroy(); } }); proj.x = player.x; proj.y = player.y; // Calculate direction from player to the press location. var dx = targetX - player.x; var dy = targetY - player.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist !== 0) { dx /= dist; dy /= dist; } var speed = 25; proj.vx = dx * speed; proj.vy = dy * speed; // Adjust scaleX based on target relative to player proj.scaleX = targetX < player.x ? -1 : 1; proj.distanceTraveled = 0; proj.maxDistance = 1000; projectiles.push(proj); game.addChild(proj); } /**** * Main update ****/ game.update = function () { // Check hold duration for long press projectile if (isPressHeld) { var holdDuration = Date.now() - pressHoldStartTime; if (holdDuration > 500) { console.log("Long press detected, spawn projectile!"); isPressHeld = false; spawnProjectile(pressDownX, pressDownY); } } // Update all projectiles for (var p = projectiles.length - 1; p >= 0; p--) { var proj = projectiles[p]; proj.x += proj.vx; proj.y += proj.vy; var stepDist = Math.sqrt(proj.vx * proj.vx + proj.vy * proj.vy); proj.distanceTraveled += stepDist; if (proj.distanceTraveled > proj.maxDistance) { projectiles.splice(p, 1); proj.destroy(); continue; } if (proj.x < -100 || proj.x > 2148 || proj.y < -100 || proj.y > 2832) { projectiles.splice(p, 1); proj.destroy(); continue; } // Check collision with enemies for (var ei = enemies.length - 1; ei >= 0; ei--) { var enemy = enemies[ei]; if (proj.intersects(enemy)) { // Use the 'throw' attack type for projectiles handleEnemyHit(enemy, ei, 'throw'); projectiles.splice(p, 1); proj.destroy(); break; } } } // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { var e = enemies[i]; e.x += e.speedX; if (e.x < -300 || e.x > 2048 + 300) { var index = enemies.indexOf(e); if (index !== -1) { enemies.splice(index, 1); } e.destroy(); continue; } // Check collision with jump collider first if (jumpColGlobal && jumpColGlobal.visible && e.intersects(jumpColGlobal)) { handleEnemyJumpHit(e, i); continue; } // Check collisions with attack collider (melee) if (attackCol.visible && e.intersects(attackCol)) { handleEnemyHit(e, i, 'melee'); } // Check if enemy intersects with player (game over) if (!isJumping && !attackCol.visible && e.intersects(player)) { LK.showGameOver(); } } }; /**** * Enemy hit logic for both attack and projectile * attackType should be 'melee' or 'throw' ****/ function handleEnemyHit(enemy, index, attackType) { if (!enemies.includes(enemy)) { return; } LK.getSound('slimedeath').play(); if (enemy.bounceTween && typeof enemy.bounceTween.cancel === 'function') { enemy.bounceTween.cancel(); } tween(enemy, { tint: 0xFF0000 }, { duration: 0, onFinish: function onFinish() { tween(enemy, { scaleX: 1.3, scaleY: 1.3 }, { duration: 50, onFinish: function onFinish() { tween(enemy, { scaleX: 0.5, scaleY: 0.5, alpha: 0 }, { duration: 100, onFinish: function onFinish() { var idx = enemies.indexOf(enemy); if (idx !== -1) { enemies.splice(idx, 1); } enemy.destroy(); if (!enemy.scoreCounted) { if (attackType === 'melee') { score += 2; } else if (attackType === 'throw') { score += 1; } else { score++; } updateScoreDisplay(); enemy.scoreCounted = true; // Determine coin drop var dropChance = Math.random(); if (dropChance < 0.5) { // 50% chance to drop a silver coin spawnCoin('silver_coin', enemy.x, enemy.y, 5); } else if (dropChance < 0.6) { // 10% chance to drop a gold coin spawnCoin('gold_coin', enemy.x, enemy.y, 10); } } } }); } }); } }); } /**** * Enemy hit logic for jump collider * When an enemy is hit by jumpCol, it will fly off the screen ****/ function handleEnemyJumpHit(enemy, index) { if (!enemies.includes(enemy)) { return; } LK.getSound('boing').play(); if (enemy.bounceTween && typeof enemy.bounceTween.cancel === 'function') { enemy.bounceTween.cancel(); } tween(enemy, { tint: 0xFF0000 }, { duration: 0, onFinish: function onFinish() { var targetX = enemy.x < 1024 ? -300 : 2048 + 300; var targetY = enemy.y - 600; tween(enemy, { x: targetX, y: targetY, alpha: 0 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { var idx = enemies.indexOf(enemy); if (idx !== -1) { enemies.splice(idx, 1); } enemy.destroy(); if (!enemy.scoreCounted) { score += 3; updateScoreDisplay(); enemy.scoreCounted = true; } } }); } }); } /**** * findChildByName helper ****/ Container.prototype.findChildByName = function (name) { for (var i = 0; i < this.children.length; i++) { if (this.children[i].name === name) { return this.children[i]; } } return null; }; /**** * game.up to reset press ****/ game.up = function (x, y) { isPressHeld = false; pressHoldStartTime = 0; };
===================================================================
--- original.js
+++ change.js
@@ -29,61 +29,47 @@
/****
* Game Code
****/
-/*
- UPDATED COIN SPAWN FUNCTION
- This version recalculates the normalized direction toward the player on every update.
- The code first checks that the distance is sufficiently large (greater than 1) before normalizing.
- Debug logging is printed so you can inspect the computed dx, dy, distance, and velocity.
- The player is assumed to be at (1024, 2732 - 250) = (1024, 2482).
-*/
function spawnCoin(coinType, x, y, scoreValue) {
var coin = new Container();
coin.attachAsset(coinType, {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y
});
- var speed = 5;
coin.update = function () {
- // Calculate direction vector from coin to player
- var dx = player.x - this.x;
- var dy = player.y - this.y;
- var dist = Math.sqrt(dx * dx + dy * dy);
- // Debug log for initial computed values
- console.log("Before normalization: dx =", dx.toFixed(2), "dy =", dy.toFixed(2), "dist =", dist.toFixed(2));
- if (dist < 1) {
- // Avoid division by nearly zero; assume coin is already at the player.
- dx = 0;
- dy = 0;
- } else {
- dx /= dist;
- dy /= dist;
- }
- // Calculate velocity components.
- var vx = dx * speed;
- var vy = dy * speed;
- // Log final computed velocity for debugging.
- console.log("Coin position:", this.x.toFixed(2), this.y.toFixed(2), "| vx =", vx.toFixed(2), "vy =", vy.toFixed(2));
- // Update coin position.
- this.x += vx;
- this.y += vy;
- // Check collision with the player.
- if (player.intersects(this)) {
+ if (player.intersects(coin)) {
score += scoreValue;
updateScoreDisplay();
- this.destroy();
+ coin.destroy();
}
};
+ coin.down = function (x, y, obj) {
+ tween(coin, {
+ x: player.x,
+ y: player.y
+ }, {
+ duration: 500,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ if (player.intersects(coin)) {
+ score += scoreValue;
+ updateScoreDisplay();
+ coin.destroy();
+ }
+ }
+ });
+ };
game.addChild(coin);
}
+// For the jump collider
/****
* Global Variables
****/
var jumpColGlobal = null;
-// For projectile input tracking.
+// For projectile input tracking
var isPressHeld = false;
var pressHoldStartTime = 0;
var pressDownX = 0; // track where the press started (X)
var pressDownY = 0; // track where the press started (Y)
@@ -92,16 +78,16 @@
****/
var score = 0;
var scoreTxt; // container for the score text
function updateScoreDisplay() {
- // Remove the old scoreTxt from the game.
+ // Remove the old scoreTxt from the game
game.removeChild(scoreTxt);
- // Create a new score container with the updated score.
+ // Create a new score container with the updated score
scoreTxt = createScoreText(score);
scoreTxt.scaleX = 1.0;
scoreTxt.scaleY = 1.0;
game.addChild(scoreTxt);
- // Add tween animation to the score display.
+ // Add tween animation to score display
tween(scoreTxt, {
scaleX: 1.5,
scaleY: 1.5
}, {
@@ -146,9 +132,9 @@
container.addChild(shadow);
container.addChild(main);
return container;
}
-// Build the score text container once.
+// build the score text container once
scoreTxt = createScoreText(score);
scoreTxt.scaleX = 1.0;
scoreTxt.scaleY = 1.0;
LK.playMusic('bgm', {
@@ -198,14 +184,13 @@
anchorX: 0.5,
anchorY: 0.5
});
player.addChild(visualContainer);
-// Place the player at the horizontal center and near the bottom (offset upward by 250).
player.x = 1024;
-player.y = 2732 - 250; // (1024, 2482)
+player.y = 2732 - 250;
game.addChild(player);
/****
-* Idle Animations
+* Idle animations
****/
function startBreathingAnimation() {
tween(player, {
scaleX: 1.05,
@@ -252,9 +237,9 @@
}
startBreathingAnimation();
startTiltAnimation();
/****
-* Attack Collider
+* Attack collider
****/
var attackCol = LK.getAsset('attackcol', {
anchorX: 0.5,
anchorY: 0.5,
@@ -263,9 +248,9 @@
game.addChild(attackCol);
attackCol.visible = false;
attackCol.alpha = 0;
/****
-* Swap Player Sprite
+* Swap player sprite
****/
function swapPlayerVisual(newVisualId, x, y) {
var flip = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
var onDone = arguments.length > 4 ? arguments[4] : undefined;
@@ -322,9 +307,9 @@
onDone();
}
}
/****
-* Input Logic
+* Input logic
****/
var isSequenceRunning = false;
var isJumping = false;
var playerState = 'idle';
@@ -333,16 +318,16 @@
return;
}
isPressHeld = true;
pressHoldStartTime = Date.now();
- pressDownX = x; // record where the press started
- pressDownY = y; // record where the press started
- // Jump if tapped in the top 2/3 of the screen.
+ pressDownX = x; // remember where the press happened
+ pressDownY = y; // remember where the press happened
+ // Jump if tapped in top 2/3
if (y < 2732 * 2.5 / 3 && !isJumping) {
isJumping = true;
LK.getSound('hup').play();
swapPlayerVisual('player_jump', player.x, player.y);
- // Create dust effect for the jump.
+ // dust effect
for (var i = 0; i < 10; i++) {
var p = LK.getAsset('dust', {
anchorX: 0.5,
anchorY: 0.5,
@@ -372,9 +357,9 @@
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
- // Create landing dust effect.
+ // landing dust effect
for (var j = 0; j < 10; j++) {
var pp = LK.getAsset('dust', {
anchorX: 0.5,
anchorY: 0.5,
@@ -421,9 +406,9 @@
}
});
return;
}
- // Attack if tapped in the bottom 1/3.
+ // Attack if tapped in bottom 1/3
isSequenceRunning = true;
var flip = x < 1024 ? -1 : 1;
swapPlayerVisual('player_attackf01', 1024, 2732 - 250, flip);
LK.getSound('retroslash').play();
@@ -445,9 +430,9 @@
});
}
LK.setTimeout(function () {
swapPlayerVisual('player_attackf02', 1024, 2732 - 250, flip);
- // Set up the melee attack collider.
+ // bigger/visible collider, offset so you see it overlapping
attackCol.width = 180;
attackCol.height = 180;
attackCol.x = flip === -1 ? 874 : 1174;
attackCol.y = 2732 - 250;
@@ -466,14 +451,14 @@
}, 250);
}, 250);
};
/****
-* Enemies Array + Spawn
+* Enemies array + spawn
****/
var enemies = [];
function spawnEnemy() {
var e = new Container();
- // Create a shape child for the enemy hitbox.
+ // shape child as the "hitbox"
var hitbox = new Shape({
width: 200,
height: 209,
anchorX: 0.5,
@@ -526,9 +511,9 @@
anchorX: 0.5,
anchorY: 0.5
});
LK.getSound('throwsnd').play();
- // Instantiate cloudsmoke at the projectile's initial position.
+ // Instantiate cloudsmoke at the same position as the projectile
proj.x = player.x;
proj.y = player.y;
var cloudSmoke = LK.getAsset('cloudsmoke', {
anchorX: 0.5,
@@ -537,9 +522,9 @@
y: proj.y,
alpha: 0.75
});
game.addChild(cloudSmoke);
- // Tween for a pop/disappear effect.
+ // Add tween for pop and disappear effect
tween(cloudSmoke, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
@@ -551,9 +536,9 @@
}
});
proj.x = player.x;
proj.y = player.y;
- // Calculate direction from the player to the press location.
+ // Calculate direction from player to the press location.
var dx = targetX - player.x;
var dy = targetY - player.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist !== 0) {
@@ -562,29 +547,29 @@
}
var speed = 25;
proj.vx = dx * speed;
proj.vy = dy * speed;
- // Adjust scaleX based on which side of the player the target is.
+ // Adjust scaleX based on target relative to player
proj.scaleX = targetX < player.x ? -1 : 1;
proj.distanceTraveled = 0;
proj.maxDistance = 1000;
projectiles.push(proj);
game.addChild(proj);
}
/****
-* Main Update Loop
+* Main update
****/
game.update = function () {
- // Check for long press for projectile spawn.
+ // Check hold duration for long press projectile
if (isPressHeld) {
var holdDuration = Date.now() - pressHoldStartTime;
if (holdDuration > 500) {
console.log("Long press detected, spawn projectile!");
isPressHeld = false;
spawnProjectile(pressDownX, pressDownY);
}
}
- // Update all projectiles.
+ // Update all projectiles
for (var p = projectiles.length - 1; p >= 0; p--) {
var proj = projectiles[p];
proj.x += proj.vx;
proj.y += proj.vy;
@@ -599,21 +584,21 @@
projectiles.splice(p, 1);
proj.destroy();
continue;
}
- // Check collision with enemies.
+ // Check collision with enemies
for (var ei = enemies.length - 1; ei >= 0; ei--) {
var enemy = enemies[ei];
if (proj.intersects(enemy)) {
- // 'throw' attack type for projectiles.
+ // Use the 'throw' attack type for projectiles
handleEnemyHit(enemy, ei, 'throw');
projectiles.splice(p, 1);
proj.destroy();
break;
}
}
}
- // Update enemies.
+ // Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var e = enemies[i];
e.x += e.speedX;
if (e.x < -300 || e.x > 2048 + 300) {
@@ -623,25 +608,25 @@
}
e.destroy();
continue;
}
- // Check collision with the jump collider.
+ // Check collision with jump collider first
if (jumpColGlobal && jumpColGlobal.visible && e.intersects(jumpColGlobal)) {
handleEnemyJumpHit(e, i);
continue;
}
- // Check collision with the melee attack collider.
+ // Check collisions with attack collider (melee)
if (attackCol.visible && e.intersects(attackCol)) {
handleEnemyHit(e, i, 'melee');
}
- // If the enemy intersects with the player (when not jumping or attacking), trigger game over.
+ // Check if enemy intersects with player (game over)
if (!isJumping && !attackCol.visible && e.intersects(player)) {
LK.showGameOver();
}
}
};
/****
-* Enemy Hit Logic (Attack and Projectile)
+* Enemy hit logic for both attack and projectile
* attackType should be 'melee' or 'throw'
****/
function handleEnemyHit(enemy, index, attackType) {
if (!enemies.includes(enemy)) {
@@ -683,15 +668,15 @@
score++;
}
updateScoreDisplay();
enemy.scoreCounted = true;
- // Determine coin drop.
+ // Determine coin drop
var dropChance = Math.random();
if (dropChance < 0.5) {
- // 50% chance to drop a silver coin.
+ // 50% chance to drop a silver coin
spawnCoin('silver_coin', enemy.x, enemy.y, 5);
} else if (dropChance < 0.6) {
- // 10% chance to drop a gold coin.
+ // 10% chance to drop a gold coin
spawnCoin('gold_coin', enemy.x, enemy.y, 10);
}
}
}
@@ -701,10 +686,10 @@
}
});
}
/****
-* Enemy Hit Logic (Jump Collider)
-* When hit by the jump collider, the enemy flies off-screen.
+* Enemy hit logic for jump collider
+* When an enemy is hit by jumpCol, it will fly off the screen
****/
function handleEnemyJumpHit(enemy, index) {
if (!enemies.includes(enemy)) {
return;
@@ -743,9 +728,9 @@
}
});
}
/****
-* findChildByName Helper Function
+* findChildByName helper
****/
Container.prototype.findChildByName = function (name) {
for (var i = 0; i < this.children.length; i++) {
if (this.children[i].name === name) {
@@ -754,9 +739,9 @@
}
return null;
};
/****
-* game.up: Reset Press Tracking
+* game.up to reset press
****/
game.up = function (x, y) {
isPressHeld = false;
pressHoldStartTime = 0;
high definition super nintendo background of a japanese sakura tree forest Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
2d snes dust particle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
silver coin, $ sign on it, snes art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
gold coin, $ sign on it, snes art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
snes white feather. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
add a wooden shield
white 3d questionmark with a shadow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
caligraphy paper front facing flat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
the letters 'Ready' in 3d with a japanese cartoon cherry blossom flair. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
add eyebrows