1
+ // -------------------------------------------------------------------------
2
+ // Color_Mapper.sv --
3
+ // Stephen Kempf --
4
+ // 3-1-06 --
5
+ // --
6
+ // Modified by David Kesler 07-16-2008 --
7
+ // Translated by Joe Meng 07-07-2013 --
8
+ // --
9
+ // Fall 2014 Distribution --
10
+ // --
11
+ // For use with ECE 385 Lab 7 --
12
+ // University of Illinois ECE Department --
13
+ // -------------------------------------------------------------------------
14
+
15
+
16
+ module color_mapper ( input [9 : 0 ] DrawX, DrawY,cloudX1, cloudY1,cloudX2, cloudY2, cloudW, cloudH,hp1_w, hp1_x, hp1_y, hp1_h,hp2_w, hp2_x, hp2_y, hp2_h,
17
+ player_h, player_w, player_x1, player_y1,player_x2, player_y2, ball_x1, ball_y1, ball_x2, ball_y2, ball_h, ball_w,
18
+ input [8 : 0 ] player_action1, player_action2, ball_action1, ball_action2,
19
+ input face1, face2, ball_face1, ball_face2, ending1, ending2, summoned_ball1, summoned_ball2,
20
+ input [0 : 39 ][0 : 79 ][0 : 3 ] cloud,
21
+ input [0 : 79 ][0 : 79 ][0 : 3 ] player_w0, player_w1, player_w2, player_w3,
22
+ player_j0, player_j1, player_j2,
23
+ player_a0, player_a1, player_a2,player_a3, player_a4, player_a5,
24
+ input [0 : 39 ][0 : 39 ][0 : 3 ] ball0, ball1, ball2,
25
+ output logic [7 : 0 ] Red, Green, Blue );
26
+
27
+ logic [3 : 0 ] cloud_on1, cloud_on2, player_on1, player_on2, ball_on1, ball_on2;
28
+ logic hp1_on,hp2_on, ground_on;
29
+ logic [9 : 0 ] vDraw1, vDraw2, hDraw1, hDraw2;
30
+ logic [9 : 0 ] vBallDraw1, hBallDraw1;
31
+ logic [9 : 0 ] vBallDraw2, hBallDraw2;
32
+
33
+ assign vDraw1 = DrawY- player_y1;
34
+ assign vDraw2 = DrawY- player_y2;
35
+ assign hDraw1 = face1 == 0 ? DrawX- player_x1 : 80 - DrawX+ player_x1;
36
+ assign hDraw2 = face2 == 0 ? DrawX- player_x2 : 80 - DrawX+ player_x2;
37
+ assign vBallDraw1 = DrawY- ball_y1;
38
+ assign hBallDraw1 = ball_face1 == 0 ? DrawX- ball_x1 : 40 - DrawX+ ball_x1;
39
+ assign vBallDraw2 = DrawY- ball_y2;
40
+ assign hBallDraw2 = ball_face2 == 0 ? DrawX- ball_x2 : 40 - DrawX+ ball_x2;
41
+
42
+
43
+ always_comb
44
+ begin : CloudSprite1
45
+ if ((DrawX >= cloudX1) && (DrawX <= cloudX1 + cloudW) && (DrawY >= cloudY1) && (DrawY <= cloudY1 + cloudH))
46
+ begin
47
+ cloud_on1 = cloud[39 - (DrawY- cloudY1)][79 - (DrawX- cloudX1)];
48
+ end
49
+
50
+ else
51
+ begin
52
+ cloud_on1 = 4'b0 ;
53
+ end
54
+ end
55
+
56
+ always_comb
57
+ begin : CloudSprite2
58
+ if ((DrawX >= cloudX2) && (DrawX <= cloudX2 + cloudW) && (DrawY >= cloudY2) && (DrawY <= cloudY2 + cloudH))
59
+ cloud_on2 = cloud[DrawY- cloudY2][DrawX- cloudX2];
60
+ else
61
+ cloud_on2 = 4'b0 ;
62
+ end
63
+
64
+ always_comb
65
+ begin : hp1
66
+ if ((DrawX >= hp1_x) && (DrawX < hp1_x+ hp1_w) && (DrawY >= hp1_y) && (DrawY <= hp1_y + hp1_h) )
67
+ hp1_on = 1 ;
68
+ else
69
+ hp1_on = 0 ;
70
+ end
71
+
72
+ always_comb
73
+ begin : hp2
74
+ if ((640 - DrawX >= hp2_x) && (640 - DrawX < hp2_x+ hp2_w) && (DrawY >= hp2_y) && (DrawY <= hp2_y + hp2_h))
75
+ begin
76
+ hp2_on = 1 ;
77
+ end
78
+ else
79
+ begin
80
+ hp2_on = 0 ;
81
+ end
82
+ end
83
+
84
+ always_comb
85
+ begin : ground
86
+ if (DrawY >= 380 )
87
+ begin
88
+ ground_on = 1 ;
89
+ end
90
+ else begin
91
+ ground_on = 0 ;
92
+ end
93
+ end
94
+
95
+
96
+ always_comb
97
+ begin : player_draw
98
+ if ((DrawX >= player_x1) && (DrawX <= player_x1 + player_w) && (DrawY >= player_y1) && (DrawY <= player_y1 + player_h))
99
+ begin
100
+ if (player_action1 <= 5 )
101
+ player_on1 = player_w0[vDraw1][hDraw1];
102
+ else if (player_action1 <= 11 )
103
+ player_on1 = player_w1[vDraw1][hDraw1];
104
+ else if (player_action1 <= 17 )
105
+ player_on1 = player_w2[vDraw1][hDraw1];
106
+ else if (player_action1 <= 23 )
107
+ player_on1 = player_w3[vDraw1][hDraw1];
108
+
109
+ else if (player_action1 <= 29 )
110
+ player_on1 = player_j0[vDraw1][hDraw1];
111
+ else if (player_action1 <= 35 )
112
+ player_on1 = player_j1[vDraw1][hDraw1];
113
+
114
+ else if (player_action1 <= 71 )
115
+ player_on1 = player_j2[vDraw1][hDraw1];
116
+
117
+ else if (player_action1 <= 77 )
118
+ player_on1 = player_j1[vDraw1][hDraw1];
119
+ else if (player_action1 <= 83 )
120
+ player_on1 = player_j0[vDraw1][hDraw1];
121
+ else if (player_action1 <= 89 )
122
+ player_on1 = player_w0[vDraw1][hDraw1];
123
+
124
+ else if (player_action1 <= 101 )
125
+ player_on1 = player_a0[vDraw1][hDraw1];
126
+ else if (player_action1 <= 113 )
127
+ player_on1 = player_a1[vDraw1][hDraw1];
128
+ else if (player_action1 <= 125 )
129
+ player_on1 = player_a2[vDraw1][hDraw1];
130
+ else if (player_action1 <= 137 )
131
+ player_on1 = player_a3[vDraw1][hDraw1];
132
+ else if (player_action1 <= 149 )
133
+ player_on1 = player_a4[vDraw1][hDraw1];
134
+ else if (player_action1 <= 161 )
135
+ player_on1 = player_a5[vDraw1][hDraw1];
136
+
137
+ else if (player_action1 <= 173 )
138
+ player_on1 = player_a4[vDraw1][hDraw1];
139
+
140
+ else if (player_action1 <= 185 )
141
+ player_on1 = player_w0[vDraw1][hDraw1];
142
+
143
+ else if (player_action1 <= 197 )
144
+ player_on1 = player_a0[vDraw1][hDraw1];
145
+ else
146
+ player_on1 = player_a1[vDraw1][hDraw1];
147
+ end
148
+ else
149
+ player_on1 = 4'b0 ;
150
+ end
151
+
152
+ always_comb
153
+ begin : player_draw2
154
+ if ((DrawX >= player_x2) && (DrawX <= player_x2 + player_w) && (DrawY >= player_y2) && (DrawY <= player_y2 + player_h))
155
+ begin
156
+ player_on2 = player_w0[vDraw2][hDraw2];
157
+ if (player_action2 <= 5 )
158
+ player_on2 = player_w0[vDraw2][hDraw2];
159
+ else if (player_action2 <= 11 )
160
+ player_on2 = player_w1[vDraw2][hDraw2];
161
+ else if (player_action2 <= 17 )
162
+ player_on2 = player_w2[vDraw2][hDraw2];
163
+ else if (player_action2 <= 23 )
164
+ player_on2 = player_w3[vDraw2][hDraw2];
165
+
166
+ else if (player_action2 <= 29 )
167
+ player_on2 = player_j0[vDraw2][hDraw2];
168
+ else if (player_action2 <= 35 )
169
+ player_on2 = player_j1[vDraw2][hDraw2];
170
+
171
+ else if (player_action2 <= 71 )
172
+ player_on2 = player_j2[vDraw2][hDraw2];
173
+
174
+ else if (player_action2 <= 77 )
175
+ player_on2 = player_j1[vDraw2][hDraw2];
176
+ else if (player_action2 <= 83 )
177
+ player_on2 = player_j0[vDraw2][hDraw2];
178
+ else if (player_action2 <= 89 )
179
+ player_on2 = player_w0[vDraw2][hDraw2];
180
+
181
+ else if (player_action2 <= 101 )
182
+ player_on2 = player_a0[vDraw2][hDraw2];
183
+ else if (player_action2 <= 113 )
184
+ player_on2 = player_a1[vDraw2][hDraw2];
185
+ else if (player_action2 <= 125 )
186
+ player_on2 = player_a2[vDraw2][hDraw2];
187
+ else if (player_action2 <= 137 )
188
+ player_on2 = player_a3[vDraw2][hDraw2];
189
+ else if (player_action2 <= 149 )
190
+ player_on2 = player_a4[vDraw2][hDraw2];
191
+ else if (player_action2 <= 161 )
192
+ player_on2 = player_a5[vDraw2][hDraw2];
193
+
194
+ else if (player_action2 <= 173 )
195
+ player_on2 = player_a4[vDraw2][hDraw2];
196
+
197
+ else if (player_action2 <= 185 )
198
+ player_on2 = player_w0[vDraw2][hDraw2];
199
+
200
+ else if (player_action2 <= 197 )
201
+ player_on2 = player_a0[vDraw2][hDraw2];
202
+ else
203
+ player_on2 = player_a1[vDraw2][hDraw2];
204
+ end
205
+ else
206
+ player_on2 = 4'b0 ;
207
+ end
208
+
209
+ always_comb
210
+ begin : draw_ball1
211
+ if (summoned_ball1 && (DrawX >= ball_x1) && (DrawX <= ball_x1 + ball_w) && (DrawY >= ball_y1) && (DrawY <= ball_y1 + ball_h)) begin
212
+ if (ball_action1 <= 5 )
213
+ ball_on1 = ball0[vBallDraw1][hBallDraw1];
214
+ else if (ball_action1 <= 11 )
215
+ ball_on1 = ball1[vBallDraw1][hBallDraw1];
216
+ else if (ball_action1 <= 17 )
217
+ ball_on1 = ball2[vBallDraw1][hBallDraw1];
218
+ else
219
+ ball_on1 = ball0[vBallDraw1][hBallDraw1];
220
+ end
221
+ else
222
+ ball_on1 = 4'b0 ;
223
+ end
224
+
225
+ always_comb
226
+ begin : draw_ball2
227
+ if (summoned_ball2 && (DrawX >= ball_x2) && (DrawX <= ball_x2 + ball_w) && (DrawY >= ball_y2) && (DrawY <= ball_y2 + ball_h)) begin
228
+ if (ball_action2 <= 5 )
229
+ ball_on2 = ball0[vBallDraw2][hBallDraw2];
230
+ else if (ball_action2 <= 11 )
231
+ ball_on2 = ball1[vBallDraw2][hBallDraw2];
232
+ else if (ball_action2 <= 17 )
233
+ ball_on2 = ball2[vBallDraw2][hBallDraw2];
234
+ else
235
+ ball_on2 = ball0[vBallDraw2][hBallDraw2];
236
+ end
237
+ else
238
+ ball_on2 = 4'b0 ;
239
+ end
240
+
241
+ always_comb
242
+ begin : RGB_Display
243
+ if (cloud_on1 == 4'b0110 )
244
+ begin
245
+ Red <= 8'hBD ;
246
+ Green <= 8'hBD ;
247
+ Blue <= 8'hBD ;
248
+ end
249
+
250
+ else if (cloud_on1 == 4'b0100 )
251
+ begin
252
+ Red <= 8'hFF ;
253
+ Green <= 8'hFF ;
254
+ Blue <= 8'hFF ;
255
+ end
256
+
257
+ else if (cloud_on1 == 4'b0111 )
258
+ begin
259
+ Red <= 8'hE7 ;
260
+ Green <= 8'hE7 ;
261
+ Blue <= 8'hE7 ;
262
+ end
263
+ else if (cloud_on2 == 4'b0110 )
264
+ begin
265
+ Red <= 8'hBD ;
266
+ Green <= 8'hBD ;
267
+ Blue <= 8'hBD ;
268
+ end
269
+
270
+ else if (cloud_on2 == 4'b0100 )
271
+ begin
272
+ Red <= 8'hFF ;
273
+ Green <= 8'hFF ;
274
+ Blue <= 8'hFF ;
275
+ end
276
+
277
+ else if (cloud_on2 == 4'b0111 )
278
+ begin
279
+ Red <= 8'hE7 ;
280
+ Green <= 8'hE7 ;
281
+ Blue <= 8'hE7 ;
282
+ end
283
+ else if (hp1_on == 1 || hp2_on == 1 )
284
+ begin
285
+ Red <= 8'hFF ;
286
+ Green <= 8'h00 ;
287
+ Blue <= 8'h00 ;
288
+ end
289
+ else if (ball_on1 == 4'b0001 )
290
+ begin
291
+ Red<= 8'hff ;
292
+ Green<= 8'hff ;
293
+ Blue<= 8'hff ;
294
+ end
295
+ else if (ball_on1 == 4'b0010 )
296
+ begin
297
+ Red<= 8'ha6 ;
298
+ Green<= 8'h08 ;
299
+ Blue<= 8'h00 ;
300
+ end
301
+ else if (ball_on1 == 4'b0011 )
302
+ begin
303
+ Red<= 8'hff ;
304
+ Green<= 8'he2 ;
305
+ Blue<= 8'h00 ;
306
+ end
307
+ else if (ball_on2 == 4'b0001 )
308
+ begin
309
+ Red<= 8'hff ;
310
+ Green<= 8'hff ;
311
+ Blue<= 8'hff ;
312
+ end
313
+ else if (ball_on2 == 4'b0010 )
314
+ begin
315
+ Red<= 8'hb1 ;
316
+ Green<= 8'h9c ;
317
+ Blue<= 8'hd9 ;
318
+ end
319
+ else if (ball_on2 == 4'b0011 )
320
+ begin
321
+ Red<= 8'h6c ;
322
+ Green<= 8'h00 ;
323
+ Blue<= 8'h6c ;
324
+ end
325
+ else if (ground_on == 1 )
326
+ begin
327
+ Red <= 8'h66 ;
328
+ Green <= 8'h33 ;
329
+ Blue <= 8'h00 ;
330
+ end
331
+ else if (player_on1== 4'b1 && ending1 == 1 )
332
+ begin
333
+ Red <= 8'hdc ;
334
+ Green <= 8'h14 ;
335
+ Blue <= 8'h3c ;
336
+ end
337
+ else if (player_on2== 4'b1 && ending2 == 1 )
338
+ begin
339
+ Red <= 8'h00 ;
340
+ Green <= 8'h00 ;
341
+ Blue <= 8'h84 ;
342
+ end
343
+ else
344
+ begin
345
+ Red = 8'h0 ;
346
+ Green = 8'hBF ;
347
+ Blue = 8'hFF ;
348
+ end
349
+ end
350
+
351
+ endmodule
0 commit comments