Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-971-969] - Increase wall colliders and fix items not spawning inside the square #977

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/arena/lib/arena/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ defmodule Arena.Configuration do
map_config
| radius: maybe_to_float(map_config.radius),
initial_positions: Enum.map(map_config.initial_positions, &parse_position/1),
square_wall: map_config.square_wall,
obstacles: Enum.map(map_config.obstacles, &parse_obstacle/1),
pools: Enum.map(map_config.pools, &parse_entity_values/1),
bushes: Enum.map(map_config.bushes, &parse_entity_values/1),
Expand Down
36 changes: 34 additions & 2 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,12 @@ defmodule Arena.GameUpdater do
item_config = Enum.random(state.game_config.items)

position =
random_position_in_map(
random_position_in_square(
item_config.radius,
state.game_state.external_wall,
state.game_state.obstacles,
state.game_state.external_wall.position,
state.game_state.external_wall.radius
state.game_state.square_wall
)

item = Entities.new_item(last_id, position, item_config)
Expand Down Expand Up @@ -792,6 +792,7 @@ defmodule Arena.GameUpdater do
|> Map.put(:damage_done, %{})
|> Map.put(:crates, %{})
|> Map.put(:external_wall, Entities.new_external_wall(0, config.map.radius))
|> Map.put(:square_wall, config.map.square_wall)
|> Map.put(:zone, %{
radius: config.map.radius,
should_start?: config.game.zone_enabled,
Expand Down Expand Up @@ -1659,6 +1660,37 @@ defmodule Arena.GameUpdater do
)
end

defp random_position_in_square(object_radius, external_wall, obstacles, initial_position, square_wall) do
x =
Enum.random(trunc(square_wall.left)..trunc(square_wall.right)) / 1.0 + initial_position.x

y =
Enum.random(trunc(square_wall.bottom)..trunc(square_wall.top)) / 1.0 + initial_position.y

circle = %{
id: 1,
shape: :circle,
position: %{x: x, y: y},
radius: object_radius,
vertices: [],
speed: 0.0,
category: :power_up,
direction: %{x: 0.0, y: 0.0},
is_moving: false,
name: "Circle 1"
}

collisionable_obstacles =
Map.filter(obstacles, fn {_obstacle_id, obstacle} -> obstacle.aditional_info.collisionable end)

Physics.get_closest_available_position(
circle.position,
circle,
external_wall,
collisionable_obstacles
)
Nico-Sanchez marked this conversation as resolved.
Show resolved Hide resolved
end

defp update_visible_players(%{players: players, bushes: bushes} = game_state, game_config) do
now = System.monotonic_time(:millisecond)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule GameBackend.CurseOfMirra.MapConfiguration do
import Ecto.Changeset
alias GameBackend.Configuration.Version

@derive {Jason.Encoder, only: [:name, :radius, :initial_positions, :obstacles, :bushes, :pools, :crates, :active]}
@derive {Jason.Encoder,
only: [:name, :radius, :initial_positions, :obstacles, :bushes, :pools, :crates, :active, :square_wall]}

schema "map_configurations" do
field(:name, :string)
Expand All @@ -18,6 +19,7 @@ defmodule GameBackend.CurseOfMirra.MapConfiguration do
embeds_many(:pools, __MODULE__.Pool, on_replace: :delete)
embeds_many(:bushes, __MODULE__.Bush, on_replace: :delete)
embeds_many(:crates, __MODULE__.Crate, on_replace: :delete)
embeds_one(:square_wall, __MODULE__.SquareWall, on_replace: :delete)

belongs_to(:version, Version)

Expand All @@ -34,9 +36,32 @@ defmodule GameBackend.CurseOfMirra.MapConfiguration do
|> cast_embed(:bushes)
|> cast_embed(:pools)
|> cast_embed(:crates)
|> cast_embed(:square_wall)
|> unique_constraint(:name)
end

defmodule SquareWall do
@moduledoc """
SquareWall embedded schema to be used by MapConfiguration
"""

use GameBackend.Schema

@derive {Jason.Encoder, only: [:right, :left, :top, :bottom]}
embedded_schema do
field(:right, :integer)
field(:left, :integer)
field(:top, :integer)
field(:bottom, :integer)
end

def changeset(square_wall, attrs) do
square_wall
|> cast(attrs, [:right, :left, :top, :bottom])
|> validate_required([:right, :left, :top, :bottom])
end
end

defmodule Position do
@moduledoc """
Position embedded schema to be used by MapConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule GameBackend.Repo.Migrations.AddSquareWallRestriction do
use Ecto.Migration

def change do
alter table(:map_configurations) do
add :square_wall, :map
end
end
end
42 changes: 24 additions & 18 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3568,7 +3568,7 @@ araban_map_config = %{

merliot_map_config = %{
name: "Merliot",
radius: 10000.0,
radius: 15000.0,
active: true,
initial_positions: [
%{
Expand Down Expand Up @@ -3615,19 +3615,19 @@ merliot_map_config = %{
vertices: [
%{
x: 6400.0,
y: 6800.0
y: 12000.0
},
%{
x: 6800.0,
y: 6800.0
x: 12000.0,
y: 12000.0
},
%{
x: 6800.0,
y: -6800.0
x: 12000.0,
y: -12000.0
},
%{
x: 6400.0,
y: -6800.0
y: -12000.0
}
]
},
Expand All @@ -3649,11 +3649,11 @@ merliot_map_config = %{
},
%{
x: 6400.0,
y: 6800.0
y: 12000.0
},
%{
x: -6400.0,
y: 6800.0
y: 12000.0
},
%{
x: -6400.0,
Expand All @@ -3675,19 +3675,19 @@ merliot_map_config = %{
vertices: [
%{
x: -6400.0,
y: 6800.0
y: 12000.0
},
%{
x: -6800.0,
y: 6800.0
x: -12000.0,
y: 12000.0
},
%{
x: -6800.0,
y: -6800.0
x: -12000.0,
y: -12000.0
},
%{
x: -6400.0,
y: -6800.0
y: -12000.0
}
]
},
Expand All @@ -3713,11 +3713,11 @@ merliot_map_config = %{
},
%{
x: 6400.0,
y: -6800.0
y: -12000.0
},
%{
x: -6400.0,
y: -6800.0
y: -12000.0
}
]
},
Expand Down Expand Up @@ -5004,7 +5004,13 @@ merliot_map_config = %{
],
bushes: [],
pools: [],
version_id: version.id
version_id: version.id,
square_wall: %{
right: 6400,
left: -6400,
bottom: -6400,
top: 6400
}
}

{:ok, _araban_map_configuration} =
Expand Down
Loading