-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add obstacles new fields * Add obstacles module * Add dynamic obstacles transition logic and active obstacles check * Show obstacle color in the game client * Remove unnecessary config * Anihilate IO inspect * Move mechanic to raised * Add make polygon helper method * Add player moving and mechanic trigger on obstacle activation * Only move players if obstacle turn active * Rename obstacle active to collisionable * Add new polygon hit mechanic * Fix credo complains * Restore dynamic obstracle * Remove unnecessary tracker pattern match * Rename missleading atom * Restore unnecessary variable * Rename status to base_status * Fix wrong obstacle * Spikes positions (#750) * north-eastern spike * add south-western spikes * fix clipping for top obstacle * Fix base statuses for spikes --------- Co-authored-by: tvillegas98 <tvillegas@fi.uba.ar> Co-authored-by: agustinesco <agustinesco@outlook.es> * Use config name instead of id name * Fix missing obstacles names * Move obstacle transition from using message to propper tick handling * Use collisionable obstacles for projectiles * Fix spike time transition not being updated * Fix credo complain * Allow power ups to spawn in dynamic obstacles and DESTROY recursion * Fix obstacle transition * fix clipping between spikes and wall on north easter obstacle * Allow to move other entities besides player * Limit entities to process * Restore bot state machine --------- Co-authored-by: Theo Katz <67983386+tkz00@users.noreply.github.com> Co-authored-by: tvillegas98 <tvillegas@fi.uba.ar> Co-authored-by: Theo <theokatz@gmail.com>
- Loading branch information
1 parent
9431143
commit 6b7c5b2
Showing
16 changed files
with
577 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
defmodule Arena.Game.Obstacle do | ||
@moduledoc """ | ||
Module to hable obstacles logic in game updater | ||
""" | ||
|
||
alias Arena.Game.Skill | ||
alias Arena.Entities | ||
alias Arena.Game.Player | ||
|
||
def collisionable_obstacle?(obstacle) do | ||
obstacle.aditional_info.collisionable | ||
end | ||
|
||
def get_collisionable_obstacles(obstacles) do | ||
Map.filter(obstacles, fn {_obstacle_id, obstacle} -> collisionable_obstacle?(obstacle) end) | ||
end | ||
|
||
def handle_transition_init(obstacle) do | ||
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond) | ||
|
||
current_status_params = | ||
Map.get(obstacle.aditional_info.statuses_cycle, String.to_existing_atom(obstacle.aditional_info.status)) | ||
|
||
update_in(obstacle, [:aditional_info], fn aditional_info -> | ||
aditional_info | ||
|> Map.put(:next_status, current_status_params.next_status) | ||
|> Map.put(:collisionable, current_status_params.make_obstacle_collisionable) | ||
|> Map.put(:time_until_transition_start, now + current_status_params.time_until_transition_ms) | ||
end) | ||
end | ||
|
||
def update_obstacle_transition_status(game_state, %{aditional_info: %{type: "dynamic"}} = obstacle) do | ||
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond) | ||
|
||
case obstacle.aditional_info.status do | ||
"transitioning" -> | ||
if obstacle.aditional_info.time_until_transition < now do | ||
handle_transition(game_state, obstacle.id) | ||
else | ||
game_state | ||
end | ||
|
||
_status -> | ||
if obstacle.aditional_info.time_until_transition_start < now do | ||
start_obstacle_transition(game_state, obstacle) | ||
else | ||
game_state | ||
end | ||
end | ||
end | ||
|
||
def update_obstacle_transition_status(game_state, _obstacle), do: game_state | ||
|
||
def start_obstacle_transition(game_state, obstacle) do | ||
next_status_params = | ||
Map.get(obstacle.aditional_info.statuses_cycle, String.to_existing_atom(obstacle.aditional_info.next_status)) | ||
|
||
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond) | ||
|
||
obstacle = | ||
update_in(obstacle, [:aditional_info], fn aditional_info -> | ||
aditional_info | ||
|> Map.put(:status, "transitioning") | ||
|> Map.put(:time_until_transition, now + next_status_params.transition_time_ms) | ||
end) | ||
|
||
put_in(game_state, [:obstacles, obstacle.id], obstacle) | ||
end | ||
|
||
def handle_transition(game_state, obstacle_id) do | ||
obstacle = get_in(game_state, [:obstacles, obstacle_id]) | ||
|
||
next_status_params = | ||
Map.get(obstacle.aditional_info.statuses_cycle, String.to_existing_atom(obstacle.aditional_info.next_status)) | ||
|
||
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond) | ||
|
||
obstacle = | ||
update_in(obstacle, [:aditional_info], fn aditional_info -> | ||
aditional_info | ||
|> Map.put(:next_status, next_status_params.next_status) | ||
|> Map.put(:status, obstacle.aditional_info.next_status) | ||
|> Map.put(:collisionable, next_status_params.make_obstacle_collisionable) | ||
|> Map.put(:time_until_transition_start, now + next_status_params.time_until_transition_ms) | ||
end) | ||
|
||
Enum.reduce(next_status_params.on_activation_mechanics, game_state, fn mechanic, game_state -> | ||
Skill.do_mechanic(game_state, obstacle, mechanic, %{skill_direction: %{x: 0, y: 0}}) | ||
end) | ||
|> put_in([:obstacles, obstacle.id], obstacle) | ||
|> maybe_move_above_players(obstacle_id) | ||
end | ||
|
||
defp maybe_move_above_players(game_state, obstacle_id) do | ||
obstacle = get_in(game_state, [:obstacles, obstacle_id]) | ||
|
||
if collisionable_obstacle?(obstacle) do | ||
obstacle_area = Entities.make_polygon_area(obstacle.id, obstacle.vertices) | ||
|
||
alive_players = | ||
Player.alive_players(game_state.players) | ||
|
||
players = | ||
Physics.check_collisions(obstacle_area, alive_players) | ||
|> Enum.reduce(game_state.players, fn player_id, players_acc -> | ||
player = Map.get(players_acc, player_id) | ||
|
||
new_position = | ||
Physics.get_closest_available_position( | ||
player.position, | ||
player, | ||
game_state.external_wall, | ||
game_state.obstacles | ||
) | ||
|
||
updated_player = | ||
Map.put(player, :position, new_position) | ||
|
||
Map.put(players_acc, player_id, updated_player) | ||
end) | ||
|
||
%{game_state | players: players} | ||
else | ||
game_state | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.