Skip to content

Commit

Permalink
Player 움직임 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
choar816 committed May 31, 2022
1 parent 8bf54d1 commit 0111de1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/characters/Player.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export const Direction = Object.freeze({
Up: 'Up',
Down: 'Down',
Left: 'Left',
Right: 'Right'
});

export default class Player extends Phaser.Physics.Arcade.Image {
static PLAYER_SPEED = 5;

Expand All @@ -10,6 +17,28 @@ export default class Player extends Phaser.Physics.Arcade.Image {
scene.physics.add.existing(this);
}

move(direction) {
switch (direction) {
case Direction.Up:
this.y -= Player.PLAYER_SPEED;
break;

case Direction.Down:
this.y += Player.PLAYER_SPEED;
break;

case Direction.Left:
this.x -= Player.PLAYER_SPEED;
this.flipX = true;
break;

case Direction.Right:
this.x += Player.PLAYER_SPEED;
this.flipX = false;
break;
}
}

hitByEnemy(damage) {

}
Expand Down
23 changes: 19 additions & 4 deletions src/scenes/PlayingScene.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Phaser from 'phaser';
import Config from "../Config";
import Player from '../characters/Player';
import Player, { Direction } from '../characters/Player';

export default class PlayingScene extends Phaser.Scene {
constructor() {
Expand All @@ -25,14 +25,29 @@ export default class PlayingScene extends Phaser.Scene {

// player
this.m_player = new Player(this);

// keys
this.m_cursorKeys = this.input.keyboard.createCursorKeys();
console.log(this.m_cursorKeys);
}


update() {

this.handlePlayerMove();
}


//////////////////////// FUNCTIONS ////////////////////////

handlePlayerMove() {
if (this.m_cursorKeys.left.isDown) {
this.m_player.move(Direction.Left);
} else if (this.m_cursorKeys.right.isDown) {
this.m_player.move(Direction.Right);
}

if (this.m_cursorKeys.up.isDown) {
this.m_player.move(Direction.Up);
} else if (this.m_cursorKeys.down.isDown) {
this.m_player.move(Direction.Down);
}
}
}

0 comments on commit 0111de1

Please sign in to comment.