User prompt
the bullets should move slowly in the direction the hero was moving in
User prompt
the hero bullets needs to move constantly after being fired
Code edit (2 edits merged)
Please save this source code
User prompt
center the text box in the top of the screen, make the text smaller
User prompt
the hero should not be able to enter any area that is 100 units from the center of each tree
User prompt
the hero should be prevented from ever entering the area occupied by a tree
User prompt
the trees area should match the icon size on the screen and the hero should not be able to enter any of that area
User prompt
the hero should not ever be able to enter the space occupied by a tree
User prompt
show the current hero speed and direction in a text box in the top right of the screen
Code edit (1 edits merged)
Please save this source code
User prompt
when the bullet is placed by the hero, it needs to continue moving until it is off the screen
User prompt
Fix Bug: 'ReferenceError: trees is not defined' in or related to this line: 'if (hero.checkCollision(trees)) {' Line Number: 82
User prompt
prevent the hero from being able to travel through a tree
User prompt
when the bullet is fired it should move quickly in the direction the character was moving and should not stop until it is off the screen
Code edit (1 edits merged)
Please save this source code
User prompt
when i click the right click button it should fire a bullet in the direction the hero is walking
User prompt
have the character follow the mouse around the screen at a slower speed
User prompt
change the character control change to be controlled by the mouse instead of arrows
User prompt
the hero is walking through a park, lets add some trees in the background
User prompt
Fix Bug: 'Uncaught TypeError: window.addEventListener is not a function' in or related to this line: 'window.addEventListener('keydown', function (event) {' Line Number: 45
User prompt
lets add a hero that can move around the screen using the arrow keys on a keyboard
Initial prompt
Starting point
/**** * 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.speed = 5; self.direction = { x: 0, y: 0 }; self.checkCollision = function (trees) { for (var i = 0; i < trees.length; i++) { var treeBounds = trees[i].getBounds(); var heroBounds = self.getBounds(); if (heroBounds.x < treeBounds.x + treeBounds.width && heroBounds.x + heroBounds.width > treeBounds.x && heroBounds.y < treeBounds.y + treeBounds.height && heroBounds.height + heroBounds.y > treeBounds.y) { self.x -= self.direction.x * self.speed; self.y -= self.direction.y * self.speed; return true; } } return false; }; }); var Tree = Container.expand(function () { var self = Container.call(this); self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); }); var Bullet = Container.expand(function () { var self = Container.call(this); self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.direction = { x: 0, y: 0 }; self.move = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; }; }); /**** * 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 var heroInfo = new Text2('', { size: 50, fill: '#ffffff' }); LK.gui.topRight.addChild(heroInfo); 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; dragNode.x += (pos.x - dragNode.x) * 0.05; dragNode.y += (pos.y - dragNode.y) * 0.05; if (dragNode === hero) { hero.direction.x = (pos.x - hero.x) / Math.sqrt(Math.pow(pos.x - hero.x, 2) + Math.pow(pos.y - hero.y, 2)); hero.direction.y = (pos.y - hero.y) / Math.sqrt(Math.pow(pos.x - hero.x, 2) + Math.pow(pos.y - hero.y, 2)); if (hero.checkCollision(trees)) { dragNode.x = oldX; dragNode.y = oldY; } } } } game.on('move', handleMove); game.on('down', function (obj) { dragNode = hero; handleMove(obj); }); // Update the text box every game tick LK.on('tick', function () { heroInfo.setText('Speed: ' + hero.speed + ', Direction: (' + hero.direction.x.toFixed(2) + ', ' + hero.direction.y.toFixed(2) + ')'); }); game.on('up', function (obj) { dragNode = null; }); game.on('rightdown', function (obj) { var bullet = game.addChild(new Bullet()); bullet.x = hero.x; bullet.y = hero.y; bullet.direction = { x: hero.direction.x, y: hero.direction.y }; bullet.speed = 100; }); // Add trees for (var i = 0; i < 10; i++) { var tree = game.addChild(new Tree()); tree.x = Math.random() * 2048; tree.y = Math.random() * 2732; }
===================================================================
--- original.js
+++ change.js
@@ -14,9 +14,11 @@
y: 0
};
self.checkCollision = function (trees) {
for (var i = 0; i < trees.length; i++) {
- if (self.intersects(trees[i])) {
+ var treeBounds = trees[i].getBounds();
+ var heroBounds = self.getBounds();
+ if (heroBounds.x < treeBounds.x + treeBounds.width && heroBounds.x + heroBounds.width > treeBounds.x && heroBounds.y < treeBounds.y + treeBounds.height && heroBounds.height + heroBounds.y > treeBounds.y) {
self.x -= self.direction.x * self.speed;
self.y -= self.direction.y * self.speed;
return true;
}
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.