🎉 Hello world
This commit is contained in:
commit
fe089ed815
22 files changed
+217438
No files matched your search
+127
@@ -0,0 +1,127 @@
|
||||
|
||||
let config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 800,
|
||||
height: 600,
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
update: update
|
||||
}
|
||||
};
|
||||
|
||||
let game = new Phaser.Game(config);
|
||||
|
||||
let that;
|
||||
let shoot;
|
||||
let win;
|
||||
let graphics;
|
||||
let rect;
|
||||
let viruses = [];
|
||||
let target;
|
||||
let maxEnemies = 20;
|
||||
let enemiesCount = maxEnemies;
|
||||
let enemiesText;
|
||||
let colors = ['bleu', 'rouge', 'vert'];
|
||||
|
||||
function preload() {
|
||||
that = this;
|
||||
this.load.audio('shoot', [ 'sound/shoot.ogg', 'sound/shoot.mp3' ]);
|
||||
this.load.audio('win', [ 'sound/win.ogg', 'sound/win.mp3' ]);
|
||||
this.load.image('target', 'img/target.png');
|
||||
this.load.image('bleu', 'img/virus-bleu.png');
|
||||
this.load.image('rouge', 'img/virus-rouge.png');
|
||||
this.load.image('vert', 'img/virus-vert.png');
|
||||
this.load.image('bg', 'img/bg.png');
|
||||
}
|
||||
|
||||
function killVirus(player, virus) {
|
||||
virus.visible = false;
|
||||
--enemiesCount;
|
||||
enemiesText.setText('virus restant : '+enemiesCount);
|
||||
if (enemiesCount === 0) {
|
||||
enemiesText.visible = false;
|
||||
that.add.text(200, 250, 'Bonne annnée 2021 !', { fontSize: '32px', fill: '#000' });
|
||||
that.add.text(250, 300, 'Si possible, sans virus', { fontSize: '14px', fill: '#000' });
|
||||
win.play();
|
||||
}
|
||||
}
|
||||
|
||||
function getRandomInt(max) {
|
||||
return Math.floor(Math.random() * Math.floor(max));
|
||||
}
|
||||
|
||||
function create() {
|
||||
this.add.image(400, 300, 'bg');
|
||||
|
||||
shoot = this.sound.add('shoot');
|
||||
win = this.sound.add('win');
|
||||
|
||||
enemiesText = this.add.text(16, 16, 'virus restant : '+maxEnemies, { fontSize: '32px', fill: '#000' });
|
||||
|
||||
graphics = this.add.graphics();
|
||||
|
||||
viruses = new Array(maxEnemies).fill(null).map(
|
||||
function() {
|
||||
let color = colors[Math.floor(Math.random() * colors.length)];
|
||||
return that.add.image(getRandomInt(800), getRandomInt(600), color);
|
||||
}
|
||||
);
|
||||
|
||||
rect = Phaser.Geom.Rectangle.Clone(this.cameras.main);
|
||||
|
||||
target = this.add.image(400, 300, 'target');
|
||||
|
||||
this.input.on('pointermove', function (pointer) {
|
||||
target.x = pointer.x;
|
||||
target.y = pointer.y;
|
||||
});
|
||||
|
||||
this.input.on('pointerdown', function (pointer) {
|
||||
let pointerX = pointer.x;
|
||||
let pointerY = pointer.y;
|
||||
shoot.play();
|
||||
for (let i = 0; i < maxEnemies; i++) {
|
||||
let virus = viruses[i];
|
||||
let virusX = virus.x;
|
||||
let virusY = virus.y;
|
||||
if (
|
||||
virus.visible &&
|
||||
pointerX >= virusX - 94 && pointerX <= virusX + 94 &&
|
||||
pointerY >= virusY - 94 && pointerY <= virusY + 94
|
||||
) {
|
||||
killVirus(null, virus);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
function update() {
|
||||
viruses.forEach(function (virus, i) {
|
||||
let direction = getRandomInt(4);
|
||||
let x = (1 + Math.random() * i);
|
||||
let y = (1 + Math.random() * i);
|
||||
switch (direction) {
|
||||
case 1:
|
||||
virus.x += x;
|
||||
virus.y += y;
|
||||
break;
|
||||
case 2:
|
||||
virus.x += x;
|
||||
virus.y -= y;
|
||||
break;
|
||||
case 3:
|
||||
virus.x -= x;
|
||||
virus.y += y;
|
||||
break;
|
||||
case 4:
|
||||
virus.x -= x;
|
||||
virus.y -= y;
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Phaser.Actions.WrapInRectangle(viruses, rect, 72);
|
||||
}
|
||||
+215417
File diff suppressed because it is too large.
Load diff
Vendored
+1
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Phaser",[],e):"object"==typeof exports?exports.Phaser=e():t.Phaser=e()}(window,function(){return n={},s.m=i=[function(t,e){function r(t,e,i,n){for(var s in e)if(e.hasOwnProperty(s)){var r=(l=e,u=s,f=d=void 0,f=(c=i)?l[u]:Object.getOwnPropertyDescriptor(l,u),!c&&f.value&&"object"==typeof f.value&&(f=f.value),!(!f||!((d=f).get&&"function"==typeof d.get||d.set&&"function"==typeof d.set))&&(void 0===f.enumerable&&(f.enumerable=!0),void 0===f.configurable&&(f.configurable=!0),f));if(!1!==r){if(o=(n||t).prototype,a=s,h=void 0,(h=Object.getOwnPropertyDescriptor(o,a))&&(h.value&&"object"==typeof h.value&&(h=h.value),!1===h.configurable)){if(p.ignoreFinals)continue;throw new Error("cannot override final property '"+s+"', set Class.ignoreFinals = true to skip")}Object.defineProperty(t.prototype,s,r)}else t.prototype[s]=e[s]}var o,a,h,l,u,c,d,f}function o(t,e){if(e){Array.isArray(e)||(e=[e]);for(var i=0;i<e.length;i++)r(t,e[i].prototype||e[i])}}function p(t){var e,i,n;if((t=t||{}).initialize){if("function"!=typeof t.initialize)throw new Error("initialize must be a function");n=t.initialize,delete t.initialize}else{n=t.Extends?(i=t.Extends,function(){i.apply(this,arguments)}):function(){}}t.Extends?(n.prototype=Object.create(t.Extends.prototype),n.prototype.constructor=n,e=t.Extends,delete t.Extends):n.prototype.constructor=n;var s=null;return t.Mixins&&(s=t.Mixins,delete t.Mixins),o(n,s),r(n,t,!0,e),n}p.extend=r,p.mixin=o,p.ignoreFinals=!1,t.exports=p},function(t,e){t.exports=function(){}},function(t,e){t.exports=function(t,e,i){var n=typeof t;return t&&"number"!=n&&"string"!=n&&t.hasOwnProperty(e)&&void 0!==t[e]?t[e]:i}},function(t,e,i){var n=i(0),s=i(123),r=new n({initialize:function(t,e){this.x=0,this.y=0,"object"==typeof t?(this.x=t.x||0,this.y=t.y||0):(void 0===e&&(e=t),this.x=t||0,this.y=e||0)},clone:function(){return new r(this.x,this.y)},copy:function(t){return this.x=t.x||0,this.y=t.y||0,this},setFromObject:function(t){return this.x=t.x||0,this.y=t.y||0,this},set:function(t,e){return void 0===e&&(e=t),this.x=t,this.y=e,this},setTo:function(t,e){return this.set(t,e)},setToPolar:function(t,e){return null==e&&(e=1),this.x=Math.cos(t)*e,this.y=Math.sin(t)*e,this},equals:function(t){return this.x===t.x&&this.y===t.y},fuzzyEquals:function(t,e){return s(this.x,t.x,e)&&s(this.y,t.y,e)},angle:function(){var t=Math.atan2(this.y,this.x);return t<0&&(t+=2*Math.PI),t},setAngle:function(t){return this.setToPolar(t,this.length())},add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.x-=t.x,this.y-=t.y,this},multiply:function(t){return this.x*=t.x,this.y*=t.y,this},scale:function(t){return isFinite(t)?(this.x*=t,this.y*=t):(this.x=0,this.y=0),this},divide:function(t){return this.x/=t.x,this.y/=t.y,this},negate:function(){return this.x=-this.x,this.y=-this.y,this},distance:function(t){var e=t.x-this.x,i=t.y-this.y;return Math.sqrt(e*e+i*i)},distanceSq:function(t){var e=t.x-this.x,i=t.y-this.y;return e*e+i*i},length:function(){var t=this.x,e=this.y;return Math.sqrt(t*t+e*e)},setLength:function(t){return this.normalize().scale(t)},lengthSq:function(){var t=this.x,e=this.y;return t*t+e*e},normalize:function(){var t=this.x,e=this.y,i=t*t+e*e;return 0<i&&(i=1/Math.sqrt(i),this.x=t*i,this.y=e*i),this},normalizeRightHand:function(){var t=this.x;return this.x=-1*this.y,this.y=t,this},normalizeLeftHand:function(){var t=this.x;return this.x=this.y,this.y=-1*t,this},dot:function(t){return this.x*t.x+this.y*t.y},cross:function(t){return this.x*t.y-this.y*t.x},lerp:function(t,e){void 0===e&&(e=0);var i=this.x,n=this.y;return this.x=i+e*(t.x-i),this.y=n+e*(t.y-n),this},transformMat3:function(t){var e=this.x,i=this.y,n=t.val;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[7],this},transformMat4:function(t){var e=this.x,i=this.y,n=t.val;return this.x=n[0]*e+n[4]*i+n[12],this.y=n[1]*e+n[5]*i+n[13],this},reset:function(){return this.x=0,this.y=0,this},limit:function(t){var e=this.length();return e&&t<e&&this.scale(t/e),this},reflect:function(t){return t=t.clone().normalize(),this.subtract(t.scale(2*this.dot(t)))},mirror:function(t){return this.reflect(t).negate()},rotate:function(t){var e=Math.cos(t),i=Math.sin(t);return this.set(e*this.x-i*this.y,i*this.x+e*this.y)}});r.ZERO=new r,r.RIGHT=new r(1,0),r.LEFT=new r(-1,0),r.UP=new r(0,-1),r.DOWN=new r(0,1),r.ONE=new r(1,1),t.exports=r},function(t,e,i){var n=i(0),s=i(55),r=new n({initialize:function(t,e){void 0===t&&(t=0),void 0===e&&(e=t),this.type=s.POINT,this.x=t,this.y=e},setTo:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.x=t,this.y=e,this}});t.exports=r},function(t,e,i){var n=i(0),s=i(24),r=i(21),o=new n({initialize:function(t){this.scene=t,this.systems=t.sys,this.events=t.sys.events,this.displayList,this.updateList,this.events.once(r.BOOT,this.boot,this),this.events.on(r.START,this.start,this)},boot:functiLine truncated
|
||||
Reference in new issue
Block a user