User prompt
Increase ball speed every 20 points
User prompt
make the balls faster every 50 points
User prompt
make the wall the backround
User prompt
make the wall bigger
User prompt
make the wall bigger
User prompt
add a orange wall in the middle of the field
User prompt
make a sound for when the ball hits the bat
User prompt
Add green backround
User prompt
Make the balls faster
User prompt
When ball gets hit launch ball to top of screen
User prompt
when ball gets touched add a hitting effect
User prompt
Only throw one ball
Initial prompt
Home run Hitters
/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Ball class var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; }; }); // Bat class var Bat = Container.expand(function () { var self = Container.call(this); var batGraphics = self.attachAsset('bat', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize variables var balls = []; var bat = game.addChild(new Bat()); bat.x = 2048 / 2; bat.y = 2500; var score = 0; var misses = 0; var pitchInterval = 1000; var ballThrown = false; // New variable to control if a ball has been thrown // Score text var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Misses text var missesTxt = new Text2('Misses: 0', { size: 100, fill: 0xFFFFFF }); missesTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(missesTxt); // Function to pitch a new ball function pitchBall() { if (!ballThrown) { // Only throw a ball if one hasn't been thrown yet var newBall = new Ball(); newBall.x = Math.random() * 2048; newBall.y = 0; balls.push(newBall); game.addChild(newBall); ballThrown = true; // Update the ballThrown variable to true } } // Game update function game.update = function () { for (var i = balls.length - 1; i >= 0; i--) { var ball = balls[i]; if (ball.y > 2732) { ball.destroy(); balls.splice(i, 1); misses++; missesTxt.setText('Misses: ' + misses); ballThrown = false; // Update the ballThrown variable to false if (misses >= 3) { LK.showGameOver(); } } else if (ball.intersects(bat)) { ball.destroy(); balls.splice(i, 1); score += 4; scoreTxt.setText('Score: ' + score); pitchInterval = Math.max(500, 1000 - score * 10); ballThrown = false; // Update the ballThrown variable to false } } }; // Pitch balls at intervals var pitchTimer = LK.setInterval(pitchBall, pitchInterval); // Handle bat movement game.down = function (x, y, obj) { bat.down(x, y, obj); };
===================================================================
--- original.js
+++ change.js
@@ -1,97 +1,104 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Ball class
var Ball = Container.expand(function () {
- var self = Container.call(this);
- var ballGraphics = self.attachAsset('ball', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ };
});
// Bat class
var Bat = Container.expand(function () {
- var self = Container.call(this);
- var batGraphics = self.attachAsset('bat', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.down = function (x, y, obj) {
- self.x = x;
- self.y = y;
- };
+ var self = Container.call(this);
+ var batGraphics = self.attachAsset('bat', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.down = function (x, y, obj) {
+ self.x = x;
+ self.y = y;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize variables
var balls = [];
var bat = game.addChild(new Bat());
bat.x = 2048 / 2;
bat.y = 2500;
var score = 0;
var misses = 0;
var pitchInterval = 1000;
+var ballThrown = false; // New variable to control if a ball has been thrown
// Score text
var scoreTxt = new Text2('Score: 0', {
- size: 100,
- fill: 0xFFFFFF
+ size: 100,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Misses text
var missesTxt = new Text2('Misses: 0', {
- size: 100,
- fill: 0xFFFFFF
+ size: 100,
+ fill: 0xFFFFFF
});
missesTxt.anchor.set(0.5, 0);
LK.gui.topRight.addChild(missesTxt);
// Function to pitch a new ball
function pitchBall() {
- var newBall = new Ball();
- newBall.x = Math.random() * 2048;
- newBall.y = 0;
- balls.push(newBall);
- game.addChild(newBall);
+ if (!ballThrown) {
+ // Only throw a ball if one hasn't been thrown yet
+ var newBall = new Ball();
+ newBall.x = Math.random() * 2048;
+ newBall.y = 0;
+ balls.push(newBall);
+ game.addChild(newBall);
+ ballThrown = true; // Update the ballThrown variable to true
+ }
}
// Game update function
game.update = function () {
- for (var i = balls.length - 1; i >= 0; i--) {
- var ball = balls[i];
- if (ball.y > 2732) {
- ball.destroy();
- balls.splice(i, 1);
- misses++;
- missesTxt.setText('Misses: ' + misses);
- if (misses >= 3) {
- LK.showGameOver();
- }
- } else if (ball.intersects(bat)) {
- ball.destroy();
- balls.splice(i, 1);
- score += 4;
- scoreTxt.setText('Score: ' + score);
- pitchInterval = Math.max(500, 1000 - score * 10);
- }
- }
+ for (var i = balls.length - 1; i >= 0; i--) {
+ var ball = balls[i];
+ if (ball.y > 2732) {
+ ball.destroy();
+ balls.splice(i, 1);
+ misses++;
+ missesTxt.setText('Misses: ' + misses);
+ ballThrown = false; // Update the ballThrown variable to false
+ if (misses >= 3) {
+ LK.showGameOver();
+ }
+ } else if (ball.intersects(bat)) {
+ ball.destroy();
+ balls.splice(i, 1);
+ score += 4;
+ scoreTxt.setText('Score: ' + score);
+ pitchInterval = Math.max(500, 1000 - score * 10);
+ ballThrown = false; // Update the ballThrown variable to false
+ }
+ }
};
// Pitch balls at intervals
var pitchTimer = LK.setInterval(pitchBall, pitchInterval);
// Handle bat movement
game.down = function (x, y, obj) {
- bat.down(x, y, obj);
+ bat.down(x, y, obj);
};
\ No newline at end of file