Code edit (1 edits merged)
Please save this source code
User prompt
Make boot rotate based on boot yspeed
User prompt
Move up the location where ball spawns by 1/4 the hight of the screen
User prompt
Don't bounce ball on floor
Code edit (1 edits merged)
Please save this source code
User prompt
Decrease bounce impact with 10x
User prompt
Make ball loose momentum when bouncing on walls
User prompt
Rather than clicking the ball to start the game, just start the game the first time the boot intersects the ball
Code edit (1 edits merged)
Please save this source code
User prompt
The ball width should be considered when bouncing on walls
User prompt
When bouncing, make sure to move the ball such that the ball and boot never overlap. Move it along the same angle as the current angle between ball and boot
User prompt
When ball is bouncing, move the ball outside the boot as the first step
User prompt
when calculating dot product reverse the impact of velocity
User prompt
when calculating calculateVelocity reverse the values
Code edit (1 edits merged)
Please save this source code
User prompt
Reverse the impact of boot velocity
User prompt
Ball seems to be attacked to boot rather than being kicked away
User prompt
The velocity calculation seems to be in reverse
User prompt
make sure boot is passed to bounce in on down
User prompt
When bouncing the ball after the game is started, use circle to circle intersection and bounce code to make the ball fly in the appropriate direction
User prompt
As I move the boot around calculate it's average velocity over the past 50ms
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'boot.x')' in this line: 'var dx = self.x - boot.x;' Line Number: 24
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'boot.x')' in this line: 'var dx = self.x - boot.x;' Line Number: 24
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'boot.x')' in this line: 'var dx = self.x - boot.x;' Line Number: 24
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'boot.x')' in this line: 'var dx = self.x - boot.x;' Line Number: 24
var Boot = Container.expand(function () { var self = Container.call(this); var bootGraphics = self.createAsset('boot', 'Boot', .5, .5); self.velocityX = 0; self.velocityY = 0; self.previousX = 0; self.previousY = 0; self.calculateVelocity = function () { self.velocityX = self.x - self.previousX; self.velocityY = self.y - self.previousY; self.previousX = self.x; self.previousY = self.y; }; }); var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.createAsset('ball', 'Soccer Ball', .5, .5); self.velocityY = 0; self.gravity = 0.5; self.bounceFactor = 0.7; self.move = function () { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; if (self.y > 2732 - self.height / 2) { self.velocityY *= -self.bounceFactor; self.y = 2732 - self.height / 2; } if (self.x < 0 || self.x > 2048) { self.velocityX *= -1; } }; self.bounce = function (boot) { var dx = self.x - boot.x; var dy = self.y - boot.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < boot.width / 2 + self.width / 2) { var normalX = dx / distance; var normalY = dy / distance; var dotProduct = normalX * boot.velocityX + normalY * boot.velocityY; self.velocityX = -2 * dotProduct * normalX + boot.velocityX; self.velocityY = -2 * dotProduct * normalY + boot.velocityY; } }; }); var Game = Container.expand(function () { var self = Container.call(this); stage.on('move', function (obj) { var pos = obj.event.getLocalPosition(self); boot.x = pos.x; boot.y = pos.y; boot.calculateVelocity(); }); var ball = self.addChild(new Ball()); ball.x = 2048 / 2; ball.y = 2732 / 2; var boot = self.addChild(new Boot()); boot.visible = true; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); var isGameOver = false; var isGameStarted = false; stage.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); boot.x = pos.x; boot.y = pos.y; boot.visible = true; if (!isGameStarted) { ball.bounce(boot); isGameStarted = true; } }); LK.on('tick', function () { if (isGameStarted) { ball.move(); var dx = boot.x - ball.x; var dy = boot.y - ball.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < boot.width / 2 + ball.width / 2) { ball.bounce(boot); } } if (ball.y > 2732 - ball.height / 2) { isGameOver = true; } if (isGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); });
===================================================================
--- original.js
+++ change.js
@@ -5,10 +5,10 @@
self.velocityY = 0;
self.previousX = 0;
self.previousY = 0;
self.calculateVelocity = function () {
- self.velocityX = self.previousX - self.x;
- self.velocityY = self.previousY - self.y;
+ self.velocityX = self.x - self.previousX;
+ self.velocityY = self.y - self.previousY;
self.previousX = self.x;
self.previousY = self.y;
};
});
@@ -33,13 +33,15 @@
self.bounce = function (boot) {
var dx = self.x - boot.x;
var dy = self.y - boot.y;
var distance = Math.sqrt(dx * dx + dy * dy);
- var normalX = dx / distance;
- var normalY = dy / distance;
- var dotProduct = normalX * boot.velocityX + normalY * boot.velocityY;
- self.velocityX = -2 * dotProduct * normalX + boot.velocityX;
- self.velocityY = -2 * dotProduct * normalY + boot.velocityY;
+ if (distance < boot.width / 2 + self.width / 2) {
+ var normalX = dx / distance;
+ var normalY = dy / distance;
+ var dotProduct = normalX * boot.velocityX + normalY * boot.velocityY;
+ self.velocityX = -2 * dotProduct * normalX + boot.velocityX;
+ self.velocityY = -2 * dotProduct * normalY + boot.velocityY;
+ }
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
Soccer ball. Single Cartoon Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Round soccer boot, cartoon style Single Cartoon Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon football stadium Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.