User prompt
In tick When a bullet and an element is hit, destroy the element and trigger the fire hexagon methid
User prompt
Remove the element hit method
User prompt
Remove the explode method from bullets
User prompt
In tick if any bullet is off screen delete them
User prompt
Make the bullet animation rotation first be fast then slow down as it gets close to its target
User prompt
The rotation of bullet graphics should be animated over about 30 ricks
User prompt
When ticking in bullet, rotate the bullet graphics 90deg counter clockwise animated when the bullet is first created
User prompt
Call the tick method for each bullet in tick
User prompt
Add a tick method to the bullet class. That moves the bullet each tick.
User prompt
Remove move method on bullet
User prompt
Set a target rotation on bullets that is 90deg counter clockwise from the initial rotation
User prompt
Also set rotation on bullets
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'direction.x')' in this line: 'this.x += this.speed * direction.x;' Line Number: 6
User prompt
Rotate the bullets so they are rotated in their direction of travel
User prompt
Add a method to game that fires bullets in 6 directions like a hexagon. When I tap the screen anywhere call that method
User prompt
The he game has levels, add a method to start the next level which deletes all bullets and elements still on screen. Then creates a new set
Initial prompt
Chain reaction game
var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5); self.speed = 5; self.move = function () { self.x += self.speed; }; self.explode = function () {}; }); var Element = Container.expand(function () { var self = Container.call(this); var elementGraphics = self.createAsset('element', 'Element Graphics', .5, .5); self.hit = function () {}; }); var Game = Container.expand(function () { var self = Container.call(this); var bullets = []; var elements = []; function startNextLevel() { bullets.forEach(function (bullet) { bullet.destroy(); }); bullets = []; elements.forEach(function (element) { element.destroy(); }); elements = []; for (var i = 0; i < 10; i++) { var element = new Element(); element.x = Math.random() * 2048; element.y = Math.random() * 2732; elements.push(element); self.addChild(element); } } self.startNextLevel = startNextLevel; startNextLevel(); self.fireBulletsHexagon = function (position) { var directions = [{ x: 1, y: 0 }, { x: -1, y: 0 }, { x: 0.5, y: Math.sqrt(3) / 2 }, { x: -0.5, y: Math.sqrt(3) / 2 }, { x: 0.5, y: -Math.sqrt(3) / 2 }, { x: -0.5, y: -Math.sqrt(3) / 2 }]; directions.forEach(function (direction, index) { var bullet = new Bullet(); bullet.x = position.x; bullet.y = position.y; bullet.rotation = Math.atan2(direction.y, direction.x); bullet.move = function () { this.x += this.speed * direction.x; this.y += this.speed * direction.y; }; bullets.push(bullet); self.addChild(bullet); }); }; stage.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); self.fireBulletsHexagon(pos); }); LK.on('tick', function () { for (var i = 0; i < bullets.length; i++) { bullets[i].move(); } for (var i = 0; i < bullets.length; i++) { for (var j = 0; j < elements.length; j++) { if (bullets[i].intersects(elements[j])) { bullets[i].explode(); elements[j].hit(); } } } }); });
===================================================================
--- original.js
+++ change.js
@@ -1,13 +1,10 @@
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
self.speed = 5;
- self.move = function (direction) {
- if (!direction) return;
- this.x += this.speed * direction.x;
- this.y += this.speed * direction.y;
- this.rotation = Math.atan2(direction.y, direction.x);
+ self.move = function () {
+ self.x += self.speed;
};
self.explode = function () {};
});
var Element = Container.expand(function () {
@@ -57,13 +54,17 @@
}, {
x: -0.5,
y: -Math.sqrt(3) / 2
}];
- directions.forEach(function (direction) {
+ directions.forEach(function (direction, index) {
var bullet = new Bullet();
bullet.x = position.x;
bullet.y = position.y;
- bullet.move(direction);
+ bullet.rotation = Math.atan2(direction.y, direction.x);
+ bullet.move = function () {
+ this.x += this.speed * direction.x;
+ this.y += this.speed * direction.y;
+ };
bullets.push(bullet);
self.addChild(bullet);
});
};
Hexagon target Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single White Hexagon, soft edges, simple, vector. Round corners. All white. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Amazing bright hexagon space background.
Triangle plasma bullet. Glowing. Pointing down. Dark outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White triangle Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Bright light particle, white. Simple, vector. Triangle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.