User prompt
allow the hero to move through trees
User prompt
have the "you suck" text color be white
User prompt
if final score is less than 10, show "You Suck" on the game over screen below the final score
User prompt
Increase the number of monsters that are generated by the amount of the levelresetcount
User prompt
make sure the monsters enter from the edge of the visible screen
User prompt
End the game when the monster touches the hero
User prompt
Change all text color to white
User prompt
change game background to black
User prompt
Make Background dark gray
User prompt
show the score in the top right portion of the screen
User prompt
have the text not move on the screen
User prompt
when all of the monsters are defeated, show "Level Cleared" and reset the level
User prompt
when the monster touches the hero, end the game and show "Game Over" and show the score
User prompt
show the score in the top right portion of the screen
User prompt
make sure the text does not move at all
User prompt
when a monster touches the hero restart the game at level one
User prompt
make sure the text is black and fully visable
User prompt
show the text for the level number on the top right corner of the screen
User prompt
make the background color white
User prompt
make sure the trees do not spawn on top of the hero
User prompt
Fix Bug: 'ReferenceError: scoreTxt is not defined' in or related to this line: 'scoreTxt.setText(LK.getScore().toString());' Line Number: 67
User prompt
Fix Bug: 'ReferenceError: score is not defined' in or related to this line: 'score += 1;' Line Number: 66
User prompt
show the levelreset count on the screen at all times
User prompt
introduce a global variable that keeps track of the number of times the level has been reset
User prompt
when the level resets add one additional monster
/**** * Classes ****/ // No assets are defined as this is a blank game var Hero = Container.expand(function () { var self = Container.call(this); self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.targetPosition = { x: self.x, y: self.y }; self.speed = 5; self.direction = { x: 0, y: 0 }; self.checkCollision = function (trees) { for (var i = 0; i < trees.length; i++) { if (self.intersects(trees[i])) { return true; } } return false; }; }); var Tree = Container.expand(function () { var self = Container.call(this); self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); }); var Monster = Container.expand(function () { var self = Container.call(this); self.attachAsset('monster', { anchorX: 0.5, anchorY: 0.5 }); self.isAlive = true; self.speed = 1; self.chaseHero = function (hero) { if (!self.isAlive || !hero) { return; } var dx = hero.x - self.x; var dy = hero.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } if (self.intersects(hero)) { LK.showGameOver(); } }; self.destroyedByBullet = function () { self.isAlive = false; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore().toString()); self.destroy(); }; }); var Bullet = Container.expand(function () { var self = Container.call(this); self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.direction = { x: 0, y: 0 }; self.move = function (trees) { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; for (var i = 0; i < trees.length; i++) { if (self.intersects(trees[i])) { self.destroy(); return true; } } for (var j = 0; j < monsters.length; j++) { if (self.intersects(monsters[j]) && monsters[j].isAlive) { monsters[j].destroyedByBullet(); self.destroy(); return true; } } return false; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Initialize game with black background }); /**** * Game Code ****/ var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 / 2; // Create a text box to display hero's speed and direction // The heroInfo variable was not defined, so we remove the lines that reference it. var dragNode = null; var trees = []; function handleMove(obj) { var event = obj.event; var pos = event.getLocalPosition(game); if (dragNode) { var oldX = dragNode.x; var oldY = dragNode.y; if (dragNode === hero) { var targetX = pos.x; var targetY = pos.y; var distance = Math.sqrt(Math.pow(targetX - hero.x, 2) + Math.pow(targetY - hero.y, 2)); hero.direction.x = (targetX - hero.x) / distance; hero.direction.y = (targetY - hero.y) / distance; var nextX = hero.x + hero.direction.x * hero.speed; var nextY = hero.y + hero.direction.y * hero.speed; if (!hero.checkCollision(trees)) { hero.x = nextX; hero.y = nextY; } else { hero.direction.x = 0; hero.direction.y = 0; } } } } game.on('move', handleMove); game.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(game); hero.targetPosition = { x: pos.x, y: pos.y }; hero.direction.x = hero.targetPosition.x - hero.x; hero.direction.y = hero.targetPosition.y - hero.y; var distance = Math.sqrt(hero.direction.x * hero.direction.x + hero.direction.y * hero.direction.y); hero.direction.x /= distance; hero.direction.y /= distance; }); // Update the text box every game tick LK.on('tick', function () { if (hero.targetPosition) { var distanceToTarget = hero.targetPosition ? Math.sqrt(Math.pow(hero.targetPosition.x - hero.x, 2) + Math.pow(hero.targetPosition.y - hero.y, 2)) : 0; } if (distanceToTarget > hero.speed) { var nextX = hero.x + hero.direction.x * hero.speed; var nextY = hero.y + hero.direction.y * hero.speed; if (!hero.checkCollision(trees)) { hero.x = nextX; hero.y = nextY; } } else { hero.x = hero.targetPosition.x; hero.y = hero.targetPosition.y; hero.direction.x = 0; hero.direction.y = 0; } levelResetTxt.setText('Level Resets: ' + levelResetCount.toString()); }); game.on('up', function (obj) { dragNode = null; }); var bullets = []; game.on('rightdown', function (obj) { var event = obj.event; var pos = event.getLocalPosition(game); var bullet = game.addChild(new Bullet()); bullet.x = hero.x; bullet.y = hero.y; var targetX = pos.x; var targetY = pos.y; var distance = Math.sqrt(Math.pow(targetX - hero.x, 2) + Math.pow(targetY - hero.y, 2)); bullet.direction = { x: (targetX - hero.x) / distance, y: (targetY - hero.y) / distance }; bullet.speed = 10; bullets.push(bullet); }); LK.on('tick', function () { for (var i = bullets.length - 1; i >= 0; i--) { if (bullets[i].move(trees)) { bullets.splice(i, 1); } } var allMonstersKilled = monsters.every(function (monster) { return !monster.isAlive; }); if (allMonstersKilled) { resetLevel(); } else { for (var i = 0; i < monsters.length; i++) { monsters[i].chaseHero(hero); } } }); // Add fewer trees for (var i = 0; i < 5; i++) { var tree = game.addChild(new Tree()); tree.x = Math.random() * 2048; tree.y = Math.random() * 2732; trees.push(tree); } var monsters = []; for (var i = 0; i < 5; i++) { var monster = game.addChild(new Monster()); monster.x = Math.random() * 2048; monster.y = Math.random() * 2732; monsters.push(monster); } function resetLevel() { levelResetCount++; // Remove existing trees and monsters trees.forEach(function (tree) { tree.destroy(); }); monsters.forEach(function (monster) { monster.destroy(); }); trees = []; monsters = []; // Add trees for (var i = 0; i < 5; i++) { var tree; var positionValid; do { positionValid = true; tree = new Tree(); tree.x = Math.random() * 2048; tree.y = Math.random() * 2732; // Check if the tree spawns on top of the hero if (tree.intersects(hero)) { positionValid = false; } } while (!positionValid); game.addChild(tree); trees.push(tree); } // Add monsters for (var i = 0; i < 6 + levelResetCount; i++) { var monster = game.addChild(new Monster()); var edge = Math.floor(Math.random() * 4); switch (edge) { case 0: // Top edge monster.x = Math.random() * 2048; monster.y = 0; break; case 1: // Right edge monster.x = 2048; monster.y = Math.random() * 2732; break; case 2: // Bottom edge monster.x = Math.random() * 2048; monster.y = 2732; break; case 3: // Left edge monster.x = 0; monster.y = Math.random() * 2732; break; } monsters.push(monster); } } var levelResetCount = 0; var score = 0; var scoreTxt = new Text2('0', { size: 30, fill: '#ffffff' }); LK.gui.topRight.addChild(scoreTxt); scoreTxt.anchor.set(1, 0); scoreTxt.x = -50; scoreTxt.y = 50; var levelResetTxt = new Text2(levelResetCount.toString(), { size: 30, fill: '#ffffff' }); LK.gui.top.addChild(levelResetTxt); levelResetTxt.anchor.set(1, 0); levelResetTxt.y = 50;
===================================================================
--- original.js
+++ change.js
@@ -248,9 +248,9 @@
game.addChild(tree);
trees.push(tree);
}
// Add monsters
- for (var i = 0; i < 6; i++) {
+ for (var i = 0; i < 6 + levelResetCount; i++) {
var monster = game.addChild(new Monster());
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
Make a Tree. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a monster that is half bat half ogre. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
create a small bullet projectile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a single bearded man in a suit reaching out holding an imaginary weapon, I want him generated in 32 bit graphic style and i want to see his entire body. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.