Ajoute le feu d'artifice et améliore le mobile

This commit is contained in:
Clément 2021-01-08 16:47:14 +01:00
parent 80336d2efb
commit 78ac5a26cf
3 changed files with 59 additions and 17 deletions

BIN
img/blue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
img/red.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -1,6 +1,6 @@
let width = window.innerWidth;
let width = window.innerWidth * window.devicePixelRatio; let height = window.innerHeight;
let height = window.innerHeight * window.devicePixelRatio; let ratio = window.devicePixelRatio;
let config = { let config = {
title: "Happy 2021!", title: "Happy 2021!",
url: "http://shikiryu.ovh/new_year_2021", url: "http://shikiryu.ovh/new_year_2021",
@ -31,15 +31,14 @@ let colors = ['bleu', 'rouge', 'vert'];
function preload() { function preload() {
that = this; that = this;
this.scale.scaleMode = Phaser.Scale.ScaleManager.SHOW_ALL;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
this.load.audio('shoot', ['sound/shoot.ogg', 'sound/shoot.mp3']); this.load.audio('shoot', ['sound/shoot.ogg', 'sound/shoot.mp3']);
this.load.audio('win', ['sound/win.ogg', 'sound/win.mp3']); this.load.audio('win', ['sound/win.ogg', 'sound/win.mp3']);
this.load.image('target', 'img/target.png'); this.load.image('target', 'img/target.png');
this.load.image('bleu', 'img/virus-bleu.png'); this.load.image('bleu', 'img/virus-bleu.png');
this.load.image('rouge', 'img/virus-rouge.png'); this.load.image('rouge', 'img/virus-rouge.png');
this.load.image('vert', 'img/virus-vert.png'); this.load.image('vert', 'img/virus-vert.png');
this.load.image('spark0', 'img/blue.png');
this.load.image('spark1', 'img/red.png');
} }
function killVirus(player, virus) { function killVirus(player, virus) {
@ -48,6 +47,49 @@ function killVirus(player, virus) {
enemiesText.setText('virus restant : ' + enemiesCount); enemiesText.setText('virus restant : ' + enemiesCount);
if (enemiesCount === 0) { if (enemiesCount === 0) {
enemiesText.visible = false; enemiesText.visible = false;
let p0 = new Phaser.Math.Vector2(width/2 - 300, height / 2);
let p1 = new Phaser.Math.Vector2(width/2 - 300, 200);
let p2 = new Phaser.Math.Vector2(width/2 + 300, 200);
let p3 = new Phaser.Math.Vector2(width/2 + 300, height / 2);
let curve = new Phaser.Curves.CubicBezier(p0, p1, p2, p3);
let max = 28;
let points = [];
let tangents = [];
for (let c = 0; c <= max; c++) {
let t = curve.getUtoTmapping(c / max);
points.push(curve.getPoint(t));
tangents.push(curve.getTangent(t));
}
let tempVec = new Phaser.Math.Vector2();
let spark0 = that.add.particles('spark0');
let spark1 = that.add.particles('spark1');
for (let i = 0; i < points.length; i++) {
let p = points[i];
tempVec.copy(tangents[i]).normalizeRightHand().scale(-32).add(p);
let angle = Phaser.Math.RadToDeg(Phaser.Math.Angle.BetweenPoints(p, tempVec));
let particles = (i % 2 === 0) ? spark0 : spark1;
particles.createEmitter({
x: tempVec.x,
y: tempVec.y,
angle: angle,
speed: {min: -100, max: 500},
gravityY: 200,
scale: {start: 0.4, end: 0.1},
lifespan: 800,
blendMode: 'SCREEN'
});
}
that.add.text(width / 2 - 200, height / 2 - 50, 'Bonne annnée 2021 !', {fontSize: '32px', fill: '#000'}); that.add.text(width / 2 - 200, height / 2 - 50, 'Bonne annnée 2021 !', {fontSize: '32px', fill: '#000'});
that.add.text(width / 2 - 50, height / 2, 'Si possible, sans virus', {fontSize: '14px', fill: '#000'}); that.add.text(width / 2 - 50, height / 2, 'Si possible, sans virus', {fontSize: '14px', fill: '#000'});
win.play(); win.play();
@ -75,7 +117,7 @@ function create() {
} }
); );
rect = Phaser.Geom.Rectangle.Clone(this.cameras.main); rect = new Phaser.Geom.Rectangle(0, 0, width, height);
target = this.add.image(400, 300, 'target'); target = this.add.image(400, 300, 'target');
@ -96,8 +138,8 @@ function create() {
let virusY = virus.y; let virusY = virus.y;
if ( if (
virus.visible && virus.visible &&
pointerX >= virusX - 94 && pointerX <= virusX + 94 && pointerX >= virusX - 94 / ratio && pointerX <= virusX + 94 / ratio &&
pointerY >= virusY - 94 && pointerY <= virusY + 94 pointerY >= virusY - 94 / ratio && pointerY <= virusY + 94 / ratio
) { ) {
killVirus(null, virus); killVirus(null, virus);
break; break;
@ -133,5 +175,5 @@ function update() {
}); });
Phaser.Actions.WrapInRectangle(viruses, rect, 72); Phaser.Actions.WrapInRectangle(viruses, rect);
} }