Skip to content

Commit

Permalink
[GH-971-969] - Increase wall colliders and fix items not spawning ins…
Browse files Browse the repository at this point in the history
…ide the square (#977)

* feat: increase wall sizes and map radius

* feat: add square mall attribute

* feat: parse square wall in config

* feat: add square wall values in seeds

* feat: add function used by items to spawn items in the square map

* feat: modularize random position functions
  • Loading branch information
tvillegas98 authored Nov 7, 2024
1 parent 1d7b74e commit 4c0a7aa
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 22 deletions.
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
21 changes: 18 additions & 3 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 @@ -1635,10 +1636,24 @@ defmodule Arena.GameUpdater do
x = Enum.random(-integer_radius..integer_radius) / 1.0 + initial_position.x
y = Enum.random(-integer_radius..integer_radius) / 1.0 + initial_position.y

set_spawn_point(%{x: x, y: y}, object_radius, external_wall, obstacles)
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

set_spawn_point(%{x: x, y: y}, object_radius, external_wall, obstacles)
end

defp set_spawn_point(desired_position, object_radius, external_wall, obstacles) do
circle = %{
id: 1,
shape: :circle,
position: %{x: x, y: y},
position: desired_position,
radius: object_radius,
vertices: [],
speed: 0.0,
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

0 comments on commit 4c0a7aa

Please sign in to comment.