pokemon / 300.bundle.js
akhaliq's picture
akhaliq HF staff
Upload 8 files
89d3000 verified
"use strict";(self.webpackChunkpokemon_red_clone=self.webpackChunkpokemon_red_clone||[]).push([[300],{300:(t,e,a)=>{a.r(e),a.d(e,{default:()=>s});class s{constructor(t,e,a,s,i,r){return this.scene=t,this.sprite=t.physics.add.sprite(e,a,s,i),this.sprite.setImmovable(!0),this.data={name:r.name||"NPC",dialog:r.dialog||["..."],facing:r.facing||"down",movementPattern:r.movementPattern||"static",pokemon:r.pokemon||[],isTrainer:r.isTrainer||!1},"static"!==this.data.movementPattern&&(this.movementTimer=t.time.addEvent({delay:2e3,callback:this.moveRandomly,callbackScope:this,loop:!0})),this.updateFrame(),this.sprite.npc=this,this}updateFrame(){switch(this.data.facing){case"left":this.sprite.setFrame(8);break;case"right":this.sprite.setFrame(12);break;case"up":this.sprite.setFrame(4);break;default:this.sprite.setFrame(0)}}moveRandomly(){if("static"===this.data.movementPattern)return;const t=["left","right","up","down","idle"],e=t[Math.floor(Math.random()*t.length)];switch(this.sprite.setVelocity(0),e){case"left":this.sprite.setVelocityX(-50),this.data.facing="left",this.sprite.anims.play("player-walk-left",!0);break;case"right":this.sprite.setVelocityX(50),this.data.facing="right",this.sprite.anims.play("player-walk-right",!0);break;case"up":this.sprite.setVelocityY(-50),this.data.facing="up",this.sprite.anims.play("player-walk-up",!0);break;case"down":this.sprite.setVelocityY(50),this.data.facing="down",this.sprite.anims.play("player-walk-down",!0);break;default:this.sprite.anims.stop(),this.updateFrame()}this.scene.time.delayedCall(500,(()=>{this.sprite.setVelocity(0),this.sprite.anims.stop(),this.updateFrame()}))}facePlayer(t){const e=t.sprite.x-this.sprite.x,a=t.sprite.y-this.sprite.y;Math.abs(e)>Math.abs(a)?this.data.facing=e>0?"right":"left":this.data.facing=a>0?"down":"up",this.updateFrame()}startDialog(t){return this.facePlayer(t),this.data.dialog}startBattle(t){return!(!this.data.isTrainer||0===this.data.pokemon.length)&&{trainerName:this.data.name,pokemon:this.data.pokemon}}}}}]);