-
Notifications
You must be signed in to change notification settings - Fork 0
/
collisionROCKETandASTEROID.v
113 lines (79 loc) · 1.41 KB
/
collisionROCKETandASTEROID.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
module collisionROCKETandASTEROID(
start,
clock,
reset,
rocketx ,
rockety,
asteroidx,
asteroidy, // is asteroid y coming in as y+9 ?? or should i do that here
gameover,
destroyasteroid);
input start;
input clock;
input reset;
input [7:0] rocketx;
input [6:0] rockety;
input [7:0] asteroidx;
input [6:0] asteroidy;
output reg gameover;
output reg destroyasteroid;
reg [3:0] current_state, next_state;
localparam S_wait= 3'd0, S_destroy=3'd2, S_play=3'd3;
always @(posedge clock) begin
case(current_state)
S_wait:
begin
if (start)
begin
next_state=S_play;
end
else
begin
next_state=S_wait;
end
end
S_play:
begin
//state only checks if the rocket and the asteroid collides
if ((rocketx==asteroidx) && ( rockety==asteroidy+9))
begin
next_state=S_destroy;
end
else
begin
next_state=S_play;
end
end
S_destroy:
begin
next_state=S_wait;
end
endcase
end
//datapath control signals
always@(posedge clock)
begin
gameover=1'b0;
destroyasteroid=1'b0;
case (current_state)
S_wait:
begin
end
S_play:
begin
end
S_destroy:
begin
gameover=1'b1;
destroyasteroid=1'b1;
end
endcase
end //for always block
always@(posedge clock)
begin
if(reset)
current_state <= S_wait;
else
current_state <= next_state;
end // state_FFS
endmodule