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

Add map collisionables #478

Closed
wants to merge 72 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
7dd7775
Handle obstacles creation with different shapes
agustinesco Feb 29, 2024
a643755
Add first polygon obstacle
agustinesco Feb 29, 2024
62b53b1
Show obstacles in game_client and remove magic numbers
agustinesco Feb 29, 2024
cc3ee1c
Send obstacles in proto
agustinesco Feb 29, 2024
01c78ce
Add helper function to get closest point in polygon
agustinesco Feb 29, 2024
86306d7
Add polygon shape to case
agustinesco Feb 29, 2024
e56e21c
Add edges to polygons
agustinesco Feb 29, 2024
58d6dd0
Delete unused function
agustinesco Mar 1, 2024
48b43fb
Delete polygon and restore zone timer
agustinesco Mar 1, 2024
0553388
Run formatter
agustinesco Mar 1, 2024
010431c
Merge branch 'main' into add-polygon-obtacles
agustinesco Mar 8, 2024
f23bb88
Fix polygon vertices
agustinesco Mar 8, 2024
10200cc
Fix credo complain
agustinesco Mar 8, 2024
16053b1
Merge branch 'main' into add-polygon-obtacles
agustinesco Mar 11, 2024
ca1ee6f
Restore polygon line check
agustinesco Mar 11, 2024
b530b49
Merge branch 'main' into add-polygon-obtacles
agustinesco Mar 11, 2024
4f8b9ca
fix clippy complain
agustinesco Mar 12, 2024
45b44b8
Add obstacles and spawn positions
agustinesco Mar 12, 2024
401d050
Add line corners to collision check
agustinesco Mar 12, 2024
e560582
Rename functions
agustinesco Mar 12, 2024
733cbdd
Add sat implementation
agustinesco Mar 18, 2024
e9ec2c8
Remove unnecessary function
agustinesco Mar 18, 2024
e94b867
Process collisions with all entities instead of first one
agustinesco Mar 18, 2024
f26f1b6
Use sat to handle collisions with polygons
agustinesco Mar 18, 2024
3186135
Fix clippy complains
agustinesco Mar 18, 2024
9c05e2e
Change reference link
agustinesco Mar 18, 2024
a422ec7
Merge branch 'main' into add-polygon-obtacles
agustinesco Mar 21, 2024
b244b6e
Remove wrong obstacles
agustinesco Mar 21, 2024
a9511c4
Use pattern match instead of error prone function
agustinesco Mar 21, 2024
545474a
Add sat collision detection to readme
agustinesco Mar 21, 2024
4d23529
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
bd65b94
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
a324732
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
cca2e22
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
2c86bce
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
52409d5
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
e883b6e
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
cc6990e
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
b4a8cf7
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
3bca299
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
badf501
Update apps/arena/docs/collision-detection.md
agustinesco Mar 22, 2024
f34e846
Apply suggestions from code review
agustinesco Mar 22, 2024
6a45472
Merge branch 'main' into add-polygon-obtacles
agustinesco Mar 26, 2024
ca163b0
Add first polygon
agustinesco Mar 26, 2024
67d8da9
Add second polygon
agustinesco Mar 26, 2024
c8a86ea
Add third polygon
agustinesco Mar 26, 2024
10160c1
Add other halfmoon
agustinesco Mar 26, 2024
0a1af6d
Fix ports temporally
Nico-Sanchez Mar 27, 2024
3970e67
Comment configurator deps
Nico-Sanchez Mar 27, 2024
bfbe177
add cactus
agustinesco Apr 4, 2024
5a93bc6
add oposite cactus
agustinesco Apr 4, 2024
f07cc6f
add collider 3
agustinesco Apr 4, 2024
61105c8
add collider 3 inverted
agustinesco Apr 4, 2024
4ab3faf
add collider 3 inverted missing half
agustinesco Apr 4, 2024
ed6eeb1
add center rocks
agustinesco Apr 4, 2024
536e0c2
Add second half of center rocks
agustinesco Apr 4, 2024
a75e38d
Remove wrong center rocks
agustinesco Apr 4, 2024
d5026ce
Merge branch 'main' into add-map-collisionbles
agustinesco Apr 4, 2024
de70dbb
replace h4ck ultimate for pool
agustinesco Apr 5, 2024
1be61fc
improve DoS config
marco-paulucci Apr 8, 2024
6fc4ac2
Merge branch 'main' into change-h4ck-ultimate-for-pool-mechanic
agustinesco Apr 8, 2024
abc9c1b
Merge branch 'main' into add-map-collisionbles
agustinesco Apr 9, 2024
5469b8a
Fix valtimer ultimer pulling players inside obstacles
agustinesco Apr 9, 2024
40238ae
Merge branch 'fix-valtimer-singularity-pulling-you-inside-obstacles' …
agustinesco Apr 9, 2024
7c3cd92
Fix nif
agustinesco Apr 9, 2024
0c831e2
Merge branch 'fix-valtimer-singularity-pulling-you-inside-obstacles' …
agustinesco Apr 9, 2024
7c14261
Fix valtimer goings inside rocks with teleport
agustinesco Apr 9, 2024
50f93ac
Merge branch 'fix-valtimer-singularity-pulling-you-inside-obstacles' …
agustinesco Apr 9, 2024
844ba80
Add missin vertex to half moons
agustinesco Apr 9, 2024
adab8d0
Merge branch 'change-h4ck-ultimate-for-pool-mechanic' into add-map-co…
agustinesco Apr 9, 2024
bd9cfea
Merge branch 'main' into add-map-collisionbles
agustinesco Apr 16, 2024
128af1e
Merge branch 'main' into add-map-collisionbles
agustinesco Apr 18, 2024
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
Prev Previous commit
Next Next commit
Merge branch 'main' into add-polygon-obtacles
agustinesco committed Mar 8, 2024
commit 010431c519bfc3f57d064492130cd3be7594b58f
26 changes: 26 additions & 0 deletions apps/arena/lib/arena/entities.ex
Original file line number Diff line number Diff line change
@@ -115,6 +115,25 @@ defmodule Arena.Entities do
}
end

