From b069ea91b095d80667475c06e62712c1bd7b537f Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 3 Oct 2024 20:39:59 +0200 Subject: next commit --- Units/basher.gd | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Units/basher.gd (limited to 'Units/basher.gd') 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() -- cgit v1.2.3