Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Cooperative Cuisine Environment
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
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
CoCoSy
Cooperative Cuisine Environment
Commits
3e34e7ad
Commit
3e34e7ad
authored
1 year ago
by
Fabian Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
View restriction in own method
parent
7995e9b9
No related branches found
No related tags found
1 merge request
!62
Resolve "Game Flow"
Pipeline
#47167
passed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
overcooked_simulator/gui_2d_vis/drawing.py
+81
-81
81 additions, 81 deletions
overcooked_simulator/gui_2d_vis/drawing.py
with
81 additions
and
81 deletions
overcooked_simulator/gui_2d_vis/drawing.py
+
81
−
81
View file @
3e34e7ad
...
...
@@ -149,92 +149,92 @@ class Visualizer:
grid_size
,
)
if
"
view_restrictions
"
in
state
and
state
[
"
view_restrictions
"
]:
self
.
draw_lightcones
(
screen
,
grid_size
,
width
,
height
,
state
)
def
draw_lightcones
(
self
,
screen
,
grid_size
,
width
,
height
,
state
):
view_restrictions
=
state
[
"
view_restrictions
"
]
mask
=
pygame
.
Surface
(
screen
.
get_size
(),
pygame
.
SRCALPHA
)
mask
.
fill
((
0
,
0
,
0
,
0
))
mask_color
=
(
0
,
0
,
0
,
0
)
if
"
view_restrictions
"
in
state
and
state
[
"
view_restrictions
"
]:
for
idx
,
restriction
in
enumerate
(
state
[
"
view_restrictions
"
]):
# if idx != 0:
# break
# rotate direction vector in both direction with the angel
# draw 2 large rect which are rotated so that one edge is the viewing border
direction
=
pygame
.
math
.
Vector2
(
restriction
[
"
direction
"
])
pos
=
pygame
.
math
.
Vector2
(
restriction
[
"
position
"
])
angle
=
restriction
[
"
angle
"
]
/
2
range
=
restriction
[
"
range
"
]
angle
=
min
(
angle
,
180
)
pos
=
pos
*
grid_size
+
pygame
.
math
.
Vector2
(
[
grid_size
/
2
,
grid_size
/
2
]
for
idx
,
restriction
in
enumerate
(
view_restrictions
):
direction
=
pygame
.
math
.
Vector2
(
restriction
[
"
direction
"
])
pos
=
pygame
.
math
.
Vector2
(
restriction
[
"
position
"
])
angle
=
restriction
[
"
angle
"
]
/
2
view_range
=
restriction
[
"
range
"
]
angle
=
min
(
angle
,
180
)
pos
=
pos
*
grid_size
+
pygame
.
math
.
Vector2
([
grid_size
/
2
,
grid_size
/
2
])
rect_scale
=
max
(
width
,
height
)
*
2
# rect_scale = 2 * grid_size
left_beam
=
pos
+
(
direction
.
rotate
(
angle
)
*
rect_scale
*
2
)
right_beam
=
pos
+
(
direction
.
rotate
(
-
angle
)
*
rect_scale
*
2
)
cone_mask
=
pygame
.
surface
.
Surface
(
screen
.
get_size
(),
pygame
.
SRCALPHA
)
cone_mask
.
fill
((
255
,
255
,
255
,
255
))
offset_front
=
direction
*
grid_size
*
0.7
if
angle
!=
180
:
shadow_cone_points
=
[
pos
-
offset_front
,
left_beam
-
offset_front
,
left_beam
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
-
(
direction
*
rect_scale
*
2
)
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
-
(
direction
*
rect_scale
*
2
)
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
right_beam
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
right_beam
-
offset_front
,
]
light_cone_points
=
[
pos
-
offset_front
,
left_beam
,
right_beam
]
pygame
.
draw
.
polygon
(
cone_mask
,
mask_color
,
shadow_cone_points
,
)
rect_scale
=
max
(
width
,
height
)
*
2
# rect_scale = 2 * grid_size
left_beam
=
pos
+
(
direction
.
rotate
(
angle
)
*
rect_scale
*
2
)
right_beam
=
pos
+
(
direction
.
rotate
(
-
angle
)
*
rect_scale
*
2
)
cone_mask
=
pygame
.
surface
.
Surface
(
screen
.
get_size
(),
pygame
.
SRCALPHA
)
cone_mask
.
fill
((
255
,
255
,
255
,
255
))
offset_front
=
direction
*
grid_size
*
0.7
if
angle
!=
180
:
pygame
.
draw
.
polygon
(
cone_mask
,
mask_color
,
(
pos
-
offset_front
,
left_beam
-
offset_front
,
left_beam
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
-
(
direction
*
rect_scale
*
2
)
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
-
(
direction
*
rect_scale
*
2
)
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
right_beam
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
right_beam
-
offset_front
,
),
)
if
range
:
n_circle_points
=
40
start_vec
=
np
.
array
(
-
direction
*
range
)
points
=
(
np
.
array
(
create_polygon
(
n_circle_points
,
start_vec
))
*
grid_size
)
+
pos
circle_closed
=
np
.
concatenate
([
points
,
points
[
0
:
1
]],
axis
=
0
)
corners
=
[
pos
-
(
direction
*
rect_scale
),
*
circle_closed
,
pos
-
(
direction
*
rect_scale
),
pos
-
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
+
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
+
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
pos
-
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
]
pygame
.
draw
.
polygon
(
cone_mask
,
mask_color
,
[
*
corners
])
mask
.
blit
(
cone_mask
,
(
0
,
0
),
special_flags
=
pygame
.
BLEND_MAX
)
screen
.
blit
(
mask
,
mask
.
get_rect
(),
special_flags
=
pygame
.
BLEND_RGBA_MULT
,
)
if
view_range
:
n_circle_points
=
40
start_vec
=
np
.
array
(
-
direction
*
view_range
)
points
=
(
np
.
array
(
create_polygon
(
n_circle_points
,
start_vec
))
*
grid_size
)
+
pos
circle_closed
=
np
.
concatenate
([
points
,
points
[
0
:
1
]],
axis
=
0
)
corners
=
[
pos
-
(
direction
*
rect_scale
),
*
circle_closed
,
pos
-
(
direction
*
rect_scale
),
pos
-
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
+
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
90
)
*
rect_scale
),
pos
+
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
pos
-
(
direction
*
rect_scale
)
+
(
direction
.
rotate
(
-
90
)
*
rect_scale
),
]
pygame
.
draw
.
polygon
(
cone_mask
,
mask_color
,
corners
)
mask
.
blit
(
cone_mask
,
(
0
,
0
),
special_flags
=
pygame
.
BLEND_MAX
)
screen
.
blit
(
mask
,
mask
.
get_rect
(),
special_flags
=
pygame
.
BLEND_RGBA_MULT
,
)
def
draw_background
(
self
,
surface
:
pygame
.
Surface
,
width
:
int
,
height
:
int
,
grid_size
:
int
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment