class Body{ constructor(parent, name){ this.parent = parent; this.createAnimations(name); } createAnimations(name){ let listOfAnimations = []; if(name == 'player'){ let runAnimationSpeed = 0.2; let runUpAnimation = { parent: this.parent, name: 'up', animation: new Animator('up', playerImages.runUp, runAnimationSpeed, true, false), get canRun(){ return this.parent.animationName == 'up'; } } listOfAnimations.push(runUpAnimation); let runRightAnimation = { parent: this.parent, name: 'right', animation: new Animator('right', playerImages.runRight, runAnimationSpeed, true, false), get canRun(){ return ( this.parent.animationName == 'right' || this.parent.animationName == 'upRight' || this.parent.animationName == 'downRight' ); } } listOfAnimations.push(runRightAnimation); let runLeftAnimation = { parent: this.parent, name: 'left', animation: new Animator('left', playerImages.runLeft, 0.15, true, false), get canRun(){ return ( this.parent.animationName == 'left' || this.parent.animationName == 'upLeft' || this.parent.animationName == 'downLeft' ); } } listOfAnimations.push(runLeftAnimation); let runDownAnimation = { parent: this.parent, name: 'down', animation: new Animator('down', playerImages.runDown, runAnimationSpeed, true, false), get canRun(){ return this.parent.animationName == 'down'; } } listOfAnimations.push(runDownAnimation); let idleAnimation = { parent: this.parent, name: 'idle', animation: new Animator('idle', playerImages.idle, 0.8, true, false), get canRun(){ return true; } } listOfAnimations.push(idleAnimation); } if(name == 'guard'){ let runSideAnimation = { parent: this.parent, name: 'side', animation: new Animator('side', guardImages.side, 0.2, true, false), get canRun(){ return this.parent.velocity.magnitude > 10; } } listOfAnimations.push(runSideAnimation); let idleAnimation = { parent: this.parent, speed: this.parent.velocity, name: 'idle', animation: new Animator('idle', guardImages.side, 9999, true, false), get canRun(){ return true; } } listOfAnimations.push(idleAnimation); } if(name = 'samurai'){ let runAnimation = { parent: this.parent, name: 'run', animation: new Animator('run', samuraiRun, 0.2, true, false), get canRun(){ return this.parent.velocity.magnitude > 10; } } listOfAnimations.push(runAnimation); let idleAnimation = { parent: this.parent, speed: this.parent.velocity, name: 'idle', animation: new Animator('idle', samuraiRun, 9999, true, false), get canRun(){ return true; } } listOfAnimations.push(idleAnimation); } this.animationManager = new AnimationManager(listOfAnimations); } update(){ // do nothing! } updateImage(){ this.animationManager.update(); this.animationManager.draw(this.parent.position.x, this.parent.position.y); } }