Potent_sorcerer
Newbie
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:
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