def new_item(id, position, config) do
%{
id: id,
category: :item,
shape: :circle,
name: "Item" <> Integer.to_string(id),
position: position,
radius: 30.0,
vertices: [],
speed: 0.0,
direction: %{x: 0.0, y: 0.0},
is_moving: false,
aditional_info: %{
name: config.name,
effects: config.effects
}
}
end

def new_obstacle(id, position, radius, shape, vertices) do
%{
id: id,
@@ -208,6 +227,13 @@ defmodule Arena.Entities do
}}
end

def maybe_add_custom_info(entity) when entity.category == :item do
{:item,
%Arena.Serialization.Item{
name: entity.aditional_info.name
}}
end

def maybe_add_custom_info(_entity) do
nil
end
6 changes: 2 additions & 4 deletions apps/arena/lib/arena/game/player.ex
Original file line number Diff line number Diff line change
@@ -99,8 +99,7 @@ defmodule Arena.Game.Player do
end

def revert_stamina_interval(player, revert_by, max_stamina_interval) do
stamina_interval =
min(player.aditional_info.stamina_interval + revert_by, max_stamina_interval)
stamina_interval = min(player.aditional_info.stamina_interval + revert_by, max_stamina_interval)

put_in(player, [:aditional_info, :stamina_interval], stamina_interval)
end
@@ -119,8 +118,7 @@ defmodule Arena.Game.Player do
end

def move(player, direction) do
current_actions =
add_or_remove_moving_action(player.aditional_info.current_actions, direction)
current_actions = add_or_remove_moving_action(player.aditional_info.current_actions, direction)

{x, y} = direction
is_moving = x != 0.0 || y != 0.0
6 changes: 2 additions & 4 deletions apps/arena/lib/arena/game/skill.ex
Original file line number Diff line number Diff line change
@@ -12,8 +12,7 @@ defmodule Arena.Game.Skill do
end

def do_mechanic(game_state, entity, {:circle_hit, circle_hit}, _skill_params) do
circular_damage_area =
Entities.make_circular_area(entity.id, entity.position, circle_hit.range)
circular_damage_area = Entities.make_circular_area(entity.id, entity.position, circle_hit.range)

entity_player_owner = get_entity_player_owner(game_state, entity)

@@ -307,8 +306,7 @@ defmodule Arena.Game.Skill do
when not is_nil(move_by) do
player_for_moving = %{player | is_moving: true, speed: move_by}

physics_player =
Physics.move_entity(player_for_moving, 1.0, game_state.external_wall, game_state.obstacles)
physics_player = Physics.move_entity(player_for_moving, 1.0, game_state.external_wall, game_state.obstacles)

player = Map.merge(player, %{physics_player | is_moving: false, speed: player.speed})
put_in(game_state, [:players, player.id], player)
3 changes: 1 addition & 2 deletions apps/arena/lib/arena/game_socket_handler.ex
Original file line number Diff line number Diff line change
@@ -25,8 +25,7 @@ defmodule Arena.GameSocketHandler do
Logger.info("Websocket INIT called")
Phoenix.PubSub.subscribe(Arena.PubSub, state.game_id)

{:ok, %{player_id: player_id, game_config: config}} =
GameUpdater.join(state.game_pid, state.client_id)
{:ok, %{player_id: player_id, game_config: config}} = GameUpdater.join(state.game_pid, state.client_id)

state =
Map.put(state, :player_id, player_id)
2 changes: 1 addition & 1 deletion apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
@@ -477,7 +477,7 @@ defmodule Arena.GameUpdater do
damage_taken: state.damage_taken,
damage_done: state.damage_done,
status: state.status,
countdown: state.countdown,
start_game_timestamp: state.start_game_timestamp,
obstacles: complete_entities(state.obstacles)
}}
})
15 changes: 8 additions & 7 deletions apps/arena/lib/arena/serialization/messages.pb.ex
Original file line number Diff line number Diff line change
@@ -231,7 +231,7 @@ defmodule Arena.Serialization.GameState.PowerUpsEntry do
field(:value, 2, type: Arena.Serialization.Entity)
end

defmodule Arena.Serialization.GameState.ObstaclesEntry do
defmodule Arena.Serialization.GameState.ItemsEntry do
@moduledoc false

use Protobuf, map: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
@@ -240,10 +240,10 @@ defmodule Arena.Serialization.GameState.ObstaclesEntry do
field(:value, 2, type: Arena.Serialization.Entity)
end

defmodule Arena.Serialization.GameState.ItemsEntry do
defmodule Arena.Serialization.GameState.ObstaclesEntry do
@moduledoc false

use Protobuf, map: true, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
use Protobuf, map: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto3

field(:key, 1, type: :uint64)
field(:value, 2, type: Arena.Serialization.Entity)
@@ -296,9 +296,10 @@ defmodule Arena.Serialization.GameState do
)

field(:status, 11, type: Arena.Serialization.GameStatus, enum: true)
field(:countdown, 12, type: :int64)
field(:start_game_timestamp, 12, type: :int64, json_name: "startGameTimestamp")
field(:items, 13, repeated: true, type: Arena.Serialization.GameState.ItemsEntry, map: true)

field(:obstacles, 13,
field(:obstacles, 14,
repeated: true,
type: Arena.Serialization.GameState.ObstaclesEntry,
map: true
@@ -375,7 +376,7 @@ end
defmodule Arena.Serialization.Item do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3

field(:name, 2, type: :string)
end
@@ -445,7 +446,7 @@ end
defmodule Arena.Serialization.UseItem do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3

field(:item, 1, type: :uint64)
end
6 changes: 2 additions & 4 deletions apps/champions/lib/champions/battle/simulator.ex
Original file line number Diff line number Diff line change
@@ -158,8 +158,7 @@ defmodule Champions.Battle.Simulator do
do: choose_targets(unit, effect, initial_step_state),
else: target_ids

targets_after_effect =
Enum.map(target_ids, fn id -> apply_effect(effect, unit, new_state[id]) end)
targets_after_effect = Enum.map(target_ids, fn id -> apply_effect(effect, unit, new_state[id]) end)

Enum.reduce(targets_after_effect, new_state, fn target_unit, acc_state ->
Map.put(acc_state, target_unit.id, target_unit)
@@ -175,8 +174,7 @@ defmodule Champions.Battle.Simulator do
targeting_strategy: "random",
targets_allies: targets_allies,
amount_of_targets: amount
} =
_effect,
} = _effect,
state
),
do:
3 changes: 1 addition & 2 deletions apps/game_backend/lib/game_backend/campaigns.ex
Original file line number Diff line number Diff line change
@@ -108,8 +108,7 @@ defmodule GameBackend.Campaigns do
def get_next_level(level) do
campaign = level.campaign

