Skip to content

Commit

Permalink
attack이 가장 가까운 enemy로 날아가도록
Browse files Browse the repository at this point in the history
  • Loading branch information
choar816 committed May 31, 2022
1 parent 3af86d1 commit 4e05baf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/effects/Beam.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ export default class Beam extends Phaser.Physics.Arcade.Image {
scene.add.existing(this);
scene.physics.world.enableBody(this);
this.setCircle(30);
this.setVelocityY(-250);
this.setVelocity();

scene.m_attacks.add(this);
scene.m_beamSound.play();

setTimeout(() => this.destroy(), Beam.DURATION);
}

update() {
setVelocity() {
if (!this.scene.m_closest) {
this.setVelocityY(-250);
return;
}
const _x = this.scene.m_closest.x - this.x;
const _y = this.scene.m_closest.y - this.y;
const _r = Math.sqrt(_x*_x + _y*_y) / 2;
this.body.velocity.x = _x / _r * Beam.SPEED;
this.body.velocity.y = _y / _r * Beam.SPEED;
}
}
3 changes: 3 additions & 0 deletions src/scenes/PlayingScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export default class PlayingScene extends Phaser.Scene {
// 마치 무한대 배경인 것처럼!
this.m_background.tilePositionX = this.m_player.x - Config.width / 2;
this.m_background.tilePositionY = this.m_player.y - Config.height / 2;

// attack -> 가장 가까운 enemy
this.m_closest = this.physics.closest(this.m_player, this.m_enemies.getChildren());
}

//////////////////////// FUNCTIONS ////////////////////////
Expand Down

0 comments on commit 4e05baf

Please sign in to comment.