Code edit (1 edits merged)
Please save this source code
User prompt
for score text add in variables for x and y position adjustment
User prompt
or score text add in x and y position adjustment
User prompt
Fix Bug: 'Uncaught ReferenceError: sackGraphics is not defined' in this line: 'scoreTxt.y = 3200 - sackGraphics.height / 2;' Line Number: 400
User prompt
hange score text position to bottom. in front of present sack
User prompt
change Score text position to top right
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in this line: 'scoreTxt.setText(gameInstance.score);' Line Number: 251
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
flip level text background around y axis
Code edit (1 edits merged)
Please save this source code
User prompt
add image behind life counter and Level text
Code edit (9 edits merged)
Please save this source code
User prompt
add variables Speed, Bounce, rotation and gravity to bonus item
Code edit (4 edits merged)
Please save this source code
User prompt
add in a reset loop for bonus item so when run it resets the main bonus timer once its been clicked or destroyed.
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
in game check that the start button has been pressed on the overlay before starting game
User prompt
add a start screen to game. full overlay with button that will allow game to start when pressed
Code edit (8 edits merged)
Please save this source code
User prompt
add in a reset loop for bonus item so when run it resets the timer once its been clicked or destroyed
User prompt
apply speed, rotation and bounce to generated bonus item
User prompt
add speed, rotation and bounce variables to bonus item
var nameStorage = ['James', 'Mary', 'John', 'Patricia', 'Robert', 'Jennifer', 'Michael', 'Linda', 'William', 'Elizabeth', 'David', 'Barbara', 'Richard', 'Susan', 'Joseph', 'Jessica', 'Thomas', 'Sarah', 'Charles', 'Karen', 'Christopher', 'Nancy', 'Daniel', 'Lisa', 'Matthew', 'Margaret', 'Anthony', 'Betty', 'Mark', 'Sandra', 'Donald', 'Ashley', 'Steven', 'Kimberly', 'Paul', 'Emily', 'Andrew', 'Donna', 'Joshua', 'Michelle', 'Kenneth', 'Dorothy', 'Kevin', 'Carol', 'Brian', 'Amanda', 'George', 'Melissa', 'Edward', 'Stephanie']; var LevelManager = (function () { var currentLevel = 1; var maxLevel = 16; function getNextLevel() { currentLevel++; return currentLevel; } function resetLevels() { currentLevel = 1; } return { getNextLevel: getNextLevel, resetLevels: resetLevels, getCurrentLevel: function () { return currentLevel; } }; })(); var levelParameters = [{ presentSpeedFactor: 2, bounceFactor: 0.6, gravity: 0.1 }, { presentSpeedFactor: 2.2, bounceFactor: 0.65, gravity: 0.12 }, { presentSpeedFactor: 3, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 4, bounceFactor: 0.8, gravity: 0.3 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }, { presentSpeedFactor: 3.5, bounceFactor: 0.8, gravity: 0.2 }]; var BonusItem = Container.expand(function () { var self = Container.call(this); self.speed = Math.random() * 7 + 1; self.rotationSpeed = (Math.random() - 0.5) * 0.1; self.bounce = Math.random() * 0.5 + 0.5; self.gravity = Math.random() * 0.1 + 0.05; self.vx = (Math.random() > 0.5 ? 1 : -1) * self.speed; self.vy = (Math.random() > 0.5 ? 1 : -1) * self.speed; BonusItem.prototype.startDestructionTimer = function (resetBonusTimerCallback) { var self = this; LK.setTimeout(function () { self.destroy(); resetBonusTimerCallback(); }, 20000); }; self.interactive = true; self.bonusAmount = Math.floor(Math.random() * (10 - 4 + 1)) + 4; var bonusGraphics = self.createAsset('bonusItem', 'Bonus Item Graphics', 0.5, 0.5); self.vx = (Math.random() > 0.5 ? 1 : -1) * (Math.random() * 2 + 1); self.on('down', function () { var gameInstance = this.parent.parent; gameInstance.score += self.bonusAmount; var scoreTxt = LK.gui.topCenter.children[0]; scoreTxt.setText(gameInstance.score); self.destroy(); gameInstance.resetBonusTimer(); }); self.move = function () { self.x += self.vx; self.y += self.vy; self.rotation += self.rotationSpeed; if (self.x < 0 || self.x > 2048) { self.vx = -self.vx * self.bounce; } if (self.y < 0 || self.y > 2732) { self.vy = -self.vy * self.bounce; } }; }); var LifeCounter = Container.expand(function (initialLives) { var self = Container.call(this); self.refreshLifeDisplay = function () { while (self.lifeIcons.length > self.lives) { var lifeToRemove = self.lifeIcons.pop(); lifeToRemove.destroy(); } for (var i = 0; i < self.lifeIcons.length; i++) { self.lifeIcons[i].x = 1948 - i * (self.lifeIcons[i].width + 10); } }; self.lives = initialLives; self.lifeIcons = []; for (var i = 0; i < self.lives; i++) { var lifeIcon = self.createAsset('lifeIcon', 'Life Icon', 0.5, 0.5); lifeIcon.x = 1948 - i * (lifeIcon.width + 10); lifeIcon.y = 250; self.lifeIcons.push(lifeIcon); self.addChild(lifeIcon); } self.removeLife = function () { if (self.lives > 0) { self.lives--; self.refreshLifeDisplay(); if (self.lives <= 0) { LK.showGameOver(); } } }; self.resetLives = function () { while (self.lifeIcons.length < initialLives) { var lifeIcon = self.createAsset('lifeIcon', 'Life Icon', 0.5, 0.5); lifeIcon.x = 1948 - (initialLives - self.lifeIcons.length - 1) * (lifeIcon.width + 10); lifeIcon.y = 250; self.lifeIcons.push(lifeIcon); self.addChild(lifeIcon); } self.lives = initialLives; }; }); var NameDisplay = Container.expand(function () { var self = Container.call(this); self.nameText = new Text2('', { size: 40, fill: "#000000", Font: "Trebuchet MS", anchor: { x: 0.5, y: 0.5 } }); self.nameText.x = 270; self.nameText.y = 130; LK.gui.addChild(self.nameText); self.updateName = function (name) { self.nameText.setText(name); }; }); var Background = Container.expand(function () { var self = Container.call(this); var background = self.createAsset('background', 'Background Image', 0, 0); background.width = 2048; background.height = 2732; self.addChild(background); }); var RotatingBackground = Container.expand(function () { var self = Container.call(this); var rotatingImage = self.createAsset('rotatingBackground', 'Rotating Background Image', 0.5, 0.5); rotatingImage.x = 2048 / 2; rotatingImage.y = 2732 / 2; self.addChild(rotatingImage); self.rotationSpeed = 0.0003; }); var presentTypeDisplay = Container.expand(function (nameDisplay) { var self = Container.call(this); var level = LevelManager.getCurrentLevel(); var presentTypesCount = 2; if (level >= 5 && level <= 8) { presentTypesCount = 4; } else if (level >= 9 && level <= 12) { presentTypesCount = 6; } else if (level >= 13) { presentTypesCount = 8; } var presentTypes = []; for (var i = 0; i < presentTypesCount; i++) { presentTypes.push('presentType' + (i + 1)); } self.currentPresentType = ''; self.getCurrentPresentType = function () { return self.currentPresentType; }; self.setRandomPresentTypeIndex = function () { var presentTypeIndex = Math.floor(Math.random() * presentTypesCount); self.currentPresentType = presentTypes[presentTypeIndex]; var displayGraphic = self.createAsset(self.currentPresentType, self.currentPresentType + ' Graphics', -0.2, -0.2); displayGraphic.scale.x = 1.5; displayGraphic.scale.y = 1.5; if (self.children.length > 0) { self.removeChildAt(0); } self.addChild(displayGraphic); var randomName = nameStorage[Math.floor(Math.random() * nameStorage.length)]; nameDisplay.updateName(randomName); }; self.setRandomPresentTypeIndex(); LK.setInterval(self.setRandomPresentTypeIndex, (Math.random() * (9 - 3) + 3) * 1000); }); var Present = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.applyGravity = function () { var level = LevelManager.getCurrentLevel() - 1; var gravity = levelParameters[level].gravity; self.vy += gravity; }; var presentGraphics = self.createAsset(type, type + ' Graphics', .5, .5); self.vx = (Math.random() - 0.5) * 10; self.vy = (Math.random() - 0.5) * 10; self.rotationSpeed = (Math.random() - 0.5) * 0.2; self.interactive = true; self.on('down', function () { var gameInstance = this.parent.parent; var currentDisplayType = gameInstance.getCurrentPresentType(); if (self.type === currentDisplayType) { gameInstance.score++; var scoreTxt = LK.gui.topCenter.children[0]; scoreTxt.setText(gameInstance.score); var gameInstance = this.parent.parent; gameInstance.presents.splice(gameInstance.presents.indexOf(self), 1); self.destroy(); } else { gameInstance.lifeCounter.removeLife(); } }); self.move = function () { self.applyMovement(); }; self.applyMovement = function () { var levelIndex = LevelManager.getCurrentLevel() - 1; var level = levelParameters[Math.max(0, Math.min(levelIndex, levelParameters.length - 1))]; var presentSpeedFactor = level.presentSpeedFactor; self.x += self.vx * presentSpeedFactor; self.y += self.vy * presentSpeedFactor; self.rotation += self.rotationSpeed; self.applyBounds(); }; self.applyBounds = function () { var mainContainer = self.parent; if (self.x < 0) { self.x = 0; self.vx = -self.vx; } if (mainContainer && self.x > mainContainer.width - self.width) { self.x = mainContainer.width - self.width; self.vx = -self.vx; } if (self.y < 0) { self.y = 0; self.vy = -self.vy; } if (mainContainer && self.y > mainContainer.height - self.height) { self.y = mainContainer.height - self.height; self.vy = -self.vy; } }; self.bounce = function (collisionNormal) { self.applyBounce(collisionNormal); }; self.applyBounce = function (collisionNormal) { var level = LevelManager.getCurrentLevel() - 1; var bounceFactor = levelParameters[level].bounceFactor; if (collisionNormal.x !== 0) { self.vx = -self.vx * bounceFactor; } if (collisionNormal.y !== 0) { self.vy = -self.vy * bounceFactor; } }; }); var MainContainer = Container.expand(function () { var self = Container.call(this); self.width = 1942; self.height = 1900; self.x = 50; self.y = 400; var background = self.createAsset('whiteBackground', 'White Background', 0, 0); background.width = self.width; background.height = self.height; background.alpha = 0.01; self.addChild(background); }); var SantaSack = Container.expand(function () { var self = Container.call(this); this.sackGraphics = self.createAsset('santaSack', 'Santa Toy Sack', 0.5, 1); self.x = 2048 / 2; self.y = 3200; }); var Game = Container.expand(function () { var self = Container.call(this); self.createBonusItem = function (mainContainer) { var bonusItem = new BonusItem(); bonusItem.x = Math.random() * (mainContainer.width - bonusItem.width) + mainContainer.x; bonusItem.y = Math.random() * (mainContainer.height - bonusItem.height) + mainContainer.y; mainContainer.addChild(bonusItem); bonusItem.startDestructionTimer(self.resetBonusTimer); self.bonusItem = bonusItem; }; self.resetBonusTimer = function () { LK.clearTimeout(bonusItemTimeout); bonusItemTimeout = LK.setTimeout(function () { self.createBonusItem(mainContainer); }, (Math.random() * (120 - 60) + 60) * 1000); }; var bonusItemTimeout = LK.setTimeout(function () { self.createBonusItem(mainContainer); }, (Math.random() * (120 - 60) + 60) * 1000); LK.on('tick', function () { if (self.bonusItem) { self.bonusItem.move(); } }); var self = Container.call(this); self.presents = []; self.levelManager = LevelManager; var rotatingBackground = new RotatingBackground(); self.addChild(rotatingBackground, 0); LK.on('tick', function () { rotatingBackground.children[0].rotation += rotatingBackground.rotationSpeed; }); var background = new Background(); self.addChildAt(background, 1); var mainContainer = new MainContainer(); self.addChild(mainContainer); var scroll = self.createAsset('newImageAsset', 'Scroll', 0.5, 0.5); scroll.x = 500; scroll.y = 220; self.addChild(scroll); var nameDisplay = new NameDisplay(); var presentDisplay = self.addChild(new presentTypeDisplay(nameDisplay)); self.presentDisplay = presentDisplay; self.getCurrentPresentType = function () { return self.presentDisplay.getCurrentPresentType(); }; self.presentDisplay.x = 0; self.presentDisplay.y = 0; var santaSack = new SantaSack(); self.addChild(santaSack); self.lifeCounter = new LifeCounter(5); self.addChild(self.lifeCounter); self.score = 0; var score = self.score; var scoreTxt = new Text2(score, { size: 120, fill: "#ffffff", weight: 800, dropShadow: true, dropShadowColor: '#ff0000', dropShadowAngle: Math.PI / 6, dropShadowDistance: 5 }); self.currentLevelTxt = new Text2('LV' + self.levelManager.getCurrentLevel(), { size: 60, fill: "#ffffff", weight: 800, dropShadow: true, dropShadowColor: '#000000', dropShadowAngle: Math.PI / 6, dropShadowDistance: 3 }); self.currentLevelTxt.anchor.set(0.5, 0); self.currentLevelTxt.x = 1224; self.currentLevelTxt.y = 50; LK.gui.addChild(self.currentLevelTxt); scoreTxt.anchor.set(0.5, 1); scoreTxt.x = 2048 / 2; scoreTxt.y = 3200 - santaSack.sackGraphics.height / 2; LK.gui.addChild(scoreTxt); var level = self.levelManager.getCurrentLevel(); var presentTypesCount = 2; if (level >= 5 && level <= 8) { presentTypesCount = 4; } else if (level >= 9 && level <= 12) { presentTypesCount = 6; } else if (level >= 13) { presentTypesCount = 8; } self.createPresents = function (presentTypesCount, mainContainer) { for (var i = 0; i < presentTypesCount; i++) { var numPresentsToCreate = 6; for (var j = 0; j < numPresentsToCreate; j++) { var presentType = new Present('presentType' + (i + 1)); presentType.x = Math.random() * (mainContainer.width - presentType.width); presentType.y = Math.random() * (mainContainer.height - presentType.height); mainContainer.addChild(presentType); self.presents.push(presentType); } } }; self.createPresents(presentTypesCount, mainContainer); LK.on('tick', function () { for (var i = self.presents.length - 1; i >= 0; i--) { var present = self.presents[i]; present.move(); if (present.y >= LK.stageContainer.height - present.height) { present.y = LK.stageContainer.height - present.height; present.vy = 0; present.destroy(); self.presents.splice(i, 1); } } if (self.presents.length === 0) { var newLevel = self.levelManager.getNextLevel(); self.currentLevelTxt.setText('LV ' + newLevel); var level = self.levelManager.getCurrentLevel(); var presentTypesCount = 2; if (level >= 5 && level <= 8) { presentTypesCount = 4; } else if (level >= 9 && level <= 12) { presentTypesCount = 6; } else if (level >= 13) { presentTypesCount = 8; } self.createPresents(presentTypesCount, mainContainer); } }); });
===================================================================
--- original.js
+++ change.js
@@ -314,9 +314,9 @@
self.addChild(background);
});
var SantaSack = Container.expand(function () {
var self = Container.call(this);
- var sackGraphics = self.createAsset('santaSack', 'Santa Toy Sack', 0.5, 1);
+ this.sackGraphics = self.createAsset('santaSack', 'Santa Toy Sack', 0.5, 1);
self.x = 2048 / 2;
self.y = 3200;
});
var Game = Container.expand(function () {
@@ -396,9 +396,9 @@
self.currentLevelTxt.y = 50;
LK.gui.addChild(self.currentLevelTxt);
scoreTxt.anchor.set(0.5, 1);
scoreTxt.x = 2048 / 2;
- scoreTxt.y = 3200 - sackGraphics.height / 2;
+ scoreTxt.y = 3200 - santaSack.sackGraphics.height / 2;
LK.gui.addChild(scoreTxt);
var level = self.levelManager.getCurrentLevel();
var presentTypesCount = 2;
if (level >= 5 && level <= 8) {
basic snowflake. white Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
open top of Santa's sack. wrapped presents with ribbons and box, vivid colours, candy canes Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
close up of a Snow covered roof, Winter scene, star lit night sky, brick chimbly on right hand side, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
stary night sky.dark blue. no land. only sky Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Candy cane, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, vivid colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
old paper scroll, blank with no writing, Single Game Texture. In-Game asset. 2d. transparent Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
rudolf the red nose raindeer Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gift wrapped box, bright colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture.
gift wrapped box, bright light colours. with bow on top Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture.
Santa's sleigh with a team of reindeer moving across a star light sky. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.