User prompt
Remove the code the redefines bells above score text, rewrite the score text variable as well
User prompt
Add 5 bells on startup
User prompt
Add bell should just use the y position of the last entry from the bell array to determine y position
User prompt
On foreground set speed to 1
User prompt
Set weight:800 on score text
User prompt
Move code out of setup method into game constructor
User prompt
Fix Bug: 'TypeError: self.addBell is not a function. (In 'self.addBell(2732)', 'self.addBell' is undefined)' in this line: 'self.addBell(2732);' Line Number: 34
User prompt
Move code out of setup method into game constructor
User prompt
Define add bell outside the setup methid
User prompt
Add a new method that dynamically inserts one more bell in the game, this bell should have a random x position but a y that is 1/2 to 2/3 times the screen height smaller than the previous bell
User prompt
Only add one bell when game starts
User prompt
Update x movement code on player to move faster or slower depending on the distance to target
User prompt
Add a foreground parallax layer to game, attach player and bells to this layer
User prompt
Make the parallax impact a property of the parallax class such that speed can be set individually per player
User prompt
Add a parallax layer class to the game. The class should calculate the actual y based on a y given to the game to control how fast it scrolls. The parallax effect is on the y axis
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'this.backgroundLayer.move')' in this line: 'this.backgroundLayer.move();' Line Number: 66
User prompt
Fix Bug: 'ReferenceError: Can't find variable: backgroundLayer' in this line: 'backgroundLayer.move();' Line Number: 65
User prompt
Fix Bug: 'ReferenceError: Can't find variable: backgroundLayer' in this line: 'backgroundLayer.move();' Line Number: 65
User prompt
We want to have layers in the game that scrolls at different speed with a parallax effect. Set this up
User prompt
Also set target x when tapping the screen
User prompt
When setting up the player initialize target x as the same as x
User prompt
When moving my mouse on the screen, set target x on player. Then in tick move player towards target z
User prompt
Player has two update methods, delete one of them
User prompt
Fix Bug: 'TypeError: player.update is not a function. (In 'player.update()', 'player.update' is undefined)' in this line: 'player.update();' Line Number: 37
User prompt
Fix Bug: 'TypeError: player.update is not a function. (In 'player.update()', 'player.update' is undefined)' in this line: 'player.update();' Line Number: 37
var ParallaxLayer = Container.expand(function () { var self = Container.call(this); self.actualY = 0; self.speed = 1; self.setParallaxY = function (y) { self.actualY = y * self.speed; self.y = self.actualY; }; }); var Bell = Container.expand(function () { var self = Container.call(this); var bellGraphics = self.createAsset('bell', 'Christmas Bell', .5, .5); self.move = function () {}; self.hit = function () {}; }); var Player = Container.expand(function () { var self = Container.call(this); self.targetX = self.x; var playerGraphics = self.createAsset('player', 'Player Character', .5, .5); self.jump = function () {}; self.fall = function () {}; self.update = function () { var distance = Math.abs(self.x - self.targetX); var speed = Math.max(1, distance / 10); if (self.x < self.targetX) { self.x += Math.min(speed, self.targetX - self.x); } else if (self.x > self.targetX) { self.x -= Math.min(speed, self.x - self.targetX); } }; }); var Game = Container.expand(function () { var self = Container.call(this); var foreground = self.addChild(new ParallaxLayer()); var player = foreground.addChild(new Player()); player.x = 2048 / 2; player.targetX = player.x; player.y = 2732 - player.height; scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", weight: 800 }); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); self.addBell = function () { var lastBellY = bells.length > 0 ? bells[bells.length - 1].y : 2732; var bell = foreground.addChild(new Bell()); bell.x = Math.random() * (2048 - bell.width); bell.y = lastBellY - (Math.random() * (2732 / 2 - 2732 / 3) + 2732 / 3); bells.push(bell); }; self.addBell(2732); var player; var bells = []; var scoreTxt; var isGameOver = false; function setup() { self.addBell(2732); } LK.on('tick', function () { player.update(); for (var i = 0; i < bells.length; i++) { bells[i].move(); } if (player.y > 2732) { isGameOver = true; } if (isGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); stage.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); player.targetX = pos.x; }); stage.on('move', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); player.targetX = pos.x; }); });
===================================================================
--- original.js
+++ change.js
@@ -35,28 +35,29 @@
var player = foreground.addChild(new Player());
player.x = 2048 / 2;
player.targetX = player.x;
player.y = 2732 - player.height;
- var scoreTxt = new Text2('0', {
+ scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
weight: 800
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
- var bells = [];
self.addBell = function () {
var lastBellY = bells.length > 0 ? bells[bells.length - 1].y : 2732;
var bell = foreground.addChild(new Bell());
bell.x = Math.random() * (2048 - bell.width);
bell.y = lastBellY - (Math.random() * (2732 / 2 - 2732 / 3) + 2732 / 3);
bells.push(bell);
};
+ self.addBell(2732);
+ var player;
+ var bells = [];
+ var scoreTxt;
var isGameOver = false;
function setup() {
- for (var i = 0; i < 5; i++) {
- self.addBell();
- }
+ self.addBell(2732);
}
LK.on('tick', function () {
player.update();
for (var i = 0; i < bells.length; i++) {
Tree line of snowy pine trees. Cartoon. Black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Mountain valley with snowy trees. Scenic view. Nighttime. Cartoon. Black background. New moon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Background mountains, nighttime, snow topped Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d platform snowy ground. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cute cartoon rabbit, jumping upwards facing camera. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Starry night sky, northern lights, looking up. Cartoon style. Above clouds Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single White Christmas bell. White decorations. Cartoon. Outline Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White Simple Cartoon snowflake Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.