User prompt
OK, so I have an idea instead of the arrows going in all directions Iโm thinking of want to tap a certain place on the screen. The arrow goes that certain place.
User prompt
Make this slime stop spawning on you
User prompt
No, make the shots go, like, out, and, like, way out, like...
User prompt
Now make the shots go out when you press the button in all directions.
User prompt
Make your shots go in all directions.
Initial prompt
arrow shooter
/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Arrow class for shooting arrows in 360 degrees var Arrow = Container.expand(function () { var self = Container.call(this); var arrowGraphics = self.attachAsset('arrow', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.direction = 0; // Direction in radians self.update = function () { // Update the direction of the arrow every frame self.direction += Math.PI / 30; // Change this value to make the arrow rotate faster or slower self.x += self.speed * Math.cos(self.direction); self.y += self.speed * Math.sin(self.direction); }; }); // Slime class for enemy slimes var Slime = Container.expand(function () { var self = Container.call(this); var slimeGraphics = self.attachAsset('slime', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.update = function () { var dx = hero.x - self.x; var dy = hero.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var hero = game.addChild(new Container()); var heroGraphics = hero.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); hero.x = 2048 / 2; hero.y = 2732 / 2; var arrows = []; var slimes = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function spawnSlimes() { for (var i = 0; i < 5; i++) { var slime = new Slime(); slime.x = Math.random() * 2048; slime.y = Math.random() * 2732; slimes.push(slime); game.addChild(slime); } } game.down = function (x, y, obj) { var angle = Math.atan2(y - hero.y, x - hero.x); var arrow = new Arrow(); arrow.x = hero.x; arrow.y = hero.y; arrow.direction = angle; arrows.push(arrow); game.addChild(arrow); }; game.update = function () { for (var i = arrows.length - 1; i >= 0; i--) { var arrow = arrows[i]; arrow.update(); if (arrow.x < 0 || arrow.x > 2048 || arrow.y < 0 || arrow.y > 2732) { arrow.destroy(); arrows.splice(i, 1); } } for (var i = slimes.length - 1; i >= 0; i--) { var slime = slimes[i]; slime.update(); if (hero.intersects(slime)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } for (var j = arrows.length - 1; j >= 0; j--) { var arrow = arrows[j]; if (arrow.intersects(slime)) { arrow.destroy(); arrows.splice(j, 1); slime.destroy(); slimes.splice(i, 1); break; } } } if (slimes.length === 0) { score++; scoreTxt.setText(score); spawnSlimes(); } }; spawnSlimes();
===================================================================
--- original.js
+++ change.js
@@ -1,115 +1,117 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Arrow class for shooting arrows in 360 degrees
var Arrow = Container.expand(function () {
- var self = Container.call(this);
- var arrowGraphics = self.attachAsset('arrow', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.direction = 0; // Direction in radians
- self.update = function () {
- self.x += self.speed * Math.cos(self.direction);
- self.y += self.speed * Math.sin(self.direction);
- };
+ var self = Container.call(this);
+ var arrowGraphics = self.attachAsset('arrow', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.direction = 0; // Direction in radians
+ self.update = function () {
+ // Update the direction of the arrow every frame
+ self.direction += Math.PI / 30; // Change this value to make the arrow rotate faster or slower
+ self.x += self.speed * Math.cos(self.direction);
+ self.y += self.speed * Math.sin(self.direction);
+ };
});
// Slime class for enemy slimes
var Slime = Container.expand(function () {
- var self = Container.call(this);
- var slimeGraphics = self.attachAsset('slime', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 1;
- self.update = function () {
- var dx = hero.x - self.x;
- var dy = hero.y - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- self.x += dx / distance * self.speed;
- self.y += dy / distance * self.speed;
- };
+ var self = Container.call(this);
+ var slimeGraphics = self.attachAsset('slime', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 1;
+ self.update = function () {
+ var dx = hero.x - self.x;
+ var dy = hero.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var hero = game.addChild(new Container());
var heroGraphics = hero.attachAsset('hero', {
- anchorX: 0.5,
- anchorY: 0.5
+ anchorX: 0.5,
+ anchorY: 0.5
});
hero.x = 2048 / 2;
hero.y = 2732 / 2;
var arrows = [];
var slimes = [];
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: 0xFFFFFF
+ size: 150,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnSlimes() {
- for (var i = 0; i < 5; i++) {
- var slime = new Slime();
- slime.x = Math.random() * 2048;
- slime.y = Math.random() * 2732;
- slimes.push(slime);
- game.addChild(slime);
- }
+ for (var i = 0; i < 5; i++) {
+ var slime = new Slime();
+ slime.x = Math.random() * 2048;
+ slime.y = Math.random() * 2732;
+ slimes.push(slime);
+ game.addChild(slime);
+ }
}
game.down = function (x, y, obj) {
- var angle = Math.atan2(y - hero.y, x - hero.x);
- var arrow = new Arrow();
- arrow.x = hero.x;
- arrow.y = hero.y;
- arrow.direction = angle;
- arrows.push(arrow);
- game.addChild(arrow);
+ var angle = Math.atan2(y - hero.y, x - hero.x);
+ var arrow = new Arrow();
+ arrow.x = hero.x;
+ arrow.y = hero.y;
+ arrow.direction = angle;
+ arrows.push(arrow);
+ game.addChild(arrow);
};
game.update = function () {
- for (var i = arrows.length - 1; i >= 0; i--) {
- var arrow = arrows[i];
- arrow.update();
- if (arrow.x < 0 || arrow.x > 2048 || arrow.y < 0 || arrow.y > 2732) {
- arrow.destroy();
- arrows.splice(i, 1);
- }
- }
- for (var i = slimes.length - 1; i >= 0; i--) {
- var slime = slimes[i];
- slime.update();
- if (hero.intersects(slime)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- return;
- }
- for (var j = arrows.length - 1; j >= 0; j--) {
- var arrow = arrows[j];
- if (arrow.intersects(slime)) {
- arrow.destroy();
- arrows.splice(j, 1);
- slime.destroy();
- slimes.splice(i, 1);
- break;
- }
- }
- }
- if (slimes.length === 0) {
- score++;
- scoreTxt.setText(score);
- spawnSlimes();
- }
+ for (var i = arrows.length - 1; i >= 0; i--) {
+ var arrow = arrows[i];
+ arrow.update();
+ if (arrow.x < 0 || arrow.x > 2048 || arrow.y < 0 || arrow.y > 2732) {
+ arrow.destroy();
+ arrows.splice(i, 1);
+ }
+ }
+ for (var i = slimes.length - 1; i >= 0; i--) {
+ var slime = slimes[i];
+ slime.update();
+ if (hero.intersects(slime)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ for (var j = arrows.length - 1; j >= 0; j--) {
+ var arrow = arrows[j];
+ if (arrow.intersects(slime)) {
+ arrow.destroy();
+ arrows.splice(j, 1);
+ slime.destroy();
+ slimes.splice(i, 1);
+ break;
+ }
+ }
+ }
+ if (slimes.length === 0) {
+ score++;
+ scoreTxt.setText(score);
+ spawnSlimes();
+ }
};
spawnSlimes();
\ No newline at end of file