-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInvader.hs
40 lines (34 loc) · 867 Bytes
/
Invader.hs
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
{-# LANGUAGE TupleSections #-}
module Invader where
import Paint
import R2
import Rect
invader :: [[Int]]
invader =
[[0,0,1,0,0,0,0,0,1,0,0]
,[0,0,0,1,0,0,0,1,0,0,0]
,[0,0,1,1,1,1,1,1,1,0,0]
,[0,1,1,0,1,1,1,0,1,1,0]
,[1,1,1,1,1,1,1,1,1,1,1]
,[1,0,1,0,0,0,0,0,1,0,1]
,[0,0,0,1,1,0,1,1,0,0,0]]
invaderSize :: (Int,Int)
invaderSize = (length (head invader), length invader)
invaderPixels :: [(Int,Int)]
invaderPixels =
map fst .
filter ((==1) . snd) .
concat .
zipWith (\j x -> zipWith (\i bit -> ((i,j),bit)) [0..] x) [0..] $
invader
invaderView :: R2 -> Int -> Color -> [Paint]
invaderView (x,y) mult color = pixels where
pixels = map f invaderPixels
f ij = Fill (g ij) color
g (i,j) = Rect () a b c d where
a = x + rf (i*mult)
b = y + rf (j*mult)
c = a + rf mult
d = b + rf mult
rf :: Int -> Double
rf = realToFrac