diff options
| author | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-16 14:10:27 +0100 |
|---|---|---|
| committer | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-25 15:16:53 +0100 |
| commit | aa9fc62a29c865452f3e5437c4166854583bba97 (patch) | |
| tree | f99d64c5b6e31bac583a88d5fd4429bf9c8b248d /app/Scratchy/Syntax.hs | |
| download | scratchy-aa9fc62a29c865452f3e5437c4166854583bba97.tar.gz scratchy-aa9fc62a29c865452f3e5437c4166854583bba97.zip | |
Initial commit
Diffstat (limited to 'app/Scratchy/Syntax.hs')
| -rw-r--r-- | app/Scratchy/Syntax.hs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/app/Scratchy/Syntax.hs b/app/Scratchy/Syntax.hs new file mode 100644 index 0000000..c77e51a --- /dev/null +++ b/app/Scratchy/Syntax.hs @@ -0,0 +1,87 @@ +module Scratchy.Syntax where + +import Graphics.Gloss.Interface.Pure.Game + + +-- Types +------------------------------------------------------------ + +type Duration = Int +type Pos = (Float, Float) +type Cell = (Int, Int) +type SpritePtr = Int + + +-- Constants +------------------------------------------------------------ + +cellsPerSec :: Float +cellsPerSec = 5 + +gridW, gridH :: Int +gridW = 30 +gridH = 30 -- FIXME: move. + +inBounds :: (Int,Int) -> Bool +inBounds (x,y) = x >= 0 && x < gridW && y >= 0 && y < gridH + +cellSize :: Float +cellSize = 30 + +winW, winH :: Int +winW = round (fromIntegral gridW * cellSize) +winH = round (fromIntegral gridH * cellSize) + + +-- Direction +------------------------------------------------------------ + +data Dir = U | D | L | R deriving (Eq,Ord,Show) + +dirVec :: Dir -> (Int, Int) +dirVec U = (0, 1) +dirVec D = (0,-1) +dirVec L = (-1,0) +dirVec R = (1, 0) + +nextCell :: Dir -> (Int, Int) -> (Int, Int) +nextCell d (cx,cy) = + let (dx,dy) = dirVec d + in (cx + dx, cy + dy) + + +-- Syntax +------------------------------------------------------------ + +data InspectionResult + = HasBarrier | HasSprite | IsFree + +data SProg a + = Pure a + + -- Event listening + | OnKeyEvent Key (SProg ()) (SProg a) -- Listener for a specific key + | OnTargetReached SpritePtr (Cell -> SProg ()) (SProg a) -- Listener for a specific sprite + | OnTargetUpdated SpritePtr (Cell -> Cell -> SProg ()) (SProg a) -- Listener for a specific sprite + | OnBarrierHit SpritePtr (Cell -> Cell -> SProg ()) (SProg a) + + -- Sprite and grid actions + | NewSprite Cell Picture (SpritePtr -> SProg a) + | SetColor SpritePtr Color (SProg a) + | SetTarget SpritePtr Cell (SProg a) + | GetTarget SpritePtr (Cell -> SProg a) + | SetBackgroundColor Color (SProg a) + | InspectCell Cell (InspectionResult -> SProg a) + + -- Timer + | After Duration (SProg ()) (SProg a) + deriving Functor + + +-- Combining programs +------------------------------------------------------------ + +combine :: SProg () -> SProg () -> SProg () +combine = undefined -- Fill this in + + |