diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-05-23 14:11:43 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-05-23 14:11:43 +0200 |
commit | 06647b11ee163bc40daf454d87e1fcae563c3ced (patch) | |
tree | 866823ed79fa1c3bbdcb8b0be417f028f0c92d9b /Scenes/Entities | |
parent | 276b7664bd4a475a3ca93a682c16b49c504c58f7 (diff) |
update
Diffstat (limited to 'Scenes/Entities')
-rw-r--r-- | Scenes/Entities/Bombs/Bomb.gd | 2 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Components/Health.gd | 5 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Projectile.gd | 2 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Tree.gd | 5 | ||||
-rw-r--r-- | Scenes/Entities/Enemies/Tree.tscn | 2 | ||||
-rw-r--r-- | Scenes/Entities/Objects/BaseDoor.tscn | 1 | ||||
-rw-r--r-- | Scenes/Entities/Objects/Tree.tscn | 1 | ||||
-rw-r--r-- | Scenes/Entities/Player.gd | 63 | ||||
-rw-r--r-- | Scenes/Entities/Player.tscn | 1 |
9 files changed, 50 insertions, 32 deletions
diff --git a/Scenes/Entities/Bombs/Bomb.gd b/Scenes/Entities/Bombs/Bomb.gd index 7a1a9eb..0456c15 100644 --- a/Scenes/Entities/Bombs/Bomb.gd +++ b/Scenes/Entities/Bombs/Bomb.gd @@ -18,7 +18,7 @@ enum COMPONENT_TYPE { var ExplosionScene = preload("res://Scenes/Entities/Bombs/Explosion.tscn") var power: int = 2 -var components: Array[COMPONENT_TYPE] = [] +var components: Dictionary = {} func _ready(): diff --git a/Scenes/Entities/Enemies/Components/Health.gd b/Scenes/Entities/Enemies/Components/Health.gd index 6f65e79..2bd2447 100644 --- a/Scenes/Entities/Enemies/Components/Health.gd +++ b/Scenes/Entities/Enemies/Components/Health.gd @@ -21,6 +21,8 @@ var drop_items = [ preload("res://Scenes/Entities/Objects/Coin.tscn"), ] +var is_dying = false + func _ready(): if component_movement_path: @@ -30,11 +32,12 @@ func _ready(): func take_damage(): health -= 1 - if health <= 0: + if health <= 0 and not is_dying: death() func death(): + is_dying = true emit_signal("died") if component_movement: # stop all movement diff --git a/Scenes/Entities/Enemies/Projectile.gd b/Scenes/Entities/Enemies/Projectile.gd index af283b4..02a1470 100644 --- a/Scenes/Entities/Enemies/Projectile.gd +++ b/Scenes/Entities/Enemies/Projectile.gd @@ -13,7 +13,7 @@ func _ready(): velocity = position.direction_to(target) * speed -func _physics_process(delta): +func _physics_process(_delta): $AnimatedSprite2D.play("default") move_and_slide() diff --git a/Scenes/Entities/Enemies/Tree.gd b/Scenes/Entities/Enemies/Tree.gd index 5572e02..bbd02a9 100644 --- a/Scenes/Entities/Enemies/Tree.gd +++ b/Scenes/Entities/Enemies/Tree.gd @@ -3,6 +3,7 @@ extends CharacterBody2D @onready var component_collision: ComponentCollision = $Collision @onready var component_movement: ComponentMovement = $Movement +@onready var component_health: ComponentHealth = $Health func _ready(): @@ -16,6 +17,10 @@ func _ready(): $AnimatedSprite2D.play("spawn") $AnimatedSprite2D.stop() $AnimatedSprite2D.set_frame_and_progress(0, 0) + + $Health.connect("died", func(): + $Detection.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, false) + ) func _physics_process(delta): diff --git a/Scenes/Entities/Enemies/Tree.tscn b/Scenes/Entities/Enemies/Tree.tscn index 3a0de4a..f216159 100644 --- a/Scenes/Entities/Enemies/Tree.tscn +++ b/Scenes/Entities/Enemies/Tree.tscn @@ -141,7 +141,7 @@ script = ExtResource("1_ktvfx") texture_filter = 1 position = Vector2(0, -8) sprite_frames = SubResource("SpriteFrames_c5ryj") -animation = &"spawn" +animation = &"death_post" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, -8) diff --git a/Scenes/Entities/Objects/BaseDoor.tscn b/Scenes/Entities/Objects/BaseDoor.tscn index 845c35d..3a1fcc4 100644 --- a/Scenes/Entities/Objects/BaseDoor.tscn +++ b/Scenes/Entities/Objects/BaseDoor.tscn @@ -7,6 +7,7 @@ size = Vector2(16, 16) [node name="BaseDoor" type="StaticBody2D"] +z_index = -2 collision_layer = 8 collision_mask = 0 script = ExtResource("1_silnh") diff --git a/Scenes/Entities/Objects/Tree.tscn b/Scenes/Entities/Objects/Tree.tscn index fdffec1..09e4fee 100644 --- a/Scenes/Entities/Objects/Tree.tscn +++ b/Scenes/Entities/Objects/Tree.tscn @@ -15,6 +15,7 @@ a = Vector2(0, -18) b = Vector2(0, 1) [node name="Tree" type="StaticBody2D"] +z_index = -1 texture_filter = 1 collision_layer = 8 collision_mask = 32 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(): diff --git a/Scenes/Entities/Player.tscn b/Scenes/Entities/Player.tscn index 4d92b3a..caf6c7c 100644 --- a/Scenes/Entities/Player.tscn +++ b/Scenes/Entities/Player.tscn @@ -240,7 +240,6 @@ size = Vector2(14, 14) collision_layer = 2 collision_mask = 236 motion_mode = 1 -wall_min_slide_angle = 1.5708 script = ExtResource("1_2xulf") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] |