From 5442988a8ccecb9c323fc98557391a15ff245b87 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 3 Oct 2024 12:51:49 +0200 Subject: next commit --- Units/default.gd | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'Units/default.gd') diff --git a/Units/default.gd b/Units/default.gd index 23987c3..bd571a8 100644 --- a/Units/default.gd +++ b/Units/default.gd @@ -10,40 +10,39 @@ func _physics_process(delta: float) -> void: if not is_on_floor(): velocity.x = 0 velocity += get_gravity() * delta * Game.speed - $AnimatedSprite.play("fall") + if velocity.y > (get_gravity().y / 10): + $AnimatedSprite.play("fall") - if $RayLeft.is_colliding(): + if $RayWallLeft.is_colliding(): direction = Vector2.RIGHT - elif $RayRight.is_colliding(): + elif $RayWallRight.is_colliding(): direction = Vector2.LEFT if is_on_floor(): + if ( + ($RaySlopeLeft.is_colliding() and not $RayWallLeft.is_colliding()) or + ($RaySlopeRight.is_colliding() and not $RayWallRight.is_colliding()) + ): + position.y -= 10 * delta * Game.speed + position.x += 10 * direction.x * delta * Game.speed + velocity.x = direction.x * speed * delta * Game.speed $AnimatedSprite.play("walk") $AnimatedSprite.flip_h = direction.x < 0 move_and_slide() - var collision = get_last_slide_collision() - if collision: - var collider = collision.get_collider() as TileMapLayer - if collider is TileMapLayer: - var cell = collider.get_cell_tile_data(collider.get_coords_for_body_rid(collision.get_collider_rid())) as TileData - cell.set_collision_polygon_points(0, 0, PackedVector2Array([ - Vector2(-7,-7), Vector2(-7,7), Vector2(7,7), Vector2(7,-7) - ])) func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: - if event.is_action_pressed("select"): - get_viewport().set_input_as_handled() - var blocker = preload("res://Units/Blocker.tscn").instantiate() - blocker.position = global_position - get_tree().current_scene.add_child(blocker) - queue_free() - if event.is_action_pressed("select2"): + if event.is_action_pressed("select") and Game.selected_unit_type: get_viewport().set_input_as_handled() - var blocker = preload("res://Units/Digger.tscn").instantiate() - blocker.position = global_position - get_tree().current_scene.add_child(blocker) + + var unit = Game.selected_unit_type.instantiate() + unit.position = global_position + + if "direction" in unit: + unit.direction = direction + + get_tree().current_scene.add_child(unit) queue_free() -- cgit v1.2.3