Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PulsGameJam2025
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabian Keßler
PulsGameJam2025
Compare revisions
531686c47c776f501f259e4ba557c9a78362c38f to 4e6edc22ab99a1c6427078ad56645590fae9cf48
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
s476696/pulsgamejam2025
Select target project
No results found
4e6edc22ab99a1c6427078ad56645590fae9cf48
Select Git revision
Branches
main
Swap
Target
s476696/pulsgamejam2025
Select target project
s476696/pulsgamejam2025
1 result
531686c47c776f501f259e4ba557c9a78362c38f
Select Git revision
Branches
main
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Penguin walking off fixed, snapping TODO
· 332574e2
Lauro S
authored
3 weeks ago
332574e2
fixes Merge branch 'main' of
https://gitlab2.informatik.uni-wuerzburg.de/s476696/pulsgamejam2025
· 4e6edc22
Lauro S
authored
3 weeks ago
4e6edc22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pulsjam2025/NPC/penguin/penguin.gd
+58
-7
58 additions, 7 deletions
pulsjam2025/NPC/penguin/penguin.gd
with
58 additions
and
7 deletions
pulsjam2025/NPC/penguin/penguin.gd
View file @
4e6edc22
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.