Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.balls.push(presentType);' Line Number: 245
User prompt
Fix Bug: 'Uncaught TypeError: LevelManager is not a constructor' in this line: 'self.levelManager = new LevelManager();' Line Number: 212
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: Present is not defined' in this line: 'if (child instanceof Present) {' Line Number: 48
User prompt
Fix Bug: 'ReferenceError: Present is not defined' in this line: 'if (child instanceof Present) {' Line Number: 48
User prompt
remove present and present factory
User prompt
add created presents to main container
User prompt
set present type creation value for each level at 5
User prompt
Fix Bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'x')' in this line: 'present.x = Math.random() * (2048 - 100) + 50;' Line Number: 91
User prompt
Fix Bug: 'Uncaught TypeError: PresentFactory.createPresent is not a function' in this line: 'var present = PresentFactory.createPresent(self.levelManager.currentLevel);' Line Number: 90
User prompt
update present in game to display all presents types for the chosen level
User prompt
in presentfactory create 2 types of presents for level 1 and 2
User prompt
for levels 1 and 2 create 2 presents
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'presentsPerLevel')' in this line: 'for (var i = 0; i < self.levelManager.presentsPerLevel; i++) {' Line Number: 88
User prompt
add in code to spawn number of presents per level
User prompt
Add in variable for number of presents to create each level
Code edit (3 edits merged)
Please save this source code
User prompt
For levels 1 to 2 create 2 present types. For levels 3 to 16 add 1 new present type every 2 levels. create one type creation routine using common settings with present 1
User prompt
For levels 1 to 2 create 2 present types. For levels 3 to 16 add 1 new present type every 2 levels. create one type creation routine using common settings with present 1
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
add bounce to present
Code edit (2 edits merged)
Please save this source code
User prompt
add a fixed scale factor to present
===================================================================
--- original.js
+++ change.js
@@ -1,14 +1,174 @@
-var LevelManager = Container.expand(function () {
+var LevelManager = (function () {
+ var currentLevel = 1;
+ var maxLevel = 16;
+ function getNextLevel() {
+ if (currentLevel < maxLevel) {
+ 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 presentTypeDisplay = Container.expand(function () {
var self = Container.call(this);
- self.currentLevel = 3;
- self.maxLevel = 16;
- self.advanceLevel = function () {
- if (self.currentLevel < self.maxLevel) {
- self.currentLevel++;
+ 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.setRandomPresentTypeIndex = function () {
+ var presentTypeIndex = Math.floor(Math.random() * presentTypesCount);
+ var displayGraphic = self.createAsset(presentTypes[presentTypeIndex], presentTypes[presentTypeIndex] + ' Graphics', 0.5, 0.5);
+ displayGraphic.scale.x = 1.5;
+ displayGraphic.scale.y = 1.5;
+ if (self.children.length > 0) {
+ self.removeChildAt(0);
}
+ self.addChild(displayGraphic);
};
+ self.setRandomPresentTypeIndex();
+ LK.setInterval(self.setRandomPresentTypeIndex, (Math.random() * (9 - 3) + 3) * 1000);
});
+var Present = Container.expand(function (type) {
+ var self = Container.call(this);
+ 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.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 (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 (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 Present = Container.expand(function () {
var self = Container.call(this);
var presentGraphics = self.createAsset('present', 'Present Graphics', 0.5, 0.5);
self.move = function () {
@@ -45,11 +205,12 @@
self.y = 3200;
});
var Game = Container.expand(function () {
var self = Container.call(this);
+ self.presents = [];
var mainContainer = new MainContainer();
self.addChild(mainContainer);
- self.levelManager = new LevelManager();
+ self.levelManager = LevelManager;
LK.on('tick', function () {
mainContainer.children.forEach(function (child) {
if (child instanceof Present) {
child.move();
@@ -61,13 +222,30 @@
var mainContainer = new MainContainer();
self.addChild(mainContainer);
var santaSack = new SantaSack();
self.addChild(santaSack);
- self.levelManager = new LevelManager();
var background = self.createAsset('background', 'Background Image', 0, 0);
background.width = 2048;
background.height = 2732;
self.addChildAt(background, 0);
+ 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;
+ }
+ for (var i = 0; i < presentTypesCount; i++) {
+ for (var j = 0; j < 5; 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.balls.push(presentType);
+ }
+ }
var snowflakes = [];
LK.on('tick', function () {
for (var i = 0; i < snowflakes.length; i++) {
snowflakes[i].move();
@@ -90,6 +268,16 @@
newSnowflake.y = 0;
snowflakes.push(newSnowflake);
self.addChild(newSnowflake);
}
+ 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;
+ self.removeChild(present);
+ self.balls.splice(i, 1);
+ }
+ }
});
});
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.