VIVADO pinball game VGA display Verilog code EGO1 development board game

Name: VIVADO pinball game VGA display Verilog code EGO1 development board game

Software: VIVADO

Language: Verilog

Code function:

Design a pinball game and display it on a VGA monitor

1. You can control the start of the game. At the beginning, the digital tube displays 0 points.

2. Use the buttons to control the movement of the racket. When the racket is controlled to catch the ball, the score will be increased by 1.

3. The pinball can bounce when it touches the edge of the screen or the racket.

4. When the ball is not successfully caught, the game ends

FPGA code Verilog/VHDL code resource download: www.hdlcode.com

This code has been verified on the ego1 development board. The development board is as follows. Other development boards can modify the pin adaptation:

ego1 development board.png

Code download:VIVADO pinball game VGA display Verilog code EGO1 development board gameName: VIVADO pinball game VGA display Verilog code EGO1 development Board game (code download at the end of the article) Software: VIVADO Language: Verilog Code function: Design a pinball game and display it on the VGA monitor 1. You can control the start of the game. At the beginning, the digital tube displays 0 points 2. Use the buttons to control the racket Movement, when the racket is controlled to catch the ball, the score is increased by 13. The pinball can bounce when it touches the edge of the screen or the racket. 4. When the ball is not successfully caught, the game ends. FPGA code Verilog/VHDL code resource download: www.icon-default.png?t=N7T8http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=324

Project Files:

a5a30f55-22d5-4bab-aec1-fcf2b815f573.png

program files:

2ecd7784-a504-41b7-8a81-b993afec9bdb.png

Program compilation:

70716d08-3fb8-410c-994b-8af42690eebf.png

RTL diagram:

7beae0dc-66cd-48af-ac5a-c7035d845461.png

Pin assignment:

a7f362ac-f6f1-48c5-b986-d32a4139b53f.png

Part of the code display:

`timescale 1ns / 1ps
//Generate wall, ball and racket
module graphic_generator(clk, rst, btn, pixel_x, pixel_y, video_on, rgb,score);
   input    clk, rst; 
   input    [1:0] btn; 
   input    [9:0] pixel_x, pixel_y; 
   input    video_on; 
   
   output   [11:0] rgb; 
   output [7:0] score;
   reg      [11:0] rgb; 
   
   wire     refr_tick; 
   
   // refr-tick: 1-clock tick asserted at st art of v-sync
   // i.e.. when the screen is refreshed (60 Hz)
   assign refr_tick = (pixel_y==481) && (pixel_x==0); 
   // ==========================
   // object output signals
   // ==========================
   
   wire wall_on, paddle_on, ball_on; 
   wire [11:0] wall_rgb, paddle_rgb, ball_rgb; 
   
   always @ (posedge clk, posedge rst) 
      if (rst) 
         begin   
            paddle_y_reg <= 0; 
            ball_x_reg   <= 0; 
            ball_y_reg   <= 0; 
            x_delta_reg  <= 10'h004; 
            y_delta_reg <= 10'h004; 
         end
      else 
         begin 
            paddle_y_reg <= paddle_y_next; 
            ball_x_reg   <= ball_x_next; 
            ball_y_reg   <= ball_y_next; 
            x_delta_reg  <= x_delta_next; 
            y_delta_reg  <= y_delta_next; 
         end 
         
   // ===============
   // wall
   // ===============
   assign wall_on  = (pixel_x >= 32) && (pixel_x <= 35); 
   assign wall_rgb = 12'hF00; // blue
   
   // ===============
   // racket
   // ===============
   
   wire [9:0] paddle_y_t, paddle_y_b; 
   // register to track top boundary (x position is fixed) 
   reg [9:0] paddle_y_reg, paddle_y_next; 
   assign paddle_y_t = paddle_y_reg; 
   assign paddle_y_b = paddle_y_t + 72 - 1; 
   
   assign paddle_on  = (pixel_x >= 600) && (pixel_x <= 603) && 
                       (pixel_y >= paddle_y_t) && (pixel_y <= paddle_y_b);  //bar top and bottom barriers
   assign paddle_rgb = 12'h0F0; // green
   
   // new paddle y-postion 
   always@ (*) 
   begin
      paddle_y_next = paddle_y_reg; 
      if (refr_tick)
         if (btn[1] & (paddle_y_b < (480 - 1 - 4))) //maxy -1- (bar moving velocity)
            paddle_y_next = paddle_y_reg + 4;  // move down 
         else if (btn[0] & (paddle_y_t > 4))
            paddle_y_next = paddle_y_reg - 4;  // move up 
   end 
   
   // ===============
   // ball
   // ===============
   
   // ball left, right boundary 
   wire [9:0] ball_x_l, ball_x_r; 
   // ball tob, bottom boundary 
   wire [9:0] ball_y_t, ball_y_b;  
   // reg to track left , top position
   reg [9:0] ball_x_reg , ball_y_reg ;
   wire [9:0] ball_x_next , ball_y_next ; 
   //registers to track ball speed
   reg [9:0] x_delta_reg, x_delta_next; 
   reg [9:0] y_delta_reg, y_delta_next; 
   
   //boundary 
   assign ball_x_l = ball_x_reg; 
   assign ball_y_t = ball_y_reg; 
   assign ball_x_r = ball_x_l + 8 - 1; 
   assign ball_y_b = ball_y_t + 8 - 1;
   
   //pixel within ball 
   assign ball_on = (pixel_x >= ball_x_l) && (pixel_x <= ball_x_r) && 
                    (pixel_y >= ball_y_t) && (pixel_y <= ball_y_b); 
   Assign ball_rgb = 12'hFF0; //The ball color is a mixture of red and green
  
  // new ball position 
   assign ball_x_next = (refr_tick) ? ball_x_reg + x_delta_reg : ball_x_reg; 
   assign ball_y_next = (refr_tick) ? ball_y_reg + y_delta_reg : ball_y_reg; 
//   assign ball_x_next = (refr_tick) ? ball_x_reg + x_delta_reg : 10'd0; 
//   assign ball_y_next = (refr_tick) ? ball_y_reg + y_delta_reg : 10'd0;    
   // new ball velocity 
   always @ (*) 
   begin 
      x_delta_next = x_delta_reg; 
      y_delta_next = y_delta_reg; 
      if (ball_y_t < 1) //reach top 
         y_delta_next = 1; 
      else if (ball_y_b > (480 - 1)) // reach bottom 
         y_delta_next = -1; 
      else if (ball_x_l <= 35) // reach wall 
         x_delta_next = 1; //bounce back 
      else if ((ball_x_r >= 600) && (ball_x_r <= 603) &&
               (ball_y_b >= paddle_y_t) && (ball_y_t <= paddle_y_b))
         // reach x of right paddle and hit, ball bounces back 
         x_delta_next = -1; 
       else if(ball_x_r>=610)begin//end game
         x_delta_next = 0;    
         y_delta_next = 0;
         end
   end

Guess you like

Origin blog.csdn.net/diaojiangxue/article/details/134796012