-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBackGroundDelegate.v
executable file
·92 lines (78 loc) · 2.76 KB
/
BackGroundDelegate.v
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module BackGroundDelegate #(parameter ratio = 1, dx = -6'd20)
(input wire moveClk,
input wire rst,
input wire [8:0] GroundY,
input wire [9:0] vgaX,
input wire [9:0] vgaY,
input wire [1:0] gameState,
output wire inGrey,
output wire inWhite);
localparam groundDisplayOffset = 0;
// Draw horizon (Module: BackGround)
wire [3:0] horizonSEL; // Multiplexor
assign horizonSEL1 = 4'b0001; // 选择画地面
assign horizonSEL2 = 4'b0000;
reg signed [11:0] Ground_1_X;
reg signed [11:0] Ground_2_X;
wire [5:0] GroundH;
localparam GroundW = 11'd1200;
wire Ground_1_inGrey;
wire Ground_2_inGrey;
/* Move Ground 1 & 2 */
always @(posedge moveClk or posedge rst) begin
if (rst) begin
Ground_1_X <= 0;
Ground_2_X <= GroundW;
end
else begin
case (gameState)
2'b00: begin
Ground_1_X <= 0;
Ground_2_X <= GroundW;
end
2'b10: begin
if (Ground_1_X == -1200) begin
Ground_1_X <= GroundW - 1;
Ground_2_X <= Ground_2_X - 1;
end
else if (Ground_2_X == -1200) begin
Ground_2_X <= GroundW - 1;
Ground_1_X <= Ground_1_X - 1;
end
else begin
Ground_1_X <= Ground_1_X - 1;
Ground_2_X <= Ground_2_X - 1;
end
end
2'b01: begin
Ground_1_X <= Ground_1_X;
Ground_2_X <= Ground_2_X;
end
default: begin
Ground_1_X <= 0;
Ground_2_X <= GroundW;
end
endcase
end
end
wire Ground1_grey;
wire Ground2_grey;
// Change ox oy to 12 bit here!
drawBackGround #(.ratio(ratio))
horizon1 (.rst(rst),
.ox(Ground_1_X + 1200),
.oy(GroundY - groundDisplayOffset),
.X(vgaX + 1200),
.Y(vgaY),
.select(horizonSEL1),
.inGrey(Ground_1_inGrey));
drawBackGround #(.ratio(ratio))
horizon2 (.rst(rst),
.ox(Ground_2_X + 1200),
.oy(GroundY - groundDisplayOffset),
.X(vgaX + 1200),
.Y(vgaY),
.select(horizonSEL2),
.inGrey(Ground_2_inGrey));
assign inGrey = Ground_1_inGrey | Ground_2_inGrey;
endmodule