User prompt
If I tap the screen make nearby squares bounce away and then rubber band back again
User prompt
Try blend mode 3
User prompt
Set blend mode to 2 instead
User prompt
Set square blend mode to 1
User prompt
Make it 2000 squares
User prompt
Add 400 more square and make them have random sizes
User prompt
Tint the squares with a random color
User prompt
Add 100 more squares
Initial prompt
Test game
===================================================================
--- original.js
+++ change.js
@@ -1,9 +1,9 @@
var SpinningSquare = Container.expand(function () {
var self = Container.call(this);
var squareGraphics = self.createAsset('square', 'Spinning Square', Math.random(), Math.random());
squareGraphics.tint = Math.random() * 0xFFFFFF;
- squareGraphics.blendMode = 3;
+ squareGraphics.blendMode = 1;
self.rotationSpeed = 0.01;
self.rotate = function () {
self.rotation += self.rotationSpeed;
};
@@ -16,10 +16,33 @@
spinningSquare.x = Math.random() * 2048;
spinningSquare.y = Math.random() * 2732;
spinningSquares.push(spinningSquare);
}
+ stage.on('down', function (obj) {
+ var event = obj.event;
+ var pos = event.getLocalPosition(self);
+ for (var i = 0; i < spinningSquares.length; i++) {
+ var dx = spinningSquares[i].x - pos.x;
+ var dy = spinningSquares[i].y - pos.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 200) {
+ spinningSquares[i].bounceBack = true;
+ spinningSquares[i].bounceBackX = dx;
+ spinningSquares[i].bounceBackY = dy;
+ }
+ }
+ });
LK.on('tick', function () {
for (var i = 0; i < spinningSquares.length; i++) {
spinningSquares[i].rotate();
+ if (spinningSquares[i].bounceBack) {
+ spinningSquares[i].x += spinningSquares[i].bounceBackX * 0.1;
+ spinningSquares[i].y += spinningSquares[i].bounceBackY * 0.1;
+ spinningSquares[i].bounceBackX *= 0.9;
+ spinningSquares[i].bounceBackY *= 0.9;
+ if (Math.abs(spinningSquares[i].bounceBackX) < 1 && Math.abs(spinningSquares[i].bounceBackY) < 1) {
+ spinningSquares[i].bounceBack = false;
+ }
+ }
}
});
});