User prompt
add in to game call to trigger popup message when game starts
User prompt
add a pop up message at beginning of game with a close button on it
Code edit (1 edits merged)
Please save this source code
User prompt
centre start button and text in middle of screen
Code edit (1 edits merged)
Please save this source code
User prompt
add alpha to overlay
Code edit (4 edits merged)
Please save this source code
User prompt
bring start button and text in front of start screen overlay
Code edit (1 edits merged)
Please save this source code
User prompt
add in before maincontainer in game a start screen that overlays all other asset with a start button and image on plus text
User prompt
make sure start screen is above all over layers
User prompt
add in to game line to call overlay start screen
User prompt
Add in an overlay screen at beginning of game that will have message on. screen will have a start button also that will then start the rest of the game set up when pressed
Code edit (1 edits merged)
Please save this source code
User prompt
Add in a start screen that will have message on. screen will have a start button also that will then start the rest of the game set up when pressed
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'width')' in this line: 'bonusItem.x = Math.random() * (mainContainer.width - bonusItem.createAsset('bonusItem', 'Bonus Item Graphics', 0.5, 0.5).width) + mainContainer.x;' Line Number: 418
User prompt
correct issues with start screen
User prompt
Fix Bug: 'Cannot read properties of undefined (reading 'width')' in this line: 'bonusItem.x = Math.random() * (mainContainer.width - bonusItem.width) + mainContainer.x;' Line Number: 421
Code edit (1 edits merged)
Please save this source code
User prompt
Add in a game start screen that will stop have message on. will have a start button also that will then start the rest of the game set up
User prompt
for display name changes blank name friest then add new name
User prompt
for name display clear name text when a new game starts or restarts
User prompt
When game ends set display name to ""
User prompt
When new game starts set display name to ""
var ParticleEffect = Container.expand(function () {
var self = Container.call(this);
self.emit = function (assetId, count, speed, scale, alphaDecay) {
for (var i = 0; i < count; i++) {
var particle = new Particle(assetId, speed, scale, alphaDecay);
particle.x = self.x;
particle.y = self.y;
self.addChild(particle);
}
};
});
var Particle = Container.expand(function (assetId, speed, scale, alphaDecay) {
var self = Container.call(this);
var particleGraphics = self.createAsset(assetId, 'Particle Graphics', 0.5, 0.5);
particleGraphics.rotation = Math.random() * Math.PI * 2;
particleGraphics.scale.x = scale;
particleGraphics.scale.y = scale;
self.vx = Math.random() * speed - speed / 2;
self.vy = Math.random() * speed - speed / 2;
self.alpha = 1;
self.lifetime = 60;
self.tick = function () {
self.x += self.vx;
self.y += self.vy;
self.alpha -= alphaDecay;
if (self.alpha <= 0) self.destroy();
};
LK.on('tick', self.tick);
});
var BonusItem = Container.expand(function () {
var self = Container.call(this);
self.speed = (Math.random() - 0.5) * 10;
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.bounce = Math.random() * 0.7 + 0.5;
self.gravity = Math.random() * 0.2 + 0.1;
self.vx = self.speed;
self.vy = self.speed;
BonusItem.prototype.startDestructionTimer = function (resetBonusTimerCallback) {
var self = this;
var destructionTimeout = LK.setTimeout(function () {
self.destroy();
resetBonusTimerCallback();
}, 15000);
self.destructionTimeout = destructionTimeout;
};
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);
LK.clearTimeout(self.destructionTimeout);
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);
var lifeCounterBg = self.createAsset('lifeCounterBg', 'Life Counter Background', 0.5, 0.5);
lifeCounterBg.x = 1710;
lifeCounterBg.y = 190;
lifeCounterBg.alpha = 0.2;
self.addChild(lifeCounterBg);
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: 45,
fill: "#000000",
font: "Comic Sans MS",
anchor: {
x: 0.0,
y: 0.0
}
});
self.nameText.x = 580;
self.nameText.y = 120;
LK.gui.addChild(self.nameText);
self.updateName = function (name) {
var particleEffect = new ParticleEffect();
particleEffect.x = 335;
particleEffect.y = 70;
LK.gui.addChild(particleEffect);
particleEffect.emit('particleAsset', 10, 6, 0.8, 0.03);
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.0002;
});
var presentTypeDisplay = Container.expand(function (nameDisplay) {
var self = Container.call(this);
var level = LevelManager.getCurrentLevel();
var presentTypesCount = 2;
if (level >= 3 && level <= 4) {
presentTypesCount = 3;
} else if (level >= 5 && level <= 6) {
presentTypesCount = 4;
} else if (level >= 7 && level <= 8) {
presentTypesCount = 5;
} else if (level >= 9 && level <= 10) {
presentTypesCount = 6;
} else if (level >= 11 && level <= 12) {
presentTypesCount = 7;
} else if (level >= 13 && level <= 14) {
presentTypesCount = 8;
} else if (level >= 15 && level <= 16) {
presentTypesCount = 9;
} else if (level >= 17) {
presentTypesCount = 10;
}
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);
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 nameStorage = ['James', 'Mary', 'John', 'Pat', 'Robert', 'Jenni', 'Michael', 'Linda', 'William', 'Elizabeth', 'David', 'Barbara', 'Richard', 'Susan', 'Joseph', 'Jessica', 'Thomas', 'Sarah', 'Charles', 'Karen', 'Chris', '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 = 20;
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
}, {
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 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();
}
});
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 santaSack = new SantaSack();
self.addChild(santaSack);
var mainContainer = new MainContainer();
self.addChild(mainContainer);
var scroll = self.createAsset('newImageAsset', 'Scroll', 0.5, 0.5);
scroll.x = 950;
scroll.y = 220;
self.addChild(scroll);
var nameDisplay = new NameDisplay();
nameDisplay.updateName(nameStorage[Math.floor(Math.random() * nameStorage.length)]);
var presentDisplay = self.addChild(new presentTypeDisplay(nameDisplay));
self.presentDisplay = presentDisplay;
self.getCurrentPresentType = function () {
return self.presentDisplay.getCurrentPresentType();
};
self.presentDisplay.x = 450;
self.presentDisplay.y = 0;
self.lifeCounter = new LifeCounter(5);
self.addChild(self.lifeCounter);
self.score = 0;
var score = self.score;
var scoreTxtXAdjust = 335;
var scoreTxtYAdjust = 20;
self.score = 0;
var scoreTxt = new Text2(self.score, {
size: 80,
fill: "#ffffff",
weight: 800,
dropShadow: true,
dropShadowColor: '#ff0000',
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 5
});
scoreTxt.x += scoreTxtXAdjust;
scoreTxt.y += scoreTxtYAdjust;
self.levelManager.resetLevels();
self.currentLevelTxt = new Text2('LV' + self.levelManager.getCurrentLevel(), {
size: 80,
fill: "#ffffff",
weight: 800,
dropShadow: true,
dropShadowColor: '#ff0000',
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 3
});
self.currentLevelTxt.anchor.set(0.5, 0);
self.currentLevelTxt.x = 1315;
self.currentLevelTxt.y = 30;
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 >= 3 && level <= 4) {
presentTypesCount = 3;
} else if (level >= 5 && level <= 6) {
presentTypesCount = 4;
} else if (level >= 7 && level <= 8) {
presentTypesCount = 5;
} else if (level >= 9 && level <= 10) {
presentTypesCount = 6;
} else if (level >= 11 && level <= 12) {
presentTypesCount = 7;
} else if (level >= 13 && level <= 14) {
presentTypesCount = 8;
} else if (level >= 15 && level <= 16) {
presentTypesCount = 9;
} else if (level >= 17) {
presentTypesCount = 10;
}
self.createPresents = function (presentTypesCount, mainContainer) {
for (var i = 0; i < presentTypesCount; i++) {
var levelAdjustment = LevelManager.getCurrentLevel() > 15 ? 3 : Math.max(0, Math.floor((LevelManager.getCurrentLevel() - 11) / 2));
var numPresentsToCreate = 6 - levelAdjustment;
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 >= 3 && level <= 4) {
presentTypesCount = 3;
} else if (level >= 5 && level <= 6) {
presentTypesCount = 4;
} else if (level >= 7 && level <= 8) {
presentTypesCount = 5;
} else if (level >= 9 && level <= 10) {
presentTypesCount = 6;
} else if (level >= 11 && level <= 12) {
presentTypesCount = 7;
} else if (level >= 13 && level <= 14) {
presentTypesCount = 8;
} else if (level >= 15 && level <= 16) {
presentTypesCount = 9;
} else if (level >= 17) {
presentTypesCount = 10;
}
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.