User prompt
i want all monsters to spawn from the bottom portion of the visible screen
User prompt
increase the number of starting monsters by 3
User prompt
reduce off screen processing of bullets
User prompt
reduce off-screen processing
User prompt
use object pooling
User prompt
Optimize collision detection
User prompt
instruction text box should be filled white and should be on top of the game picture
User prompt
remove fire button from the game
Code edit (1 edits merged)
Please save this source code
User prompt
Center the instructions text in the middle of the visable screen
Code edit (1 edits merged)
Please save this source code
User prompt
Have the instructions text wrap the text on three lines
User prompt
The instructions should be centered justified horizontally
User prompt
The instruction text should be centered in the top third of the visible screen
User prompt
The instruction text should be centered in the top third of the visible screen
User prompt
The monsters should not spawn until the instruction text has been cleared
User prompt
When the game loads create an Instructions screen that explains how the game works
User prompt
when on mobile device, show a button on the screen that fires the bullet
User prompt
how do i add a control scheme that works on mobile devices?
User prompt
Have the levelresetcount start at 1 instead of 0
User prompt
Add text before the displayed Score that says "# of Monsters Killed:"
User prompt
change the text "Level Reset" to instead say "Level Number:"
User prompt
have the image of the hero rotate when it is moving, in the direction it is moving
User prompt
increase number of trees on each level by the amount of the levelresetcount
User prompt
at the start of the game only allow the monsters to spawn from the edge of the visible screen
/**** * Classes ****/ var Instructions = Container.expand(function () { var self = Container.call(this); var instructionsText = new Text2('Instructions: Use your mouse to move the hero. Click to shoot bullets. Kill all the monsters to advance to the next level.', { size: 30, fill: '#ffffff' }); self.addChild(instructionsText); self.on('destroy', function () { for (var i = 0; i < 5; i++) { var monster = game.addChild(new Monster()); var edge = Math.floor(Math.random() * 4); switch (edge) { case 0: monster.x = Math.random() * 2048; monster.y = 0; break; case 1: monster.x = 2048; monster.y = Math.random() * 2732; break; case 2: monster.x = Math.random() * 2048; monster.y = 2732; break; case 3: monster.x = 0; monster.y = Math.random() * 2732; break; } monsters.push(monster); } }); }); // 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.update = function () { // Calculate the angle in radians and rotate the hero var angle = Math.atan2(self.direction.y, self.direction.x); self.rotation = angle; }; self.checkCollision = function (trees) { 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)) { if (LK.getScore() < 10) { LK.showGameOver({ text: 'You Suck', color: '#FFFFFF' }); } else { LK.showGameOver(); } } }; self.destroyedByBullet = function () { self.isAlive = false; LK.setScore(LK.getScore() + 1); scoreTxt.setText('# of Monsters Killed: ' + 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 instructions = game.addChild(new Instructions()); instructions.x = 2048 / 2; instructions.y = 2732 / 2; 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) { if (instructions) { instructions.destroy(); instructions = null; } 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; }); // Add touch controls for mobile devices LK.on('touchstart', 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 Number: ' + 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 = []; 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 + levelResetCount; 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 = 1; var score = 0; var scoreTxt = new Text2('# of Monsters Killed: 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; // Add a button for mobile devices to fire the bullet var fireButton = new Text2('Fire', { size: 50, fill: '#ffffff' }); LK.gui.bottomRight.addChild(fireButton); fireButton.anchor.set(1, 0); fireButton.x = -50; fireButton.y = -50; fireButton.interactive = true; fireButton.on('down', function (obj) { var bullet = game.addChild(new Bullet()); bullet.x = hero.x; bullet.y = hero.y; var targetX = hero.targetPosition.x; var targetY = hero.targetPosition.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); });
===================================================================
--- original.js
+++ change.js
@@ -7,8 +7,33 @@
size: 30,
fill: '#ffffff'
});
self.addChild(instructionsText);
+ self.on('destroy', function () {
+ for (var i = 0; i < 5; i++) {
+ var monster = game.addChild(new Monster());
+ var edge = Math.floor(Math.random() * 4);
+ switch (edge) {
+ case 0:
+ monster.x = Math.random() * 2048;
+ monster.y = 0;
+ break;
+ case 1:
+ monster.x = 2048;
+ monster.y = Math.random() * 2732;
+ break;
+ case 2:
+ monster.x = Math.random() * 2048;
+ monster.y = 2732;
+ break;
+ case 3:
+ monster.x = 0;
+ monster.y = Math.random() * 2732;
+ break;
+ }
+ monsters.push(monster);
+ }
+ });
});
// No assets are defined as this is a blank game
var Hero = Container.expand(function () {
var self = Container.call(this);
@@ -249,31 +274,8 @@
tree.y = Math.random() * 2732;
trees.push(tree);
}
var monsters = [];
-for (var i = 0; i < 5; i++) {
- var monster = game.addChild(new Monster());
- var edge = Math.floor(Math.random() * 4);
- switch (edge) {
- case 0:
- monster.x = Math.random() * 2048;
- monster.y = 0;
- break;
- case 1:
- monster.x = 2048;
- monster.y = Math.random() * 2732;
- break;
- case 2:
- monster.x = Math.random() * 2048;
- monster.y = 2732;
- break;
- case 3:
- monster.x = 0;
- monster.y = Math.random() * 2732;
- break;
- }
- monsters.push(monster);
-}
function resetLevel() {
levelResetCount++;
// Remove existing trees and monsters
trees.forEach(function (tree) {
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.