Skip to content

Commit

Permalink
Fix deprecated names in Invaders
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinb committed Mar 25, 2017
1 parent ac34d09 commit 72e9d64
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
1 change: 0 additions & 1 deletion Intro/Vect.idr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ data Vect : Nat -> Type -> Type where

append : Vect n a -> Vect m a -> Vect (n + m) a


{-
Try to write this using the interactive tools alone:
Expand Down
2 changes: 1 addition & 1 deletion Invaders/Aliens.idr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ checkHit bs as = checkAll bs as [] []
checkAll [] as asAcc bsAcc = (bsAcc, as ++ asAcc)

drawAliens : List Alien -> { [SDL_ON] } Eff ()
drawAliens [] = return ()
drawAliens [] = pure ()
drawAliens (a :: as) = do let (x, y) = Alien.position a
drawAlien x y
drawAliens as
Expand Down
30 changes: 15 additions & 15 deletions Invaders/Gamestate.idr
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ removeHit gs = let bs = bullets gs in
record { bullets = bs', aliens = as' } gs

drawBullets : List (Int, Int) -> { [SDL_ON] } Eff ()
drawBullets [] = return ()
drawBullets [] = pure ()
drawBullets ((x, y) :: bs) = do rectangle red (x-1) (y-4) 2 8
drawBullets bs

drawBombs : List (Int, Int) -> { [SDL_ON] } Eff ()
drawBombs [] = return ()
drawBombs [] = pure ()
drawBombs ((x, y) :: bs) = do rectangle yellow (x-1) (y-4) 2 8
drawBombs bs

randomDropBomb : GS ()
randomDropBomb = randomDrop (map (Alien.position) (aliens !(Gamestate :- get)))
where
randomDrop : List (Int, Int) -> GS ()
randomDrop [] = return ()
randomDrop [] = pure ()
randomDrop ((x, y) :: as)
= do if (!(rndInt 1 3000) == 100)
then (do s <- Gamestate :- get
Expand All @@ -94,7 +94,7 @@ updateGamestate = do gs <- Gamestate :- get

getPos : GS (Int, Int)
getPos = do s <- Gamestate :- get
return (position s)
pure (position s)

xmove : Int -> GS ()
xmove x = do s <- Gamestate :- get
Expand All @@ -112,14 +112,14 @@ addBullet = do s <- Gamestate :- get

-- Deal with keypresses from SDL
process : Maybe Event -> GS Bool
process (Just AppQuit) = return False
process (Just (KeyDown KeyLeftArrow)) = do xmove (-2); return True
process (Just (KeyUp KeyLeftArrow)) = do xmove 0; return True
process (Just (KeyDown KeyRightArrow)) = do xmove 2; return True
process (Just (KeyUp KeyRightArrow)) = do xmove 0; return True
process (Just (KeyDown KeyUpArrow)) = do ymove (-2); return True
process (Just (KeyUp KeyUpArrow)) = do ymove 0; return True
process (Just (KeyDown KeyDownArrow)) = do ymove 2; return True
process (Just (KeyUp KeyDownArrow)) = do ymove 0; return True
process (Just (KeyDown KeySpace)) = do addBullet; return True
process _ = return True
process (Just AppQuit) = pure False
process (Just (KeyDown KeyLeftArrow)) = do xmove (-2); pure True
process (Just (KeyUp KeyLeftArrow)) = do xmove 0; pure True
process (Just (KeyDown KeyRightArrow)) = do xmove 2; pure True
process (Just (KeyUp KeyRightArrow)) = do xmove 0; pure True
process (Just (KeyDown KeyUpArrow)) = do ymove (-2); pure True
process (Just (KeyUp KeyUpArrow)) = do ymove 0; pure True
process (Just (KeyDown KeyDownArrow)) = do ymove 2; pure True
process (Just (KeyUp KeyDownArrow)) = do ymove 0; pure True
process (Just (KeyDown KeySpace)) = do addBullet; pure True
process _ = pure True
2 changes: 1 addition & 1 deletion Invaders/Rnd.idr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ RND = MkEff Int Random

rndInt : Int -> Int -> { [RND] } Eff Int
rndInt lower upper = do v <- call GetRandom
return (abs (v `prim__sremInt` (upper - lower)) + lower)
pure (abs (v `prim__sremInt` (upper - lower)) + lower)


4 changes: 2 additions & 2 deletions Invaders/Starfield.idr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ updateStarfield = do xs <- Starfield :- get
Starfield :- put xs'
where
upd : List (Int, Int) -> List (Int, Int) -> { [RND] } Eff (List (Int, Int))
upd acc [] = return acc
upd acc [] = pure acc
upd acc ((x, y) :: xs)
= if (y > 479) then do
x <- rndInt 0 639
Expand All @@ -38,7 +38,7 @@ updateStarfield = do xs <- Starfield :- get
upd ((x, y+1) :: acc) xs

drawStarfield : List (Int, Int) -> { [SDL_ON] } Eff ()
drawStarfield [] = return ()
drawStarfield [] = pure ()
drawStarfield ((x, y) :: xs) = do line white x y x y
drawStarfield xs

0 comments on commit 72e9d64

Please sign in to comment.