Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns / 1ps
- //////////////////////////////////////////////////////////////////////////////////
- // Company:
- // Engineer:
- //
- // Create Date: 25.03.2018 17:39:53
- // Design Name:
- // Module Name: draw_rect_ctl
- // Project Name:
- // Target Devices:
- // Tool Versions:
- // Description:
- //
- // Dependencies:
- //
- // Revision:
- // Revision 0.01 - File Created
- // Additional Comments:
- //
- //////////////////////////////////////////////////////////////////////////////////
- module draw_rect_ctl(
- input wire frameClk,
- input wire left,
- input wire[11:0] xpos,
- input wire[11:0] ypos,
- output reg[11:0] rectx,
- output wire[11:0] recty
- );
- localparam RECT_HEIGHT = 64;
- localparam SPEED_INC = 24'b0_000000000001;
- localparam BOUNCE_FACTOR = 24'b0_110011010000;//0.8
- localparam BOTTOM = {600-RECT_HEIGHT,12'h000};//600.0 - RECT_HEIGHT
- reg[11:0] rectx_nxt;
- reg signed[23:0] rectyf,velocity;
- reg signed[23:0] rectyf_nxt,velocity_nxt;
- always @* begin
- if(~left) begin
- velocity_nxt = 0;
- rectx_nxt = xpos;
- rectyf_nxt = {ypos,12'b0};
- end else begin
- velocity_nxt = velocity + SPEED_INC; //przyspieszenie grawitacyjne
- rectx_nxt = rectx;
- rectyf_nxt = rectyf + velocity_nxt;
- if(rectyf_nxt > BOTTOM) begin //odbicie
- rectyf_nxt = BOTTOM - (rectyf_nxt-BOTTOM);
- //pomnoz przez wspolczynnik odbicia
- velocity_nxt = ({24'b0,velocity_nxt}*BOUNCE_FACTOR)>>12;
- velocity_nxt = -velocity_nxt;//odwroc wektor predkosci
- end
- end
- end
- always @(posedge frameClk) begin
- rectx <= rectx_nxt;
- rectyf <= rectyf_nxt;
- velocity <= velocity_nxt;
- end
- assign recty = rectyf[23:12];//czesc calkowita ulamka
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement