Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • s476696/pulsgamejam2025
1 result
Show changes
Commits on Source (2)
......@@ -67,24 +67,75 @@ func suspend():
ice_floe.get_parent().add_child(self)
func set_target(t: Vector2):
var ice_floe = get_parent() # Assuming the penguin is directly a child of an IceFloe node
if ice_floe:
var polygon: PackedVector2Array = ice_floe.get_child(0).polygon # Assuming the first child is the polygon
if !Geometry2D.is_point_in_polygon(ice_floe.to_local(t), polygon):
# If the target is outside the ice floe, clamp the target to the closest valid point
t = get_closest_point_in_polygon(t, polygon)
target = t
func get_closest_point_in_polygon(p: Vector2, polygon: PackedVector2Array) -> Vector2:
var closest_point = polygon[0] # Get the first point in the polygon
var min_distance = p.distance_to(closest_point)
for i in range(1, polygon.size()): # Loop through all points in the polygon
var point = polygon[i]
var dist = p.distance_to(point)
if dist < min_distance:
min_distance = dist
closest_point = point
return closest_point
func _process(delta: float) -> void:
var dir = (target - global_position).normalized()
var bump_dir = Vector2.ZERO
self.rotation = -get_parent().rotation
var near_areas: Array[Area2D] = $Area2D.get_overlapping_areas();
var near_areas: Array[Area2D] = $Area2D.get_overlapping_areas()
cluster_score = 0
for area in near_areas:
if area.get_parent() is Penguin && area.get_parent().get_parent() == get_parent():
cluster_score += pow( position.distance_to(area.get_parent().position), -1)
if(position.distance_to(target) >= 50):
for area in near_areas:
if area.get_parent() is Penguin and area.get_parent().get_parent() == get_parent():
cluster_score += pow(position.distance_to(area.get_parent().position), -1)
if position.distance_to(target) >= 50:
$AnimationPlayer.play(type + "_walk")
translate(dir * delta * move_speed)
else:
$AnimationPlayer.play(type + "_idle")
# Ensure the penguin doesn't move off the ice floe by checking Globals.ice_floes
var closest_ice_floe = get_closest_ice_floe()
if closest_ice_floe:
var polygon: PackedVector2Array = closest_ice_floe.get_child(0).polygon # Assuming the first child is the polygon
var local_position = closest_ice_floe.to_local(global_position)
# Check if the penguin is about to move outside the ice floe
if !Geometry2D.is_point_in_polygon(local_position, polygon):
# If the penguin is about to leave, prevent the movement in that direction
var new_direction = get_opposite_direction(dir)
translate(new_direction * delta * move_speed)
# Function to get the closest ice floe (unchanged)
func get_closest_ice_floe() -> IceFloe:
var closest_ice_floe : IceFloe = null
var closest_distance = INF
for ice_floe in Globals.ice_floes:
var distance = global_position.distance_to(ice_floe.global_position)
if distance < closest_distance:
closest_distance = distance
closest_ice_floe = ice_floe
return closest_ice_floe
# Function to get the opposite direction
func get_opposite_direction(direction: Vector2) -> Vector2:
return -direction
func get_middle_point(points: Array) -> Vector2:
......