8000 colors · abuseofnotation/no-control@79568dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 79568dd

Browse files
author
Boris Marinov
committed
colors
1 parent c5e8b47 commit 79568dd

File tree

6 files changed

+91
-14
lines changed

6 files changed

+91
-14
lines changed

src/Engine/Effect.purs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Effect as NoControl.Engine
1313
import Effect.Console (logShow)
1414
import Effect.Ref (Ref)
1515
import Effect.Ref as Ref
16-
import Graphics.Canvas (Context2D, clearRect, fillPath, rect)
16+
import Graphics.Canvas (Context2D, clearRect, fillPath, rect, setFillStyle)
1717
import Web.Event.EventTarget (addEventListener, eventListener)
1818
import Web.HTML (window)
1919
import Web.HTML.Window (toEventTarget)
@@ -53,11 +53,19 @@ loop fn beginningMap = do
5353
Ref.write newMap mapState
5454
pure unit
5555

56+
renderLayer :: forall a. Context2D -> Objects a -> Effect Unit
57+
renderLayer ctx o =
58+
Data.traverse_
59+
( \object -> do
60+
setFillStyle ctx object.characteristics.color
61+
fillPath ctx $ rect ctx object.position
62+
)
63+
o
64+
5665
renderFrame :: forall a. Context2D -> Map a -> Effect (Map a)
5766
renderFrame ctx gameMap = do
5867
clearRect ctx { x: 0.0, y: 0.0, width: width, height: height }
59-
Data.traverse_ (\object -> fillPath ctx $ rect ctx object.position)
60-
gameMap.objects
61-
Data.traverse_ (\object -> fillPath ctx $ rect ctx object.position)
62-
gameMap.foreground
68+
renderLayer ctx gameMap.background
69+
renderLayer ctx gameMap.objects
70+
renderLayer ctx gameMap.foreground
6371
pure gameMap

src/Engine/Engine.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type ObjectCharacteristics
2222
Number
2323
, bounceability ::
2424
Number
25+
, color :: String
26+
, distance :: Number
2527
}
2628

2729
type GameObject a

src/Engine/Step.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module NoControl.Engine.Step where
33
import Prelude
44
import NoControl.Engine
55

6-
gravityVector = { x: 0.0, y: 1.0 }
6+
gravityVector = { x: 0.0, y: 0.999 }
77

88
updateObjectEnergy :: forall a. GameObject (a) -> Vector
99
updateObjectEnergy o =

src/Level.purs

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module Main.Level where
22

33
import Prelude
4-
import Data.Array (cons, range)
4+
import Data.Array (concat, cons, range)
55
import Data.Int (toNumber)
66
import Main.Types (ObjectType(..))
77
import NoControl.Engine (ObjectPosition, Objects, GameObject)
88
import Web.HTML.HTMLCanvasElement (height)
9+
import Web.HTML.HTMLProgressElement (position)
910

1011
towerDistance = 900.0
1112

@@ -32,6 +33,58 @@ floorGround position =
3233
, height:
3334
1.0
3435
}
36+
"white"
37+
]
38+
39+
backgroundDecor =
40+
[ { position:
41+
{ x: 0.0
42+
, y: 0.0
43+
, width: 2000.0
44+
, height: 1600.0
45+
}
46+
, energy: { x: 0.0, y: 0.0 }
47+
, characteristics:
48+
{ bounceability:
49+
0.0
50+
, maxFallSpeed: 0.0
51+
, color: "black"
52+
, distance: 0.000001
53+
}
54+
, type: unit
55+
}
56+
, { position:
57+
{ x: -100.0
58+
, y: 100.0
59+
, width: 200.0
60+
, height: 1600.0
61+
}
62+
, energy: { x: 0.0, y: 0.0 }
63+
, characteristics:
64+
{ bounceability:
65+
0.0
66+
, maxFallSpeed: 0.0
67+
, color: "darkslategrey"
68+
, distance: 0.1
69+
}
70+
, type: unit
71+
}
72+
, { position:
73+
{ x: 600.0
74+
, y: 100.0
75+
, width: 200.0
76+
, height: 1600.0
77+
}
78+
, energy: { x: 0.0, y: 0.0 }
79+
, characteristics:
80+
{ bounceability:
81+
0.0
82+
, maxFallSpeed: 0.0
83+
, color: "darkslategrey"
84+
, distance: 0.1
85+
}
86+
, type: unit
87+
}
3588
]
3689

