User prompt
haz que la pelota sea mas grande y se mueva mas rapido
User prompt
se queda trabada si la pelota esta en algun borde
User prompt
la ia no se mueve
User prompt
yo me referia el tejo de hockey 1vs1
User prompt
haz el juego
User prompt
Tejo Challenge: Skill Levels
Initial prompt
haz un tejo donde puedas elegir el nivel con el que te enfretas ya sea facil medio o dificil
/****
* Classes
****/
var AIPaddle = Container.expand(function () {
var self = Container.call(this);
var aiPaddleGraphics = self.attachAsset('aiPaddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// AI follows puck with some lag
if (puck) {
var targetX = puck.x;
var diff = targetX - self.x;
if (Math.abs(diff) > 10) {
self.x += diff > 0 ? self.speed : -self.speed;
}
// Keep AI paddle in its half
self.y = Math.min(self.y, 600);
// Keep within bounds
self.x = Math.max(214, Math.min(1834, self.x));
}
};
return self;
});
var Goal = Container.expand(function () {
var self = Container.call(this);
var goalGraphics = self.attachAsset('goal', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Puck = Container.expand(function () {
var self = Container.call(this);
var puckGraphics = self.attachAsset('puck', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.friction = 0.98;
self.lastIntersecting = false;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityX *= self.friction;
self.velocityY *= self.friction;
// Bounce off side walls
if (self.x <= 154 || self.x >= 1894) {
self.velocityX *= -0.8;
self.x = Math.max(154, Math.min(1894, self.x));
}
// Stop very slow movement
if (Math.abs(self.velocityX) < 0.1) self.velocityX = 0;
if (Math.abs(self.velocityY) < 0.1) self.velocityY = 0;
};
self.reset = function () {
self.x = 1024;
self.y = 1366;
self.velocityX = 0;
self.velocityY = 0;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228b22
});
/****
* Game Code
****/
// Game state variables
var gameState = 'menu'; // 'menu', 'playing', 'gameOver'
var currentDifficulty = null;
var playerScore = 0;
var aiScore = 0;
var targetScore = 5;
// Difficulty settings
var difficulties = {
easy: {
aiSpeed: 2,
name: 'EASY'
},
medium: {
aiSpeed: 3,
name: 'MEDIUM'
},
hard: {
aiSpeed: 4,
name: 'HARD'
}
};
// UI Elements
var titleText = new Text2('AIR HOCKEY 1VS1', {
size: 120,
fill: '#FFFFFF'
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 600;
var instructionText = new Text2('Choose your difficulty level:', {
size: 80,
fill: '#FFFFFF'
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 800;
var playerScoreText = new Text2('Player: 0', {
size: 100,
fill: '#FF0000'
});
playerScoreText.anchor.set(0.5, 0);
var aiScoreText = new Text2('AI: 0', {
size: 100,
fill: '#0000FF'
});
aiScoreText.anchor.set(0.5, 0);
// Difficulty buttons
var easyButton = new Text2('EASY', {
size: 100,
fill: '#00FF00'
});
easyButton.anchor.set(0.5, 0.5);
easyButton.x = 1024;
easyButton.y = 1100;
var mediumButton = new Text2('MEDIUM', {
size: 100,
fill: '#FFFF00'
});
mediumButton.anchor.set(0.5, 0.5);
mediumButton.x = 1024;
mediumButton.y = 1300;
var hardButton = new Text2('HARD', {
size: 100,
fill: '#FF0000'
});
hardButton.anchor.set(0.5, 0.5);
hardButton.x = 1024;
hardButton.y = 1500;
// Game objects
var rink = null;
var puck = null;
var playerPaddle = null;
var aiPaddle = null;
var playerGoal = null;
var aiGoal = null;
var isDragging = false;
// Initialize menu
function showMenu() {
gameState = 'menu';
game.addChild(titleText);
game.addChild(instructionText);
game.addChild(easyButton);
game.addChild(mediumButton);
game.addChild(hardButton);
}
function startGame(difficulty) {
gameState = 'playing';
currentDifficulty = difficulty;
playerScore = 0;
aiScore = 0;
// Clear menu
game.removeChild(titleText);
game.removeChild(instructionText);
game.removeChild(easyButton);
game.removeChild(mediumButton);
game.removeChild(hardButton);
// Create rink
rink = game.addChild(LK.getAsset('rink', {
anchorX: 0.5,
anchorY: 0.5
}));
rink.x = 1024;
rink.y = 1366;
// Create goals
playerGoal = game.addChild(new Goal());
playerGoal.x = 1024;
playerGoal.y = 2700;
aiGoal = game.addChild(new Goal());
aiGoal.x = 1024;
aiGoal.y = 32;
// Create puck
puck = game.addChild(new Puck());
puck.reset();
// Create paddles
playerPaddle = game.addChild(new Paddle());
playerPaddle.x = 1024;
playerPaddle.y = 2200;
aiPaddle = game.addChild(new AIPaddle());
aiPaddle.x = 1024;
aiPaddle.y = 500;
aiPaddle.speed = difficulties[difficulty].aiSpeed;
// Update UI
updateScore();
LK.gui.top.addChild(playerScoreText);
LK.gui.top.addChild(aiScoreText);
playerScoreText.y = 100;
aiScoreText.y = 200;
}
function updateScore() {
playerScoreText.setText('Player: ' + playerScore);
aiScoreText.setText('AI: ' + aiScore);
}
function resetGame() {
if (puck) {
puck.destroy();
puck = null;
}
if (playerPaddle) {
playerPaddle.destroy();
playerPaddle = null;
}
if (aiPaddle) {
aiPaddle.destroy();
aiPaddle = null;
}
if (playerGoal) {
playerGoal.destroy();
playerGoal = null;
}
if (aiGoal) {
aiGoal.destroy();
aiGoal = null;
}
if (rink) {
rink.destroy();
rink = null;
}
// Clear UI
if (playerScoreText.parent) {
LK.gui.top.removeChild(playerScoreText);
}
if (aiScoreText.parent) {
LK.gui.top.removeChild(aiScoreText);
}
showMenu();
}
function checkGoalScored() {
// Check if puck scored in AI goal (top)
if (puck.y <= 92) {
playerScore++;
updateScore();
LK.getSound('goal').play();
LK.effects.flashScreen(0x00FF00, 500);
if (playerScore >= targetScore) {
LK.showYouWin();
return;
}
puck.reset();
}
// Check if puck scored in player goal (bottom)
else if (puck.y >= 2640) {
aiScore++;
updateScore();
LK.getSound('goal').play();
LK.effects.flashScreen(0xFF0000, 500);
if (aiScore >= targetScore) {
LK.showGameOver();
return;
}
puck.reset();
}
}
// Event handlers
game.down = function (x, y, obj) {
if (gameState === 'menu') {
// Check button clicks
var buttonHeight = 100;
var buttonWidth = 300;
if (x >= 1024 - buttonWidth / 2 && x <= 1024 + buttonWidth / 2) {
if (y >= 1100 - buttonHeight / 2 && y <= 1100 + buttonHeight / 2) {
startGame('easy');
} else if (y >= 1300 - buttonHeight / 2 && y <= 1300 + buttonHeight / 2) {
startGame('medium');
} else if (y >= 1500 - buttonHeight / 2 && y <= 1500 + buttonHeight / 2) {
startGame('hard');
}
}
} else if (gameState === 'playing') {
isDragging = true;
}
};
game.move = function (x, y, obj) {
if (gameState === 'playing' && isDragging && playerPaddle) {
playerPaddle.x = x;
playerPaddle.y = y;
// Keep player paddle in bottom half and within bounds
playerPaddle.y = Math.max(playerPaddle.y, 1366);
playerPaddle.x = Math.max(214, Math.min(1834, playerPaddle.x));
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing') {
isDragging = false;
}
};
game.update = function () {
if (gameState === 'playing' && puck && playerPaddle && aiPaddle) {
// Check paddle-puck collisions
var playerCollision = puck.intersects(playerPaddle);
var aiCollision = puck.intersects(aiPaddle);
if (playerCollision) {
var deltaX = puck.x - playerPaddle.x;
var deltaY = puck.y - playerPaddle.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > 0) {
puck.velocityX += deltaX / distance * 8;
puck.velocityY += deltaY / distance * 8;
}
LK.getSound('hit').play();
}
if (aiCollision) {
var deltaX = puck.x - aiPaddle.x;
var deltaY = puck.y - aiPaddle.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > 0) {
puck.velocityX += deltaX / distance * 6;
puck.velocityY += deltaY / distance * 6;
}
LK.getSound('hit').play();
}
checkGoalScored();
}
};
// Start with menu
showMenu(); ===================================================================
--- original.js
+++ change.js
@@ -1,103 +1,112 @@
/****
* Classes
****/
-var Target = Container.expand(function () {
+var AIPaddle = Container.expand(function () {
var self = Container.call(this);
- var targetGraphics = self.attachAsset('target', {
+ var aiPaddleGraphics = self.attachAsset('aiPaddle', {
anchorX: 0.5,
- anchorY: 1.0
+ anchorY: 0.5
});
- var clayGraphics = self.attachAsset('clay', {
+ self.speed = 3;
+ self.update = function () {
+ // AI follows puck with some lag
+ if (puck) {
+ var targetX = puck.x;
+ var diff = targetX - self.x;
+ if (Math.abs(diff) > 10) {
+ self.x += diff > 0 ? self.speed : -self.speed;
+ }
+ // Keep AI paddle in its half
+ self.y = Math.min(self.y, 600);
+ // Keep within bounds
+ self.x = Math.max(214, Math.min(1834, self.x));
+ }
+ };
+ return self;
+});
+var Goal = Container.expand(function () {
+ var self = Container.call(this);
+ var goalGraphics = self.attachAsset('goal', {
anchorX: 0.5,
- anchorY: 0.5,
- y: -75
+ anchorY: 0.5
});
return self;
});
-// Game state variables
-var Tejo = Container.expand(function () {
+var Paddle = Container.expand(function () {
var self = Container.call(this);
- var tejoGraphics = self.attachAsset('tejo', {
+ var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
+ return self;
+});
+var Puck = Container.expand(function () {
+ var self = Container.call(this);
+ var puckGraphics = self.attachAsset('puck', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.velocityX = 0;
self.velocityY = 0;
- self.gravity = 0.3;
- self.isThrown = false;
- self.lastY = 0;
+ self.friction = 0.98;
self.lastIntersecting = false;
self.update = function () {
- if (self.isThrown) {
- self.velocityY += self.gravity;
- self.x += self.velocityX;
- self.y += self.velocityY;
- // Check if tejo went off screen
- if (self.lastY <= 2800 && self.y > 2800) {
- self.reset();
- }
- self.lastY = self.y;
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityX *= self.friction;
+ self.velocityY *= self.friction;
+ // Bounce off side walls
+ if (self.x <= 154 || self.x >= 1894) {
+ self.velocityX *= -0.8;
+ self.x = Math.max(154, Math.min(1894, self.x));
}
+ // Stop very slow movement
+ if (Math.abs(self.velocityX) < 0.1) self.velocityX = 0;
+ if (Math.abs(self.velocityY) < 0.1) self.velocityY = 0;
};
- self["throw"] = function (powerX, powerY) {
- self.velocityX = powerX;
- self.velocityY = powerY;
- self.isThrown = true;
- LK.getSound('throw').play();
- };
self.reset = function () {
- self.x = startX;
- self.y = startY;
+ self.x = 1024;
+ self.y = 1366;
self.velocityX = 0;
self.velocityY = 0;
- self.isThrown = false;
- self.lastY = self.y;
- self.lastIntersecting = false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x654321
+ backgroundColor: 0x228b22
});
/****
* Game Code
****/
// Game state variables
var gameState = 'menu'; // 'menu', 'playing', 'gameOver'
var currentDifficulty = null;
-var score = 0;
-var targetScore = 0;
-var startX = 1024;
-var startY = 2400;
+var playerScore = 0;
+var aiScore = 0;
+var targetScore = 5;
// Difficulty settings
var difficulties = {
easy: {
- targetY: 1800,
- targetScore: 50,
- pointsPerHit: 20,
+ aiSpeed: 2,
name: 'EASY'
},
medium: {
- targetY: 1400,
- targetScore: 100,
- pointsPerHit: 15,
+ aiSpeed: 3,
name: 'MEDIUM'
},
hard: {
- targetY: 1000,
- targetScore: 150,
- pointsPerHit: 10,
+ aiSpeed: 4,
name: 'HARD'
}
};
// UI Elements
-var titleText = new Text2('TEJO CHALLENGE', {
+var titleText = new Text2('AIR HOCKEY 1VS1', {
size: 120,
fill: '#FFFFFF'
});
titleText.anchor.set(0.5, 0.5);
@@ -109,18 +118,18 @@
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 800;
-var scoreText = new Text2('Score: 0', {
+var playerScoreText = new Text2('Player: 0', {
size: 100,
- fill: '#FFFFFF'
+ fill: '#FF0000'
});
-scoreText.anchor.set(0.5, 0);
-var targetScoreText = new Text2('Target: 0', {
- size: 80,
- fill: '#FFFF00'
+playerScoreText.anchor.set(0.5, 0);
+var aiScoreText = new Text2('AI: 0', {
+ size: 100,
+ fill: '#0000FF'
});
-targetScoreText.anchor.set(0.5, 0);
+aiScoreText.anchor.set(0.5, 0);
// Difficulty buttons
var easyButton = new Text2('EASY', {
size: 100,
fill: '#00FF00'
@@ -142,14 +151,15 @@
hardButton.anchor.set(0.5, 0.5);
hardButton.x = 1024;
hardButton.y = 1500;
// Game objects
-var tejo = null;
-var target = null;
-var throwPower = 0;
+var rink = null;
+var puck = null;
+var playerPaddle = null;
+var aiPaddle = null;
+var playerGoal = null;
+var aiGoal = null;
var isDragging = false;
-var dragStartX = 0;
-var dragStartY = 0;
// Initialize menu
function showMenu() {
gameState = 'menu';
game.addChild(titleText);
@@ -160,52 +170,112 @@
}
function startGame(difficulty) {
gameState = 'playing';
currentDifficulty = difficulty;
- score = 0;
- targetScore = difficulties[difficulty].targetScore;
+ playerScore = 0;
+ aiScore = 0;
// Clear menu
game.removeChild(titleText);
game.removeChild(instructionText);
game.removeChild(easyButton);
game.removeChild(mediumButton);
game.removeChild(hardButton);
- // Create game objects
- tejo = game.addChild(new Tejo());
- tejo.x = startX;
- tejo.y = startY;
- target = game.addChild(new Target());
- target.x = 1024;
- target.y = difficulties[difficulty].targetY;
+ // Create rink
+ rink = game.addChild(LK.getAsset('rink', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ rink.x = 1024;
+ rink.y = 1366;
+ // Create goals
+ playerGoal = game.addChild(new Goal());
+ playerGoal.x = 1024;
+ playerGoal.y = 2700;
+ aiGoal = game.addChild(new Goal());
+ aiGoal.x = 1024;
+ aiGoal.y = 32;
+ // Create puck
+ puck = game.addChild(new Puck());
+ puck.reset();
+ // Create paddles
+ playerPaddle = game.addChild(new Paddle());
+ playerPaddle.x = 1024;
+ playerPaddle.y = 2200;
+ aiPaddle = game.addChild(new AIPaddle());
+ aiPaddle.x = 1024;
+ aiPaddle.y = 500;
+ aiPaddle.speed = difficulties[difficulty].aiSpeed;
// Update UI
updateScore();
- LK.gui.top.addChild(scoreText);
- LK.gui.top.addChild(targetScoreText);
- scoreText.y = 100;
- targetScoreText.y = 200;
+ LK.gui.top.addChild(playerScoreText);
+ LK.gui.top.addChild(aiScoreText);
+ playerScoreText.y = 100;
+ aiScoreText.y = 200;
}
function updateScore() {
- scoreText.setText('Score: ' + score);
- targetScoreText.setText('Target: ' + targetScore);
+ playerScoreText.setText('Player: ' + playerScore);
+ aiScoreText.setText('AI: ' + aiScore);
}
function resetGame() {
- if (tejo) {
- tejo.destroy();
- tejo = null;
+ if (puck) {
+ puck.destroy();
+ puck = null;
}
- if (target) {
- target.destroy();
- target = null;
+ if (playerPaddle) {
+ playerPaddle.destroy();
+ playerPaddle = null;
}
+ if (aiPaddle) {
+ aiPaddle.destroy();
+ aiPaddle = null;
+ }
+ if (playerGoal) {
+ playerGoal.destroy();
+ playerGoal = null;
+ }
+ if (aiGoal) {
+ aiGoal.destroy();
+ aiGoal = null;
+ }
+ if (rink) {
+ rink.destroy();
+ rink = null;
+ }
// Clear UI
- if (scoreText.parent) {
- LK.gui.top.removeChild(scoreText);
+ if (playerScoreText.parent) {
+ LK.gui.top.removeChild(playerScoreText);
}
- if (targetScoreText.parent) {
- LK.gui.top.removeChild(targetScoreText);
+ if (aiScoreText.parent) {
+ LK.gui.top.removeChild(aiScoreText);
}
showMenu();
}
+function checkGoalScored() {
+ // Check if puck scored in AI goal (top)
+ if (puck.y <= 92) {
+ playerScore++;
+ updateScore();
+ LK.getSound('goal').play();
+ LK.effects.flashScreen(0x00FF00, 500);
+ if (playerScore >= targetScore) {
+ LK.showYouWin();
+ return;
+ }
+ puck.reset();
+ }
+ // Check if puck scored in player goal (bottom)
+ else if (puck.y >= 2640) {
+ aiScore++;
+ updateScore();
+ LK.getSound('goal').play();
+ LK.effects.flashScreen(0xFF0000, 500);
+ if (aiScore >= targetScore) {
+ LK.showGameOver();
+ return;
+ }
+ puck.reset();
+ }
+}
// Event handlers
game.down = function (x, y, obj) {
if (gameState === 'menu') {
// Check button clicks
@@ -219,58 +289,52 @@
} else if (y >= 1500 - buttonHeight / 2 && y <= 1500 + buttonHeight / 2) {
startGame('hard');
}
}
- } else if (gameState === 'playing' && !tejo.isThrown) {
+ } else if (gameState === 'playing') {
isDragging = true;
- dragStartX = x;
- dragStartY = y;
}
};
+game.move = function (x, y, obj) {
+ if (gameState === 'playing' && isDragging && playerPaddle) {
+ playerPaddle.x = x;
+ playerPaddle.y = y;
+ // Keep player paddle in bottom half and within bounds
+ playerPaddle.y = Math.max(playerPaddle.y, 1366);
+ playerPaddle.x = Math.max(214, Math.min(1834, playerPaddle.x));
+ }
+};
game.up = function (x, y, obj) {
- if (gameState === 'playing' && isDragging && !tejo.isThrown) {
+ if (gameState === 'playing') {
isDragging = false;
- var deltaX = x - dragStartX;
- var deltaY = y - dragStartY;
- var power = Math.sqrt(deltaX * deltaX + deltaY * deltaY) / 10;
- if (power > 2) {
- var powerX = deltaX / 20;
- var powerY = deltaY / 20;
- tejo["throw"](powerX, powerY);
- }
}
};
game.update = function () {
- if (gameState === 'playing' && tejo && target) {
- // Check collision with target
- var currentIntersecting = tejo.intersects(target);
- if (!tejo.lastIntersecting && currentIntersecting && tejo.isThrown) {
- // Hit the target!
- score += difficulties[currentDifficulty].pointsPerHit;
- updateScore();
+ if (gameState === 'playing' && puck && playerPaddle && aiPaddle) {
+ // Check paddle-puck collisions
+ var playerCollision = puck.intersects(playerPaddle);
+ var aiCollision = puck.intersects(aiPaddle);
+ if (playerCollision) {
+ var deltaX = puck.x - playerPaddle.x;
+ var deltaY = puck.y - playerPaddle.y;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance > 0) {
+ puck.velocityX += deltaX / distance * 8;
+ puck.velocityY += deltaY / distance * 8;
+ }
LK.getSound('hit').play();
- LK.effects.flashObject(target, 0xFFFF00, 500);
- // Check win condition
- if (score >= targetScore) {
- LK.showYouWin();
- return;
+ }
+ if (aiCollision) {
+ var deltaX = puck.x - aiPaddle.x;
+ var deltaY = puck.y - aiPaddle.y;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance > 0) {
+ puck.velocityX += deltaX / distance * 6;
+ puck.velocityY += deltaY / distance * 6;
}
- // Reset tejo for next throw
- LK.setTimeout(function () {
- if (tejo) {
- tejo.reset();
- }
- }, 1000);
+ LK.getSound('hit').play();
}
- tejo.lastIntersecting = currentIntersecting;
- // Reset tejo if it's been thrown and is off screen or stopped
- if (tejo.isThrown && tejo.y > startY + 100) {
- LK.setTimeout(function () {
- if (tejo) {
- tejo.reset();
- }
- }, 500);
- }
+ checkGoalScored();
}
};
// Start with menu
showMenu();
\ No newline at end of file