aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities/Types.hs
blob: 8d78f22bb9962d841f986c0323862948b5ae0263 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module Game.Entities.Types
  ( Dir (..),
    Type (..),
    Collision,
    IsBlocked,
    Entities (..),
    Action (..),
    Entity (..),
    EntityData (..),
  )
where

import Data.IORef
import Game.Sprites qualified as S

data Dir = DirRight | DirLeft deriving (Eq, Show, Ord)

data Type = TypePlayer | TypePickup | TypeEffect | TypeEnemy deriving (Eq)

data EntityData = NoData | ShooterData {coolDown :: Int} | RunnerData {wallCount :: Int} | PlayerData {checkx :: Int, checky :: Int}

type Collision = Entity -> IO Bool

type IsBlocked = Int -> Int -> Bool

data Entities = Entities
  { sprites :: S.SpriteSheet,
    player :: IORef Entity,
    entities :: [Entity]
  }

-- | The effect name must match the sprite name in the spritesheet.
type EffectName = String

data Action
  = ActionAddEffect Int Int EffectName
  | ActionAddBattery Int Int
  | ActionHitPlayer
  | ActionHitPlayerDeadly
  | ActionExitStarted
  | ActionEntryDone
  | ActionExitDone
  | ActionAddBlast Int Int Dir Collision IsBlocked

data Entity = Entity
  { typ :: Type,
    x :: Int,
    y :: Int,
    delay :: Int,
    frame :: Int,
    set :: Int,
    jumping :: Bool,
    gravity :: Int,
    dir :: Dir,
    sprite :: S.Sprite,
    update :: Entity -> IO Entity,
    destroy :: Bool,
    actions :: [Action],
    dat :: EntityData
  }