-
Notifications
You must be signed in to change notification settings - Fork 0
/
collisionLASERandASTEROID.v
197 lines (135 loc) · 2.66 KB
/
collisionLASERandASTEROID.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
module collisionLASERandASTEROID
(
clock,
reset,
start,
rocketx ,
rockety,
asteroidx,
asteroidy,
laser_x,
laser_y,
asteroid_move_done,
asteroid_destroyed,
laser_move_done,
laser_destroyed,
fire,
destroy_laser,
destroy_asteroid);
input clock;
input reset;
input start;
input [7:0] rocketx;
input [6:0] rockety;
input [7:0] asteroidx;
input [6:0] asteroidy;
input [7:0] laser_x;
input [6:0] laser_y;
input asteroid_move_done;
input asteroid_destroyed;
input laser_move_done;
input laser_destroyed;
input fire;
output reg destroy_laser;
output reg destroy_asteroid;
reg [8:0] score;
//score= 4'b0000;
reg [4:0] current_state, next_state;
localparam
S_nothing=4'd0,
S_play=4'd1,
S_wait_fire= 4'd2,
S_check= 4'd3,
S_destroy=4'd4;
always @(posedge clock)
begin
case (current_state)
S_nothing:
begin
if (start)
begin
next_state=S_play;
end
else
begin
next_state=S_nothing; //stays in s_nothing state
end
end
S_play:
begin
if (fire)
begin
next_state=S_wait_fire;
end
else
begin
next_state=S_play; //if laser is not fired it stays in the s_play state
end
end
S_wait_fire:
begin
if (!fire) // s wait fire only goes to s check when fire is pulsed down to zero
begin
next_state= S_check;
end
else
begin
next_state= S_wait_fire;
end //for else
end //for state
S_check:
begin
if (laser_move_done)
begin //then goes to splay state to wait for fire to be shot again because nothing was shot and laser reached the end of the screen
next_state=S_play;
end
//now check if the locations of the laser and asteroids are same
else if ((laser_x==asteroidx) && (laser_y==(asteroidy+9)))
begin
next_state=S_destroy; //it will destroy the laser and asteroid and increase the score
end
else
begin next_state=S_check;
end
end //end for state
S_destroy: //increases score and sends destroy signal
begin
next_state=S_play; //after destroying it goes to check if laser is shot again
end
endcase
end
//datapath control signals
always@(posedge clock)
begin
destroy_laser=1'b0;
destroy_asteroid=1'b0;
case (current_state)
S_nothing:
begin
score= 9'b000000000;
end
S_play:
begin
end
S_wait_fire:
begin
end
S_check:
begin
end
S_destroy: //score is incremented here
begin
destroy_laser=1'b1;
destroy_asteroid=1'b1;
score<=score+1;
end
endcase
end
always@(posedge clock)
begin
if(reset)
current_state <= S_nothing;
else
current_state <= next_state;
end // state_FFS
endmodule