summaryrefslogtreecommitdiff
path: root/Units/basher.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Units/basher.gd')
-rw-r--r--Units/basher.gd53
1 files changed, 53 insertions, 0 deletions
diff --git a/Units/basher.gd b/Units/basher.gd
new file mode 100644
index 0000000..7f92297
--- /dev/null
+++ b/Units/basher.gd
@@ -0,0 +1,53 @@
+extends Unit
+
+
+var direction := Vector2.RIGHT
+
+var last_position: Vector2
+
+
+func _ready():
+ $AnimationPlayer.play("mine")
+ scale = Vector2(direction.x, 1)
+
+ $RayForward.force_raycast_update()
+
+
+func _physics_process(delta: float) -> void:
+ if not is_on_floor():
+ velocity += get_gravity() * delta * Game.speed
+
+ velocity.x = direction.x * 100 * delta * Game.speed
+
+ if not $RayForward.is_colliding():
+ # TODO: erase step gerade aus
+ var default = load("res://Units/Default.tscn").instantiate()
+ default.global_position = global_position
+ default.direction = direction
+ get_tree().current_scene.add_child(default)
+ queue_free()
+
+ last_position = global_position
+ move_and_slide()
+
+ if last_position == global_position: # jumping over fraction pixel collisions, left over after mining
+ position.y -= 10 * delta * Game.speed
+ position.x += 10 * direction.x * delta * Game.speed
+
+
+func mine() -> void:
+ var points = []
+ for point: Vector2 in $Polygon.polygon:
+ points.append(
+ global_position +
+ ($Polygon.position * Vector2(direction.x, 1)) +
+ (point.rotated($Polygon.rotation) * Vector2(direction.x, 1))
+ )
+
+ (func():
+ Game.erase_map(
+ PackedVector2Array(points),
+ get_tree().current_scene.get_node("GroundCollision"),
+ get_tree().current_scene.get_node("Map")
+ )
+ ).call_deferred()