diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2023-12-28 09:07:41 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2023-12-28 09:07:41 +0100 |
commit | 96d36cee33d6321834565f0a5d412ef95c5ceffd (patch) | |
tree | 0dec02c5915cc154d48eef6ac9c2cd0be7df7982 /Scenes/Entities | |
parent | 46556d864b9685c3b09a0038f5de83966fe7ff94 (diff) |
Diffstat (limited to 'Scenes/Entities')
-rw-r--r-- | Scenes/Entities/Bombs/Bomb.gd | 19 | ||||
-rw-r--r-- | Scenes/Entities/Objects/Coin.gd | 2 | ||||
-rw-r--r-- | Scenes/Entities/Player.gd | 156 | ||||
-rw-r--r-- | Scenes/Entities/Player.tscn | 5 |
4 files changed, 137 insertions, 45 deletions
diff --git a/Scenes/Entities/Bombs/Bomb.gd b/Scenes/Entities/Bombs/Bomb.gd index 96a5e62..3981122 100644 --- a/Scenes/Entities/Bombs/Bomb.gd +++ b/Scenes/Entities/Bombs/Bomb.gd @@ -7,8 +7,18 @@ signal body_exited signal exploded +enum COMPONENT_TYPE { + BREAKBLE, + REMOTE_CONTROL, + REMOTE_DETONATE, + WATER, + SALT, +} + + var Explosion = preload("res://Scenes/Entities/Bombs/Explosion.tscn") -var power = 2 +var power: int = 2 +var components: Array[COMPONENT_TYPE] = [] func _ready(): @@ -19,6 +29,8 @@ func _ready(): collision_area.connect("body_exited", Callable(self, "_body_exited")) add_child(collision_area) + self.components = Global.player.bomb_components + $AnimatedSprite2D.play() @@ -31,6 +43,8 @@ func _process(delta): func explode(): $CollisionShape2D.disabled = true + Input.start_joy_vibration(0, 0.5, 0.75, 0.1) + # explode on the spot var explosion = self.spawn_explosion(self.global_position) @@ -158,6 +172,9 @@ func _on_collide_group_bombs(): func _on_collide_group_breakables(): + if self.components.has(COMPONENT_TYPE.BREAKBLE): + return EXPLOSION_COLLISION_TYPE.HIT_CONTINUE + return EXPLOSION_COLLISION_TYPE.HIT_STOP diff --git a/Scenes/Entities/Objects/Coin.gd b/Scenes/Entities/Objects/Coin.gd index 77fc6c2..48e30b3 100644 --- a/Scenes/Entities/Objects/Coin.gd +++ b/Scenes/Entities/Objects/Coin.gd @@ -2,6 +2,8 @@ extends StaticBody2D func _ready(): + add_to_group("coins") + var collision_area = Utilities.Collision.Area.new(self, $CollisionShape2D, false) collision_area.connect("collided", Callable(self, "_collide")) add_child(collision_area) diff --git a/Scenes/Entities/Player.gd b/Scenes/Entities/Player.gd index a578bbb..12c5fc2 100644 --- a/Scenes/Entities/Player.gd +++ b/Scenes/Entities/Player.gd @@ -4,14 +4,19 @@ class_name Player signal damaged +signal health_changed const SPEED = 60 const KICK_SPEED = 300 const THROW_DISTANCE = 3 -@export var Bomb: PackedScene = preload("res://Scenes/Entities/Bombs/Bomb__Normal.tscn") +@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] = [] +var bombs: Array = [] +var last_planted_bomb: Bomb @export var maxHealth: int = 12 @export var health: int = self.maxHealth @@ -20,6 +25,9 @@ const THROW_DISTANCE = 3 var is_invincible = false var held_bomb: Bomb +var just_planted_bomb: bool = false +var accumulated_bomb_wait_delta = 0 +var bomb_wait_delta_mutiplier = 5 var DIRECTION = Vector2.DOWN @@ -38,55 +46,83 @@ func _ready(): func _process(delta): - if Input.is_action_pressed("ui_left"): - velocity.x -= SPEED - $AnimatedSprite2D.play("left") - self.DIRECTION = Vector2.LEFT - if Input.is_action_pressed("ui_right"): - velocity.x += SPEED - $AnimatedSprite2D.play("right") - self.DIRECTION = Vector2.RIGHT - if Input.is_action_pressed("ui_up"): - velocity.y -= SPEED - $AnimatedSprite2D.play("up") - self.DIRECTION = Vector2.UP - if Input.is_action_pressed("ui_down"): - velocity.y += SPEED - $AnimatedSprite2D.play("down") - self.DIRECTION = Vector2.DOWN - - if velocity.x < 0 && velocity.y < 0: - $AnimatedSprite2D.play("tl") - elif velocity.x > 0 && velocity.y < 0: - $AnimatedSprite2D.play("tr") - elif velocity.x < 0 && velocity.y > 0: - $AnimatedSprite2D.play("bl") - elif velocity.x > 0 && velocity.y > 0: - $AnimatedSprite2D.play("br") - - if Input.is_action_just_pressed("ui_accept"): - if self.held_bomb: - self.throw_bomb() + if (self.bomb_components.has(Bomb.COMPONENT_TYPE.REMOTE_DETONATE) + and Input.is_action_just_pressed("ui_cancel")): + if self.bombs.size() > 0: + self.bombs[self.bombs.size() - 1].explode() + + if (self.bomb_components.has(Bomb.COMPONENT_TYPE.REMOTE_CONTROL) + 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): + if Input.is_action_pressed("ui_left"): + self.last_planted_bomb.position.x -= SPEED * delta + if Input.is_action_pressed("ui_right"): + self.last_planted_bomb.position.x += SPEED * delta + if Input.is_action_pressed("ui_up"): + self.last_planted_bomb.position.y -= SPEED * delta + if Input.is_action_pressed("ui_down"): + self.last_planted_bomb.position.y += SPEED * delta + else: + if (self.just_planted_bomb and + self.accumulated_bomb_wait_delta < delta * self.bomb_wait_delta_mutiplier): + self.accumulated_bomb_wait_delta += delta else: - var interacted = false - var areas = $InteractionArea.get_overlapping_areas() - for area in areas: - if area.is_in_group("bombs"): - var bomb = area.get_parent() + self.accumulated_bomb_wait_delta = 0 + self.just_planted_bomb = false +# self.just_planted_bomb = false + + if Input.is_action_pressed("ui_left"): + velocity.x -= SPEED + $AnimatedSprite2D.play("left") + self.DIRECTION = Vector2.LEFT + if Input.is_action_pressed("ui_right"): + velocity.x += SPEED + $AnimatedSprite2D.play("right") + self.DIRECTION = Vector2.RIGHT + if Input.is_action_pressed("ui_up"): + velocity.y -= SPEED + $AnimatedSprite2D.play("up") + self.DIRECTION = Vector2.UP + if Input.is_action_pressed("ui_down"): + velocity.y += SPEED + $AnimatedSprite2D.play("down") + self.DIRECTION = Vector2.DOWN + + if velocity.x < 0 && velocity.y < 0: + $AnimatedSprite2D.play("tl") + elif velocity.x > 0 && velocity.y < 0: + $AnimatedSprite2D.play("tr") + elif velocity.x < 0 && velocity.y > 0: + $AnimatedSprite2D.play("bl") + elif velocity.x > 0 && velocity.y > 0: + $AnimatedSprite2D.play("br") + + if Input.is_action_just_pressed("ui_accept"): + if self.held_bomb: + self.throw_bomb() + else: + var interacted = false + var bomb = self.has_pickable_bomb() + if bomb: self.pick_up_bomb(bomb) - interacted = true - break - - if not interacted: - self.plant_bomb() - - self.collide(move_and_collide(velocity * delta)) - velocity = velocity.lerp(Vector2(0, 0), 1) + + if not interacted: + if self.can_plant_bomb(): + self.plant_bomb() + self.just_planted_bomb = true + #$JustPlantedBomb.start() + + self.collide(move_and_collide(velocity * delta)) + velocity = velocity.lerp(Vector2(0, 0), 1) + + +func can_plant_bomb(): + return self.bombs.size() < self.max_bombs func plant_bomb(): - var bomb = Bomb.instantiate() + var bomb = BombScene.instantiate() bomb.position = Utilities.get_level_position_grid(self) bomb.power = self.bomb_power @@ -96,9 +132,28 @@ func plant_bomb(): self.remove_collision_exception_with(bomb) ) + self.bombs.append(bomb) + self.last_planted_bomb = bomb + bomb.connect("exploded", func(_bomb): + self.bombs.erase(bomb) + if self.last_planted_bomb == bomb: + self.last_planted_bomb = null + ) + get_tree().get_current_scene().add_child(bomb) +func has_pickable_bomb(): + var areas = $InteractionArea.get_overlapping_areas() + for area in areas: + if area.is_in_group("bombs"): + var bomb = area.get_parent() + + return bomb + + return null + + func pick_up_bomb(bomb: Bomb): get_tree().get_current_scene().remove_child(bomb) bomb.position = Vector2(0, 0) @@ -183,6 +238,13 @@ func take_damage(amount): self.health -= amount self.emit_signal("damaged", self.health) + self.emit_signal("health_changed", self.health) + + +func heal(amount: int): + self.health = min(self.health + amount, self.maxHealth) + + self.emit_signal("health_changed", self.health) func set_invincibility(): @@ -200,3 +262,9 @@ func _collide(area: Area2D): self.take_damage(2) elif area.is_in_group("enemies"): self.take_damage(1) + elif area.is_in_group("coins"): + self.heal(1) + + +func _on_just_planted_bomb_timeout(): + self.just_planted_bomb = true diff --git a/Scenes/Entities/Player.tscn b/Scenes/Entities/Player.tscn index f4ef6ab..04d328f 100644 --- a/Scenes/Entities/Player.tscn +++ b/Scenes/Entities/Player.tscn @@ -115,4 +115,9 @@ shape = SubResource("RectangleShape2D_c6666") wait_time = 1.5 one_shot = true +[node name="JustPlantedBomb" type="Timer" parent="."] +wait_time = 0.05 +one_shot = true + [connection signal="timeout" from="Invincibility" to="." method="_on_invincibility_timeout"] +[connection signal="timeout" from="JustPlantedBomb" to="." method="_on_just_planted_bomb_timeout"] |