diff options
Diffstat (limited to 'Scenes/Entities/Player.gd')
-rw-r--r-- | Scenes/Entities/Player.gd | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/Scenes/Entities/Player.gd b/Scenes/Entities/Player.gd index 1e4b0c2..e8e9fbb 100644 --- a/Scenes/Entities/Player.gd +++ b/Scenes/Entities/Player.gd @@ -14,10 +14,11 @@ const THROW_DISTANCE = 3 @export var BombScene: PackedScene = preload("res://Scenes/Entities/Bombs/Bomb__Normal.tscn") @export var bomb_power: int = 2 @export var max_bombs: int = 5 -@export var bomb_components: Array[Bomb.COMPONENT_TYPE] = [ - Bomb.COMPONENT_TYPE.REMOTE_CONTROL, - Bomb.COMPONENT_TYPE.REMOTE_DETONATE -] +@export var bomb_components: Dictionary = { + 0: Bomb.COMPONENT_TYPE.REMOTE_CONTROL, + 1: Bomb.COMPONENT_TYPE.REMOTE_DETONATE, + 2: -1, +} var bombs: Array = [] var last_planted_bomb: Bomb @@ -52,14 +53,16 @@ func _ready(): func _process(delta): - if (self.bomb_components.has(Bomb.COMPONENT_TYPE.REMOTE_DETONATE) + if (self.bomb_components.find_key(Bomb.COMPONENT_TYPE.REMOTE_DETONATE) != null and Input.is_action_just_pressed("ui_cancel")): if self.bombs.size() > 0: - self.bombs[self.bombs.size() - 1].explode() + #self.bombs[self.bombs.size() - 1].explode() + self.bombs[0].explode() - if (self.bomb_components.has(Bomb.COMPONENT_TYPE.REMOTE_CONTROL) + if (self.bomb_components.find_key(Bomb.COMPONENT_TYPE.REMOTE_CONTROL) != null and self.last_planted_bomb and Input.is_action_pressed("ui_accept") and self.just_planted_bomb and self.accumulated_bomb_wait_delta >= delta * self.bomb_wait_delta_mutiplier): + play_idle() if Input.is_action_pressed("ui_left"): self.last_planted_bomb.position.x -= SPEED * delta if Input.is_action_pressed("ui_right"): @@ -79,22 +82,24 @@ func _process(delta): self.DIRECTIONS = [] if Input.is_action_pressed("ui_left"): - velocity.x -= SPEED + velocity.x -= 1 self.DIRECTIONS.append(Vector2.LEFT) self.DIRECTION = Vector2.LEFT if Input.is_action_pressed("ui_right"): - velocity.x += SPEED + velocity.x += 1 self.DIRECTIONS.append(Vector2.RIGHT) self.DIRECTION = Vector2.RIGHT if Input.is_action_pressed("ui_up"): - velocity.y -= SPEED + velocity.y -= 1 self.DIRECTIONS.append(Vector2.UP) self.DIRECTION = Vector2.UP if Input.is_action_pressed("ui_down"): - velocity.y += SPEED + velocity.y += 1 self.DIRECTION = Vector2.DOWN self.DIRECTIONS.append(Vector2.DOWN) + velocity = velocity.normalized() * SPEED + var last_animation = $AnimatedSprite2D.animation var frame = $AnimatedSprite2D.frame var progress = $AnimatedSprite2D.frame_progress @@ -117,22 +122,7 @@ func _process(delta): $AnimatedSprite2D.play("bottom_right") else: - if self.LAST_DIRECTIONS == [Vector2.LEFT]: - $AnimatedSprite2D.play("idle_left") - elif self.LAST_DIRECTIONS == [Vector2.RIGHT]: - $AnimatedSprite2D.play("idle_right") - elif self.LAST_DIRECTIONS == [Vector2.UP]: - $AnimatedSprite2D.play("idle_up") - elif self.LAST_DIRECTIONS == [Vector2.DOWN]: - $AnimatedSprite2D.play("idle_down") - elif self.LAST_DIRECTIONS == [Vector2.LEFT, Vector2.UP]: - $AnimatedSprite2D.play("idle_top_left") - elif self.LAST_DIRECTIONS == [Vector2.RIGHT, Vector2.UP]: - $AnimatedSprite2D.play("idle_top_right") - elif self.LAST_DIRECTIONS == [Vector2.LEFT, Vector2.DOWN]: - $AnimatedSprite2D.play("idle_bottom_left") - elif self.LAST_DIRECTIONS == [Vector2.RIGHT, Vector2.DOWN]: - $AnimatedSprite2D.play("idle_bottom_right") + play_idle() if last_animation != $AnimatedSprite2D.animation: $AnimatedSprite2D.set_frame_and_progress(frame, progress) @@ -296,6 +286,25 @@ func heal(amount: int): self.emit_signal("health_changed", self.health) +func play_idle(): + if self.LAST_DIRECTIONS == [Vector2.LEFT]: + $AnimatedSprite2D.play("idle_left") + elif self.LAST_DIRECTIONS == [Vector2.RIGHT]: + $AnimatedSprite2D.play("idle_right") + elif self.LAST_DIRECTIONS == [Vector2.UP]: + $AnimatedSprite2D.play("idle_up") + elif self.LAST_DIRECTIONS == [Vector2.DOWN]: + $AnimatedSprite2D.play("idle_down") + elif self.LAST_DIRECTIONS == [Vector2.LEFT, Vector2.UP]: + $AnimatedSprite2D.play("idle_top_left") + elif self.LAST_DIRECTIONS == [Vector2.RIGHT, Vector2.UP]: + $AnimatedSprite2D.play("idle_top_right") + elif self.LAST_DIRECTIONS == [Vector2.LEFT, Vector2.DOWN]: + $AnimatedSprite2D.play("idle_bottom_left") + elif self.LAST_DIRECTIONS == [Vector2.RIGHT, Vector2.DOWN]: + $AnimatedSprite2D.play("idle_bottom_right") + + func is_in_interaction_area(): if collision_area.has_overlapping_areas(): for area in collision_area.get_overlapping_areas(): |