User prompt
When updating score also call the build in score tracking method
User prompt
set bg color to 385b50
User prompt
set bg color to 60cbab
User prompt
in tick where using player.height in the intersection check line use player.playerGraphics.height
User prompt
in thick, in the places where you use player.height use player.playerGraphics.height
User prompt
expose playerGraphics on player
User prompt
Set max magnitude to 1100
User prompt
Increase max magnitude to 1200
User prompt
Delete the creation of indicator then afterwards add it back in at the top of player
User prompt
Move the indicator creation at the top of the player class
User prompt
Make the player indicator have lower z index than player graph is
User prompt
Move the creation of indicator up before the creation of playergraphics
User prompt
At the bottom of player, call addChild to attach playergraphics again
User prompt
Move indicator creation to the top of player
User prompt
Remove the second creation of indicator in player
User prompt
Call addChild on playerGrapchis after the indicator is created
User prompt
At the bottom of the player class attach the player graphics again
User prompt
Only show the indicator if the player is not currently jumping
User prompt
Fix Bug: 'ReferenceError: Can't find variable: player' in this line: 'this.x = player.x + 200 * Math.cos(this.rotation);' Line Number: 8
User prompt
Move the starting point of the indicator 200 px away from the center point of the player
User prompt
Set indicator anchor to 0,.5
User prompt
Make the indicator be anchored at .5,1
User prompt
Anchor the preview at .5,0
User prompt
Add a direction and power indicator emitting from the player that shows while you aim
User prompt
Hide the drag and release text after successful jump
/**** * Classes ****/ var Indicator = Container.expand(function () { var self = Container.call(this); var indicatorGraphics = self.attachAsset('indicator', { anchorY: 0.5 }); self.alpha = 0; self.update = function (x, y) { this.rotation = Math.atan2(y, x); this.scale.x = Math.sqrt(x * x + y * y) / 100; }; }); var Player = Container.expand(function () { var self = Container.call(this); self.indicator = self.addChild(new Indicator()); self.playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.gravity = 1; self.jumpForce = 20; self.velocityX = 0; self.velocityY = 0; self.setJumpForce = function (x, y) { var vectorMagnitude = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); var maxMagnitude = 1100; if (vectorMagnitude > maxMagnitude) { x = x / vectorMagnitude * maxMagnitude; y = y / vectorMagnitude * maxMagnitude; } this.jumpForceX = x / 12.5; this.jumpForceY = y / 12.5; }; self.jumping = false; self.onPlatform = false; self.update = function () { this.x += this.velocityX; this.y += this.velocityY; this.velocityY += this.gravity; this.velocityX *= 0.98; this.velocityY *= 0.98; if (this.y > 2732) { LK.showGameOver(); } if (this.x < 0 || this.x > 2048) { this.velocityX *= -1; } if (this.velocityY >= 0) { this.jumping = false; } else if (this.velocityY < 0) { this.jumping = true; this.onPlatform = false; } }; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.hitTestAsset = self.attachAsset('hitTest', { anchorX: 0.5, anchorY: 0.5 }); self.hitTestAsset.alpha = 0; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x385b50 }); /**** * Game Code ****/ var gameSpeed = 0; var score = 0; var background = game.attachAsset('background', {}); background.alpha = 0.5; game.on('up', function (obj) { if (dragStart && player.onPlatform) { var pos = obj.event.getLocalPosition(game); player.setJumpForce(dragStart.x - pos.x, dragStart.y - pos.y); player.velocityX = player.jumpForceX; player.velocityY = player.jumpForceY; dragStart = null; gameSpeed += 0.5; score += 1; LK.setScore(score); scoreTxt.setText(LK.getScore()); instructionTxt.destroy(); player.indicator.alpha = 0; } }); game.on('move', function (obj) { if (dragStart && !player.jumping) { var pos = obj.event.getLocalPosition(game); player.indicator.update(dragStart.x - pos.x, dragStart.y - pos.y); player.indicator.alpha = 1; } }); var platforms = []; var platformSpeed = 0; for (var i = 0; i < 5; i++) { var platform = new Platform(); platform.x = Math.random() * 2048; platform.y = i * (2732 / 5); platforms.push(platform); game.addChild(platform); } var scoreTxt = new Text2('0', { size: 150, fill: '#ffffff', font: 'Impact', dropShadow: true, dropShadowColor: '#000000', dropShadowBlur: 4, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); LK.gui.topCenter.addChild(scoreTxt); var instructionTxt = new Text2('Drag and release to jump', { size: 100, fill: '#ffffff', font: 'Impact', dropShadow: true, dropShadowColor: '#000000', dropShadowBlur: 4, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); instructionTxt.anchor.set(.5, .5); instructionTxt.x = 2048 / 2; instructionTxt.y = 2732 / 2; game.addChild(instructionTxt); var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - player.playerGraphics.height; var firstJump = false; platforms[0].x = player.x; platforms[0].y = player.y + player.playerGraphics.height; LK.on('tick', function () { player.update(); if (player.y < 2732 / 2) { platformSpeed = Math.min(platformSpeed + 0.1, 5); } else { platformSpeed = Math.max(platformSpeed - 0.1, 0); } for (var i = 0; i < platforms.length; i++) { platforms[i].y += platformSpeed + gameSpeed; } player.y += platformSpeed + gameSpeed; for (var i = 0; i < platforms.length; i++) { if (player.intersects(platforms[i].hitTestAsset) && !player.jumping && player.y + player.playerGraphics.height / 2 < platforms[i].y) { player.y = platforms[i].y - player.playerGraphics.height / 2 - platforms[i].hitTestAsset.height / 2; player.velocityY = 0; player.velocityX *= 0.8; player.onPlatform = true; } else if (platforms[i].y - platforms[i].height > 2732) { platforms[i].y = -platforms[i].height; platforms[i].x = Math.random() * 2048; } } }); var dragStart = null; game.on('down', function (obj) { dragStart = obj.event.getLocalPosition(game); });
===================================================================
--- original.js
+++ change.js
@@ -90,9 +90,10 @@
player.velocityY = player.jumpForceY;
dragStart = null;
gameSpeed += 0.5;
score += 1;
- scoreTxt.setText(score);
+ LK.setScore(score);
+ scoreTxt.setText(LK.getScore());
instructionTxt.destroy();
player.indicator.alpha = 0;
}
});
Single cartoon frog sitting. Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Cartoon lillypad seen edge on. No flower Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cozy cartoon swamp background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.