===================================================================
--- original.js
+++ change.js
@@ -1,56 +1,56 @@
-/****
+/****
* Classes
****/
// Ball class
var Ball = Container.expand(function () {
- var self = Container.call(this);
- var ballGraphics = self.createAsset('ball', 'Ball asset', 0.5, 0.5);
- self.velocity = {
- x: 0,
- y: 0
- };
- self.radius = ballGraphics.width / 2;
- self.update = function () {
- self.x += self.velocity.x;
- self.y += self.velocity.y;
- };
- self.reset = function () {
- self.x = game.width / 2;
- self.y = game.height / 2;
- var angle = Math.random() * Math.PI * 2;
- self.velocity = {
- x: Math.cos(angle) * 5,
- y: Math.sin(angle) * 5
- };
- };
+ var self = Container.call(this);
+ var ballGraphics = self.createAsset('ball', 'Ball asset', 0.5, 0.5);
+ self.velocity = {
+ x: 0,
+ y: 0
+ };
+ self.radius = ballGraphics.width / 2;
+ self.update = function () {
+ self.x += self.velocity.x;
+ self.y += self.velocity.y;
+ };
+ self.reset = function () {
+ self.x = game.width / 4;
+ self.y = game.height / 4;
+ var angle = Math.random() * Math.PI * 2;
+ self.velocity = {
+ x: Math.cos(angle) * 5,
+ y: Math.sin(angle) * 5
+ };
+ };
});
// Paddle class
var Paddle = Container.expand(function () {
- var self = Container.call(this);
- var paddleGraphics = self.createAsset('paddle', 'Paddle asset', 0.5, 0.5);
- self.update = function () {
- // Paddle update logic
- };
+ var self = Container.call(this);
+ var paddleGraphics = self.createAsset('paddle', 'Paddle asset', 0.5, 0.5);
+ self.update = function () {
+ // Paddle update logic
+ };
});
// Planet class
var Planet = Container.expand(function () {
- var self = Container.call(this);
- var planetGraphics = self.createAsset('planet', 'Planet asset', 0.5, 0.5);
- self.mass = 1000; // Arbitrary mass for gravity calculation
- self.radius = planetGraphics.width / 2;
- self.x = game.width / 2;
- self.y = game.height / 2;
+ var self = Container.call(this);
+ var planetGraphics = self.createAsset('planet', 'Planet asset', 0.5, 0.5);
+ self.mass = 1000; // Arbitrary mass for gravity calculation
+ self.radius = planetGraphics.width / 2;
+ self.x = game.width / 2;
+ self.y = game.height / 2;
});
-/****
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
****/
// Initialize game elements
var ball = game.addChild(new Ball());
@@ -64,43 +64,43 @@
rightPaddle.y = game.height / 2;
ball.reset();
// Game logic
LK.on('tick', function () {
- ball.update();
- leftPaddle.update();
- rightPaddle.update();
- // Check for collisions with paddles
- if (ball.intersects(leftPaddle) || ball.intersects(rightPaddle)) {
- ball.velocity.x *= -1;
- }
- // Check for collisions with top and bottom boundaries
- if (ball.y - ball.radius <= 0 || ball.y + ball.radius >= game.height) {
- ball.velocity.y *= -1;
- }
- // Gravity effect from planet
- var dx = planet.x - ball.x;
- var dy = planet.y - ball.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < planet.radius + ball.radius) {
- // Simple gravity effect
- var gravity = planet.mass / (distance * distance);
- var gravityX = dx / distance * gravity;
- var gravityY = dy / distance * gravity;
- ball.velocity.x += gravityX;
- ball.velocity.y += gravityY;
- }
- // Reset ball if it goes off screen
- if (ball.x < -ball.radius || ball.x > game.width + ball.radius) {
- ball.reset();
- }
+ ball.update();
+ leftPaddle.update();
+ rightPaddle.update();
+ // Check for collisions with paddles
+ if (ball.intersects(leftPaddle) || ball.intersects(rightPaddle)) {
+ ball.velocity.x *= -1;
+ }
+ // Check for collisions with top and bottom boundaries
+ if (ball.y - ball.radius <= 0 || ball.y + ball.radius >= game.height) {
+ ball.velocity.y *= -1;
+ }
+ // Gravity effect from planet
+ var dx = planet.x - ball.x;
+ var dy = planet.y - ball.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < planet.radius + ball.radius) {
+ // Simple gravity effect
+ var gravity = planet.mass / (distance * distance);
+ var gravityX = dx / distance * gravity;
+ var gravityY = dy / distance * gravity;
+ ball.velocity.x += gravityX;
+ ball.velocity.y += gravityY;
+ }
+ // Reset ball if it goes off screen
+ if (ball.x < -ball.radius || ball.x > game.width + ball.radius) {
+ ball.reset();
+ }
});
// Touch controls for paddles
function handleTouch(obj) {
- var touchPos = obj.event.getLocalPosition(game);
- if (touchPos.x < game.width / 2) {
- leftPaddle.y = touchPos.y;
- } else {
- rightPaddle.y = touchPos.y;
- }
+ var touchPos = obj.event.getLocalPosition(game);
+ if (touchPos.x < game.width / 2) {
+ leftPaddle.y = touchPos.y;
+ } else {
+ rightPaddle.y = touchPos.y;
+ }
}
game.on('down', handleTouch);
game.on('move', handleTouch);
\ No newline at end of file
plasma barrier. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
neutron star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
neutron star, pulsar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cat eye nebula, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
flying saucer, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
erase