summaryrefslogtreecommitdiff
path: root/Units/default.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-10-03 12:51:49 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-10-03 12:51:49 +0200
commit5442988a8ccecb9c323fc98557391a15ff245b87 (patch)
tree1864a03602291e2c495a8846b80ec90414060f61 /Units/default.gd
parentc8bd14d6feeca72fc96b895c9382ebc16a1caf55 (diff)
next commit
Diffstat (limited to 'Units/default.gd')
-rw-r--r--Units/default.gd41
1 files changed, 20 insertions, 21 deletions
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()