Skip to content

Commit

Permalink
Prepare for class generalization
Browse files Browse the repository at this point in the history
  • Loading branch information
danneu committed Aug 21, 2016
1 parent 98b66bb commit fa69e98
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 187 deletions.
33 changes: 9 additions & 24 deletions src/Action.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,24 @@
module Action exposing (..)


-- Elm
import Time exposing (Time)
--
-- Actions are things that a champ can enqueue at a Waypoint
--


type alias Angle =
Float


-- TODO: Figure out how to leverage the type system here better.
-- For example, is it possible for a Warrior's waypoint to only
-- enqueue Warrior actions?
-- TODO: Will there be General actions not specific to a class?
-- type Action
-- -- WARRIOR
-- = Charge Angle
-- | WarCry Angle
-- -- RANGER
-- | Snipe Angle

type Action
= WarAct WarriorAction
| RanAct RangerAction


-- Starts at (1, tickDuration), ends at (tickDuration, tickDuration)
type alias Duration =
(Int, Int)


type WarriorAction
-- TODO: Will there be General actions not specific to a class?
type Action
-- WARRIOR
= Charge Angle
| WarCry Angle Duration


type RangerAction
= Snipe Angle Duration
--| WarCry Angle Duration
-- RANGER
| Snipe Angle Duration
88 changes: 63 additions & 25 deletions src/Champ.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import Action exposing (Action)
import Class exposing (Class)


type ClassStatus
-- ALL
= Acting Action
-- WARRIOR
| AutoAttacking (Int, Int) Champ


type Status
-- Champ is just standing there (no waypoints)
= Idling
Expand All @@ -24,7 +31,8 @@ type Status
-- Champ is in the middle of its autoattack animation
-- Holds the current tick and the total tick count of the status
-- and also holds the target champ
| AutoAttacking (Int, Int) Champ
--| AutoAttacking (Int, Int) Champ
| ClassSpecific ClassStatus
| Dead


Expand Down Expand Up @@ -52,7 +60,7 @@ init name position (currHp, maxHp) =
, speed = 2
, angle = 0
, waypoints = []
, class = Class.Warrior Nothing
, class = Class.Warrior
}


Expand Down Expand Up @@ -85,15 +93,15 @@ faceWaypoint champ =


-- Makes champ face its attack victim if there is one
faceVictim : Champ -> Champ
faceVictim champ =
case champ.status of
AutoAttacking _ enemy ->
{ champ
| angle = Vector.angleTo champ.position enemy.position
}
_ ->
champ
-- faceVictim : Champ -> Champ
-- faceVictim champ =
-- case champ.status of
-- AutoAttacking _ enemy ->
-- { champ
-- | angle = Vector.angleTo champ.position enemy.position
-- }
-- _ ->
-- champ


-- Sorting the dead champs first lets us render them behind the alive champs.
Expand Down Expand Up @@ -158,10 +166,19 @@ statusToEmoji status =
""
Moving ->
"⏩️"
AutoAttacking _ _ ->
"👊" --"⚔"
Dead ->
""
ClassSpecific classStatus ->
case classStatus of
AutoAttacking _ _ ->
"👊" --"⚔"
Acting action ->
case action of
Action.Charge _ ->
"🚀"
Action.Snipe _ _ ->
"🔫"



statusToSimpleName : Status -> String
Expand All @@ -171,10 +188,18 @@ statusToSimpleName status =
"Idling"
Moving ->
"Moving"
AutoAttacking _ _ ->
"Auto-Attacking"
Dead ->
"Dead"
ClassSpecific classStatus ->
case classStatus of
AutoAttacking _ _ ->
"AutoAttacking"
Acting action ->
case action of
Action.Charge _ ->
"Charging"
Action.Snipe _ _ ->
"Sniping"


viewWaypoint : Maybe Waypoint -> (Waypoint -> msg) -> Waypoint -> Svg msg
Expand Down Expand Up @@ -287,16 +312,6 @@ view ctx champ =
-- TODO: DRY or extract
-- animSpeed 1.0 means play one loop of the animation per round
case champ.status of
AutoAttacking (curr, duration) _ ->
let
animSpeed =
1.0
frames =
9 -- frame count of animation
bucket =
floor (toFloat (curr - 1) / (toFloat duration / frames / animSpeed)) % frames
in
"./img/sprites/champ/attack_" ++ toString bucket ++ ".png"
Moving ->
let
animSpeed =
Expand All @@ -319,6 +334,29 @@ view ctx champ =
"./img/sprites/champ/idle_" ++ toString bucket ++ ".png"
Dead ->
"./img/tombstone.png"
ClassSpecific classStatus ->
case classStatus of
AutoAttacking (curr, duration) _ ->
let
animSpeed =
1.0
frames =
9 -- frame count of animation
bucket =
floor (toFloat (curr - 1) / (toFloat duration / frames / animSpeed)) % frames
in
"./img/sprites/champ/attack_" ++ toString bucket ++ ".png"
_ ->
-- For now use idling for other stuff
let
animSpeed =
2.0
frames =
17
bucket =
floor (toFloat ctx.tickIdx / (toFloat Constants.ticksPerRound / frames / animSpeed)) % frames
in
"./img/sprites/champ/idle_" ++ toString bucket ++ ".png"
-- Scale the champ image to 128x128 instead of 64x64
-- unless they are dead
(x', y', side) =
Expand Down
12 changes: 4 additions & 8 deletions src/Class.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
module Class exposing (..)


-- 1st
import Action


type Class
= Warrior (Maybe Action.WarriorAction)
| Ranger (Maybe Action.RangerAction)
= Warrior
| Ranger


toEmoji : Class -> String
toEmoji class =
case class of
Warrior _ ->
Warrior ->
""
Ranger _ ->
Ranger ->
"🏹"
8 changes: 7 additions & 1 deletion src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,13 @@ view model =
}
in
Grid.view ctx model.grid
, Html.App.map SidebarMsg (Sidebar.view model.sidebar)
-- Only show the Sidebar in Planning mode since it doesn't update
-- as the simulation plays.
, case model.mode of
Planning _ ->
Html.App.map SidebarMsg (Sidebar.view model.sidebar)
_ ->
Html.text ""
, Html.div
[ Html.Attributes.id "footerbar" ]
[ Html.button
Expand Down
Loading

0 comments on commit fa69e98

Please sign in to comment.