-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHero.hs
More file actions
30 lines (26 loc) · 734 Bytes
/
Hero.hs
File metadata and controls
30 lines (26 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE MultiParamTypeClasses #-}
module Hero (
Hero (..)
) where
import Object (Object (..))
import Interaction (Interaction (..), Reaction (..))
import Geometry (Point, Velocity, (|*), (|/))
import Number (Number)
-- The physics of a Hero.
data Hero
= Hero {
hLocation :: Point,
hVelocity :: Velocity,
hMass :: Number
}
deriving (Eq, Show, Read)
-- Heroes are Objects.
instance Object Hero where
position = hLocation
mass = hMass
velocity = hVelocity
tick time (Hero l v m) = Hero (l + v |* (realToFrac time)) v m
impel p (Hero l v m) = Hero l (v + p |/ m) m
-- Heroes never interact.
instance Interaction Hero Hero () where
interaction _ _ = Nothing