3790
decor :: FloorGenerator Unit
@@ -47,6 +100,7 @@ decor position =
47100
, height:
48101
10.0
49102
}
103+
"slategrey"
50104
--floor
51105
, emptyObject unit
52106
{ x:
@@ -58,6 +112,7 @@ decor position =
58112
, height:
59113
30.0
60114
}
115+
"slategrey"
61116
--left end
62117
, emptyObject unit
63118
{ x:
@@ -69,6 +124,7 @@ decor position =
69124
, height:
70125
position.height
71126
}
127+
"slategrey"
72128
-- right end
73129
, emptyObject unit
74130
{ x:
@@ -80,6 +136,7 @@ decor position =
80136
, height:
81137
position.height
82138
}
139+
"slategrey"
83140
-- middle
84141
, emptyObject unit
85142
{ x:
@@ -91,6 +148,12 @@ decor position =
91148
, height:
92149
position.height
93150
}
151+
"slategrey"
152+
]
153+
154+
background :: FloorGenerator Unit
155+
background position =
156+
[ emptyObject unit position "palegoldenrod"
94157
]
95158

96159
generateTowers :: forall a. FloorGenerator a -> Objects a
@@ -99,14 +162,16 @@ generateTowers fn = bind (range 0 towers) (generateTower fn)
99162
generateTower :: forall a. FloorGenerator a -> Int -> Objects a
100163
generateTower fn towerNumber = bind (range 0 towerFloors) (generateFloor fn towerNumber)
101164

102-
emptyObject :: forall a. a -> ObjectPosition -> GameObject a
103-
emptyObject objectType position =
165+
emptyObject :: forall a. a -> ObjectPosition -> String -> GameObject a
166+
emptyObject objectType position color =
104167
{ position: position
105168
, energy: { x: 0.0, y: 0.0 }
106169
, characteristics:
107170
{ bounceability:
108171
0.0
109172
, maxFallSpeed: 0.0
173+
, color: color
174+
, distance: 1.0
110175
}
111176
, type: objectType
112177
}
@@ -139,6 +204,8 @@ generateObjects =
139204
0.0
140205
, maxFallSpeed:
141206
10.0
207+
, color: "red"
208+
, distance: 1.0
142209
}
143210
, type: Player
144211
}
@@ -154,6 +221,6 @@ generateMap =
154221
, y: 0
155222
}
156223
, objects: generateObjects
157-
, foreground: (generateTowers decor)
158-
, background: []
224+
, foreground: concat [ (generateTowers decor) ]
225+
, background: concat [ backgroundDecor, (generateTowers background) ]
159226
}

src/Step.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ isPlayer o = case o.type of
6868
updateCoordinates :: forall a. Maybe (GameObject ObjectType) -> GameObject a -> GameObject a
6969
updateCoordinates (Just player) a =
7070
{ position:
71-
{ x: a.position.x - player.position.x + 400.0
72-
, y: a.position.y - player.position.y + 300.0
71+
{ x: a.position.x - (player.position.x - 400.0) * a.characteristics.distance
72+
, y: a.position.y - (player.position.y - 300.0) * a.characteristics.distance
7373
, width:
7474
a.position.width
7575
, height:

test/Collisions.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Test.Assert (assert)
1313
o position =
1414
{ position
1515
, energy: { x: 3.0, y: -2.0 }
16-
, characteristics: { maxFallSpeed: 10.0, bounceability: 0.0 }
16+
, characteristics: { maxFallSpeed: 10.0, bounceability: 0.0, color: "red", distance: 1.0 }
1717
, type: None
1818
}
1919

0 commit comments

Comments
 (0)
0