go-board-code/pong_paddle.v

60 lines
1.4 KiB
Verilog

/**
* Paddles maintain their own location on the screen
*/
module PongPaddle (
input i_Clk,
input [5:0] i_CellX,
input [5:0] i_CellY,
input i_PaddleUp,
input i_PaddleDown,
output reg o_DoDrawPaddle,
output reg [5:0] o_PaddleY
);
parameter X_POS_CELLS = 0;
parameter PADDLE_HEIGHT_CELLS = 6;
parameter SCREEN_HEIGHT_CELLS = 30;
parameter CLOCKS_PER_SECOND = 25000000;
parameter PADDLE_MOVE_TIME_MS = 50;
// omg i can't get this
parameter integer PADDLE_SPEED = 1250000;
reg [$clog2(PADDLE_SPEED)-1:0] r_paddleMoveCount;
wire w_onlyOneButtonDown = i_PaddleUp ^ i_PaddleDown;
always @(posedge i_Clk) begin
// handle end of move delay
if (w_onlyOneButtonDown) begin
if (r_paddleMoveCount == PADDLE_SPEED) begin
r_paddleMoveCount <= 0;
end else begin
r_paddleMoveCount <= r_paddleMoveCount + 1;
end
end
if (
i_PaddleUp &&
r_paddleMoveCount == PADDLE_SPEED &&
o_PaddleY > 0
) begin
o_PaddleY <= o_PaddleY - 1;
end else if (
i_PaddleDown &&
r_paddleMoveCount == PADDLE_SPEED &&
o_PaddleY < SCREEN_HEIGHT_CELLS - PADDLE_HEIGHT_CELLS - 1
) begin
o_PaddleY <= o_PaddleY + 1;
end
if (
i_CellX == X_POS_CELLS &&
i_CellY >= o_PaddleY &&
i_CellY <= o_PaddleY + PADDLE_HEIGHT_CELLS) begin
o_DoDrawPaddle <= 1;
end else begin
o_DoDrawPaddle <= 0;
end
end
endmodule