User prompt
the shape of footballer and ball should be circle, not square
User prompt
make footballer and ball as circle
User prompt
move footballer with mouse too
User prompt
Fix Bug: 'Uncaught TypeError: window.addEventListener is not a function' in this line: 'window.addEventListener('keydown', function (event) {' Line Number: 31
User prompt
move Footballer character left and right when pressing arrows
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'originalEvent')' in this line: 'if (event.data.originalEvent.key === 'ArrowLeft') {' Line Number: 64
User prompt
you need to change the horizontal position of footballer by arrows
User prompt
control the footballer with arrows - move to left and right
User prompt
add the footballer character who will need to kick the ball
Initial prompt
Juggle Football Ball
var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.createAsset('ball', 'Juggling Ball', .5, .5); self.speed = 0; self.move = function () { self.y += self.speed; self.speed += 0.1; }; self.bounce = function () { self.speed = -20; }; }); var Footballer = Container.expand(function () { var self = Container.call(this); var footballerGraphics = self.createAsset('footballer', 'Footballer character', .5, 1); self.speed = 10; self.moveLeft = function () { self.x -= self.speed; }; self.moveRight = function () { self.x += self.speed; }; self.kick = function (ball) { if (ball.y >= self.y - ball.height && ball.x >= self.x - ball.width / 2 && ball.x <= self.x + ball.width / 2) { ball.bounce(); } }; }); var Game = Container.expand(function () { var self = Container.call(this); LK.on('keydown', function (obj) { var event = obj.event; if (event.key === 'ArrowLeft') { footballer.moveLeft(); } else if (event.key === 'ArrowRight') { footballer.moveRight(); } }); var ball = self.addChild(new Ball()); ball.x = 2048 / 2; ball.y = 2732 - 100; var footballer = self.addChild(new Footballer()); footballer.x = 2048 / 2; footballer.y = 2732 - footballer.height / 2; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); var isGameOver = false; LK.on('tick', function () { footballer.kick(ball); if (ball.speed < 0) { score++; scoreTxt.setText(score); } }); LK.on('tick', function () { ball.move(); if (ball.y > 2732) { isGameOver = true; } if (isGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); });
===================================================================
--- original.js
+++ change.js
@@ -27,9 +27,10 @@
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
- window.addEventListener('keydown', function (event) {
+ LK.on('keydown', function (obj) {
+ var event = obj.event;
if (event.key === 'ArrowLeft') {
footballer.moveLeft();
} else if (event.key === 'ArrowRight') {
footballer.moveRight();