data/full_repos/permissive/427163843/Pong_game_v1.1.srcs/sources_1/imports/test folder/Pong_Ball_Ctrl.v
1: b'%Error: Cannot find file containing module: folder,data/full_repos/permissive/427163843\n        ... Looked in:\n             data/full_repos/permissive/427163843/Pong_game_v1.1.srcs/sources_1/imports/test/folder,data/full_repos/permissive/427163843\n             data/full_repos/permissive/427163843/Pong_game_v1.1.srcs/sources_1/imports/test/folder,data/full_repos/permissive/427163843.v\n             data/full_repos/permissive/427163843/Pong_game_v1.1.srcs/sources_1/imports/test/folder,data/full_repos/permissive/427163843.sv\n             folder,data/full_repos/permissive/427163843\n             folder,data/full_repos/permissive/427163843.v\n             folder,data/full_repos/permissive/427163843.sv\n             obj_dir/folder,data/full_repos/permissive/427163843\n             obj_dir/folder,data/full_repos/permissive/427163843.v\n             obj_dir/folder,data/full_repos/permissive/427163843.sv\n%Error: Cannot find file containing module: data/full_repos/permissive/427163843/Pong_game_v1.1.srcs/sources_1/imports/test\n%Error: Cannot find file containing module: folder/Pong_Ball_Ctrl.v\n%Error: Exiting due to 3 error(s)\n'
module Pong_Ball_Ctrl 
  #(parameter c_GAME_WIDTH=40, 
    parameter c_GAME_HEIGHT=30,
    parameter c_PADDLE_HEIGHT = 6) 
  (input            clk,
   input            i_Game_Active,
   input [5:0]      i_Col_Count_Div,
   input [5:0]      i_Row_Count_Div,
   input [5:0]      i_Paddle_Y_1,
   input [5:0]      i_Paddle_Y_2,
   output reg       o_Draw_Ball,
   output reg [5:0] o_Ball_X = 0,
   output reg [5:0] o_Ball_Y = 0);
 



  parameter c_BALL_SPEED = 1250000;
  parameter c_SCORE_LIMIT = 9;
 
  reg [5:0]  r_Ball_X_Prev = 0;
  reg [5:0]  r_Ball_Y_Prev = 0;
  reg [31:0] r_Ball_Count = 0;
  reg [5:0]  r_Paddle_Y_1 = 0;
  reg [5:0]  r_Paddle_Y_2 = 0;
  reg [5:0]  r_Paddle_middle_1 = 0;
  reg [5:0]  r_Paddle_middle_2 = 0;
  reg [5:0]  r_Paddle_middle_1_plus = 0;
  reg [5:0]  r_Paddle_middle_2_plus = 0;
  reg [3:0]  Ball =0;
  reg [3:0] r_P1_Score = 0;
  reg [3:0] r_Bot_Score = 0;

  reg [3:0]  game_not_active = 4'b0000;
  reg [3:0]  game_active     = 4'b0001;
  reg [3:0]  paddle_edge_1   = 4'b0010;
  reg [3:0]  paddle_edge_2   = 4'b0011;
  reg [3:0]  paddle_middle   = 4'b0100;
  reg [3:0]  paddle_normal   = 4'b0101;
  reg [3:0]  player_1_goal   = 4'b0110;
  reg [3:0]  player_2_goal   = 4'b0111;
  reg [3:0]  reset_game      = 4'b1000;

  always @(posedge clk)
  begin
    case (Ball)


    game_not_active :
     if (i_Game_Active == 1'b0)
     begin
       o_Ball_X      <= c_GAME_WIDTH/2;
       o_Ball_Y      <= c_GAME_HEIGHT/2;
       r_Ball_X_Prev <= c_GAME_WIDTH/2 + 1;
       r_Ball_Y_Prev <= c_GAME_HEIGHT/2 - 1;
     end
     else if (i_Game_Active == 1'b1)
     Ball <= game_active;


    game_active :




    begin
      if (r_Ball_Count < c_BALL_SPEED)      
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;  
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 

        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;
 





        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        if ((r_Ball_Y_Prev < o_Ball_Y && o_Ball_Y == c_GAME_HEIGHT-1) ||
            (r_Ball_Y_Prev > o_Ball_Y && o_Ball_Y != 0 ))
          o_Ball_Y <= o_Ball_Y - 1;
        else
          o_Ball_Y <= o_Ball_Y + 1;



        if ((o_Ball_Y == i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y == r_Paddle_Y_1 && o_Ball_X == 0) )
            Ball <= paddle_edge_1;

        else if ((o_Ball_Y == i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y == r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) )
                 Ball <= paddle_edge_2;

        else if ((o_Ball_Y == r_Paddle_middle_1 && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                 (o_Ball_Y == r_Paddle_middle_1_plus && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2_plus && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= paddle_middle;




        else
        Ball <= game_active;


        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;


        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end



    paddle_edge_1:
    begin
      if (r_Ball_Count < c_BALL_SPEED)
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 
        
        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;

        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        if ((r_Ball_Y_Prev < o_Ball_Y &&
            (o_Ball_Y == c_GAME_HEIGHT-2 || o_Ball_Y == c_GAME_HEIGHT-1)) ||
            (r_Ball_Y_Prev > o_Ball_Y && o_Ball_Y != 0) )
          o_Ball_Y <= o_Ball_Y - 2;
        else
          o_Ball_Y <= o_Ball_Y + 2;



        if ((o_Ball_Y != i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_middle_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1))
            Ball <= game_active;
        else if ((o_Ball_Y == i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y == r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) )
                 Ball <= paddle_edge_2;
        else if ((o_Ball_Y == r_Paddle_middle_1 && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                 (o_Ball_Y == r_Paddle_middle_1_plus && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2_plus && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= paddle_middle;

        else
        Ball <= paddle_edge_1;

        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;
        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end
    



    paddle_edge_2:
    begin
      if (r_Ball_Count < c_BALL_SPEED)
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 

        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;

        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        if ((r_Ball_Y_Prev < o_Ball_Y &&
            (o_Ball_Y == c_GAME_HEIGHT-2 || o_Ball_Y == c_GAME_HEIGHT-1)) ||
            (r_Ball_Y_Prev > o_Ball_Y && o_Ball_Y != 0) )
          o_Ball_Y <= o_Ball_Y - 2;
        else
          o_Ball_Y <= o_Ball_Y + 2;

        if ((o_Ball_Y != i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_middle_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1))
            Ball <= game_active;
        else if ((o_Ball_Y == i_Paddle_Y_1 && o_Ball_X == 0) ||
                (o_Ball_Y == r_Paddle_Y_1 && o_Ball_X == 0) )
                Ball <= paddle_edge_1;
        else if ((o_Ball_Y == r_Paddle_middle_1 && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                 (o_Ball_Y == r_Paddle_middle_1_plus && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2_plus && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= paddle_middle;
        else
        Ball <= paddle_edge_2;

        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;
        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end


    paddle_middle:
    begin
      if (r_Ball_Count < c_BALL_SPEED)
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 
        
        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;
 

        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        
        if ((o_Ball_Y == i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y == r_Paddle_Y_1 && o_Ball_X == 0) )
            Ball <= paddle_edge_1;
        else if ((o_Ball_Y == i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y == r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) )
                 Ball <= paddle_edge_2;
        else if ((o_Ball_Y != i_Paddle_Y_1 && o_Ball_X == 0) ||
                (o_Ball_Y != r_Paddle_Y_1 && o_Ball_X == 0) ||
                (o_Ball_Y != i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y != r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y != r_Paddle_middle_1 && o_Ball_X == 0) ||
                (o_Ball_Y != r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= game_active;
        else
        Ball <= paddle_middle;
        
        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;
        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end

    player_1_goal:
    begin
      if (r_P1_Score == c_SCORE_LIMIT-1)
        r_P1_Score <= 0;
      else
      begin
        r_P1_Score <= r_P1_Score + 1;
        Ball <= reset_game;
      end
    end

    player_2_goal:
    begin
      if (r_Bot_Score == c_SCORE_LIMIT-1)
        r_Bot_Score <= 0;
      else
      begin 
        r_Bot_Score <= r_Bot_Score + 1;
        Ball <= reset_game;
      end
    end

    reset_game:
      Ball <= game_not_active;
    endcase
  end
 
 

  always @(posedge clk)
  begin
    if (i_Col_Count_Div == o_Ball_X && i_Row_Count_Div == o_Ball_Y)
      o_Draw_Ball <= 1'b1;
    else
      o_Draw_Ball <= 1'b0;
  end
 
 
endmodule
module Pong_Ball_Ctrl 
  #(parameter c_GAME_WIDTH=40, 
    parameter c_GAME_HEIGHT=30,
    parameter c_PADDLE_HEIGHT = 6) 
  (input            clk,
   input            i_Game_Active,
   input [5:0]      i_Col_Count_Div,
   input [5:0]      i_Row_Count_Div,
   input [5:0]      i_Paddle_Y_1,
   input [5:0]      i_Paddle_Y_2,
   output reg       o_Draw_Ball,
   output reg [5:0] o_Ball_X = 0,
   output reg [5:0] o_Ball_Y = 0);

 



  parameter c_BALL_SPEED = 1250000;
  parameter c_SCORE_LIMIT = 9;
 
  reg [5:0]  r_Ball_X_Prev = 0;
  reg [5:0]  r_Ball_Y_Prev = 0;
  reg [31:0] r_Ball_Count = 0;
  reg [5:0]  r_Paddle_Y_1 = 0;
  reg [5:0]  r_Paddle_Y_2 = 0;
  reg [5:0]  r_Paddle_middle_1 = 0;
  reg [5:0]  r_Paddle_middle_2 = 0;
  reg [5:0]  r_Paddle_middle_1_plus = 0;
  reg [5:0]  r_Paddle_middle_2_plus = 0;
  reg [3:0]  Ball =0;
  reg [3:0] r_P1_Score = 0;
  reg [3:0] r_Bot_Score = 0;

  reg [3:0]  game_not_active = 4'b0000;
  reg [3:0]  game_active     = 4'b0001;
  reg [3:0]  paddle_edge_1   = 4'b0010;
  reg [3:0]  paddle_edge_2   = 4'b0011;
  reg [3:0]  paddle_middle   = 4'b0100;
  reg [3:0]  paddle_normal   = 4'b0101;
  reg [3:0]  player_1_goal   = 4'b0110;
  reg [3:0]  player_2_goal   = 4'b0111;
  reg [3:0]  reset_game      = 4'b1000;

  always @(posedge clk)
  begin
    case (Ball)


    game_not_active :
     if (i_Game_Active == 1'b0)
     begin
       o_Ball_X      <= c_GAME_WIDTH/2;
       o_Ball_Y      <= c_GAME_HEIGHT/2;
       r_Ball_X_Prev <= c_GAME_WIDTH/2 + 1;
       r_Ball_Y_Prev <= c_GAME_HEIGHT/2 - 1;
     end
     else if (i_Game_Active == 1'b1)
     Ball <= game_active;


    game_active :




    begin
      if (r_Ball_Count < c_BALL_SPEED)      
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;  
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 

        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;
 





        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        if ((r_Ball_Y_Prev < o_Ball_Y && o_Ball_Y == c_GAME_HEIGHT-1) ||
            (r_Ball_Y_Prev > o_Ball_Y && o_Ball_Y != 0 ))
          o_Ball_Y <= o_Ball_Y - 1;
        else
          o_Ball_Y <= o_Ball_Y + 1;



        if ((o_Ball_Y == i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y == r_Paddle_Y_1 && o_Ball_X == 0) )
            Ball <= paddle_edge_1;

        else if ((o_Ball_Y == i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y == r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) )
                 Ball <= paddle_edge_2;

        else if ((o_Ball_Y == r_Paddle_middle_1 && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                 (o_Ball_Y == r_Paddle_middle_1_plus && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2_plus && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= paddle_middle;




        else
        Ball <= game_active;


        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;


        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end



    paddle_edge_1:
    begin
      if (r_Ball_Count < c_BALL_SPEED)
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 
        
        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;

        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        if ((r_Ball_Y_Prev < o_Ball_Y &&
            (o_Ball_Y == c_GAME_HEIGHT-2 || o_Ball_Y == c_GAME_HEIGHT-1)) ||
            (r_Ball_Y_Prev > o_Ball_Y && o_Ball_Y != 0) )
          o_Ball_Y <= o_Ball_Y - 2;
        else
          o_Ball_Y <= o_Ball_Y + 2;



        if ((o_Ball_Y != i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_middle_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1))
            Ball <= game_active;
        else if ((o_Ball_Y == i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y == r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) )
                 Ball <= paddle_edge_2;
        else if ((o_Ball_Y == r_Paddle_middle_1 && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                 (o_Ball_Y == r_Paddle_middle_1_plus && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2_plus && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= paddle_middle;

        else
        Ball <= paddle_edge_1;

        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;
        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end
    



    paddle_edge_2:
    begin
      if (r_Ball_Count < c_BALL_SPEED)
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 

        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;

        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        if ((r_Ball_Y_Prev < o_Ball_Y &&
            (o_Ball_Y == c_GAME_HEIGHT-2 || o_Ball_Y == c_GAME_HEIGHT-1)) ||
            (r_Ball_Y_Prev > o_Ball_Y && o_Ball_Y != 0) )
          o_Ball_Y <= o_Ball_Y - 2;
        else
          o_Ball_Y <= o_Ball_Y + 2;

        if ((o_Ball_Y != i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y != i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
            (o_Ball_Y != r_Paddle_middle_1 && o_Ball_X == 0) ||
            (o_Ball_Y != r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1))
            Ball <= game_active;
        else if ((o_Ball_Y == i_Paddle_Y_1 && o_Ball_X == 0) ||
                (o_Ball_Y == r_Paddle_Y_1 && o_Ball_X == 0) )
                Ball <= paddle_edge_1;
        else if ((o_Ball_Y == r_Paddle_middle_1 && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                 (o_Ball_Y == r_Paddle_middle_1_plus && o_Ball_X == 0) ||
                 (o_Ball_Y == r_Paddle_middle_2_plus && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= paddle_middle;
        else
        Ball <= paddle_edge_2;

        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;
        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end


    paddle_middle:
    begin
      if (r_Ball_Count < c_BALL_SPEED)
        r_Ball_Count <= r_Ball_Count + 1;
      else
      begin
        r_Ball_Count <= 0;
        r_Paddle_Y_1 <= i_Paddle_Y_1 + 6;
        r_Paddle_Y_2 <= i_Paddle_Y_2 + 6;
        r_Paddle_middle_1 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_2 <= i_Paddle_Y_1 + 2;
        r_Paddle_middle_1_plus <= i_Paddle_Y_1 + 3;
        r_Paddle_middle_2_plus <= i_Paddle_Y_2 + 3;
 
        
        r_Ball_X_Prev <= o_Ball_X;
        r_Ball_Y_Prev <= o_Ball_Y;
 

        if ((r_Ball_X_Prev < o_Ball_X && o_Ball_X == c_GAME_WIDTH-1) ||
            (r_Ball_X_Prev > o_Ball_X && o_Ball_X != 0))
          o_Ball_X <= o_Ball_X - 1;
        else
          o_Ball_X <= o_Ball_X + 1;
 
        
        if ((o_Ball_Y == i_Paddle_Y_1 && o_Ball_X == 0) ||
            (o_Ball_Y == r_Paddle_Y_1 && o_Ball_X == 0) )
            Ball <= paddle_edge_1;
        else if ((o_Ball_Y == i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y == r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) )
                 Ball <= paddle_edge_2;
        else if ((o_Ball_Y != i_Paddle_Y_1 && o_Ball_X == 0) ||
                (o_Ball_Y != r_Paddle_Y_1 && o_Ball_X == 0) ||
                (o_Ball_Y != i_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y != r_Paddle_Y_2 && o_Ball_X == c_GAME_WIDTH-1) ||
                (o_Ball_Y != r_Paddle_middle_1 && o_Ball_X == 0) ||
                (o_Ball_Y != r_Paddle_middle_2 && o_Ball_X == c_GAME_WIDTH-1))
                Ball <= game_active;
        else
        Ball <= paddle_middle;
        
        if (o_Ball_X == 0 && 
                (o_Ball_Y < i_Paddle_Y_1 || 
                o_Ball_Y > r_Paddle_Y_1))
                Ball <= player_2_goal;
        if (o_Ball_X == c_GAME_WIDTH-1 && 
                (o_Ball_Y < i_Paddle_Y_2 ||
                o_Ball_Y > r_Paddle_Y_2))
                Ball <= player_1_goal;
      end
    end

    player_1_goal:
    begin
      if (r_P1_Score == c_SCORE_LIMIT-1)
        r_P1_Score <= 0;
      else
      begin
        r_P1_Score <= r_P1_Score + 1;
        Ball <= reset_game;
      end
    end

    player_2_goal:
    begin
      if (r_Bot_Score == c_SCORE_LIMIT-1)
        r_Bot_Score <= 0;
      else
      begin 
        r_Bot_Score <= r_Bot_Score + 1;
        Ball <= reset_game;
      end
    end

    reset_game:
      Ball <= game_not_active;
    endcase
  end
 
 

  always @(posedge clk)
  begin
    if (i_Col_Count_Div == o_Ball_X && i_Row_Count_Div == o_Ball_Y)
      o_Draw_Ball <= 1'b1;
    else
      o_Draw_Ball <= 1'b0;
  end
 
 
endmodule