Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

FPGA jumping logic

Status
Not open for further replies.
Joined
Apr 20, 2022
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18
I am new to FPGA programming and I am using HDL Verilog (Using Vivado) to generate a game similar to geometry dash.

I've written a code such that whilst the button is being pressed the block jumps up and down in the same x position. Once the button is released, the floor changes to 32 pixels above the initial floor and this stays as the new floor position.

However, this was not what was trying to achieve. My code makes it so the floor position is dictated by whether the button is being pressed or not. I was trying to make it such that when the button is pressed the block keeps jumping and if a certain condition is met (i.e. The floor position changes) then the block starts jumping from the new floor position and if the button is released the block rests on the new floor position (exactly like the platforming in geometry dash).

I can see that I need to make the floor position and button press independent but I have no idea how to do it. Any guidance is appreciated

My code referring to the jumping logic:

Code:
module jumping#(parameter

    FLR_POS = 11'd696,

    BLK_HGT = 11'd32,

    INL_BLK_X = 11'd300,

    INL_BLK_Y = FLR_POS - BLK_HGT,

    SPD = 11'd32,

    ACCEL = 11'd2)(

  

    //input pix_clk,

    input game_clk,

    input [4:0] btn,

    output [10:0] blkpos_x,

    output [10:0] blkpos_y

    );

  

    reg [10:0] floor = 11'd696;

    reg [10:0] blkpos_x_r = 11'd300;

    reg [10:0] blkpos_y_r = 11'd664;

    reg jump_state;

    reg [10:0] spd_y = 11'd32;

    reg [10:0] acc_y = 11'd2;

  



    always@(posedge game_clk) begin   

        if(btn[1]) begin                     

            jump_state <= 1;

        end

        else if ((btn[1]==0) && (blkpos_y_r + BLK_HGT >= (floor - 11'd32))) begin

            jump_state <= 0;

        end

    end

  

    always@(posedge game_clk) begin

 

        if(btn[0]) begin                       

            blkpos_x_r <= 11'd503;

            blkpos_y_r <= FLR_POS - BLK_HGT;

        end



        else if(jump_state == 1) begin         

           blkpos_y_r <= blkpos_y_r - spd_y;

           spd_y <= spd_y - acc_y;

          

           if (spd_y == -SPD - acc_y) begin

               spd_y <= SPD;

               blkpos_y_r <= blkpos_y_r;

           end

          

           if (blkpos_y_r + BLK_HGT >= (FLR_POS - 11'd32)) begin

               floor <= floor - 11'd32;

           end

        end

  

        else if(jump_state == 0) begin

            blkpos_y_r <= blkpos_y_r;     

            spd_y = SPD;

            acc_y = ACCEL;

        end

    end

  

    assign blkpos_x = blkpos_x_r;

    assign blkpos_y = blkpos_y_r;

  

endmodule
 

Hello,

I don't understand why input [4:0] btn is 5-bit vector when you wolud like only have two states: pushed and not(pushed). The second question is that you have not the debouncer for button - in such case pushing buttons might generate sequence of states pushed and not pushed (joint oscilations). I don't see any interface to display state of game - the easiest is VGA - which one could implement using several resistors. And in such case you have to synchronise state of objects in game with displaying it on VGA monitor.

Best Regards
--- Updated ---

Hello,

I don't understand why input [4:0] btn is 5-bit vector when you wolud like only have two states: pushed and not(pushed). The second question is that you have not the debouncer for button - in such case pushing buttons might generate sequence of states pushed and not pushed (joint oscilations). I don't see any interface to display state of game - the easiest is VGA - which one could implement using several resistors. And in such case you have to synchronise state of objects in game with displaying it on VGA monitor.

Best Regards
BTW: if you want to have button position counter then you should have incrementation/decrementation of [4:0] btn vector when button is pushed (or maybe two buttons: left and right).
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top