User prompt
make circle around start
Code edit (1 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
User prompt
Fix Bug: 'Uncaught TypeError: Graphics is not a constructor' in this line: 'var startButton = new Graphics();' Line Number: 341
User prompt
Fix Bug: 'Uncaught TypeError: Graphics is not a constructor' in this line: 'var levelProgress = new Graphics();' Line Number: 274
User prompt
Fix Bug: 'Uncaught TypeError: Graphics is not a constructor' in this line: 'var levelBar = new Graphics();' Line Number: 268
User prompt
Fix Bug: 'Uncaught TypeError: Graphics is not a constructor' in this line: 'var modalBackground = new Graphics();' Line Number: 30
User prompt
Fix Bug: 'Uncaught TypeError: Graphics is not a constructor' in this line: 'var gridGraphics = new Graphics();' Line Number: 126
Code edit (1 edits merged)
Please save this source code
User prompt
Add stars to the background
User prompt
Remove everything from the game
Initial prompt
Rogue Defuse
/**** * Classes ****/ var ActiveBomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = LK.getAsset('activeBomb', { anchorX: 0.5, anchorY: 0.5 }); var cellSize = 2048 * 0.7 / 4; bombGraphics.width = cellSize * 0.9; bombGraphics.height = cellSize * 0.9; self.addChild(bombGraphics); self.isAnimating = false; self.visible = false; self.on('down', function () { if (self.visible) { self.hide(); LK.score += 20; LK.experience += 100; if (LK.experience >= LK.experienceToNextLevel) { LK.level++; if (LK.level <= 35) { LK.experienceToNextLevel += 150; } else { LK.experienceToNextLevel += 180; } LK.experience = 0; var levelUpModal = self.parent.parent.parent.children.find(function (child) { return child instanceof LevelUpModal; }); if (levelUpModal) { levelUpModal.visible = true; } } LK.gui.top.children[0].setText(LK.score.toString()); self.parent.children.forEach(function (child) { if (child instanceof IdleBomb && typeof child.show === 'function') { child.show(); } }); } }); self.show = function () { self.visible = true; }; self.hide = function () { self.visible = false; }; }); var CriticalChance = Container.expand(function () { var self = Container.call(this); self.attachAsset('criticalChance', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function () { LK.criticalChance += 0.1; self.visible = false; }); }); var DeadBomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = LK.getAsset('deadBomb', { anchorX: 0.5, anchorY: 0.5 }); var cellSize = 2048 * 0.7 / 4; bombGraphics.width = cellSize * 0.9; bombGraphics.height = cellSize * 0.9; self.addChild(bombGraphics); self.visible = false; self.show = function () { if (LK.gameState === 'LOST') { self.visible = true; } }; self.hide = function () { self.visible = false; }; }); var Grid = Container.expand(function () { var self = Container.call(this); this.columns = 4; this.rows = 3; var cellSize = 2048 * 0.7 / this.columns; var cellWidth = cellSize * 0.9; var cellHeight = cellSize * 0.9; var cellSpacing = cellSize * 0.35; for (var i = 0; i < this.columns; i++) { for (var j = 0; j < this.rows; j++) { var gridGraphics = LK.getAsset('gridCell', { anchorX: 0.5, anchorY: 0.5 }); gridGraphics.width = cellWidth; gridGraphics.height = cellHeight; gridGraphics.tint = i % 2 === 0 ? 0x808080 : 0xFFFFFF; gridGraphics.x = (2048 - (this.columns * cellWidth + (this.columns - 1) * cellSpacing)) / 2 + i * (cellWidth + cellSpacing); gridGraphics.y = (2732 - this.rows * cellHeight) / 2 + j * (cellHeight + cellSpacing) + 200; self.addChild(gridGraphics); var cellLabel = new Text2(i + '.' + j, { size: cellSize * 0.2, fill: '#000000' }); cellLabel.x = (2048 - (this.columns * cellWidth + (this.columns - 1) * cellSpacing)) / 2 + i * (cellWidth + cellSpacing) + cellWidth / 2; cellLabel.y = (2732 - this.rows * cellHeight) / 2 + j * (cellHeight + cellSpacing) + cellHeight / 2 + 200; cellLabel.anchor.set(0.5, 0.5); cellLabel.visible = LK.testMode; gridGraphics.addChild(cellLabel); var idleBomb = new IdleBomb(); idleBomb.x = cellLabel.x; idleBomb.y = cellLabel.y; gridGraphics.addChild(idleBomb); var activeBomb = new ActiveBomb(); activeBomb.x = cellLabel.x; activeBomb.y = cellLabel.y; gridGraphics.addChild(activeBomb); var deadBomb = new DeadBomb(); deadBomb.x = cellLabel.x; deadBomb.y = cellLabel.y; gridGraphics.addChild(deadBomb); } } }); var Health = Container.expand(function () { var self = Container.call(this); self.attachAsset('health', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function () { LK.health += 100; self.visible = false; }); }); var IdleBomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = LK.getAsset('idleBomb', { anchorX: 0.5, anchorY: 0.5 }); var cellSize = 2048 * 0.7 / 4; bombGraphics.width = cellSize * 0.9; bombGraphics.height = cellSize * 0.9; self.addChild(bombGraphics); self.isAnimating = false; self.visibilityTimeout = null; self.on('down', function () { if (!self.isAnimating) { self.isAnimating = true; var originalScale = self.scale.x; var tweenScale = originalScale * 1.05; var interval = LK.setInterval(function () { if (self.scale.x < tweenScale) { self.scale.x += 0.01; self.scale.y += 0.01; } else { LK.clearInterval(interval); interval = LK.setInterval(function () { if (self.scale.x > originalScale) { self.scale.x -= 0.01; self.scale.y -= 0.01; } else { LK.clearInterval(interval); self.isAnimating = false; } }, 1000 / 60); } }, 1000 / 60); } }); self.hide = function () { self.visible = false; }; self.show = function () { if (self.visibilityTimeout) { LK.clearTimeout(self.visibilityTimeout); self.visibilityTimeout = null; } self.visible = true; }; }); var LevelUpModal = Container.expand(function () { var self = Container.call(this); self.rewards = [new ScoreMultiplier(), new Health(), new CriticalChance()]; var rewardHeight = self.rewards[0].height; var modalHeight = rewardHeight * 1.15; var modalBackground = self.attachAsset('modalBackground', { anchorX: 0.5, anchorY: 0.5 }); modalBackground.width = 2048; modalBackground.height = modalHeight; modalBackground.alpha = 0.8; modalBackground.y = (2732 - modalHeight) / 2; self.addChild(modalBackground); self.visible = false; var totalWidth = self.rewards.reduce(function (total, reward) { return total + reward.width + 20; }, -20); var rewardSpacing = 20; var totalRewardWidth = self.rewards.reduce(function (total, reward) { return total + reward.width; }, 0); var startRewardX = (2048 - totalRewardWidth - rewardSpacing * (self.rewards.length - 1)) / 2; var gridWidth = (self.rewards[0].width + rewardSpacing) * self.rewards.length - rewardSpacing; var gridStartX = (2048 - gridWidth) / 2; self.rewards.forEach(function (reward, index) { reward.x = gridStartX + index * (reward.width + rewardSpacing); reward.y = (2732 - modalHeight) / 2 + modalHeight / 2; reward.on('down', function () { self.visible = false; }); self.addChild(reward); }); }); var ScoreMultiplier = Container.expand(function () { var self = Container.call(this); self.attachAsset('scoreMultiplier', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function () { LK.score *= 2; self.visible = false; }); }); var StarField = Container.expand(function () { var self = Container.call(this); var starGraphics = LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(starGraphics); self._move_migrated = function () { self.y += 1; if (self.y > 2732) { self.y = 0; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ LK.gameState = 'IDLE'; LK.testMode = true; var grid = new Grid(); var lastBombActivated = null; var levelUpModal = new LevelUpModal(); game.addChild(grid); game.addChild(levelUpModal); var starField = []; for (var i = 0; i < 100; i++) { var star = new StarField(); star.x = Math.random() * 2048; star.y = Math.random() * 2732; starField.push(star); game.addChildAt(star, 0); } function handleTick() { if (LK.gameState === 'START') { starField.forEach(function (star) { star._move_migrated(); }); levelProgress.width = LK.experience / LK.experienceToNextLevel * levelBar.width; } else if (LK.gameState === 'LOST') { grid.children.forEach(function (cell) { cell.children.forEach(function (child) { if (child instanceof DeadBomb) { child.show(); } }); }); } else if (LK.gameState === 'START' || LK.gameState === 'IDLE') { grid.children.forEach(function (cell) { cell.children.forEach(function (child) { if (child instanceof DeadBomb) { child.hide(); } }); }); } } game.scoreTxt = new Text2('0', { size: 100, fill: '#ffff00' }); game.scoreTxt.anchor.set(0.5, 0.5); game.scoreTxt.x = LK.width / 2; game.scoreTxt.y = 200; LK.gui.top.addChild(game.scoreTxt); LK.score = 0; LK.level = 1; LK.experience = 0; LK.experienceToNextLevel = 50; var levelUpModal = new LevelUpModal(); game.addChild(levelUpModal); var levelBar = LK.getAsset('levelBar', {}); levelBar.width = game.width * 0.8; levelBar.height = 100; levelBar.y = 0; levelBar.x = 2048 / 2 - levelBar.width / 2; LK.gui.topLeft.addChild(levelBar); var levelProgress = LK.getAsset('levelProgress', {}); levelProgress.width = 1; levelProgress.height = 100; levelProgress.y = 0; levelProgress.x = 2048 / 2 - levelBar.width / 2; LK.gui.topLeft.addChild(levelProgress); var testButton = LK.getAsset('testButton', { anchorX: 0.5, anchorY: 0.5 }); testButton.x = 0; testButton.y = LK.height - testButton.height; LK.gui.bottomLeft.addChild(testButton); testButton.on('down', function () { LK.testMode = !LK.testMode; console.log('Test Mode is: ', LK.testMode); testButton.alpha = LK.testMode ? 1 : 0; grid.children.forEach(function (cell) { cell.children.forEach(function (child) { if (child instanceof Text2) { child.visible = LK.testMode; } if (!LK.testMode) { cell.alpha = 0; } else { cell.alpha = 1; } }); }); }); LK.on('tick', handleTick); game.activateBomb = function () { if (LK.gameState === 'START') { var idleBombs = []; grid.children.forEach(function (cell) { cell.children.forEach(function (child) { if (child instanceof IdleBomb && child.visible) { var hasActiveBomb = false; child.parent.children.forEach(function (sibling) { if (sibling instanceof ActiveBomb && sibling.visible) { hasActiveBomb = true; } }); if (!hasActiveBomb) { idleBombs.push(child); } } }); }); if (idleBombs.length > 0) { var bombToActivate; do { bombToActivate = idleBombs[Math.floor(Math.random() * idleBombs.length)]; } while (bombToActivate === lastBombActivated); lastBombActivated = bombToActivate; bombToActivate.hide(); bombToActivate.parent.children.forEach(function (child) { if (child instanceof ActiveBomb) { child.show(); bombToActivate.visibilityTimeout = LK.setTimeout(function () { child.hide(); bombToActivate.visibilityTimeout = null; bombToActivate.visible = true; }, 2000); } }); } } }; LK.setInterval(game.activateBomb, 450); var startButton = LK.getAsset('startButton', { anchorX: 0.5, anchorY: 0.5 }); startButton.width = 200; startButton.height = 100; startButton.x = 2048 / 2 - startButton.width / 2; startButton.y = 2732 - startButton.height; game.addChild(startButton); var startText = new Text2('Start', { size: 50, fill: '#ffffff' }); startText.anchor.set(0.5, 0.5); startText.x = startButton.width / 2; startText.y = startButton.height / 2; startButton.addChild(startText); startButton.on('down', function () { if (LK.gameState === 'IDLE') { LK.gameState = 'START'; var originalScale = startButton.scale.x; var tweenScale = originalScale * 1.05; var interval = LK.setInterval(function () { if (startButton.scale.x < tweenScale) { startButton.scale.x += 0.01; startButton.scale.y += 0.01; } else { LK.clearInterval(interval); interval = LK.setInterval(function () { if (startButton.scale.x > originalScale) { startButton.scale.x -= 0.01; startButton.scale.y -= 0.01; } else { LK.clearInterval(interval); var fadeOutInterval = LK.setInterval(function () { if (startButton.alpha > 0) { startButton.alpha -= 0.0668; } else { LK.clearInterval(fadeOutInterval); startButton.visible = false; } }, 1000 / 60); } }, 1000 / 60); } }, 1000 / 60); } }); var bounceUp = true; var bounceInterval = LK.setInterval(function () { if (bounceUp) { if (startButton.y > 2732 - startButton.height - 10) { startButton.y -= 1; } else { bounceUp = false; } } else { if (startButton.y < 2732 - startButton.height) { startButton.y += 1; } else { bounceUp = true; } } }, 1000 / 60);
===================================================================
--- original.js
+++ change.js
@@ -1,83 +1,17 @@
-var CriticalChance = Container.expand(function () {
+/****
+* Classes
+****/
+var ActiveBomb = Container.expand(function () {
var self = Container.call(this);
- self.createAsset('criticalChance', 'Critical Chance', 0.5, 0.5);
- self.on('down', function () {
- LK.criticalChance += 0.1;
- self.visible = false;
+ var bombGraphics = LK.getAsset('activeBomb', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
-});
-var Health = Container.expand(function () {
- var self = Container.call(this);
- self.createAsset('health', 'Health', 0.5, 0.5);
- self.on('down', function () {
- LK.health += 100;
- self.visible = false;
- });
-});
-var ScoreMultiplier = Container.expand(function () {
- var self = Container.call(this);
- self.createAsset('scoreMultiplier', 'Score Multiplier', 0.5, 0.5);
- self.on('down', function () {
- LK.score *= 2;
- self.visible = false;
- });
-});
-var LevelUpModal = Container.expand(function () {
- var self = Container.call(this);
- self.rewards = [new ScoreMultiplier(), new Health(), new CriticalChance()];
- var rewardHeight = self.rewards[0].height;
- var modalHeight = rewardHeight * 1.15;
- var modalBackground = self.createAsset('modalBackground', 'Modal Background', 0.5, 0.5);
- modalBackground.width = 2048;
- modalBackground.height = modalHeight;
- modalBackground.alpha = 0.8;
- modalBackground.y = (2732 - modalHeight) / 2;
- self.addChild(modalBackground);
- self.visible = false;
- var totalWidth = self.rewards.reduce(function (total, reward) {
- return total + reward.width + 20;
- }, -20);
- var rewardSpacing = 20;
- var totalRewardWidth = self.rewards.reduce(function (total, reward) {
- return total + reward.width;
- }, 0);
- var startRewardX = (2048 - totalRewardWidth - rewardSpacing * (self.rewards.length - 1)) / 2;
- var gridWidth = (self.rewards[0].width + rewardSpacing) * self.rewards.length - rewardSpacing;
- var gridStartX = (2048 - gridWidth) / 2;
- self.rewards.forEach(function (reward, index) {
- reward.x = gridStartX + index * (reward.width + rewardSpacing);
- reward.y = (2732 - modalHeight) / 2 + modalHeight / 2;
- reward.on('down', function () {
- self.visible = false;
- });
- self.addChild(reward);
- });
-});
-var DeadBomb = Container.expand(function () {
- var self = Container.call(this);
- var bombGraphics = LK.getAsset('deadBomb', 'Dead Bomb Graphics', 0.5, 0.5);
var cellSize = 2048 * 0.7 / 4;
bombGraphics.width = cellSize * 0.9;
bombGraphics.height = cellSize * 0.9;
self.addChild(bombGraphics);
- self.visible = false;
- self.show = function () {
- if (LK.gameState === 'LOST') {
- self.visible = true;
- }
- };
- self.hide = function () {
- self.visible = false;
- };
-});
-var ActiveBomb = Container.expand(function () {
- var self = Container.call(this);
- var bombGraphics = LK.getAsset('activeBomb', 'Active Bomb Graphics', 0.5, 0.5);
- var cellSize = 2048 * 0.7 / 4;
- bombGraphics.width = cellSize * 0.9;
- bombGraphics.height = cellSize * 0.9;
- self.addChild(bombGraphics);
self.isAnimating = false;
self.visible = false;
self.on('down', function () {
if (self.visible) {
@@ -98,9 +32,9 @@
if (levelUpModal) {
levelUpModal.visible = true;
}
}
- LK.gui.topCenter.children[0].setText(LK.score.toString());
+ LK.gui.top.children[0].setText(LK.score.toString());
self.parent.children.forEach(function (child) {
if (child instanceof IdleBomb && typeof child.show === 'function') {
child.show();
}
@@ -113,8 +47,39 @@
self.hide = function () {
self.visible = false;
};
});
+var CriticalChance = Container.expand(function () {
+ var self = Container.call(this);
+ self.attachAsset('criticalChance', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.on('down', function () {
+ LK.criticalChance += 0.1;
+ self.visible = false;
+ });
+});
+var DeadBomb = Container.expand(function () {
+ var self = Container.call(this);
+ var bombGraphics = LK.getAsset('deadBomb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var cellSize = 2048 * 0.7 / 4;
+ bombGraphics.width = cellSize * 0.9;
+ bombGraphics.height = cellSize * 0.9;
+ self.addChild(bombGraphics);
+ self.visible = false;
+ self.show = function () {
+ if (LK.gameState === 'LOST') {
+ self.visible = true;
+ }
+ };
+ self.hide = function () {
+ self.visible = false;
+ };
+});
var Grid = Container.expand(function () {
var self = Container.call(this);
this.columns = 4;
this.rows = 3;
@@ -123,9 +88,12 @@
var cellHeight = cellSize * 0.9;
var cellSpacing = cellSize * 0.35;
for (var i = 0; i < this.columns; i++) {
for (var j = 0; j < this.rows; j++) {
- var gridGraphics = LK.getAsset('gridCell', 'Grid Cell Graphics', 0.5, 0.5);
+ var gridGraphics = LK.getAsset('gridCell', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
gridGraphics.width = cellWidth;
gridGraphics.height = cellHeight;
gridGraphics.tint = i % 2 === 0 ? 0x808080 : 0xFFFFFF;
gridGraphics.x = (2048 - (this.columns * cellWidth + (this.columns - 1) * cellSpacing)) / 2 + i * (cellWidth + cellSpacing);
@@ -154,22 +122,25 @@
gridGraphics.addChild(deadBomb);
}
}
});
-var StarField = Container.expand(function () {
+var Health = Container.expand(function () {
var self = Container.call(this);
- var starGraphics = LK.getAsset('star', 'Star Graphics', 0.5, 0.5);
- self.addChild(starGraphics);
- self.move = function () {
- self.y += 1;
- if (self.y > 2732) {
- self.y = 0;
- }
- };
+ self.attachAsset('health', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.on('down', function () {
+ LK.health += 100;
+ self.visible = false;
+ });
});
var IdleBomb = Container.expand(function () {
var self = Container.call(this);
- var bombGraphics = LK.getAsset('idleBomb', 'Idle Bomb Graphics', 0.5, 0.5);
+ var bombGraphics = LK.getAsset('idleBomb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
var cellSize = 2048 * 0.7 / 4;
bombGraphics.width = cellSize * 0.9;
bombGraphics.height = cellSize * 0.9;
self.addChild(bombGraphics);
@@ -209,194 +180,267 @@
}
self.visible = true;
};
});
-var Game = Container.expand(function () {
+var LevelUpModal = Container.expand(function () {
var self = Container.call(this);
- LK.gameState = 'IDLE';
- LK.testMode = true;
- var grid = new Grid();
- var lastBombActivated = null;
- var levelUpModal = new LevelUpModal();
- self.addChild(grid);
- self.addChild(levelUpModal);
- var starField = [];
- for (var i = 0; i < 100; i++) {
- var star = new StarField();
- star.x = Math.random() * 2048;
- star.y = Math.random() * 2732;
- starField.push(star);
- self.addChildAt(star, 0);
- }
- function handleTick() {
- if (LK.gameState === 'START') {
- starField.forEach(function (star) {
- star.move();
- });
- levelProgress.width = LK.experience / LK.experienceToNextLevel * levelBar.width;
- } else if (LK.gameState === 'LOST') {
- grid.children.forEach(function (cell) {
- cell.children.forEach(function (child) {
- if (child instanceof DeadBomb) {
- child.show();
- }
- });
- });
- } else if (LK.gameState === 'START' || LK.gameState === 'IDLE') {
- grid.children.forEach(function (cell) {
- cell.children.forEach(function (child) {
- if (child instanceof DeadBomb) {
- child.hide();
- }
- });
- });
- }
- }
- self.scoreTxt = new Text2('0', {
- size: 100,
- fill: '#ffff00'
+ self.rewards = [new ScoreMultiplier(), new Health(), new CriticalChance()];
+ var rewardHeight = self.rewards[0].height;
+ var modalHeight = rewardHeight * 1.15;
+ var modalBackground = self.attachAsset('modalBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- self.scoreTxt.anchor.set(0.5, 0.5);
- self.scoreTxt.x = LK.width / 2;
- self.scoreTxt.y = 200;
- LK.gui.topCenter.addChild(self.scoreTxt);
- LK.score = 0;
- LK.level = 1;
- LK.experience = 0;
- LK.experienceToNextLevel = 50;
- var levelUpModal = new LevelUpModal();
- self.addChild(levelUpModal);
- var levelBar = LK.getAsset('levelBar', 'Level Progress Bar', 0, 0);
- levelBar.width = LK.stage.width * 0.8;
- levelBar.height = 100;
- levelBar.y = 0;
- levelBar.x = 2048 / 2 - levelBar.width / 2;
- LK.gui.topLeft.addChild(levelBar);
- var levelProgress = LK.getAsset('levelProgress', 'Level Progress Bar', 0, 0);
- levelProgress.width = 1;
- levelProgress.height = 100;
- levelProgress.y = 0;
- levelProgress.x = 2048 / 2 - levelBar.width / 2;
- LK.gui.topLeft.addChild(levelProgress);
- var testButton = LK.getAsset('testButton', 'Test Button', 0.5, 0.5);
- testButton.x = 0;
- testButton.y = LK.height - testButton.height;
- LK.gui.bottomLeft.addChild(testButton);
- testButton.on('down', function () {
- LK.testMode = !LK.testMode;
- console.log('Test Mode is: ', LK.testMode);
- testButton.alpha = LK.testMode ? 1 : 0;
+ modalBackground.width = 2048;
+ modalBackground.height = modalHeight;
+ modalBackground.alpha = 0.8;
+ modalBackground.y = (2732 - modalHeight) / 2;
+ self.addChild(modalBackground);
+ self.visible = false;
+ var totalWidth = self.rewards.reduce(function (total, reward) {
+ return total + reward.width + 20;
+ }, -20);
+ var rewardSpacing = 20;
+ var totalRewardWidth = self.rewards.reduce(function (total, reward) {
+ return total + reward.width;
+ }, 0);
+ var startRewardX = (2048 - totalRewardWidth - rewardSpacing * (self.rewards.length - 1)) / 2;
+ var gridWidth = (self.rewards[0].width + rewardSpacing) * self.rewards.length - rewardSpacing;
+ var gridStartX = (2048 - gridWidth) / 2;
+ self.rewards.forEach(function (reward, index) {
+ reward.x = gridStartX + index * (reward.width + rewardSpacing);
+ reward.y = (2732 - modalHeight) / 2 + modalHeight / 2;
+ reward.on('down', function () {
+ self.visible = false;
+ });
+ self.addChild(reward);
+ });
+});
+var ScoreMultiplier = Container.expand(function () {
+ var self = Container.call(this);
+ self.attachAsset('scoreMultiplier', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.on('down', function () {
+ LK.score *= 2;
+ self.visible = false;
+ });
+});
+var StarField = Container.expand(function () {
+ var self = Container.call(this);
+ var starGraphics = LK.getAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(starGraphics);
+ self._move_migrated = function () {
+ self.y += 1;
+ if (self.y > 2732) {
+ self.y = 0;
+ }
+ };
+});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+LK.gameState = 'IDLE';
+LK.testMode = true;
+var grid = new Grid();
+var lastBombActivated = null;
+var levelUpModal = new LevelUpModal();
+game.addChild(grid);
+game.addChild(levelUpModal);
+var starField = [];
+for (var i = 0; i < 100; i++) {
+ var star = new StarField();
+ star.x = Math.random() * 2048;
+ star.y = Math.random() * 2732;
+ starField.push(star);
+ game.addChildAt(star, 0);
+}
+function handleTick() {
+ if (LK.gameState === 'START') {
+ starField.forEach(function (star) {
+ star._move_migrated();
+ });
+ levelProgress.width = LK.experience / LK.experienceToNextLevel * levelBar.width;
+ } else if (LK.gameState === 'LOST') {
grid.children.forEach(function (cell) {
cell.children.forEach(function (child) {
- if (child instanceof Text2) {
- child.visible = LK.testMode;
+ if (child instanceof DeadBomb) {
+ child.show();
}
- if (!LK.testMode) {
- cell.alpha = 0;
- } else {
- cell.alpha = 1;
+ });
+ });
+ } else if (LK.gameState === 'START' || LK.gameState === 'IDLE') {
+ grid.children.forEach(function (cell) {
+ cell.children.forEach(function (child) {
+ if (child instanceof DeadBomb) {
+ child.hide();
}
});
});
+ }
+}
+game.scoreTxt = new Text2('0', {
+ size: 100,
+ fill: '#ffff00'
+});
+game.scoreTxt.anchor.set(0.5, 0.5);
+game.scoreTxt.x = LK.width / 2;
+game.scoreTxt.y = 200;
+LK.gui.top.addChild(game.scoreTxt);
+LK.score = 0;
+LK.level = 1;
+LK.experience = 0;
+LK.experienceToNextLevel = 50;
+var levelUpModal = new LevelUpModal();
+game.addChild(levelUpModal);
+var levelBar = LK.getAsset('levelBar', {});
+levelBar.width = game.width * 0.8;
+levelBar.height = 100;
+levelBar.y = 0;
+levelBar.x = 2048 / 2 - levelBar.width / 2;
+LK.gui.topLeft.addChild(levelBar);
+var levelProgress = LK.getAsset('levelProgress', {});
+levelProgress.width = 1;
+levelProgress.height = 100;
+levelProgress.y = 0;
+levelProgress.x = 2048 / 2 - levelBar.width / 2;
+LK.gui.topLeft.addChild(levelProgress);
+var testButton = LK.getAsset('testButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+testButton.x = 0;
+testButton.y = LK.height - testButton.height;
+LK.gui.bottomLeft.addChild(testButton);
+testButton.on('down', function () {
+ LK.testMode = !LK.testMode;
+ console.log('Test Mode is: ', LK.testMode);
+ testButton.alpha = LK.testMode ? 1 : 0;
+ grid.children.forEach(function (cell) {
+ cell.children.forEach(function (child) {
+ if (child instanceof Text2) {
+ child.visible = LK.testMode;
+ }
+ if (!LK.testMode) {
+ cell.alpha = 0;
+ } else {
+ cell.alpha = 1;
+ }
+ });
});
- LK.on('tick', handleTick);
- self.activateBomb = function () {
- if (LK.gameState === 'START') {
- var idleBombs = [];
- grid.children.forEach(function (cell) {
- cell.children.forEach(function (child) {
- if (child instanceof IdleBomb && child.visible) {
- var hasActiveBomb = false;
- child.parent.children.forEach(function (sibling) {
- if (sibling instanceof ActiveBomb && sibling.visible) {
- hasActiveBomb = true;
- }
- });
- if (!hasActiveBomb) {
- idleBombs.push(child);
+});
+LK.on('tick', handleTick);
+game.activateBomb = function () {
+ if (LK.gameState === 'START') {
+ var idleBombs = [];
+ grid.children.forEach(function (cell) {
+ cell.children.forEach(function (child) {
+ if (child instanceof IdleBomb && child.visible) {
+ var hasActiveBomb = false;
+ child.parent.children.forEach(function (sibling) {
+ if (sibling instanceof ActiveBomb && sibling.visible) {
+ hasActiveBomb = true;
}
+ });
+ if (!hasActiveBomb) {
+ idleBombs.push(child);
}
- });
+ }
});
- if (idleBombs.length > 0) {
- var bombToActivate;
- do {
- bombToActivate = idleBombs[Math.floor(Math.random() * idleBombs.length)];
- } while (bombToActivate === lastBombActivated);
- lastBombActivated = bombToActivate;
- bombToActivate.hide();
- bombToActivate.parent.children.forEach(function (child) {
- if (child instanceof ActiveBomb) {
- child.show();
- bombToActivate.visibilityTimeout = LK.setTimeout(function () {
- child.hide();
- bombToActivate.visibilityTimeout = null;
- bombToActivate.visible = true;
- }, 2000);
- }
- });
- }
- }
- };
- LK.setInterval(self.activateBomb, 450);
- var startButton = LK.getAsset('startButton', 'Start Button', 0.5, 0.5);
- startButton.width = 200;
- startButton.height = 100;
- startButton.x = 2048 / 2 - startButton.width / 2;
- startButton.y = 2732 - startButton.height;
- self.addChild(startButton);
- var startText = new Text2('Start', {
- size: 50,
- fill: '#ffffff'
- });
- startText.anchor.set(0.5, 0.5);
- startText.x = startButton.width / 2;
- startText.y = startButton.height / 2;
- startButton.addChild(startText);
- startButton.on('down', function () {
- if (LK.gameState === 'IDLE') {
- LK.gameState = 'START';
- var originalScale = startButton.scale.x;
- var tweenScale = originalScale * 1.05;
- var interval = LK.setInterval(function () {
- if (startButton.scale.x < tweenScale) {
- startButton.scale.x += 0.01;
- startButton.scale.y += 0.01;
- } else {
- LK.clearInterval(interval);
- interval = LK.setInterval(function () {
- if (startButton.scale.x > originalScale) {
- startButton.scale.x -= 0.01;
- startButton.scale.y -= 0.01;
- } else {
- LK.clearInterval(interval);
- var fadeOutInterval = LK.setInterval(function () {
- if (startButton.alpha > 0) {
- startButton.alpha -= 0.0668;
- } else {
- LK.clearInterval(fadeOutInterval);
- startButton.visible = false;
- }
- }, 1000 / 60);
- }
- }, 1000 / 60);
+ });
+ if (idleBombs.length > 0) {
+ var bombToActivate;
+ do {
+ bombToActivate = idleBombs[Math.floor(Math.random() * idleBombs.length)];
+ } while (bombToActivate === lastBombActivated);
+ lastBombActivated = bombToActivate;
+ bombToActivate.hide();
+ bombToActivate.parent.children.forEach(function (child) {
+ if (child instanceof ActiveBomb) {
+ child.show();
+ bombToActivate.visibilityTimeout = LK.setTimeout(function () {
+ child.hide();
+ bombToActivate.visibilityTimeout = null;
+ bombToActivate.visible = true;
+ }, 2000);
}
- }, 1000 / 60);
+ });
}
- });
- var bounceUp = true;
- var bounceInterval = LK.setInterval(function () {
- if (bounceUp) {
- if (startButton.y > 2732 - startButton.height - 10) {
- startButton.y -= 1;
+ }
+};
+LK.setInterval(game.activateBomb, 450);
+var startButton = LK.getAsset('startButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+startButton.width = 200;
+startButton.height = 100;
+startButton.x = 2048 / 2 - startButton.width / 2;
+startButton.y = 2732 - startButton.height;
+game.addChild(startButton);
+var startText = new Text2('Start', {
+ size: 50,
+ fill: '#ffffff'
+});
+startText.anchor.set(0.5, 0.5);
+startText.x = startButton.width / 2;
+startText.y = startButton.height / 2;
+startButton.addChild(startText);
+startButton.on('down', function () {
+ if (LK.gameState === 'IDLE') {
+ LK.gameState = 'START';
+ var originalScale = startButton.scale.x;
+ var tweenScale = originalScale * 1.05;
+ var interval = LK.setInterval(function () {
+ if (startButton.scale.x < tweenScale) {
+ startButton.scale.x += 0.01;
+ startButton.scale.y += 0.01;
} else {
- bounceUp = false;
+ LK.clearInterval(interval);
+ interval = LK.setInterval(function () {
+ if (startButton.scale.x > originalScale) {
+ startButton.scale.x -= 0.01;
+ startButton.scale.y -= 0.01;
+ } else {
+ LK.clearInterval(interval);
+ var fadeOutInterval = LK.setInterval(function () {
+ if (startButton.alpha > 0) {
+ startButton.alpha -= 0.0668;
+ } else {
+ LK.clearInterval(fadeOutInterval);
+ startButton.visible = false;
+ }
+ }, 1000 / 60);
+ }
+ }, 1000 / 60);
}
+ }, 1000 / 60);
+ }
+});
+var bounceUp = true;
+var bounceInterval = LK.setInterval(function () {
+ if (bounceUp) {
+ if (startButton.y > 2732 - startButton.height - 10) {
+ startButton.y -= 1;
} else {
- if (startButton.y < 2732 - startButton.height) {
- startButton.y += 1;
- } else {
- bounceUp = true;
- }
+ bounceUp = false;
}
- }, 1000 / 60);
-});
+ } else {
+ if (startButton.y < 2732 - startButton.height) {
+ startButton.y += 1;
+ } else {
+ bounceUp = true;
+ }
+ }
+}, 1000 / 60);
\ No newline at end of file