User prompt
Pues no me deja jugarlo
User prompt
Este juego no es como tigerball
Code edit (1 edits merged)
Please save this source code
User prompt
Portal Pong Championship
User prompt
Que cada 5 niveles cambie de modo como en tigerball y q haya como portales q te metes en uno y sales en el siguiente
Initial prompt
Quiero hacer un juego como tigerball pero con otras pelotas y niveles más chulos
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 8;
self.lastPortalUsed = null;
self.portalCooldown = 0;
self.reset = function () {
self.x = 1024;
self.y = 1366;
var angle = (Math.random() - 0.5) * Math.PI * 0.5;
self.velocityX = Math.cos(angle) * self.speed * (Math.random() > 0.5 ? 1 : -1);
self.velocityY = Math.sin(angle) * self.speed;
self.lastPortalUsed = null;
self.portalCooldown = 0;
};
self.update = function () {
if (self.portalCooldown > 0) {
self.portalCooldown--;
}
self.x += self.velocityX;
self.y += self.velocityY;
// Top and bottom bounds
if (self.y <= 15 || self.y >= 2717) {
self.velocityY = -self.velocityY;
self.y = self.y <= 15 ? 15 : 2717;
LK.getSound('bounce').play();
}
};
return self;
});
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.targetY = 0;
self.update = function () {
// Smooth movement towards target position
var diff = self.targetY - self.y;
if (Math.abs(diff) > 2) {
self.y += diff * 0.15;
}
// Keep paddle within bounds
if (self.y < 100) self.y = 100;
if (self.y > 2632) self.y = 2632;
};
return self;
});
var Portal = Container.expand(function () {
var self = Container.call(this);
var portalGraphics = self.attachAsset('portal', {
anchorX: 0.5,
anchorY: 0.5
});
self.paired = null;
self.animationPhase = 0;
self.update = function () {
self.animationPhase += 0.2;
portalGraphics.rotation = self.animationPhase * 0.5;
portalGraphics.scaleX = 1 + Math.sin(self.animationPhase) * 0.2;
portalGraphics.scaleY = 1 + Math.sin(self.animationPhase) * 0.2;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x001122
});
/****
* Game Code
****/
// Game variables
var level = 1;
var gameMode = 'normal'; // normal, multiball, gravity, obstacles, speed
var ballCount = 0;
var modeChangeTimer = 0;
var portalSpawnTimer = 0;
var lastBallOut = '';
// Game objects
var playerPaddle, aiPaddle, balls, portals, centerLine;
var levelText, modeText, scoreText;
// Initialize game objects
balls = [];
portals = [];
// Create center line
centerLine = game.addChild(LK.getAsset('centerLine', {
anchorX: 0.5,
anchorY: 0.5
}));
centerLine.x = 1024;
centerLine.y = 1366;
// Create paddles
playerPaddle = game.addChild(new Paddle());
playerPaddle.x = 100;
playerPaddle.y = 1366;
playerPaddle.targetY = 1366;
aiPaddle = game.addChild(new Paddle());
aiPaddle.x = 1948;
aiPaddle.y = 1366;
aiPaddle.targetY = 1366;
// Create initial ball
var initialBall = game.addChild(new Ball());
initialBall.reset();
balls.push(initialBall);
// Create UI
levelText = new Text2('Level: 1', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
levelText.y = 100;
modeText = new Text2('Mode: Normal', {
size: 50,
fill: 0x00FFFF
});
modeText.anchor.set(0.5, 0);
LK.gui.top.addChild(modeText);
modeText.y = 180;
scoreText = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 250;
// Functions
function updateGameMode() {
var newMode = 'normal';
if (level >= 21) newMode = 'speed';else if (level >= 16) newMode = 'obstacles';else if (level >= 11) newMode = 'gravity';else if (level >= 6) newMode = 'multiball';
if (newMode !== gameMode) {
gameMode = newMode;
modeText.setText('Mode: ' + gameMode.charAt(0).toUpperCase() + gameMode.slice(1));
// Mode-specific initialization
if (gameMode === 'multiball' && balls.length === 1) {
var ball2 = game.addChild(new Ball());
ball2.reset();
ball2.speed = 6;
balls.push(ball2);
}
if (gameMode === 'speed') {
balls.forEach(function (ball) {
ball.speed = Math.min(ball.speed * 1.5, 20);
});
}
}
}
function spawnPortalPair() {
if (portals.length >= 4) return;
var portal1 = game.addChild(new Portal());
var portal2 = game.addChild(new Portal());
// Position portals randomly but not too close to paddles
portal1.x = 300 + Math.random() * 600;
portal1.y = 200 + Math.random() * 2332;
portal2.x = 1148 + Math.random() * 600;
portal2.y = 200 + Math.random() * 2332;
// Pair them
portal1.paired = portal2;
portal2.paired = portal1;
// Color the pair differently
portal2.getChildAt(0).tint = 0xff00ff;
portals.push(portal1, portal2);
// Remove portals after 10 seconds
LK.setTimeout(function () {
var index1 = portals.indexOf(portal1);
var index2 = portals.indexOf(portal2);
if (index1 >= 0) {
portal1.destroy();
portals.splice(index1, 1);
}
if (index2 >= 0) {
portal2.destroy();
portals.splice(index2, 1);
}
}, 10000);
}
function checkCollisions() {
balls.forEach(function (ball, ballIndex) {
// Paddle collisions
if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle)) {
var paddle = ball.intersects(playerPaddle) ? playerPaddle : aiPaddle;
// Reverse X velocity and add some angle based on where it hit the paddle
ball.velocityX = -ball.velocityX;
var hitPos = (ball.y - paddle.y) / 100; // -1 to 1
ball.velocityY += hitPos * 3;
// Keep ball from paddle
if (ball.intersects(playerPaddle)) {
ball.x = playerPaddle.x + 50;
} else {
ball.x = aiPaddle.x - 50;
}
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore().toString());
LK.getSound('bounce').play();
}
// Portal collisions
if (ball.portalCooldown === 0) {
portals.forEach(function (portal) {
if (ball.intersects(portal) && portal.paired && ball.lastPortalUsed !== portal) {
ball.x = portal.paired.x;
ball.y = portal.paired.y;
ball.lastPortalUsed = portal;
ball.portalCooldown = 30;
LK.setScore(LK.getScore() + 5);
scoreText.setText(LK.getScore().toString());
LK.getSound('portal').play();
// Add some visual effect
tween(portal.paired.getChildAt(0), {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(portal.paired.getChildAt(0), {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
}
});
}
// Check if ball is out of bounds
if (ball.x < -50) {
lastBallOut = 'left';
ball.destroy();
balls.splice(ballIndex, 1);
} else if (ball.x > 2098) {
lastBallOut = 'right';
ball.destroy();
balls.splice(ballIndex, 1);
}
});
}
function updateAI() {
if (balls.length > 0) {
var closestBall = balls[0];
var closestDist = Math.abs(balls[0].x - aiPaddle.x);
balls.forEach(function (ball) {
var dist = Math.abs(ball.x - aiPaddle.x);
if (dist < closestDist) {
closestBall = ball;
closestDist = dist;
}
});
// AI follows the closest ball
aiPaddle.targetY = closestBall.y;
}
}
// Touch controls
game.move = function (x, y, obj) {
playerPaddle.targetY = y;
};
game.down = function (x, y, obj) {
playerPaddle.targetY = y;
};
// Main game loop
game.update = function () {
// Update game mode based on level
updateGameMode();
// Spawn portals periodically
portalSpawnTimer++;
if (portalSpawnTimer > 300) {
// Every 5 seconds
spawnPortalPair();
portalSpawnTimer = 0;
}
// Update AI
updateAI();
// Check collisions
checkCollisions();
// Check if all balls are out
if (balls.length === 0) {
if (lastBallOut === 'left') {
// AI scored, game over
LK.showGameOver();
} else {
// Player scored, next level
level++;
levelText.setText('Level: ' + level);
var newBall = game.addChild(new Ball());
newBall.reset();
newBall.speed = Math.min(8 + level * 0.5, 15);
balls.push(newBall);
LK.getSound('score').play();
}
}
// Apply gravity mode effect
if (gameMode === 'gravity') {
balls.forEach(function (ball) {
ball.velocityY += 0.3; // Gravity effect
});
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,316 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Ball = Container.expand(function () {
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.speed = 8;
+ self.lastPortalUsed = null;
+ self.portalCooldown = 0;
+ self.reset = function () {
+ self.x = 1024;
+ self.y = 1366;
+ var angle = (Math.random() - 0.5) * Math.PI * 0.5;
+ self.velocityX = Math.cos(angle) * self.speed * (Math.random() > 0.5 ? 1 : -1);
+ self.velocityY = Math.sin(angle) * self.speed;
+ self.lastPortalUsed = null;
+ self.portalCooldown = 0;
+ };
+ self.update = function () {
+ if (self.portalCooldown > 0) {
+ self.portalCooldown--;
+ }
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Top and bottom bounds
+ if (self.y <= 15 || self.y >= 2717) {
+ self.velocityY = -self.velocityY;
+ self.y = self.y <= 15 ? 15 : 2717;
+ LK.getSound('bounce').play();
+ }
+ };
+ return self;
+});
+var Paddle = Container.expand(function () {
+ var self = Container.call(this);
+ var paddleGraphics = self.attachAsset('paddle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 12;
+ self.targetY = 0;
+ self.update = function () {
+ // Smooth movement towards target position
+ var diff = self.targetY - self.y;
+ if (Math.abs(diff) > 2) {
+ self.y += diff * 0.15;
+ }
+ // Keep paddle within bounds
+ if (self.y < 100) self.y = 100;
+ if (self.y > 2632) self.y = 2632;
+ };
+ return self;
+});
+var Portal = Container.expand(function () {
+ var self = Container.call(this);
+ var portalGraphics = self.attachAsset('portal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.paired = null;
+ self.animationPhase = 0;
+ self.update = function () {
+ self.animationPhase += 0.2;
+ portalGraphics.rotation = self.animationPhase * 0.5;
+ portalGraphics.scaleX = 1 + Math.sin(self.animationPhase) * 0.2;
+ portalGraphics.scaleY = 1 + Math.sin(self.animationPhase) * 0.2;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x001122
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var level = 1;
+var gameMode = 'normal'; // normal, multiball, gravity, obstacles, speed
+var ballCount = 0;
+var modeChangeTimer = 0;
+var portalSpawnTimer = 0;
+var lastBallOut = '';
+// Game objects
+var playerPaddle, aiPaddle, balls, portals, centerLine;
+var levelText, modeText, scoreText;
+// Initialize game objects
+balls = [];
+portals = [];
+// Create center line
+centerLine = game.addChild(LK.getAsset('centerLine', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+centerLine.x = 1024;
+centerLine.y = 1366;
+// Create paddles
+playerPaddle = game.addChild(new Paddle());
+playerPaddle.x = 100;
+playerPaddle.y = 1366;
+playerPaddle.targetY = 1366;
+aiPaddle = game.addChild(new Paddle());
+aiPaddle.x = 1948;
+aiPaddle.y = 1366;
+aiPaddle.targetY = 1366;
+// Create initial ball
+var initialBall = game.addChild(new Ball());
+initialBall.reset();
+balls.push(initialBall);
+// Create UI
+levelText = new Text2('Level: 1', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+levelText.anchor.set(0.5, 0);
+LK.gui.top.addChild(levelText);
+levelText.y = 100;
+modeText = new Text2('Mode: Normal', {
+ size: 50,
+ fill: 0x00FFFF
+});
+modeText.anchor.set(0.5, 0);
+LK.gui.top.addChild(modeText);
+modeText.y = 180;
+scoreText = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 250;
+// Functions
+function updateGameMode() {
+ var newMode = 'normal';
+ if (level >= 21) newMode = 'speed';else if (level >= 16) newMode = 'obstacles';else if (level >= 11) newMode = 'gravity';else if (level >= 6) newMode = 'multiball';
+ if (newMode !== gameMode) {
+ gameMode = newMode;
+ modeText.setText('Mode: ' + gameMode.charAt(0).toUpperCase() + gameMode.slice(1));
+ // Mode-specific initialization
+ if (gameMode === 'multiball' && balls.length === 1) {
+ var ball2 = game.addChild(new Ball());
+ ball2.reset();
+ ball2.speed = 6;
+ balls.push(ball2);
+ }
+ if (gameMode === 'speed') {
+ balls.forEach(function (ball) {
+ ball.speed = Math.min(ball.speed * 1.5, 20);
+ });
+ }
+ }
+}
+function spawnPortalPair() {
+ if (portals.length >= 4) return;
+ var portal1 = game.addChild(new Portal());
+ var portal2 = game.addChild(new Portal());
+ // Position portals randomly but not too close to paddles
+ portal1.x = 300 + Math.random() * 600;
+ portal1.y = 200 + Math.random() * 2332;
+ portal2.x = 1148 + Math.random() * 600;
+ portal2.y = 200 + Math.random() * 2332;
+ // Pair them
+ portal1.paired = portal2;
+ portal2.paired = portal1;
+ // Color the pair differently
+ portal2.getChildAt(0).tint = 0xff00ff;
+ portals.push(portal1, portal2);
+ // Remove portals after 10 seconds
+ LK.setTimeout(function () {
+ var index1 = portals.indexOf(portal1);
+ var index2 = portals.indexOf(portal2);
+ if (index1 >= 0) {
+ portal1.destroy();
+ portals.splice(index1, 1);
+ }
+ if (index2 >= 0) {
+ portal2.destroy();
+ portals.splice(index2, 1);
+ }
+ }, 10000);
+}
+function checkCollisions() {
+ balls.forEach(function (ball, ballIndex) {
+ // Paddle collisions
+ if (ball.intersects(playerPaddle) || ball.intersects(aiPaddle)) {
+ var paddle = ball.intersects(playerPaddle) ? playerPaddle : aiPaddle;
+ // Reverse X velocity and add some angle based on where it hit the paddle
+ ball.velocityX = -ball.velocityX;
+ var hitPos = (ball.y - paddle.y) / 100; // -1 to 1
+ ball.velocityY += hitPos * 3;
+ // Keep ball from paddle
+ if (ball.intersects(playerPaddle)) {
+ ball.x = playerPaddle.x + 50;
+ } else {
+ ball.x = aiPaddle.x - 50;
+ }
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText(LK.getScore().toString());
+ LK.getSound('bounce').play();
+ }
+ // Portal collisions
+ if (ball.portalCooldown === 0) {
+ portals.forEach(function (portal) {
+ if (ball.intersects(portal) && portal.paired && ball.lastPortalUsed !== portal) {
+ ball.x = portal.paired.x;
+ ball.y = portal.paired.y;
+ ball.lastPortalUsed = portal;
+ ball.portalCooldown = 30;
+ LK.setScore(LK.getScore() + 5);
+ scoreText.setText(LK.getScore().toString());
+ LK.getSound('portal').play();
+ // Add some visual effect
+ tween(portal.paired.getChildAt(0), {
+ scaleX: 1.5,
+ scaleY: 1.5
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(portal.paired.getChildAt(0), {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200
+ });
+ }
+ });
+ }
+ });
+ }
+ // Check if ball is out of bounds
+ if (ball.x < -50) {
+ lastBallOut = 'left';
+ ball.destroy();
+ balls.splice(ballIndex, 1);
+ } else if (ball.x > 2098) {
+ lastBallOut = 'right';
+ ball.destroy();
+ balls.splice(ballIndex, 1);
+ }
+ });
+}
+function updateAI() {
+ if (balls.length > 0) {
+ var closestBall = balls[0];
+ var closestDist = Math.abs(balls[0].x - aiPaddle.x);
+ balls.forEach(function (ball) {
+ var dist = Math.abs(ball.x - aiPaddle.x);
+ if (dist < closestDist) {
+ closestBall = ball;
+ closestDist = dist;
+ }
+ });
+ // AI follows the closest ball
+ aiPaddle.targetY = closestBall.y;
+ }
+}
+// Touch controls
+game.move = function (x, y, obj) {
+ playerPaddle.targetY = y;
+};
+game.down = function (x, y, obj) {
+ playerPaddle.targetY = y;
+};
+// Main game loop
+game.update = function () {
+ // Update game mode based on level
+ updateGameMode();
+ // Spawn portals periodically
+ portalSpawnTimer++;
+ if (portalSpawnTimer > 300) {
+ // Every 5 seconds
+ spawnPortalPair();
+ portalSpawnTimer = 0;
+ }
+ // Update AI
+ updateAI();
+ // Check collisions
+ checkCollisions();
+ // Check if all balls are out
+ if (balls.length === 0) {
+ if (lastBallOut === 'left') {
+ // AI scored, game over
+ LK.showGameOver();
+ } else {
+ // Player scored, next level
+ level++;
+ levelText.setText('Level: ' + level);
+ var newBall = game.addChild(new Ball());
+ newBall.reset();
+ newBall.speed = Math.min(8 + level * 0.5, 15);
+ balls.push(newBall);
+ LK.getSound('score').play();
+ }
+ }
+ // Apply gravity mode effect
+ if (gameMode === 'gravity') {
+ balls.forEach(function (ball) {
+ ball.velocityY += 0.3; // Gravity effect
+ });
+ }
+};
\ No newline at end of file