next_level =
Repo.get_by(Level, campaign_id: campaign.id, level_number: level.level_number + 1)
next_level = Repo.get_by(Level, campaign_id: campaign.id, level_number: level.level_number + 1)

next_campaign =
Repo.get_by(Campaign,
36 changes: 35 additions & 1 deletion apps/game_client/assets/js/protobuf/messages_pb.js
Original file line number Diff line number Diff line change
@@ -2938,7 +2938,8 @@ proto.GameState.toObject = function(includeInstance, msg) {
powerUpsMap: (f = msg.getPowerUpsMap()) ? f.toObject(includeInstance, proto.Entity.toObject) : [],
status: jspb.Message.getFieldWithDefault(msg, 11, 0),
startGameTimestamp: jspb.Message.getFieldWithDefault(msg, 12, 0),
itemsMap: (f = msg.getItemsMap()) ? f.toObject(includeInstance, proto.Entity.toObject) : []
itemsMap: (f = msg.getItemsMap()) ? f.toObject(includeInstance, proto.Entity.toObject) : [],
obstaclesMap: (f = msg.getObstaclesMap()) ? f.toObject(includeInstance, proto.Entity.toObject) : []
};

if (includeInstance) {
@@ -3043,6 +3044,12 @@ proto.GameState.deserializeBinaryFromReader = function(msg, reader) {
jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readUint64, jspb.BinaryReader.prototype.readMessage, proto.Entity.deserializeBinaryFromReader, 0, new proto.Entity());
});
break;
case 14:
var value = msg.getObstaclesMap();
reader.readMessage(value, function(message, reader) {
jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readUint64, jspb.BinaryReader.prototype.readMessage, proto.Entity.deserializeBinaryFromReader, 0, new proto.Entity());
});
break;
default:
reader.skipField();
break;
@@ -3144,6 +3151,10 @@ proto.GameState.serializeBinaryToWriter = function(message, writer) {
if (f && f.getLength() > 0) {
f.serializeBinary(13, writer, jspb.BinaryWriter.prototype.writeUint64, jspb.BinaryWriter.prototype.writeMessage, proto.Entity.serializeBinaryToWriter);
}
f = message.getObstaclesMap(true);
if (f && f.getLength() > 0) {
f.serializeBinary(14, writer, jspb.BinaryWriter.prototype.writeUint64, jspb.BinaryWriter.prototype.writeMessage, proto.Entity.serializeBinaryToWriter);
}
};


@@ -3455,6 +3466,29 @@ proto.GameState.prototype.clearItemsMap = function() {
};


/**
* map<uint64, Entity> obstacles = 14;
* @param {boolean=} opt_noLazyCreate Do not create the map if
* empty, instead returning `undefined`
* @return {!jspb.Map<number,!proto.Entity>}
*/
proto.GameState.prototype.getObstaclesMap = function(opt_noLazyCreate) {
return /** @type {!jspb.Map<number,!proto.Entity>} */ (
jspb.Message.getMapField(this, 14, opt_noLazyCreate,
proto.Entity));
};


/**
* Clears values from the map. The map will be non-null.
* @return {!proto.GameState} returns this
*/
proto.GameState.prototype.clearObstaclesMap = function() {
this.getObstaclesMap().clear();
return this;
};



/**
* List of repeated fields within this message type.
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.