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
User prompt
add bonus item move to tick
User prompt
when bonus item has been created then display for 20 seconds and then remove it. Keep existing bonusitem timer that generates bonusitem
User prompt
when bonus item has been created then display for 20 seconds and then remove it.
User prompt
hen bonus item created display for 20 seconds and then destroy
User prompt
Fix Bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'createBonusItem')' in this line: 'self.createBonusItem = function (mainContainer) {' Line Number: 304
User prompt
add a bonus point item that will travel across the main container at a random time (between 1 and 2 minutes). When clicked it will ass a random bonus amount to the score of between 4 and 10 points
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
refersh level indicator when level changes
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 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 = 75;
self.lifeIcons.push(lifeIcon);
self.addChild(lifeIcon);
self.levelText = new Text2('Level ' + LevelManager.getCurrentLevel(), {
size: 40,
fill: '#ffffff',
anchor: {
x: 0.5,
y: 0
}
});
self.levelText.x = 1024;
self.levelText.y = 150;
LK.gui.addChild(self.levelText);
}
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 = 750;
self.lifeIcons.push(lifeIcon);
self.addChild(lifeIcon);
}
self.lives = initialLives;
self.levelText.setText('Level ' + LevelManager.getCurrentLevel());
};
});
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.0005;
});
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);
var 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.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('Level ' + 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 = 1024;
self.currentLevelTxt.y = 50;
LK.gui.addChild(self.currentLevelTxt);
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.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('Level ' + 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);
}
});
});
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.