const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'game-container',
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
const game = new Phaser.Game(config);
let frog;
let cursors;
let food = 3;
let lives = 3;
let foodTimer;
let foodDecreaseRate = 10000; // 10 secondes
let tongue;
let monsters = [];
let mosquitoes = [];
let lilyPads = [];
let gameOver = false;
let gameOverText;
let restartBtn;
let foodText;
let livesText;
function preload() {
// Charger les assets
this.load.image('frog', 'assets/frog.png');
this.load.image('crown', 'assets/crown.png');
this.load.image('lily_pad', 'assets/lily_pad.png');
this.load.image('mosquito', 'assets/mosquito.png');
this.load.image('tentacle', 'assets/tentacle.png');
this.load.image('crab_claw', 'assets/crab_claw.png');
this.load.image('squid', 'assets/squid.png');
this.load.image('river_background', 'assets/river_background.png');
}
function create() {
// Créer le fond
this.add.image(400, 300, 'river_background');
// Créer la grenouille
frog = this.physics.add.sprite(100, 500, 'frog');
frog.setCollideWorldBounds(true);
frog.setBounce(0.1);
frog.setDepth(10);
// Ajouter la couronne
const crown = this.add.image(frog.x, frog.y - 20, 'crown');
crown.setDepth(11);
frog.crown = crown;
// Créer la langue (invisible au début)
tongue = this.add.graphics();
tongue.setDepth(9);
// Créer les nénuphars
for (let i = 0; i < 5; i++) {
const lilyPad = this.physics.add.staticImage(
Phaser.Math.Between(800, 1200),
570,
'lily_pad'
);
lilyPads.push(lilyPad);
}
// Créer des moustiques
for (let i = 0; i < 10; i++) {
const mosquito = this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
Phaser.Math.Between(100, 500),
'mosquito'
);
mosquitoes.push(mosquito);
}
// Créer des monstres marins
for (let i = 0; i < 5; i++) {
const monster = this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
Phaser.Math.Between(100, 500),
Phaser.Math.RND.pick(['tentacle', 'crab_claw', 'squid'])
);
monsters.push(monster);
}
// Configurer les collisions
this.physics.add.collider(frog, lilyPads, () => {
frog.setVelocityY(-150); // Sauter plus haut si sur un nénuphar
});
// Configurer les monstres pour qu'ils bougent
monsters.forEach(monster => {
monster.setVelocityX(-Phaser.Math.FloatBetween(50, 150));
monster.setCollideWorldBounds(true);
monster.setBounce(0.5);
});
// Configurer les moustiques
mosquitoes.forEach(mosquito => {
mosquito.setVelocityX(-Phaser.Math.FloatBetween(50, 100));
mosquito.setCollideWorldBounds(true);
mosquito.setBounce(0.2);
});
// Configurer les contrôles
cursors = this.input.keyboard.createCursorKeys();
this.input.keyboard.on('keydown-A', () => useTongue('whirl'));
this.input.keyboard.on('keydown-Z', () => useTongue('catch'));
this.input.keyboard.on('keydown-E', () => useTongue('avoid'));
// Timer pour la nourriture
foodTimer = this.time.addEvent({
delay: foodDecreaseRate,
callback: decreaseFood,
loop: true
});
// Afficher le score
foodText = document.getElementById('food');
livesText = document.getElementById('lives');
// Game Over
gameOverText = document.getElementById('game-over');
restartBtn = document.getElementById('restart-btn');
restartBtn.addEventListener('click', restartGame);
}
function update() {
if (gameOver) return;
// Déplacer la grenouille
frog.setVelocityX(0);
if (cursors.left.isDown) {
frog.setVelocityX(-200);
frog.flipX = true;
} else if (cursors.right.isDown) {
frog.setVelocityX(200);
frog.flipX = false;
}
// Sauter
if ((cursors.up.isDown || cursors.space.isDown) && frog.body.blocked.down) {
frog.setVelocityY(-250);
}
// Défilement du fond (simplifié)
lilyPads.forEach(lilyPad => {
lilyPad.x -= 2;
if (lilyPad.x < -100) {
lilyPad.x = 800 + Phaser.Math.Between(0, 200);
}
});
monsters.forEach(monster => {
monster.x -= 2;
if (monster.x < -100) {
monster.x = 800 + Phaser.Math.Between(0, 500);
monster.setVelocityX(-Phaser.Math.FloatBetween(50, 150));
}
});
mosquitoes.forEach(mosquito => {
mosquito.x -= 2;
if (mosquito.x < -100) {
mosquito.x = 800 + Phaser.Math.Between(0, 500);
mosquito.setVelocityX(-Phaser.Math.FloatBetween(50, 100));
}
});
// Vérifier les collisions avec les monstres
monsters.forEach(monster => {
if (Phaser.Geom.Intersects.RectangleToRectangle(frog.getBounds(), monster.getBounds())) {
if (!frog.isInvulnerable) {
lives--;
livesText.textContent = lives;
frog.isInvulnerable = true;
frog.setTint(0xff0000);
this.time.delayedCall(1000, () => {
frog.clearTint();
frog.isInvulnerable = false;
});
if (lives <= 0) {
gameOver = true;
gameOverText.style.display = 'block';
}
}
}
});
// Vérifier si la grenouille attrape un moustique
mosquitoes.forEach((mosquito, index) => {
if (Phaser.Geom.Intersects.RectangleToRectangle(frog.getBounds(), mosquito.getBounds())) {
food = Math.min(3, food + 1);
foodText.textContent = food;
mosquitoes.splice(index, 1);
mosquitoes.push(this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
Phaser.Math.Between(100, 500),
'mosquito'
));
}
});
}
// Fonction pour utiliser la langue
function useTongue(type) {
if (gameOver) return;
tongue.clear();
if (type === 'whirl') {
// Tourbillon
this.tweens.add({
targets: frog,
angle: 360,
duration: 1000,
repeat: -1,
ease: 'Linear'
});
} else if (type === 'catch') {
// Attraper un moustique
const closestMosquito = Phaser.Math.Distance.BetweenPoints(
frog,
mosquitoes.reduce((a, b) => Phaser.Math.Distance.BetweenPoints(frog, a) < Phaser.Math.Distance.BetweenPoints(frog, b) ? a : b)
);
tongue.lineStyle(3, 0xffff00);
tongue.lineBetween(
frog.x,
frog.y,
closestMosquito.x,
closestMosquito.y
);
} else if (type === 'avoid') {
// Éviter un monstre
const closestMonster = monsters.reduce((a, b) => Phaser.Math.Distance.BetweenPoints(frog, a) < Phaser.Math.Distance.BetweenPoints(frog, b) ? a : b);
frog.x = closestMonster.x + 100;
}
}
// Diminuer la nourriture
function decreaseFood() {
if (gameOver) return;
food--;
foodText.textContent = food;
if (food <= 0) {
gameOver = true;
gameOverText.style.display = 'block';
}
}
// Recommencer le jeu
function restartGame() {
food = 3;
lives = 3;
foodText.textContent = food;
livesText.textContent = lives;
gameOverText.style.display = 'none';
gameOver = false;
// Réinitialiser la grenouille
frog.setPosition(100, 500);
frog.setVelocity(0, 0);
frog.clearTint();
frog.angle = 0;
}
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'game-container',
physics: {
default: 'arcade',
arcade: {
gravity: { y: 500 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
const game = new Phaser.Game(config);
let frog;
let cursors;
let food = 3;
let lives = 3;
let foodTimer;
let foodDecreaseRate = 10000; // 10 secondes
let monsters = [];
let mosquitoes = [];
let lilyPads = [];
let gameOver = false;
let tongue;
let waterParticles;
let bubbles;
let soundJump, soundTongue, soundEat, soundSplash, soundGameOver;
// Pré-chargement des assets
function preload() {
// Sprites de la grenouille (animations)
this.load.atlas('frog', 'assets/sprites/frog/frog.png', 'assets/sprites/frog/frog.json');
// Couronne
this.load.image('crown', 'assets/sprites/crown.png');
// Nénuphars
this.load.image('lily_pad', 'assets/sprites/lily_pad.png');
// Moustiques
this.load.image('mosquito', 'assets/sprites/mosquito.png');
// Monstres
this.load.image('tentacle', 'assets/sprites/monsters/tentacle.png');
this.load.image('crab_claw', 'assets/sprites/monsters/crab_claw.png');
this.load.image('squid', 'assets/sprites/monsters/squid.png');
// Arrière-plan (tile)
this.load.image('water_tile', 'assets/river/water.png');
// Particules
this.load.image('splash', 'assets/particles/splash.png');
this.load.image('bubble', 'assets/particles/bubble.png');
// Sons
this.load.audio('jump', 'assets/sounds/jump.wav');
this.load.audio('tongue', 'assets/sounds/tongue.wav');
this.load.audio('eat', 'assets/sounds/eat.wav');
this.load.audio('splash', 'assets/sounds/splash.wav');
this.load.audio('game_over', 'assets/sounds/game_over.wav');
}
function create() {
// Créer un arrière-plan avec tile
const water = this.add.tileSprite(0, 0, 800, 600, 'water_tile');
water.setOrigin(0, 0);
// Créer la grenouille avec animations
frog = this.physics.add.sprite(100, 500, 'frog');
frog.setCollideWorldBounds(true);
frog.setBounce(0.1);
frog.setSize(30, 40); // Ajustement de la hitbox
// Animations de la grenouille
this.anims.create({
key: 'idle',
frames: this.anims.generateFrameNames('frog', { prefix: 'idle_', start: 0, end: 3 }),
frameRate: 5,
repeat: -1
});
this.anims.create({
key: 'walk',
frames: this.anims.generateFrameNames('frog', { prefix: 'walk_', start: 0, end: 3 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'jump',
frames: this.anims.generateFrameNames('frog', { prefix: 'jump_', start: 0, end: 1 }),
frameRate: 5,
repeat: 0
});
frog.play('idle');
// Ajouter la couronne
const crown = this.add.image(frog.x, frog.y - 30, 'crown');
crown.setDepth(11);
// Créer la langue (invisible au début)
tongue = this.add.graphics();
tongue.setDepth(9);
// Particules d'eau
waterParticles = this.add.particles('splash');
const waterEmitter = waterParticles.createEmitter({
speed: 50,
scale: { start: 0.5, end: 0 },
alpha: { start: 1, end: 0 },
lifespan: 500,
blendMode: 'ADD',
emitting: false
});
// Bulles
bubbles = this.add.particles('bubble');
const bubbleEmitter = bubbles.createEmitter({
speed: 20,
scale: { start: 0.3, end: 0 },
alpha: { start: 0.8, end: 0 },
lifespan: 1500,
blendMode: 'ADD',
emitting: false
});
// Créer des nénuphars
for (let i = 0; i < 5; i++) {
const lilyPad = this.physics.add.staticImage(
Phaser.Math.Between(800, 1200),
570,
'lily_pad'
);
lilyPads.push(lilyPad);
}
// Créer des moustiques
for (let i = 0; i < 10; i++) {
const mosquito = this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
Phaser.Math.Between(100, 500),
'mosquito'
);
mosquitoes.push(mosquito);
}
// Créer des monstres marins
for (let i = 0; i < 5; i++) {
const monster = this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
Phaser.Math.Between(100, 500),
Phaser.Math.RND.pick(['tentacle', 'crab_claw', 'squid'])
);
monster.setDepth(5); // Monsters behind water
monsters.push(monster);
}
// Configurer les collisions
this.physics.add.collider(frog, lilyPads, () => {
frog.setVelocityY(-250); // Saut plus haut sur un nénuphar
playSound('splash');
waterEmitter.explode(20, frog.x, frog.y + 20);
});
// Configurer les monstres pour qu'ils bougent
monsters.forEach(monster => {
monster.setVelocityX(-Phaser.Math.FloatBetween(50, 150));
monster.setCollideWorldBounds(true);
monster.setBounce(0.3);
monster.setDepth(5);
});
// Configurer les moustiques
mosquitoes.forEach(mosquito => {
mosquito.setVelocityX(-Phaser.Math.FloatBetween(50, 100));
mosquito.setCollideWorldBounds(true);
mosquito.setBounce(0.2);
});
// Configurer les contrôles
cursors = this.input.keyboard.createCursorKeys();
this.input.keyboard.on('keydown-A', () => useTongue('whirl'));
this.input.keyboard.on('keydown-Z', () => useTongue('catch'));
this.input.keyboard.on('keydown-E', () => useTongue('avoid'));
// Timer pour la nourriture
foodTimer = this.time.addEvent({
delay: foodDecreaseRate,
callback: decreaseFood,
loop: true
});
// Sons
soundJump = this.sound.add('jump');
soundTongue = this.sound.add('tongue');
soundEat = this.sound.add('eat');
soundSplash = this.sound.add('splash');
soundGameOver = this.sound.add('game_over');
// Game Over
document.getElementById('restart-btn').addEventListener('click', restartGame);
}
function update() {
if (gameOver) return;
// Déplacer la grenouille
frog.setVelocityX(0);
if (cursors.left.isDown) {
frog.setVelocityX(-200);
frog.flipX = true;
frog.play('walk', true);
} else if (cursors.right.isDown) {
frog.setVelocityX(200);
frog.flipX = false;
frog.play('walk', true);
} else {
frog.play('idle', true);
}
// Sauter
if ((cursors.up.isDown || cursors.space.isDown) && frog.body.blocked.down) {
frog.setVelocityY(-250);
frog.play('jump', true);
playSound('jump');
waterEmitter.explode(15, frog.x, frog.y + 20);
}
// Défilement du fond (eau)
water.tilePositionX += 2;
// Défilement des nénuphars et monstres
lilyPads.forEach(lilyPad => {
lilyPad.x -= 2;
if (lilyPad.x < -100) {
lilyPad.x = 800 + Phaser.Math.Between(0, 200);
}
});
monsters.forEach(monster => {
monster.x -= 2;
if (monster.x < -100) {
monster.x = 800 + Phaser.Math.Between(0, 500);
monster.setVelocityX(-Phaser.Math.FloatBetween(50, 150));
}
});
mosquitoes.forEach(mosquito => {
mosquito.x -= 2;
if (mosquito.x < -100) {
mosquito.x = 800 + Phaser.Math.Between(0, 500);
mosquito.setVelocityX(-Phaser.Math.FloatBetween(50, 100));
}
});
// Vérifier les collisions avec les monstres
monsters.forEach(monster => {
if (Phaser.Geom.Intersects.RectangleToRectangle(frog.getBounds(), monster.getBounds())) {
if (!frog.isInvulnerable) {
lives--;
updateLivesUI();
frog.isInvulnerable = true;
frog.setTint(0xff0000);
this.time.delayedCall(1000, () => {
frog.clearTint();
frog.isInvulnerable = false;
});
if (lives <= 0) {
gameOver = true;
playSound('game_over');
document.getElementById('game-over').style.display = 'flex';
}
}
}
});
// Vérifier si la grenouille attrape un moustique
mosquitoes.forEach((mosquito, index) => {
if (Phaser.Geom.Intersects.RectangleToRectangle(frog.getBounds(), mosquito.getBounds())) {
food = Math.min(3, food + 1);
updateFoodUI();
playSound('eat');
mosquitoes.splice(index, 1);
mosquitoes.push(this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
Phaser.Math.Between(100, 500),
'mosquito'
));
}
});
}
// Fonction pour utiliser la langue
function useTongue(type) {
if (gameOver) return;
tongue.clear();
if (type === 'whirl') {
// Tourbillon
playSound('tongue');
this.tweens.add({
targets: frog,
angle: 360,
duration: 1000,
repeat: -1,
ease: 'Linear'
});
} else if (type === 'catch') {
// Attraper un moustique
const closestMosquito = mosquitoes.reduce((a, b) =>
Phaser.Math.Distance.BetweenPoints(frog, a) < Phaser.Math.Distance.BetweenPoints(frog, b) ? a : b
);
tongue.lineStyle(8, 0xffff00);
tongue.lineBetween(frog.x, frog.y, closestMosquito.x, closestMosquito.y);
playSound('tongue');
} else if (type === 'avoid') {
// Éviter un monstre
const closestMonster = monsters.reduce((a, b) =>
Phaser.Math.Distance.BetweenPoints(frog, a) < Phaser.Math.Distance.BetweenPoints(frog, b) ? a : b
);
frog.x = closestMonster.x + 100;
playSound('tongue');
}
}
// Diminuer la nourriture
function decreaseFood() {
if (gameOver) return;
food--;
updateFoodUI();
if (food <= 0) {
gameOver = true;
playSound('game_over');
document.getElementById('game-over').style.display = 'flex';
}
}
// Mettre à jour l'UI de la nourriture
function updateFoodUI() {
const foodItems = document.querySelectorAll('.food-item');
foodItems.forEach((item, index) => {
if (index < food) {
item.style.backgroundImage = "url('assets/ui/food_bar.png')";
item.style.opacity = '1';
} else {
item.style.opacity = '0.3';
}
});
}
// Mettre à jour l'UI des vies
function updateLivesUI() {
const hearts = document.querySelectorAll('.heart');
hearts.forEach((heart, index) => {
if (index < lives) {
heart.style.opacity = '1';
} else {
heart.style.opacity = '0.3';
}
});
}
// Jouer un son
function playSound(key) {
if (config.scene.sound) {
config.scene.sound.play(key);
}
}
// Recommencer le jeu
function restartGame() {
food = 3;
lives = 3;
updateFoodUI();
updateLivesUI();
document.getElementById('game-over').style.display = 'none';
gameOver = false;
// Réinitialiser la grenouille
frog.setPosition(100, 500);
frog.setVelocity(0, 0);
frog.clearTint();
frog.angle = 0;
frog.play('idle');
}
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'game-container',
physics: {
default: 'arcade',
arcade: {
gravity: { y: 800 },
debug: false,
fps: 60
}
},
scene: {
preload: preload,
create: create,
update: update
},
render: {
pixelArt: true, // Anti-aliasing désactivé pour un style rétro
antialias: false
}
};
const game = new Phaser.Game(config);
let frog, cursors, food = 3, lives = 3, gameOver = false;
let monsters = [], mosquitoes = [], lilyPads = [];
let foodTimer, tongue, particles, bubbles, postFX;
let soundJump, soundTongue, soundEat, soundSplash, soundMonsterHit, soundAmbience, soundGameOver;
// Pré-chargement des assets HD
function preload() {
// Sprites de la grenouille (HD)
this.load.atlas('frog', 'assets/sprites/frog/frog.png', 'assets/sprites/frog/frog.json');
// Couronne
this.load.image('crown', 'assets/sprites/crown.png');
// Nénuphars
this.load.image('lily_pad', 'assets/sprites/lily_pad.png');
// Moustiques
this.load.image('mosquito', 'assets/sprites/mosquito.png');
// Monstres (HD)
this.load.atlas('tentacle', 'assets/sprites/monsters/tentacle.png', 'assets/sprites/monsters/tentacle.json');
this.load.atlas('crab_claw', 'assets/sprites/monsters/crab_claw.png', 'assets/sprites/monsters/crab_claw.json');
this.load.atlas('squid', 'assets/sprites/monsters/squid.png', 'assets/sprites/monsters/squid.json');
// Arrière-plan (couches de profondeur)
this.load.image('sky', 'assets/background/sky.png');
this.load.image('depth1', 'assets/background/depth_1.png');
this.load.image('depth2', 'assets/background/depth_2.png');
this.load.image('depth3', 'assets/background/depth_3.png');
this.load.image('water_tile', 'assets/background/river_tile.png');
// Particules (HD)
this.load.image('splash_0', 'assets/particles/splash_0.png');
this.load.image('splash_1', 'assets/particles/splash_1.png');
this.load.image('bubble_0', 'assets/particles/bubble_0.png');
this.load.image('bubble_1', 'assets/particles/bubble_1.png');
// Sons
this.load.audio('ambience', 'assets/sounds/ambience.mp3');
this.load.audio('jump', 'assets/sounds/jump.wav');
this.load.audio('tongue', 'assets/sounds/tongue.wav');
this.load.audio('eat', 'assets/sounds/eat.wav');
this.load.audio('splash', 'assets/sounds/splash.wav');
this.load.audio('monster_hit', 'assets/sounds/monster_hit.wav');
this.load.audio('game_over', 'assets/sounds/game_over.mp3');
}
// Création du jeu (graphismes avancés)
function create() {
// Arrière-plan avec parallaxe
this.add.image(400, 100, 'sky').setDepth(0);
this.add.image(400, 300, 'depth1').setDepth(1);
this.add.image(400, 400, 'depth2').setDepth(2);
this.add.image(400, 500, 'depth3').setDepth(3);
// Tiles de la rivière (défilement)
const water = this.add.tileSprite(0, 550, 800, 50, 'water_tile').setDepth(4);
water.setTileScale(2, 2);
// Effets de lumière (glow)
postFX = this.plugins.get('rexGlowFilterPipeline').add(water, {
distance: 10,
outerStrength: 3,
innerStrength: 0,
glowColor: 0x00aaff,
quality: 0.5
});
// Grenouille avec animations fluides
frog = this.physics.add.sprite(100, 500, 'frog');
frog.setCollideWorldBounds(true);
frog.setBounce(0.2);
frog.setSize(24, 32);
// Animations grenouille (12 FPS)
this.anims.create({
key: 'frog_idle',
frames: this.anims.generateFrameNames('frog', { prefix: 'idle_', start: 0, end: 3 }),
frameRate: 12,
repeat: -1
});
this.anims.create({
key: 'frog_walk',
frames: this.anims.generateFrameNames('frog', { prefix: 'walk_', start: 0, end: 5 }),
frameRate: 12,
repeat: -1
});
this.anims.create({
key: 'frog_jump',
frames: this.anims.generateFrameNames('frog', { prefix: 'jump_', start: 0, end: 2 }),
frameRate: 12,
repeat: 0
});
this.anims.create({
key: 'frog_tongue',
frames: this.anims.generateFrameNames('frog', { prefix: 'tongue_', start: 0, end: 4 }),
frameRate: 12,
repeat: 0
});
this.anims.create({
key: 'frog_hurt',
frames: this.anims.generateFrameNames('frog', { prefix: 'hurt_', start: 0, end: 1 }),
frameRate: 6,
repeat: 0
});
frog.play('frog_idle');
// Couronne (avec effet de brillance)
const crown = this.add.image(frog.x, frog.y - 30, 'crown').setDepth(10);
crown.setPipeline('Light2D'); // Effet de lumière
// Particules (éclaboussures et bulles)
particles = this.add.particles('splash_0');
const splashEmitter = particles.createEmitter({
speed: 100,
scale: { start: 0.8, end: 0 },
alpha: { start: 1, end: 0 },
lifespan: 800,
blendMode: 'ADD',
emitting: false,
frame: ['splash_0', 'splash_1']
});
bubbles = this.add.particles('bubble_0');
const bubbleEmitter = bubbles.createEmitter({
speed: 30,
scale: { start: 0.5, end: 0 },
alpha: { start: 0.8, end: 0 },
lifespan: 1500,
blendMode: 'ADD',
emitting: false,
frame: ['bubble_0', 'bubble_1']
});
// Nénuphars
for (let i = 0; i < 5; i++) {
const lilyPad = this.physics.add.staticImage(
Phaser.Math.Between(800, 1200),
570,
'lily_pad'
).setDepth(5);
lilyPads.push(lilyPad);
}
// Moustiques
for (let i = 0; i < 10; i++) {
const mosquito = this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
Phaser.Math.Between(100, 500),
'mosquito'
).setDepth(6);
mosquitoes.push(mosquito);
}
// Monstres (avec animations)
for (let i = 0; i < 5; i++) {
const monsterType = Phaser.Math.RND.pick(['tentacle', 'crab_claw', 'squid']);
const monster = this.physics.add.sprite(
Phaser.Math.Between(800, 1500),
monsterType === 'squid' ? Phaser.Math.Between(200, 400) : Phaser.Math.Between(400, 500),
monsterType
).setDepth(4);
// Animations par type de monstre
if (monsterType === 'tentacle') {
this.anims.create({
key: 'tentacle_idle',
frames: this.anims.generateFrameNames('tentacle', { prefix: 'idle_', start: 0, end: 4 }),
frameRate: 8,
repeat: -1
});
monster.play('tentacle_idle');
} else if (monsterType === 'crab_claw') {
this.anims.create({
key: 'crab_idle',
frames: this.anims.generateFrameNames('crab_claw', { prefix: 'idle_', start: 0, end: 3 }),
frameRate: 6,
repeat: -1
});
monster.play('crab_idle');
} else {
this.anims.create({
key: 'squid_idle',
frames: this.anims.generateFrameNames('squid', { prefix: 'idle_', start: 0, end: 3 }),
frameRate: 8,
repeat: -1
});
monster.play('squid_idle');
}
monster.setVelocityX(-Phaser.Math.FloatBetween(50, 150));
monster.setCollideWorldBounds(true);
monster.setBounce(0.3);
monsters.push(monster);
}
// Collisions
this.physics.add.collider(frog, lilyPads, () => {
frog.setVelocityY(-300);
playSound('splash');
splashEmitter.explode(20, frog.x, frog.y + 20);
});
// Contrôles
cursors = this.input.keyboard.createCursorKeys();
this.input.keyboard.on('keydown-A', () => useTongue('whirl'));
this.input.keyboard.on('keydown-Z', () => useTongue('catch'));
this.input.keyboard.on('keydown-E', () => useTongue('avoid'));
// Timer nourriture
foodTimer = this.time.addEvent({
delay: 10000,
callback: decreaseFood,
loop: true
});
// Sons
soundAmbience = this.sound.add('ambience', { loop: true, volume: 0.3 });
soundJump = this.sound.add('jump');
soundTongue = this.sound.add('tongue');
soundEat = this.sound.add('eat');
soundSplash = this.sound.add('splash');
soundMonsterHit = this.sound.add('monster_hit');
soundGameOver = this.sound.add('game_over');
soundAmbience.play();
// UI
updateFoodUI();
updateLivesUI();
}
// Mise à jour du jeu
function update() {
if (gameOver) return;
// Déplacement grenouille
frog.setVelocityX(0);
if (cursors.left.isDown) {
frog.setVelocityX(-250);
frog.flipX = true;
frog.play('frog_walk', true);
} else if (cursors.right.isDown) {
frog.setVelocityX(250);
frog.flipX = false;
frog.play('frog_walk', true);
} else {
frog.play('frog_idle', true);
}
// Saut
if ((cursors.up.isDown || cursors.space.isDown) && frog.body.blocked.down) {
frog.setVelocityY(-400);
frog.play('frog_jump', true);
playSound('jump');
splashEmitter.explode(15, frog.x, frog.y + 20);
}
// Défilement arrière-plan
water.tilePositionX += 3;
// Défilement des éléments
lilyPads.forEach(lp => { lp.x -= 3; if (lp.x < -100) lp.x = 800 + Phaser.Math.Between(0, 200); });
monsters.forEach(m => { m.x -= 3; if (m.x < -100) m.x = 800 + Phaser.Math.Between(0, 500); });
mosquitoes.forEach(m => { m.x -= 3; if (m.x < -100) m.x = 800 + Phaser.Math.Between(0, 500); });
// Collisions monstres
monsters.forEach(monster => {
if (Phaser.Geom.Intersects.RectangleToRectangle(frog.getBounds(), monster.getBounds())) {
if (!frog.isInvulnerable) {
lives--;
updateLivesUI();
frog.isInvulnerable = true;
frog.play('frog_hurt');
frog.setTint(0xff0000);
this.time.delayedCall(1000, () => {
frog.clearTint();
frog.isInvulnerable = false;
});
playSound('monster_hit');
if (lives <= 0) {
gameOver = true;
playSound('game_over');
document.getElementById('game-over').style.display = 'flex';
}
}
}
});
// Attraper moustiques
mosquitoes.forEach((m, i) => {
if (Phaser.Geom.Intersects.RectangleToRectangle(frog.getBounds(), m.getBounds())) {
food = Math.min(3, food + 1);
updateFoodUI();
playSound('eat');
mosquitoes.splice(i, 1);
mosquitoes.push(this.physics.add.sprite(
800 + Phaser.Math.Between(0, 500),
Phaser.Math.Between(100, 500),
'mosquito'
).setDepth(6));
}
});
}
// Utilisation de la langue (animations)
function useTongue(type) {
if (gameOver) return;
if (type === 'whirl') {
playSound('tongue');
frog.play('frog_tongue');
this.tweens.add({
targets: frog,
angle: 360,
duration: 1500,
repeat: -1,
ease: 'Linear'
});
} else if (type === 'catch') {
playSound('tongue');
const closestMosquito = mosquitoes.reduce((a, b) =>
Phaser.Math.Distance.BetweenPoints(frog, a) < Phaser.Math.Distance.BetweenPoints(frog, b) ? a : b
);
this.add.line(0, 0, frog.x, frog.y, closestMosquito.x, closestMosquito.y, 0xFFFF00)
.setLineWidth(6)
.setDepth(9);
} else if (type === 'avoid') {
const closestMonster = monsters.reduce((a, b) =>
Phaser.Math.Distance.BetweenPoints(frog, a) < Phaser.Math.Distance.BetweenPoints(frog, b) ? a : b
);
frog.x = closestMonster.x + 100;
playSound('tongue');
}
}
// UI
function updateFoodUI() {
document.querySelectorAll('.food-item').forEach((item, i) => {
item.style.backgroundImage = food > i ? "url('assets/ui/food_bar.png')" : "url('assets/ui/food_bar_empty.png')";
});
}
function updateLivesUI() {
document.querySelectorAll('.heart').forEach((heart, i) => {
heart.src = lives > i ? "assets/ui/heart_full.png" : "assets/ui/heart_empty.png";
});
}
// Sons
function playSound(key) {
if (config.scene.sound) config.scene.sound.play(key);
}
// Game Over
function restartGame() {
food = 3; lives = 3;
updateFoodUI(); updateLivesUI();
document.getElementById('game-over').style.display = 'none';
gameOver = false;
frog.setPosition(100, 500);
frog.setVelocity(0, 0);
frog.clearTint();
frog.play('frog_idle');
}