-
-
Save larsrh/8266599 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{-# LANGUAGE ExistentialQuantification #-} | |
module Entities where | |
data Point = TwoD Int Int | ThreeD Int Int Int | |
class Entity a where | |
pos :: a -> Point | |
speed :: a -> Int | |
id :: a -> String | |
alive :: a -> Bool | |
data TurretTpl = TurretTpl { | |
tViewAngle :: Int | |
, tTurnSpeed :: Int | |
} | |
data Turret = Turret { | |
tAzimuth :: Int | |
, tpl :: Int | |
} | |
data TankTpl = TankTpl { | |
tMaxSpeed :: Int | |
, tMaxHP :: Int | |
, tTurretTpl :: TurretTpl | |
} | |
data Tank = Tank { | |
tName :: String | |
, tPos :: Point | |
, tSpeed :: Int | |
, tHP :: Int | |
, tTurret :: Turret | |
} | |
instance Entity Tank where | |
pos = tPos | |
speed = tSpeed | |
id = tName | |
alive t = tHP t > 0 | |
data Polygon = Polygon [Point] | |
data Terrain = Terrain [Polygon] | |
class Agent a where | |
iterate :: a -> Terrain -> [(Tank, TankTpl)] -> [(Tank, TankTpl)] | |
data Agent' = forall a. Agent a => Agent' a | |
iterate' (Agent' a) = Entities.iterate a | |
data World = World { | |
wTerrain :: Terrain | |
, wTanks :: [(Agent', [(Tank, TankTpl)])] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment