/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AIPaddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('aiPaddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 1024;
self.baseSpeed = 4;
self.update = function () {
// AI follows ball with increasing difficulty
var difficulty = Math.min(1 + (playerScore + aiScore) * 0.1, 3);
var speed = self.baseSpeed * difficulty;
if (ball.velocityY < 0) {
self.targetX = ball.x + ball.velocityX * 30;
} else {
self.targetX = 1024;
}
self.targetX = Math.max(374, Math.min(1674, self.targetX));
if (Math.abs(self.x - self.targetX) > speed) {
if (self.x < self.targetX) {
self.x += speed;
} else {
self.x -= speed;
}
} else {
self.x = self.targetX;
}
};
return self;
});
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.lastPlayerHit = false;
self.lastAIHit = false;
self.lastTableHit = false;
self.reset = function () {
self.x = 1024;
self.y = 1366;
self.velocityX = Math.random() > 0.5 ? self.speed : -self.speed;
self.velocityY = Math.random() > 0.5 ? self.speed * 0.7 : -self.speed * 0.7;
self.lastPlayerHit = false;
self.lastAIHit = false;
self.lastTableHit = false;
};
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
// Ball vs table bounds
if (self.x <= 224 || self.x >= 1824) {
self.velocityX = -self.velocityX;
}
// Ball vs player paddle collision
var currentPlayerHit = self.intersects(playerPaddle);
if (!self.lastPlayerHit && currentPlayerHit) {
self.velocityY = -Math.abs(self.velocityY);
self.velocityX += (self.x - playerPaddle.x) * 0.1;
LK.getSound('paddleHit').play();
}
self.lastPlayerHit = currentPlayerHit;
// Ball vs AI paddle collision
var currentAIHit = self.intersects(aiPaddle);
if (!self.lastAIHit && currentAIHit) {
self.velocityY = Math.abs(self.velocityY);
self.velocityX += (self.x - aiPaddle.x) * 0.1;
LK.getSound('paddleHit').play();
}
self.lastAIHit = currentAIHit;
// Ball vs table collision (sound effect)
var onTable = self.x > 224 && self.x < 1824 && self.y > 866 && self.y < 1866;
if (!self.lastTableHit && onTable) {
LK.getSound('tableHit').play();
}
self.lastTableHit = onTable;
// Scoring
if (self.y < 800 && !ballScored) {
playerScore++;
ballScored = true;
LK.getSound('score').play();
LK.setScore(playerScore);
updateScore();
checkWin();
} else if (self.y > 1932 && !ballScored) {
aiScore++;
ballScored = true;
LK.getSound('score').play();
updateScore();
checkWin();
}
};
return self;
});
var PaddleShop = Container.expand(function () {
var self = Container.call(this);
var shopBg = LK.getAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
self.addChild(shopBg);
var titleText = new Text2('Changer de Raquette', {
size: 80,
fill: 0xffffff
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -400;
self.addChild(titleText);
var paddles = [{
name: 'Base',
asset: 'playerPaddle',
type: 'image'
}, {
name: 'Cute Rose',
asset: 'paddleCute',
type: 'shape'
}, {
name: 'Abeille',
asset: 'paddleBee',
type: 'shape'
}, {
name: 'Pro',
asset: 'paddlePro',
type: 'shape'
}, {
name: 'Mer',
asset: 'paddleSea',
type: 'shape'
}];
self.paddleButtons = [];
for (var i = 0; i < paddles.length; i++) {
var paddleData = paddles[i];
var button = new Container();
var bg = LK.getAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
button.addChild(bg);
var paddlePreview = LK.getAsset(paddleData.asset, {
anchorX: 0.5,
anchorY: 0.5,
y: -20
});
button.addChild(paddlePreview);
var nameText = new Text2(paddleData.name, {
size: 30,
fill: 0xffffff
});
nameText.anchor.set(0.5, 0.5);
nameText.y = 20;
button.addChild(nameText);
button.x = (i % 3 - 1) * 300;
button.y = Math.floor(i / 3) * 200 - 100;
button.paddleAsset = paddleData.asset;
button.paddleType = paddleData.type;
button.down = function (x, y, obj) {
storage.selectedPaddle = this.paddleAsset;
storage.selectedPaddleType = this.paddleType;
updatePlayerPaddle();
self.destroy();
};
self.addChild(button);
self.paddleButtons.push(button);
}
var closeButton = new Container();
var closeBg = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
closeButton.addChild(closeBg);
var closeText = new Text2('Fermer', {
size: 40,
fill: 0xffffff
});
closeText.anchor.set(0.5, 0.5);
closeButton.addChild(closeText);
closeButton.y = 300;
closeButton.down = function () {
self.destroy();
};
self.addChild(closeButton);
return self;
});
var PlayerPaddle = Container.expand(function () {
var self = Container.call(this);
self.paddleGraphics = null;
self.setPaddleAsset = function (assetName) {
if (self.paddleGraphics) {
self.removeChild(self.paddleGraphics);
}
self.paddleGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
};
// Initialize with default or saved paddle
var selectedPaddle = storage.selectedPaddle || 'playerPaddle';
self.setPaddleAsset(selectedPaddle);
return self;
});
var StartButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
// Coins arrondis visuels avec alpha
buttonGraphics.alpha = 0.9;
var buttonText = new Text2('Commencer', {
size: 50,
fill: 0xffffff
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
// Effet de hover/press
self.down = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100
});
tween(buttonGraphics, {
alpha: 0.7
}, {
duration: 100
});
};
self.up = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(buttonGraphics, {
alpha: 0.9
}, {
duration: 100
});
// Démarrer le jeu
startGame();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Variables pour la page d'accueil
// Assets pour la page d'accueil
// Assets du jeu
var isOnHomePage = true;
var gameInitialized = false;
var loadingProgress = 0;
// Variables globales du jeu
var playerScore = 0;
var aiScore = 0;
var ballScored = false;
var gameEnded = false;
var playerLevel = storage.playerLevel || 1;
var pointsToWin = getPointsToWin(playerLevel);
var paddleShop = null;
function getPointsToWin(level) {
if (level < 4) {
return 10;
} else {
return 10 * Math.pow(2, level - 3);
}
}
function updatePlayerPaddle() {
if (playerPaddle) {
var selectedPaddle = storage.selectedPaddle || 'playerPaddle';
playerPaddle.setPaddleAsset(selectedPaddle);
}
}
// Variables pour les éléments du jeu
var table, net, centerLine, playerPaddle, aiPaddle, ball, scoreText, levelText;
// Éléments de la page d'accueil
var homeBackground = game.addChild(LK.getAsset('homeBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Titre du jeu
var titleText = new Text2('PING PONG PRO', {
size: 120,
fill: 0xffffff
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 500;
game.addChild(titleText);
// Barre de progression
var progressBarBg = game.addChild(LK.getAsset('progressBarBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600
}));
var progressBarFill = game.addChild(LK.getAsset('progressBarFill', {
anchorX: 0,
anchorY: 0.5,
x: 724,
// 1024 - 300 (la moitié de la largeur de la barre)
y: 1600
}));
// Texte de progression
var progressText = new Text2('Chargement... 0%', {
size: 40,
fill: 0xffffff
});
progressText.anchor.set(0.5, 0.5);
progressText.x = 1024;
progressText.y = 1700;
game.addChild(progressText);
// Bouton de démarrage (initialement invisible)
var startButton = game.addChild(new StartButton());
startButton.x = 1024;
startButton.y = 1900;
startButton.alpha = 0;
startButton.visible = false;
function updateLoadingProgress() {
loadingProgress += 2; // Augmente de 2% par frame
if (loadingProgress > 100) loadingProgress = 100;
// Mettre à jour la barre de progression
var fillWidth = loadingProgress / 100 * 600;
progressBarFill.width = fillWidth;
// Mettre à jour le texte
progressText.setText('Chargement... ' + Math.floor(loadingProgress) + '%');
// Animation de couleur de la barre
var green = Math.floor(loadingProgress / 100 * 255);
var red = 255 - green;
progressBarFill.tint = red << 16 | green << 8 | 0;
// Quand le chargement est terminé
if (loadingProgress >= 100) {
// Animation du bouton qui pulse
var _pulseButton = function pulseButton() {
tween(startButton, {
scaleX: 1.05,
scaleY: 1.05
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(startButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: _pulseButton
});
}
});
};
// Cacher le texte de progression
progressText.alpha = 0;
// Afficher le bouton avec animation
startButton.visible = true;
tween(startButton, {
alpha: 1
}, {
duration: 500,
easing: tween.easeOut
});
_pulseButton();
}
}
function startGame() {
if (gameInitialized) return;
isOnHomePage = false;
gameInitialized = true;
// Cacher tous les éléments de la page d'accueil avec animation
tween(homeBackground, {
alpha: 0
}, {
duration: 500
});
tween(titleText, {
alpha: 0
}, {
duration: 500
});
tween(progressBarBg, {
alpha: 0
}, {
duration: 500
});
tween(progressBarFill, {
alpha: 0
}, {
duration: 500
});
tween(startButton, {
alpha: 0
}, {
duration: 500
});
// Attendre la fin de l'animation avant de créer les éléments du jeu
LK.setTimeout(function () {
// Supprimer les éléments de la page d'accueil
game.removeChild(homeBackground);
game.removeChild(titleText);
game.removeChild(progressBarBg);
game.removeChild(progressBarFill);
game.removeChild(startButton);
// Créer les éléments du jeu
initializeGameElements();
// Démarrer la musique
LK.playMusic('bgMusic');
}, 500);
}
function initializeGameElements() {
// Create table
table = game.addChild(LK.getAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create net
net = game.addChild(LK.getAsset('net', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create center line
centerLine = game.addChild(LK.getAsset('centerLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create paddles
playerPaddle = game.addChild(new PlayerPaddle());
playerPaddle.x = 1024;
playerPaddle.y = 1800;
aiPaddle = game.addChild(new AIPaddle());
aiPaddle.x = 1024;
aiPaddle.y = 932;
// Create ball
ball = game.addChild(new Ball());
ball.reset();
// Create score display
scoreText = new Text2('Player: 0 - AI: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create level display
levelText = new Text2('Level: ' + playerLevel, {
size: 60,
fill: 0xFFD700
});
levelText.anchor.set(0.5, 0);
levelText.y = 90;
LK.gui.top.addChild(levelText);
// Create shop button
var shopButton = new Container();
var shopBg = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
shopButton.addChild(shopBg);
var shopText = new Text2('Changer de raquette', {
size: 30,
fill: 0xffffff
});
shopText.anchor.set(0.5, 0.5);
shopButton.addChild(shopText);
shopButton.x = 1024;
shopButton.y = 200;
shopButton.down = function () {
if (!paddleShop) {
paddleShop = game.addChild(new PaddleShop());
paddleShop.x = 1024;
paddleShop.y = 1366;
}
};
game.addChild(shopButton);
}
function updateScore() {
if (scoreText) {
scoreText.setText('Player: ' + playerScore + '/' + pointsToWin + ' - AI: ' + aiScore + '/' + pointsToWin);
levelText.setText('Level: ' + playerLevel);
}
}
function checkWin() {
if (playerScore >= pointsToWin && !gameEnded) {
gameEnded = true;
playerLevel++;
storage.playerLevel = playerLevel;
pointsToWin = getPointsToWin(playerLevel);
LK.showYouWin();
} else if (aiScore >= pointsToWin && !gameEnded) {
gameEnded = true;
playerLevel = 1;
storage.playerLevel = playerLevel;
pointsToWin = getPointsToWin(playerLevel);
LK.showGameOver();
} else {
// Reset ball for next point
LK.setTimeout(function () {
ball.reset();
ballScored = false;
}, 1000);
}
}
// Touch controls for player paddle
var isDragging = false;
game.down = function (x, y, obj) {
if (playerPaddle) {
isDragging = true;
playerPaddle.x = Math.max(374, Math.min(1674, x));
}
};
game.move = function (x, y, obj) {
if (isDragging && playerPaddle) {
playerPaddle.x = Math.max(374, Math.min(1674, x));
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
game.update = function () {
if (isOnHomePage) {
// Logique de la page d'accueil
if (loadingProgress < 100) {
updateLoadingProgress();
}
} else if (gameInitialized && !gameEnded) {
// Logique du jeu
if (ball && ball.y < 700 || ball && ball.y > 2032) {
if (!ballScored) {
if (ball.y < 700) {
playerScore++;
LK.setScore(playerScore);
} else {
aiScore++;
}
ballScored = true;
LK.getSound('score').play();
updateScore();
checkWin();
}
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AIPaddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('aiPaddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 1024;
self.baseSpeed = 4;
self.update = function () {
// AI follows ball with increasing difficulty
var difficulty = Math.min(1 + (playerScore + aiScore) * 0.1, 3);
var speed = self.baseSpeed * difficulty;
if (ball.velocityY < 0) {
self.targetX = ball.x + ball.velocityX * 30;
} else {
self.targetX = 1024;
}
self.targetX = Math.max(374, Math.min(1674, self.targetX));
if (Math.abs(self.x - self.targetX) > speed) {
if (self.x < self.targetX) {
self.x += speed;
} else {
self.x -= speed;
}
} else {
self.x = self.targetX;
}
};
return self;
});
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.lastPlayerHit = false;
self.lastAIHit = false;
self.lastTableHit = false;
self.reset = function () {
self.x = 1024;
self.y = 1366;
self.velocityX = Math.random() > 0.5 ? self.speed : -self.speed;
self.velocityY = Math.random() > 0.5 ? self.speed * 0.7 : -self.speed * 0.7;
self.lastPlayerHit = false;
self.lastAIHit = false;
self.lastTableHit = false;
};
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
// Ball vs table bounds
if (self.x <= 224 || self.x >= 1824) {
self.velocityX = -self.velocityX;
}
// Ball vs player paddle collision
var currentPlayerHit = self.intersects(playerPaddle);
if (!self.lastPlayerHit && currentPlayerHit) {
self.velocityY = -Math.abs(self.velocityY);
self.velocityX += (self.x - playerPaddle.x) * 0.1;
LK.getSound('paddleHit').play();
}
self.lastPlayerHit = currentPlayerHit;
// Ball vs AI paddle collision
var currentAIHit = self.intersects(aiPaddle);
if (!self.lastAIHit && currentAIHit) {
self.velocityY = Math.abs(self.velocityY);
self.velocityX += (self.x - aiPaddle.x) * 0.1;
LK.getSound('paddleHit').play();
}
self.lastAIHit = currentAIHit;
// Ball vs table collision (sound effect)
var onTable = self.x > 224 && self.x < 1824 && self.y > 866 && self.y < 1866;
if (!self.lastTableHit && onTable) {
LK.getSound('tableHit').play();
}
self.lastTableHit = onTable;
// Scoring
if (self.y < 800 && !ballScored) {
playerScore++;
ballScored = true;
LK.getSound('score').play();
LK.setScore(playerScore);
updateScore();
checkWin();
} else if (self.y > 1932 && !ballScored) {
aiScore++;
ballScored = true;
LK.getSound('score').play();
updateScore();
checkWin();
}
};
return self;
});
var PaddleShop = Container.expand(function () {
var self = Container.call(this);
var shopBg = LK.getAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
self.addChild(shopBg);
var titleText = new Text2('Changer de Raquette', {
size: 80,
fill: 0xffffff
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -400;
self.addChild(titleText);
var paddles = [{
name: 'Base',
asset: 'playerPaddle',
type: 'image'
}, {
name: 'Cute Rose',
asset: 'paddleCute',
type: 'shape'
}, {
name: 'Abeille',
asset: 'paddleBee',
type: 'shape'
}, {
name: 'Pro',
asset: 'paddlePro',
type: 'shape'
}, {
name: 'Mer',
asset: 'paddleSea',
type: 'shape'
}];
self.paddleButtons = [];
for (var i = 0; i < paddles.length; i++) {
var paddleData = paddles[i];
var button = new Container();
var bg = LK.getAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
button.addChild(bg);
var paddlePreview = LK.getAsset(paddleData.asset, {
anchorX: 0.5,
anchorY: 0.5,
y: -20
});
button.addChild(paddlePreview);
var nameText = new Text2(paddleData.name, {
size: 30,
fill: 0xffffff
});
nameText.anchor.set(0.5, 0.5);
nameText.y = 20;
button.addChild(nameText);
button.x = (i % 3 - 1) * 300;
button.y = Math.floor(i / 3) * 200 - 100;
button.paddleAsset = paddleData.asset;
button.paddleType = paddleData.type;
button.down = function (x, y, obj) {
storage.selectedPaddle = this.paddleAsset;
storage.selectedPaddleType = this.paddleType;
updatePlayerPaddle();
self.destroy();
};
self.addChild(button);
self.paddleButtons.push(button);
}
var closeButton = new Container();
var closeBg = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
closeButton.addChild(closeBg);
var closeText = new Text2('Fermer', {
size: 40,
fill: 0xffffff
});
closeText.anchor.set(0.5, 0.5);
closeButton.addChild(closeText);
closeButton.y = 300;
closeButton.down = function () {
self.destroy();
};
self.addChild(closeButton);
return self;
});
var PlayerPaddle = Container.expand(function () {
var self = Container.call(this);
self.paddleGraphics = null;
self.setPaddleAsset = function (assetName) {
if (self.paddleGraphics) {
self.removeChild(self.paddleGraphics);
}
self.paddleGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
};
// Initialize with default or saved paddle
var selectedPaddle = storage.selectedPaddle || 'playerPaddle';
self.setPaddleAsset(selectedPaddle);
return self;
});
var StartButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
// Coins arrondis visuels avec alpha
buttonGraphics.alpha = 0.9;
var buttonText = new Text2('Commencer', {
size: 50,
fill: 0xffffff
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
// Effet de hover/press
self.down = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100
});
tween(buttonGraphics, {
alpha: 0.7
}, {
duration: 100
});
};
self.up = function (x, y, obj) {
tween(buttonGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(buttonGraphics, {
alpha: 0.9
}, {
duration: 100
});
// Démarrer le jeu
startGame();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Variables pour la page d'accueil
// Assets pour la page d'accueil
// Assets du jeu
var isOnHomePage = true;
var gameInitialized = false;
var loadingProgress = 0;
// Variables globales du jeu
var playerScore = 0;
var aiScore = 0;
var ballScored = false;
var gameEnded = false;
var playerLevel = storage.playerLevel || 1;
var pointsToWin = getPointsToWin(playerLevel);
var paddleShop = null;
function getPointsToWin(level) {
if (level < 4) {
return 10;
} else {
return 10 * Math.pow(2, level - 3);
}
}
function updatePlayerPaddle() {
if (playerPaddle) {
var selectedPaddle = storage.selectedPaddle || 'playerPaddle';
playerPaddle.setPaddleAsset(selectedPaddle);
}
}
// Variables pour les éléments du jeu
var table, net, centerLine, playerPaddle, aiPaddle, ball, scoreText, levelText;
// Éléments de la page d'accueil
var homeBackground = game.addChild(LK.getAsset('homeBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Titre du jeu
var titleText = new Text2('PING PONG PRO', {
size: 120,
fill: 0xffffff
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 500;
game.addChild(titleText);
// Barre de progression
var progressBarBg = game.addChild(LK.getAsset('progressBarBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600
}));
var progressBarFill = game.addChild(LK.getAsset('progressBarFill', {
anchorX: 0,
anchorY: 0.5,
x: 724,
// 1024 - 300 (la moitié de la largeur de la barre)
y: 1600
}));
// Texte de progression
var progressText = new Text2('Chargement... 0%', {
size: 40,
fill: 0xffffff
});
progressText.anchor.set(0.5, 0.5);
progressText.x = 1024;
progressText.y = 1700;
game.addChild(progressText);
// Bouton de démarrage (initialement invisible)
var startButton = game.addChild(new StartButton());
startButton.x = 1024;
startButton.y = 1900;
startButton.alpha = 0;
startButton.visible = false;
function updateLoadingProgress() {
loadingProgress += 2; // Augmente de 2% par frame
if (loadingProgress > 100) loadingProgress = 100;
// Mettre à jour la barre de progression
var fillWidth = loadingProgress / 100 * 600;
progressBarFill.width = fillWidth;
// Mettre à jour le texte
progressText.setText('Chargement... ' + Math.floor(loadingProgress) + '%');
// Animation de couleur de la barre
var green = Math.floor(loadingProgress / 100 * 255);
var red = 255 - green;
progressBarFill.tint = red << 16 | green << 8 | 0;
// Quand le chargement est terminé
if (loadingProgress >= 100) {
// Animation du bouton qui pulse
var _pulseButton = function pulseButton() {
tween(startButton, {
scaleX: 1.05,
scaleY: 1.05
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(startButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: _pulseButton
});
}
});
};
// Cacher le texte de progression
progressText.alpha = 0;
// Afficher le bouton avec animation
startButton.visible = true;
tween(startButton, {
alpha: 1
}, {
duration: 500,
easing: tween.easeOut
});
_pulseButton();
}
}
function startGame() {
if (gameInitialized) return;
isOnHomePage = false;
gameInitialized = true;
// Cacher tous les éléments de la page d'accueil avec animation
tween(homeBackground, {
alpha: 0
}, {
duration: 500
});
tween(titleText, {
alpha: 0
}, {
duration: 500
});
tween(progressBarBg, {
alpha: 0
}, {
duration: 500
});
tween(progressBarFill, {
alpha: 0
}, {
duration: 500
});
tween(startButton, {
alpha: 0
}, {
duration: 500
});
// Attendre la fin de l'animation avant de créer les éléments du jeu
LK.setTimeout(function () {
// Supprimer les éléments de la page d'accueil
game.removeChild(homeBackground);
game.removeChild(titleText);
game.removeChild(progressBarBg);
game.removeChild(progressBarFill);
game.removeChild(startButton);
// Créer les éléments du jeu
initializeGameElements();
// Démarrer la musique
LK.playMusic('bgMusic');
}, 500);
}
function initializeGameElements() {
// Create table
table = game.addChild(LK.getAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create net
net = game.addChild(LK.getAsset('net', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create center line
centerLine = game.addChild(LK.getAsset('centerLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create paddles
playerPaddle = game.addChild(new PlayerPaddle());
playerPaddle.x = 1024;
playerPaddle.y = 1800;
aiPaddle = game.addChild(new AIPaddle());
aiPaddle.x = 1024;
aiPaddle.y = 932;
// Create ball
ball = game.addChild(new Ball());
ball.reset();
// Create score display
scoreText = new Text2('Player: 0 - AI: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create level display
levelText = new Text2('Level: ' + playerLevel, {
size: 60,
fill: 0xFFD700
});
levelText.anchor.set(0.5, 0);
levelText.y = 90;
LK.gui.top.addChild(levelText);
// Create shop button
var shopButton = new Container();
var shopBg = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
shopButton.addChild(shopBg);
var shopText = new Text2('Changer de raquette', {
size: 30,
fill: 0xffffff
});
shopText.anchor.set(0.5, 0.5);
shopButton.addChild(shopText);
shopButton.x = 1024;
shopButton.y = 200;
shopButton.down = function () {
if (!paddleShop) {
paddleShop = game.addChild(new PaddleShop());
paddleShop.x = 1024;
paddleShop.y = 1366;
}
};
game.addChild(shopButton);
}
function updateScore() {
if (scoreText) {
scoreText.setText('Player: ' + playerScore + '/' + pointsToWin + ' - AI: ' + aiScore + '/' + pointsToWin);
levelText.setText('Level: ' + playerLevel);
}
}
function checkWin() {
if (playerScore >= pointsToWin && !gameEnded) {
gameEnded = true;
playerLevel++;
storage.playerLevel = playerLevel;
pointsToWin = getPointsToWin(playerLevel);
LK.showYouWin();
} else if (aiScore >= pointsToWin && !gameEnded) {
gameEnded = true;
playerLevel = 1;
storage.playerLevel = playerLevel;
pointsToWin = getPointsToWin(playerLevel);
LK.showGameOver();
} else {
// Reset ball for next point
LK.setTimeout(function () {
ball.reset();
ballScored = false;
}, 1000);
}
}
// Touch controls for player paddle
var isDragging = false;
game.down = function (x, y, obj) {
if (playerPaddle) {
isDragging = true;
playerPaddle.x = Math.max(374, Math.min(1674, x));
}
};
game.move = function (x, y, obj) {
if (isDragging && playerPaddle) {
playerPaddle.x = Math.max(374, Math.min(1674, x));
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
game.update = function () {
if (isOnHomePage) {
// Logique de la page d'accueil
if (loadingProgress < 100) {
updateLoadingProgress();
}
} else if (gameInitialized && !gameEnded) {
// Logique du jeu
if (ball && ball.y < 700 || ball && ball.y > 2032) {
if (!ballScored) {
if (ball.y < 700) {
playerScore++;
LK.setScore(playerScore);
} else {
aiScore++;
}
ballScored = true;
LK.getSound('score').play();
updateScore();
checkWin();
}
}
}
};
Raquette de ping pong ia. In-Game asset. 2d. High contrast. No shadows
Balle de ping pong. In-Game asset. 2d. High contrast. No shadows
Fond d'écran manga ping pong. In-Game asset. 2d. High contrast. No shadows
Raquette aux designs dabeilles. In-Game asset. 2d. High contrast. No shadows
Raquette rose cute. In-Game asset. 2d. High contrast. No shadows
Raquette ocean. In-Game asset. 2d. High contrast. No shadows
Raquette professionnelle. In-Game asset. 2d. High contrast. No shadows