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 Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 1.0
});
var clayGraphics = self.attachAsset('clay', {
anchorX: 0.5,
anchorY: 0.5,
y: -75
});
return self;
});
// Game state variables
var Tejo = Container.expand(function () {
var self = Container.call(this);
var tejoGraphics = self.attachAsset('tejo', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.3;
self.isThrown = false;
self.lastY = 0;
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["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.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
});
/****
* 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;
// Difficulty settings
var difficulties = {
easy: {
targetY: 1800,
targetScore: 50,
pointsPerHit: 20,
name: 'EASY'
},
medium: {
targetY: 1400,
targetScore: 100,
pointsPerHit: 15,
name: 'MEDIUM'
},
hard: {
targetY: 1000,
targetScore: 150,
pointsPerHit: 10,
name: 'HARD'
}
};
// UI Elements
var titleText = new Text2('TEJO CHALLENGE', {
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 scoreText = new Text2('Score: 0', {
size: 100,
fill: '#FFFFFF'
});
scoreText.anchor.set(0.5, 0);
var targetScoreText = new Text2('Target: 0', {
size: 80,
fill: '#FFFF00'
});
targetScoreText.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 tejo = null;
var target = null;
var throwPower = 0;
var isDragging = false;
var dragStartX = 0;
var dragStartY = 0;
// 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;
score = 0;
targetScore = difficulties[difficulty].targetScore;
// 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;
// Update UI
updateScore();
LK.gui.top.addChild(scoreText);
LK.gui.top.addChild(targetScoreText);
scoreText.y = 100;
targetScoreText.y = 200;
}
function updateScore() {
scoreText.setText('Score: ' + score);
targetScoreText.setText('Target: ' + targetScore);
}
function resetGame() {
if (tejo) {
tejo.destroy();
tejo = null;
}
if (target) {
target.destroy();
target = null;
}
// Clear UI
if (scoreText.parent) {
LK.gui.top.removeChild(scoreText);
}
if (targetScoreText.parent) {
LK.gui.top.removeChild(targetScoreText);
}
showMenu();
}
// 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' && !tejo.isThrown) {
isDragging = true;
dragStartX = x;
dragStartY = y;
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing' && isDragging && !tejo.isThrown) {
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();
LK.getSound('hit').play();
LK.effects.flashObject(target, 0xFFFF00, 500);
// Check win condition
if (score >= targetScore) {
LK.showYouWin();
return;
}
// Reset tejo for next throw
LK.setTimeout(function () {
if (tejo) {
tejo.reset();
}
}, 1000);
}
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);
}
}
};
// Start with menu
showMenu(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,276 @@
-/****
+/****
+* Classes
+****/
+var Target = Container.expand(function () {
+ var self = Container.call(this);
+ var targetGraphics = self.attachAsset('target', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ var clayGraphics = self.attachAsset('clay', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -75
+ });
+ return self;
+});
+// Game state variables
+var Tejo = Container.expand(function () {
+ var self = Container.call(this);
+ var tejoGraphics = self.attachAsset('tejo', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.gravity = 0.3;
+ self.isThrown = false;
+ self.lastY = 0;
+ 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["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.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: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x654321
+});
+
+/****
+* 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;
+// Difficulty settings
+var difficulties = {
+ easy: {
+ targetY: 1800,
+ targetScore: 50,
+ pointsPerHit: 20,
+ name: 'EASY'
+ },
+ medium: {
+ targetY: 1400,
+ targetScore: 100,
+ pointsPerHit: 15,
+ name: 'MEDIUM'
+ },
+ hard: {
+ targetY: 1000,
+ targetScore: 150,
+ pointsPerHit: 10,
+ name: 'HARD'
+ }
+};
+// UI Elements
+var titleText = new Text2('TEJO CHALLENGE', {
+ 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 scoreText = new Text2('Score: 0', {
+ size: 100,
+ fill: '#FFFFFF'
+});
+scoreText.anchor.set(0.5, 0);
+var targetScoreText = new Text2('Target: 0', {
+ size: 80,
+ fill: '#FFFF00'
+});
+targetScoreText.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 tejo = null;
+var target = null;
+var throwPower = 0;
+var isDragging = false;
+var dragStartX = 0;
+var dragStartY = 0;
+// 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;
+ score = 0;
+ targetScore = difficulties[difficulty].targetScore;
+ // 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;
+ // Update UI
+ updateScore();
+ LK.gui.top.addChild(scoreText);
+ LK.gui.top.addChild(targetScoreText);
+ scoreText.y = 100;
+ targetScoreText.y = 200;
+}
+function updateScore() {
+ scoreText.setText('Score: ' + score);
+ targetScoreText.setText('Target: ' + targetScore);
+}
+function resetGame() {
+ if (tejo) {
+ tejo.destroy();
+ tejo = null;
+ }
+ if (target) {
+ target.destroy();
+ target = null;
+ }
+ // Clear UI
+ if (scoreText.parent) {
+ LK.gui.top.removeChild(scoreText);
+ }
+ if (targetScoreText.parent) {
+ LK.gui.top.removeChild(targetScoreText);
+ }
+ showMenu();
+}
+// 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' && !tejo.isThrown) {
+ isDragging = true;
+ dragStartX = x;
+ dragStartY = y;
+ }
+};
+game.up = function (x, y, obj) {
+ if (gameState === 'playing' && isDragging && !tejo.isThrown) {
+ 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();
+ LK.getSound('hit').play();
+ LK.effects.flashObject(target, 0xFFFF00, 500);
+ // Check win condition
+ if (score >= targetScore) {
+ LK.showYouWin();
+ return;
+ }
+ // Reset tejo for next throw
+ LK.setTimeout(function () {
+ if (tejo) {
+ tejo.reset();
+ }
+ }, 1000);
+ }
+ 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);
+ }
+ }
+};
+// Start with menu
+showMenu();
\ No newline at end of file