summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Player.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-04-14 21:49:20 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-04-14 21:49:20 +0200
commitf27937e6e9b6a7146dd09fc711d2d293ecf5abbf (patch)
treee0ddd5e6d356000e4f29af6211a736284a4972ee /Scenes/Entities/Player.gd
parent96d36cee33d6321834565f0a5d412ef95c5ceffd (diff)
update
Diffstat (limited to 'Scenes/Entities/Player.gd')
-rw-r--r--Scenes/Entities/Player.gd96
1 files changed, 70 insertions, 26 deletions
diff --git a/Scenes/Entities/Player.gd b/Scenes/Entities/Player.gd
index 12c5fc2..1994b75 100644
--- a/Scenes/Entities/Player.gd
+++ b/Scenes/Entities/Player.gd
@@ -30,6 +30,8 @@ var accumulated_bomb_wait_delta = 0
var bomb_wait_delta_mutiplier = 5
var DIRECTION = Vector2.DOWN
+var DIRECTIONS: Array = [Vector2.DOWN]
+var LAST_DIRECTIONS: Array = []
var collision_area: Area2D
@@ -71,49 +73,82 @@ func _process(delta):
self.just_planted_bomb = false
# self.just_planted_bomb = false
+ self.DIRECTIONS = []
if Input.is_action_pressed("ui_left"):
velocity.x -= SPEED
- $AnimatedSprite2D.play("left")
+ self.DIRECTIONS.append(Vector2.LEFT)
self.DIRECTION = Vector2.LEFT
if Input.is_action_pressed("ui_right"):
velocity.x += SPEED
- $AnimatedSprite2D.play("right")
+ self.DIRECTIONS.append(Vector2.RIGHT)
self.DIRECTION = Vector2.RIGHT
if Input.is_action_pressed("ui_up"):
velocity.y -= SPEED
- $AnimatedSprite2D.play("up")
+ self.DIRECTIONS.append(Vector2.UP)
self.DIRECTION = Vector2.UP
if Input.is_action_pressed("ui_down"):
velocity.y += SPEED
- $AnimatedSprite2D.play("down")
self.DIRECTION = Vector2.DOWN
+ self.DIRECTIONS.append(Vector2.DOWN)
- if velocity.x < 0 && velocity.y < 0:
- $AnimatedSprite2D.play("tl")
+ if velocity.x < 0 && velocity.y == 0:
+ $AnimatedSprite2D.play("left")
+ elif velocity.x > 0 && velocity.y == 0:
+ $AnimatedSprite2D.play("right")
+ elif velocity.x == 0 && velocity.y < 0:
+ $AnimatedSprite2D.play("up")
+ elif velocity.x == 0 && velocity.y > 0:
+ $AnimatedSprite2D.play("down")
+ elif velocity.x < 0 && velocity.y < 0:
+ $AnimatedSprite2D.play("top_left")
elif velocity.x > 0 && velocity.y < 0:
- $AnimatedSprite2D.play("tr")
+ $AnimatedSprite2D.play("top_right")
elif velocity.x < 0 && velocity.y > 0:
- $AnimatedSprite2D.play("bl")
+ $AnimatedSprite2D.play("bottom_left")
elif velocity.x > 0 && velocity.y > 0:
- $AnimatedSprite2D.play("br")
+ $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")
+
+ self.LAST_DIRECTIONS = self.DIRECTIONS
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
-
- if not interacted:
- if self.can_plant_bomb():
- self.plant_bomb()
- self.just_planted_bomb = true
- #$JustPlantedBomb.start()
+ if not self.is_in_interaction_area():
+ 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
+
+ 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))
+ move_and_slide()
+ self.collide(get_last_slide_collision())
- self.collide(move_and_collide(velocity * delta))
velocity = velocity.lerp(Vector2(0, 0), 1)
@@ -162,8 +197,8 @@ func pick_up_bomb(bomb: Bomb):
self.add_child(bomb)
self.held_bomb = bomb
- bomb.connect("exploded", func(bomb):
- if self.held_bomb == bomb:
+ bomb.connect("exploded", func(exploded_bomb):
+ if self.held_bomb == exploded_bomb:
self.held_bomb = null
)
@@ -247,6 +282,15 @@ func heal(amount: int):
self.emit_signal("health_changed", self.health)
+func is_in_interaction_area():
+ if collision_area.has_overlapping_areas():
+ for area in collision_area.get_overlapping_areas():
+ if area.is_in_group("interactables"):
+ return true
+
+ return false
+
+
func set_invincibility():
$Invincibility.start()
$AnimatedSprite2D.set_modulate(Color(10, 10, 10, 1))