Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module pipe ( input Clk, // 50 MHz clock
- Reset, // Active-high reset signal
- frame_clk, // The clock indicating a new frame (~60Hz)
- input [9:0] DrawX, DrawY, // Current pixel coordinates
- input [9:0] StartX, StartY,
- output logic is_pipe1 // Whether current pixel belongs to ball or backgroun
- );
- logic [9:0] Pipe_X_Pos, Pipe_X_Motion, Pipe_Y_Pos, Pipe_Y_Motion;
- logic [9:0] Pipe_X_Pos_in, Pipe_X_Motion_in, Pipe_Y_Pos_in, Pipe_Y_Motion_in;
- parameter [9:0] Pipe_X_Center = 10'd320; // Center position on the X axis
- parameter [9:0] Pipe_Y_Center = 10'd240; // Center position on the Y axis
- parameter [9:0] Pipe_X_Min = 10'd0; // Leftmost point on the X axis
- parameter [9:0] Pipe_X_Max = 10'd639; // Rightmost point on the X axis
- parameter [9:0] Pipe_Y_Min = 10'd0; // Topmost point on the Y axis
- parameter [9:0] Pipe_Y_Max = 10'd479; // Bottommost point on the Y axis
- parameter [9:0] Pipe_X_Step = (~(10'd1) + 1'b1); // Step size on the X axis
- parameter [9:0] Pipe_Y_Step = 10'd0;
- parameter [9:0] Pipe_Size = 10'd4; // Ball size
- logic frame_clk_delayed, frame_clk_rising_edge;
- always_ff @ (posedge Clk) begin
- frame_clk_delayed <= frame_clk;
- frame_clk_rising_edge <= (frame_clk == 1'b1) && (frame_clk_delayed == 1'b0);
- end
- always_ff @ (posedge frame_clk_rising_edge)
- begin
- if(Reset)
- begin
- // Pipe_X_Motion <= (~(10'd1) + 1'b1);
- Pipe_X_Motion <= Pipe_X_Step;
- Pipe_Y_Motion <= Pipe_Y_Step;
- Pipe_X_Pos <= StartX;
- Pipe_Y_Pos <= StartY;
- end
- else
- begin
- // Pipe_X_Motion <= (~(10'd1) + 1'b1);
- Pipe_X_Motion <= Pipe_X_Motion_in;
- Pipe_Y_Motion <= Pipe_Y_Motion_in;
- Pipe_X_Pos <= Pipe_X_Pos_in;
- Pipe_Y_Pos <= Pipe_Y_Pos_in;
- end
- end
- always_comb
- begin
- Pipe_X_Pos_in = Pipe_X_Pos;
- Pipe_Y_Pos_in = Pipe_Y_Pos;
- Pipe_X_Motion_in = (~(10'd1) + 1'b1);
- Pipe_Y_Motion_in = Pipe_Y_Motion;
- if (frame_clk_rising_edge)
- begin
- Pipe_X_Pos_in = Pipe_X_Pos + Pipe_X_Motion_in;
- Pipe_Y_Pos_in = Pipe_Y_Pos;
- end
- else
- begin
- Pipe_X_Pos_in = Pipe_X_Pos;
- Pipe_Y_Pos_in = Pipe_Y_Pos;
- end
- end
- always_comb
- begin
- if (DrawX < Pipe_X_Pos + 10'd25 && DrawX > Pipe_X_Pos + (~(10'd25) + 1'b1) && DrawY < Pipe_Y_Pos + 10'd90 && DrawY > Pipe_Y_Pos + (~(10'd90) + 1'b1))
- is_pipe1 = 1'b1;
- else
- is_pipe1 = 1'b0;
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement