Skip to content

Commit

Permalink
Improve placing ball in hand
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Nov 17, 2023
1 parent afe5424 commit 52e5ee3
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/Game.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Illuminance
import Json.Decode
import Length exposing (Meters)
import List
import Physics.Body as Body
import Physics.Body as Body exposing (Body)
import Physics.Contact as Contact
import Physics.Coordinates exposing (WorldCoordinates)
import Physics.World as World exposing (World)
Expand Down Expand Up @@ -356,7 +356,7 @@ preUpdate msg model =



-- Ball in hand
-- Placing ball in hand


placeBallInHand : Axis3d Meters WorldCoordinates -> Rectangle3d Meters WorldCoordinates -> World Id -> BallInHand
Expand All @@ -375,25 +375,7 @@ placeBallInHand mouseRay spawnArea world =
Just position ->
case Axis3d.intersectionWithRectangle elevatedSpawnArea mouseRay of
Just _ ->
let
canPlace =
List.all
(\body ->
case Body.data body of
Numbered _ ->
Point3d.distanceFrom position (Body.originPoint body)
|> Quantity.greaterThan (Quantity.twice Bodies.ballRadius)

_ ->
True
)
(World.bodies world)
in
if canPlace then
OnTable CanPlace position

else
OnTable CannotPlace position
placeBallInHandHelp (World.bodies world) position

Nothing ->
OnTable CannotPlace position
Expand All @@ -402,6 +384,31 @@ placeBallInHand mouseRay spawnArea world =
OutsideOfTable


{-| Check if overlaps with any of the numbered balls
-}
placeBallInHandHelp : List (Body Id) -> Point3d Meters WorldCoordinates -> BallInHand
placeBallInHandHelp bodies position =
case bodies of
body :: remaining ->
case Body.data body of
Numbered _ ->
if
Body.originPoint body
|> Point3d.distanceFrom position
|> Quantity.lessThan (Quantity.twice Bodies.ballRadius)
then
OnTable CannotPlace position

else
placeBallInHandHelp remaining position

_ ->
placeBallInHandHelp remaining position

[] ->
OnTable CanPlace position



-- Aiming cue

Expand Down

0 comments on commit 52e5ee3

Please sign in to comment.