summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Player.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2023-12-28 09:07:41 +0100
committerDaniel Weipert <git@mail.dweipert.de>2023-12-28 09:07:41 +0100
commit96d36cee33d6321834565f0a5d412ef95c5ceffd (patch)
tree0dec02c5915cc154d48eef6ac9c2cd0be7df7982 /Scenes/Entities/Player.gd
parent46556d864b9685c3b09a0038f5de83966fe7ff94 (diff)
next commitHEADmain
Diffstat (limited to 'Scenes/Entities/Player.gd')
-rw-r--r--Scenes/Entities/Player.gd156
1 files changed, 112 insertions, 44 deletions
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