data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v
1: b'%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:263: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_x <= p1_x + 28 ;        \n                   ^~\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:264: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s VARREF \'p1_y\' generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_y <= p1_y;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:267: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_x <= p1_x + 6 ;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:268: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_y <= p1_y + p_h;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:271: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s VARREF \'p1_x\' generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_x <= p1_x;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:272: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_y <= p1_y + 6;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:275: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s SUB generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_x <= p1_x + p_w - b_w ;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:276: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b1_y <= p1_y + 28;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:294: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_x <= p2_x + 28 ;        \n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:295: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s VARREF \'p2_y\' generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_y <= p2_y;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:298: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_x <= p2_x + 6 ;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:299: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_y <= p2_y + p_h;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:302: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s VARREF \'p2_x\' generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_x <= p2_x;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:303: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_y <= p2_y + 6;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:306: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s SUB generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_x <= p2_x + p_w - b_w ;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:307: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 bits.\n                                                                                                    : ... In instance color_generator\n              b2_y <= p2_y + 28;\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:330: Operator LT expects 32 bits on the LHS, but LHS\'s VARREF \'b1_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n        if ((((b1_x < p2_x &&  b1_x + b_w > p2_x) || (p2_x < b1_x &&  p2_x + p_w > b1_x)) &&\n                    ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:330: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b1_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n        if ((((b1_x < p2_x &&  b1_x + b_w > p2_x) || (p2_x < b1_x &&  p2_x + p_w > b1_x)) &&\n                                    ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:331: Operator LT expects 32 bits on the LHS, but LHS\'s VARREF \'b1_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n              ((b1_y < p2_y &&  b1_y + b_h > p2_y) || (p2_y < b1_y &&  p2_y + p_h > b1_y))\n                     ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:331: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b1_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n              ((b1_y < p2_y &&  b1_y + b_h > p2_y) || (p2_y < b1_y &&  p2_y + p_h > b1_y))\n                                     ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:337: Operator LT expects 32 bits on the LHS, but LHS\'s VARREF \'b2_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n        if ((((b2_x < p1_x &&  b2_x + b_w > p1_x) || (p1_x < b2_x &&  p1_x + p_w > b2_x)) &&\n                    ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:337: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b2_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n        if ((((b2_x < p1_x &&  b2_x + b_w > p1_x) || (p1_x < b2_x &&  p1_x + p_w > b2_x)) &&\n                                    ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:338: Operator LT expects 32 bits on the LHS, but LHS\'s VARREF \'b2_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n              ((b2_y < p1_y &&  b2_y + b_h > p1_y) || (p1_y < b2_y &&  p1_y + p_h > b2_y))\n                     ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:338: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b2_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n              ((b2_y < p1_y &&  b2_y + b_h > p1_y) || (p1_y < b2_y &&  p1_y + p_h > b2_y))\n                                     ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:407: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b1_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n assign b1_en = ((column >= b1_x) && (column < b1_x + b_w)) && ((row >= b1_y) && (row < b1_y + b_h)) && b1_fired;\n                                                    ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:407: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b1_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n assign b1_en = ((column >= b1_x) && (column < b1_x + b_w)) && ((row >= b1_y) && (row < b1_y + b_h)) && b1_fired;\n                                                                                             ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:409: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b2_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n assign b2_en = ((column >= b2_x) && (column < b2_x + b_w)) && ((row >= b2_y) && (row < b2_y + b_h)) && b2_fired;\n                                                    ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:409: Operator ADD expects 32 bits on the LHS, but LHS\'s VARREF \'b2_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n assign b2_en = ((column >= b2_x) && (column < b2_x + b_w)) && ((row >= b2_y) && (row < b2_y + b_h)) && b2_fired;\n                                                                                             ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:423: Operator SUB expects 32 bits on the RHS, but RHS\'s VARREF \'b1_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n  assign obj_b1_x = column - b1_x;\n                           ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:424: Operator SUB expects 32 bits on the RHS, but RHS\'s VARREF \'b2_x\' generates 10 bits.\n                                                                                                    : ... In instance color_generator\n  assign obj_b2_x = column - b2_x;\n                           ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:427: Operator SUB expects 32 bits on the RHS, but RHS\'s VARREF \'b1_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n  assign obj_b1_y = row - b1_y;\n                        ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:428: Operator SUB expects 32 bits on the RHS, but RHS\'s VARREF \'b2_y\' generates 9 bits.\n                                                                                                    : ... In instance color_generator\n  assign obj_b2_y = row - b2_y;\n                        ^\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:429: Cannot find file containing module: \'obj_p\'\n  obj_p obj_p1(.x(obj_p1_x[5:0]), .y(obj_p1_y[5:0]), .dir(p1_dir), .en(p1_en), .data(p1_data));\n  ^~~~~\n        ... Looked in:\n             data/full_repos/permissive/502126697/verilog/rtl/shooting_game,data/full_repos/permissive/502126697/obj_p\n             data/full_repos/permissive/502126697/verilog/rtl/shooting_game,data/full_repos/permissive/502126697/obj_p.v\n             data/full_repos/permissive/502126697/verilog/rtl/shooting_game,data/full_repos/permissive/502126697/obj_p.sv\n             obj_p\n             obj_p.v\n             obj_p.sv\n             obj_dir/obj_p\n             obj_dir/obj_p.v\n             obj_dir/obj_p.sv\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:430: Cannot find file containing module: \'obj_b\'\n  obj_b obj_b1(.x(obj_b1_x[2:0]), .y(obj_b1_y[2:0]) ,  .en(b1_en), .data(b1_data));\n  ^~~~~\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:431: Cannot find file containing module: \'obj_p\'\n  obj_p obj_p2(.x(obj_p2_x[5:0]), .y(obj_p2_y[5:0]), .dir(p2_dir), .en(p2_en), .data(p2_data));\n  ^~~~~\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:432: Cannot find file containing module: \'obj_b\'\n  obj_b obj_b2(.x(obj_b2_x[2:0]), .y(obj_b2_y[2:0]),  .en(b2_en), .data(b2_data));\n  ^~~~~\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:460: Cannot find file containing module: \'obj_heart\'\n  obj_heart obj_h11(.x(obj_h11_x[3:0]), .y(obj_h11_y[3:0]), .en(p1_h_en[0]), .data(p1_h_data[0]));\n  ^~~~~~~~~\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:461: Cannot find file containing module: \'obj_heart\'\n  obj_heart obj_h12(.x(obj_h12_x[3:0]), .y(obj_h12_y[3:0]), .en(p1_h_en[1]), .data(p1_h_data[1]));\n  ^~~~~~~~~\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:462: Cannot find file containing module: \'obj_heart\'\n  obj_heart obj_h21(.x(obj_h21_x[3:0]), .y(obj_h22_y[3:0]), .en(p2_h_en[0]), .data(p2_h_data[0]));\n  ^~~~~~~~~\n%Error: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:463: Cannot find file containing module: \'obj_heart\'\n  obj_heart obj_h22(.x(obj_h22_x[3:0]), .y(obj_h21_y[3:0]), .en(p2_h_en[1]), .data(p2_h_data[1]));\n  ^~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:525: Operator COND expects 3 bits on the Conditional True, but Conditional True\'s SEL generates 2 bits.\n                                                                                                    : ... In instance color_generator\n  assign blue = disp_en  ? pix[1:0] : 3\'b000;\n                         ^\n%Warning-WIDTH: data/full_repos/permissive/502126697/verilog/rtl/shooting_game/color_generator.v:525: Operator ASSIGNW expects 2 bits on the Assign RHS, but Assign RHS\'s COND generates 3 bits.\n                                                                                                    : ... In instance color_generator\n  assign blue = disp_en  ? pix[1:0] : 3\'b000;\n              ^\n%Error: Exiting due to 8 error(s), 34 warning(s)\n'
module color_generator(
  input        game_clk,
  input        reset,
  input        disp_en,
  input [4:0]  p1_control,
  input [4:0]  p2_control,
  input        start,
  input [31:0]  column,
  input [31:0]  row,
  output [2:0] red,
  output [2:0] green,
  output [1:0] blue
);


  wire up_1     ;
  wire down_1   ;
  wire left_1   ;
  wire right_1  ;
  wire shoot_1  ;
  
  wire up_2     ;
  wire down_2   ;
  wire left_2   ;
  wire right_2  ;
  wire shoot_2  ;
  

  localparam window_w = 639;
  localparam window_h = 479;


  


  localparam menu_main = 2'b00;
  localparam menu_win_p1 = 2'b01;
  localparam menu_win_p2 = 2'b10;
  localparam game_running = 2'b11;
  
    reg [1:0] game_state;
    



	

	localparam p_vel = 6;
  localparam b_vel = 15;
	  
	  
	localparam p_w = 40;
  localparam p_h = 40;
  localparam b_w = 6;
  localparam b_h = 6;
  localparam h_w = 15;
  localparam h_h = 15;
  
  
  



	 reg signed [31:0] p1_x ;
	reg signed [31:0]  p1_y ;
	reg p1_moving         ;
	wire [1:0] p1_data     ;
	wire p1_en             ;
	reg  [1:0] p1_dir     ;

	reg [1:0] p1_health ;
	wire [1:0] p1_h_en;
	localparam integer p1_h_x = window_w - 45 ;
	localparam integer p1_h_y = window_h - 25 ;
	wire [1:0]  p1_h_data ;

	reg [9:0] b1_x ;
	reg [8:0] b1_y ;
	wire b1_data ;
	wire b1_en ;
	reg b1_fired ;
	reg [1:0] b1_dir;
	


	reg signed [31:0] p2_x ;
	reg signed [31:0] p2_y ;
	reg p2_moving         ;
	wire [1:0] p2_data     ;
	wire p2_en             ;
	reg  [1:0] p2_dir     ;

	reg [1:0] p2_health ;
	wire [1:0] p2_h_en;
	localparam integer p2_h_x = 10 ;
	localparam integer p2_h_y = 10 ;
	wire [1:0]  p2_h_data ;

	reg [9:0] b2_x  ;
	reg [8:0] b2_y;
	wire b2_data ;
	wire b2_en ;
	reg b2_fired ;
	reg [1:0] b2_dir;
	






  localparam px_menu_bg = 4'd0;
  localparam px_menu_main = 4'd1;
  localparam px_menu_p1 = 4'd2;
  localparam px_menu_p2 = 4'd3;
  localparam px_game_bg = 4'd4;
  localparam px_game_p1 = 4'd5;
  localparam px_game_p2 = 4'd6;
  localparam px_game_b1 = 4'd7;
  localparam px_game_b2 = 4'd8;
  localparam px_game_h11 = 4'd9;
  localparam px_game_h12 = 4'd10;
  localparam px_game_h21 = 4'd11;
  localparam px_game_h22 = 4'd12;
  
  reg [3:0] sel_pix;
  reg [7:0] pix;


  localparam color_red = 8'hE0;
  localparam color_green = 8'h1C;
  localparam color_blue = 8'h03;
  localparam color_white = 8'hFF;
  localparam color_black = 8'h00;
  localparam color_brown = 8'hB1;
  localparam color_gray = 8'hDB;




  assign up_1     = p1_control[0];
  assign down_1   = p1_control[1];
  assign left_1   = p1_control[2];
  assign right_1  = p1_control[3];
  assign shoot_1  = p1_control[4];
  assign up_2     = p2_control[0];
  assign down_2   = p2_control[1];
  assign left_2   = p2_control[2];
  assign right_2  = p2_control[3];
  assign shoot_2  = p2_control[4];

      

  always@(posedge game_clk or posedge reset) begin
    if(reset) begin
      game_state  <= menu_main;
      p1_moving <= 0;
      p1_dir      <= 2'b00;
      p1_x        <= window_w-180;
      p1_y        <= window_h-80;
      b1_fired    <= 0;
      b1_dir      <= 0;
      b1_x        <= 0;
      b1_y        <= 0;
      
      p1_health   <= 2;
        
            
      p2_moving <= 0;
      p2_dir      <= 2'b01;
      p2_x        <= 140;
      p2_y        <= 40;
      b2_fired    <= 0;
      b2_dir      <= 0;
      b2_x        <= 0;
      b2_y        <= 0;
      p2_health   <= 2;
    end else begin
      if(game_state == menu_main) begin
        if(start) begin
          game_state <= game_running;
        end        
      end
      
      if(game_state == menu_win_p2 || game_state == menu_win_p1) begin
        if(start) begin
          p1_moving <= 0;
          p1_dir      <= 2'b00;
          p1_x        <= window_w-180;
          p1_y        <= window_h-80;
          b1_fired    <= 0;
          b1_dir      <= 0;
          b1_x        <= 0;
          b1_y        <= 0;
          
          p1_health   <= 2;
            
                
          p2_moving <= 0;
          p2_dir      <= 2'b01;
          p2_x        <= 140;
          p2_y        <= 40;
          b2_fired    <= 0;
          b2_dir      <= 0;
          b2_x        <= 0;
          b2_y        <= 0;
          p2_health   <= 2;
          game_state <= game_running;
        end        
      end
      


      if(game_state == game_running) begin


        if (up_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b00; 
          p1_y      <= p1_y - p_vel;
        end else if (down_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b01;
          p1_y      <= p1_y + p_vel;
        end else if (left_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b10;
          p1_x      <= p1_x - p_vel;
        end else if (right_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b11;
          p1_x      <= p1_x + p_vel;
        end else begin
          p1_moving <= 0;
        end

        if (up_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b00;
          p2_y      <= p2_y - p_vel;
        end else if (down_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b01;
          p2_y      <= p2_y + p_vel;
        end else if (left_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b10;
          p2_x      <= p2_x - p_vel;
        end else if (right_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b11;
          p2_x      <= p2_x + p_vel;
        end else begin
          p2_moving <= 0;
        end


        if (shoot_1 && ~b1_fired) begin
          b1_fired <= 1;
          b1_dir <= p1_dir;
          case(b1_dir) 
            0: begin 
              b1_x <= p1_x + 28 ;        
              b1_y <= p1_y;
            end
            1: begin 
              b1_x <= p1_x + 6 ;
              b1_y <= p1_y + p_h;
            end
            2: begin 
              b1_x <= p1_x;
              b1_y <= p1_y + 6;
            end
            default: begin 
              b1_x <= p1_x + p_w - b_w ;
              b1_y <= p1_y + 28;
            end
          endcase
        end else if (b1_fired) begin
          case(b1_dir)
            0: b1_y <= b1_y - b_vel;
            1: b1_y <= b1_y + b_vel;
            2: b1_x <= b1_x - b_vel;
            3: b1_x <= b1_x + b_vel;
          endcase
        end


        if (shoot_2 && ~b2_fired) begin
          b2_fired <= 1;
          b2_dir <= p2_dir;
          case(b2_dir) 
            0: begin 
              b2_x <= p2_x + 28 ;        
              b2_y <= p2_y;
            end
            1: begin 
              b2_x <= p2_x + 6 ;
              b2_y <= p2_y + p_h;
            end
            2: begin 
              b2_x <= p2_x;
              b2_y <= p2_y + 6;
            end
            default: begin 
              b2_x <= p2_x + p_w - b_w ;
              b2_y <= p2_y + 28;
            end
          endcase
        end else if (b2_fired) begin
          case(b2_dir)
            0: b2_y <= b2_y - b_vel;
            1: b2_y <= b2_y + b_vel;
            2: b2_x <= b2_x - b_vel;
            3: b2_x <= b2_x + b_vel;
          endcase
        end



        if (((b1_x <= 0) || (b1_x >= window_w - b_w)) || ((b1_y <= 0) || (b1_y >= window_h - b_h))) begin
          b1_fired <= 0;
        end

        if ( ( (b2_x <= 0) || (b2_x >= window_w - b_w) ) || ( (b2_y <= 0) || (b2_y >= window_h - b_h) ) ) begin
          b2_fired <= 0;
        end


        if ((((b1_x < p2_x &&  b1_x + b_w > p2_x) || (p2_x < b1_x &&  p2_x + p_w > b1_x)) &&
              ((b1_y < p2_y &&  b1_y + b_h > p2_y) || (p2_y < b1_y &&  p2_y + p_h > b1_y))
            ) && b1_fired ) begin
          p2_health <= p2_health - 1;
          b1_fired <= 0;
        end

        if ((((b2_x < p1_x &&  b2_x + b_w > p1_x) || (p1_x < b2_x &&  p1_x + p_w > b2_x)) &&
              ((b2_y < p1_y &&  b2_y + b_h > p1_y) || (p1_y < b2_y &&  p1_y + p_h > b2_y))
            ) && b2_fired ) begin
          p1_health <= p1_health - 1;
          b2_fired <= 0;
        end


        if (((p1_x < p2_x+2 && p1_x + p_w > p2_x) || (p2_x < p1_x+2 && p2_x + p_w > p1_x)) &&
            ((p1_y < p2_y+2 && p1_y + p_h > p2_y) || (p2_y < p1_y+2 && p2_y + p_h > p1_y))) begin
          if (p1_moving) begin
            case(p1_dir)
              0: p2_y <= p2_y - p_vel;
              1: p2_y <= p2_y + p_vel;
              2: p2_x <= p2_x - p_vel;
              3: p2_x <= p2_x + p_vel;
            endcase
          end
          if (p2_moving) begin
            case(p2_dir)
              0: p1_y <= p1_y - p_vel;
              1: p1_y <= p1_y + p_vel;
              2: p1_x <= p1_x - p_vel;
              3: p1_x <= p1_x + p_vel;
            endcase
          end
        end


        if(p1_x < 0) begin 
          p1_x <= 3;
        end
        if(p1_x > window_w - p_w) begin 
          p1_x <= window_w - p_w ;
        end
        if(p1_y < 0) begin 
          p1_y <= 3 ;
        end
        if(p1_y > window_h - p_h) begin 
          p1_y <= window_h - p_h;
        end


        if(p2_x < 0) begin 
          p2_x <= 3;
        end
        if(p2_x > window_w - p_w) begin 
          p2_x <= window_w - p_w ;
        end
        if(p2_y < 0) begin 
          p2_y <= 3 ;
        end
        if(p2_y > window_h - p_h) begin 
          p2_y <= window_h - p_h;
        end


        if(p1_health == 0) begin
          game_state <= menu_win_p2;
        end
        if(p2_health == 0) begin
          game_state <= menu_win_p1;
        end
        
      end
    end
  end


	assign p1_en = ((column >= p1_x) && (column < p1_x + p_w)) && ((row >= p1_y) && (row < p1_y + p_h));
	assign b1_en = ((column >= b1_x) && (column < b1_x + b_w)) && ((row >= b1_y) && (row < b1_y + b_h)) && b1_fired;
	assign p2_en = ((column >= p2_x) && (column < p2_x + p_w)) && ((row >= p2_y) && (row < p2_y + p_h));
	assign b2_en = ((column >= b2_x) && (column < b2_x + b_w)) && ((row >= b2_y) && (row < b2_y + b_h)) && b2_fired;


  wire [31:0] obj_p1_x;
  wire [31:0] obj_b1_x;
  wire [31:0] obj_b2_x;
  wire [31:0] obj_p1_y;
  wire [31:0] obj_b2_y;
  wire [31:0] obj_b1_y;
  wire [31:0] obj_p2_x;
  wire [31:0] obj_p2_y;
  
  assign obj_p1_x = column - p1_x;
  assign obj_p2_x = column - p2_x;
  assign obj_b1_x = column - b1_x;
  assign obj_b2_x = column - b2_x;
  assign obj_p1_y = row - p1_y;
  assign obj_p2_y = row - p2_y;
  assign obj_b1_y = row - b1_y;
  assign obj_b2_y = row - b2_y;
  obj_p obj_p1(.x(obj_p1_x[5:0]), .y(obj_p1_y[5:0]), .dir(p1_dir), .en(p1_en), .data(p1_data));
  obj_b obj_b1(.x(obj_b1_x[2:0]), .y(obj_b1_y[2:0]) ,  .en(b1_en), .data(b1_data));
  obj_p obj_p2(.x(obj_p2_x[5:0]), .y(obj_p2_y[5:0]), .dir(p2_dir), .en(p2_en), .data(p2_data));
  obj_b obj_b2(.x(obj_b2_x[2:0]), .y(obj_b2_y[2:0]),  .en(b2_en), .data(b2_data));


  assign p1_h_en[0] = ((column >= p1_h_x) && (column < p1_h_x + h_w)) && ((row >= p1_h_y) && (row < p1_h_y + h_h)) && p1_health > 0;
  assign p1_h_en[1] = ((column >= p1_h_x + h_w+5) && (column < p1_h_x + 2*h_w+5)) && ((row >= p1_h_y) && (row < p1_h_y + h_h)) && p1_health > 1;

  assign p2_h_en[0] = ((column >= p2_h_x) && (column < p2_h_x + h_w)) && ((row >= p2_h_y) && (row < p2_h_y + h_h)) && p2_health > 0;
  assign p2_h_en[1] = ((column >= p2_h_x + h_w+5) && (column < p2_h_x + 2*h_w+5)) && ((row >= p2_h_y) && (row < p2_h_y + h_h)) && p2_health > 1;

  wire [31:0]  obj_h11_x;
  wire [31:0]  obj_h12_x;
  wire [31:0]  obj_h22_x;
  wire [31:0]  obj_h21_x;
  wire [31:0]  obj_h11_y;
  wire [31:0]  obj_h12_y;
  wire [31:0]  obj_h22_y;
  wire [31:0]  obj_h21_y;
  
  assign  obj_h11_x = column-p1_h_x;
  assign  obj_h12_x = column-(p1_h_x+h_w+5);
  assign  obj_h22_x = column-(p2_h_x+h_w+5);
  assign  obj_h21_x = column-p2_h_x;
  assign  obj_h11_y = row-p1_h_y;
  assign  obj_h12_y = row-p1_h_y;
  assign  obj_h22_y = row-p2_h_y;
  assign  obj_h21_y = row-p2_h_y;
   
  
  obj_heart obj_h11(.x(obj_h11_x[3:0]), .y(obj_h11_y[3:0]), .en(p1_h_en[0]), .data(p1_h_data[0]));
  obj_heart obj_h12(.x(obj_h12_x[3:0]), .y(obj_h12_y[3:0]), .en(p1_h_en[1]), .data(p1_h_data[1]));
  obj_heart obj_h21(.x(obj_h21_x[3:0]), .y(obj_h22_y[3:0]), .en(p2_h_en[0]), .data(p2_h_data[0]));
  obj_heart obj_h22(.x(obj_h22_x[3:0]), .y(obj_h21_y[3:0]), .en(p2_h_en[1]), .data(p2_h_data[1]));

  always@(*) begin

    if(game_state == menu_win_p1 )begin
      sel_pix = px_menu_p1 ;
    end else if (game_state == menu_win_p2) begin
      sel_pix = px_menu_p2;
    end else if(game_state == game_running) begin
      if(p1_en) sel_pix = px_game_p1;
      else if(p2_en) sel_pix = px_game_p2;
      else if(b1_en) sel_pix = px_game_b1;
      else if(b2_en) sel_pix = px_game_b2;
      else if(p1_h_en[0]) sel_pix = px_game_h11;
      else if(p1_h_en[1]) sel_pix = px_game_h12;
      else if(p2_h_en[0]) sel_pix = px_game_h21;
      else if(p2_h_en[1]) sel_pix = px_game_h22;
      else sel_pix = px_game_bg;
    end else begin
      sel_pix = px_menu_main ;
    end
  end

  always @(*) begin
    case(sel_pix)

      px_menu_main: pix = color_brown;
      px_menu_p1: pix = color_blue;
      px_menu_p2: pix = color_green;

      px_game_h11: pix = p1_h_data[0] ? color_red : color_gray;
      px_game_h12: pix = p1_h_data[1] ? color_red : color_gray;
      px_game_h21: pix = p2_h_data[0] ? color_red : color_gray;
      px_game_h22: pix = p2_h_data[1] ? color_red : color_gray;

      px_game_p1: begin
        case(p1_data)
          2'b00: pix = color_gray;
          2'b01: pix = color_blue;
          2'b10: pix = color_black;
          2'b11: pix = color_brown;
        endcase
      end
      px_game_p2: begin
        case(p2_data)
          2'b00: pix = color_gray;
          2'b01: pix = color_green;
          2'b10: pix = color_black;
          2'b11: pix = color_red;
        endcase
      end

      px_game_b1: pix = b1_data ? color_blue : color_gray;
      px_game_b2: pix = b2_data ? color_green  :color_gray;

      px_game_bg: pix = color_gray;
      default: pix = color_gray;
    endcase
  end

  assign red = disp_en   ? pix[7:5] : 3'b000;
  assign green = disp_en ? pix[4:2] : 3'b000;
  assign blue = disp_en  ? pix[1:0] : 3'b000;

endmodule
module color_generator(
  input        game_clk,
  input        reset,
  input        disp_en,
  input [4:0]  p1_control,
  input [4:0]  p2_control,
  input        start,
  input [31:0]  column,
  input [31:0]  row,
  output [2:0] red,
  output [2:0] green,
  output [1:0] blue
);



  wire up_1     ;
  wire down_1   ;
  wire left_1   ;
  wire right_1  ;
  wire shoot_1  ;
  
  wire up_2     ;
  wire down_2   ;
  wire left_2   ;
  wire right_2  ;
  wire shoot_2  ;
  

  localparam window_w = 639;
  localparam window_h = 479;


  


  localparam menu_main = 2'b00;
  localparam menu_win_p1 = 2'b01;
  localparam menu_win_p2 = 2'b10;
  localparam game_running = 2'b11;
  
    reg [1:0] game_state;
    



	

	localparam p_vel = 6;
  localparam b_vel = 15;
	  
	  
	localparam p_w = 40;
  localparam p_h = 40;
  localparam b_w = 6;
  localparam b_h = 6;
  localparam h_w = 15;
  localparam h_h = 15;
  
  
  



	 reg signed [31:0] p1_x ;
	reg signed [31:0]  p1_y ;
	reg p1_moving         ;
	wire [1:0] p1_data     ;
	wire p1_en             ;
	reg  [1:0] p1_dir     ;

	reg [1:0] p1_health ;
	wire [1:0] p1_h_en;
	localparam integer p1_h_x = window_w - 45 ;
	localparam integer p1_h_y = window_h - 25 ;
	wire [1:0]  p1_h_data ;

	reg [9:0] b1_x ;
	reg [8:0] b1_y ;
	wire b1_data ;
	wire b1_en ;
	reg b1_fired ;
	reg [1:0] b1_dir;
	


	reg signed [31:0] p2_x ;
	reg signed [31:0] p2_y ;
	reg p2_moving         ;
	wire [1:0] p2_data     ;
	wire p2_en             ;
	reg  [1:0] p2_dir     ;

	reg [1:0] p2_health ;
	wire [1:0] p2_h_en;
	localparam integer p2_h_x = 10 ;
	localparam integer p2_h_y = 10 ;
	wire [1:0]  p2_h_data ;

	reg [9:0] b2_x  ;
	reg [8:0] b2_y;
	wire b2_data ;
	wire b2_en ;
	reg b2_fired ;
	reg [1:0] b2_dir;
	






  localparam px_menu_bg = 4'd0;
  localparam px_menu_main = 4'd1;
  localparam px_menu_p1 = 4'd2;
  localparam px_menu_p2 = 4'd3;
  localparam px_game_bg = 4'd4;
  localparam px_game_p1 = 4'd5;
  localparam px_game_p2 = 4'd6;
  localparam px_game_b1 = 4'd7;
  localparam px_game_b2 = 4'd8;
  localparam px_game_h11 = 4'd9;
  localparam px_game_h12 = 4'd10;
  localparam px_game_h21 = 4'd11;
  localparam px_game_h22 = 4'd12;
  
  reg [3:0] sel_pix;
  reg [7:0] pix;


  localparam color_red = 8'hE0;
  localparam color_green = 8'h1C;
  localparam color_blue = 8'h03;
  localparam color_white = 8'hFF;
  localparam color_black = 8'h00;
  localparam color_brown = 8'hB1;
  localparam color_gray = 8'hDB;




  assign up_1     = p1_control[0];
  assign down_1   = p1_control[1];
  assign left_1   = p1_control[2];
  assign right_1  = p1_control[3];
  assign shoot_1  = p1_control[4];
  assign up_2     = p2_control[0];
  assign down_2   = p2_control[1];
  assign left_2   = p2_control[2];
  assign right_2  = p2_control[3];
  assign shoot_2  = p2_control[4];

      

  always@(posedge game_clk or posedge reset) begin
    if(reset) begin
      game_state  <= menu_main;
      p1_moving <= 0;
      p1_dir      <= 2'b00;
      p1_x        <= window_w-180;
      p1_y        <= window_h-80;
      b1_fired    <= 0;
      b1_dir      <= 0;
      b1_x        <= 0;
      b1_y        <= 0;
      
      p1_health   <= 2;
        
            
      p2_moving <= 0;
      p2_dir      <= 2'b01;
      p2_x        <= 140;
      p2_y        <= 40;
      b2_fired    <= 0;
      b2_dir      <= 0;
      b2_x        <= 0;
      b2_y        <= 0;
      p2_health   <= 2;
    end else begin
      if(game_state == menu_main) begin
        if(start) begin
          game_state <= game_running;
        end        
      end
      
      if(game_state == menu_win_p2 || game_state == menu_win_p1) begin
        if(start) begin
          p1_moving <= 0;
          p1_dir      <= 2'b00;
          p1_x        <= window_w-180;
          p1_y        <= window_h-80;
          b1_fired    <= 0;
          b1_dir      <= 0;
          b1_x        <= 0;
          b1_y        <= 0;
          
          p1_health   <= 2;
            
                
          p2_moving <= 0;
          p2_dir      <= 2'b01;
          p2_x        <= 140;
          p2_y        <= 40;
          b2_fired    <= 0;
          b2_dir      <= 0;
          b2_x        <= 0;
          b2_y        <= 0;
          p2_health   <= 2;
          game_state <= game_running;
        end        
      end
      


      if(game_state == game_running) begin


        if (up_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b00; 
          p1_y      <= p1_y - p_vel;
        end else if (down_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b01;
          p1_y      <= p1_y + p_vel;
        end else if (left_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b10;
          p1_x      <= p1_x - p_vel;
        end else if (right_1) begin
          p1_moving <= 1;
          p1_dir    <= 2'b11;
          p1_x      <= p1_x + p_vel;
        end else begin
          p1_moving <= 0;
        end

        if (up_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b00;
          p2_y      <= p2_y - p_vel;
        end else if (down_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b01;
          p2_y      <= p2_y + p_vel;
        end else if (left_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b10;
          p2_x      <= p2_x - p_vel;
        end else if (right_2) begin
          p2_moving <= 1;
          p2_dir    <= 2'b11;
          p2_x      <= p2_x + p_vel;
        end else begin
          p2_moving <= 0;
        end


        if (shoot_1 && ~b1_fired) begin
          b1_fired <= 1;
          b1_dir <= p1_dir;
          case(b1_dir) 
            0: begin 
              b1_x <= p1_x + 28 ;        
              b1_y <= p1_y;
            end
            1: begin 
              b1_x <= p1_x + 6 ;
              b1_y <= p1_y + p_h;
            end
            2: begin 
              b1_x <= p1_x;
              b1_y <= p1_y + 6;
            end
            default: begin 
              b1_x <= p1_x + p_w - b_w ;
              b1_y <= p1_y + 28;
            end
          endcase
        end else if (b1_fired) begin
          case(b1_dir)
            0: b1_y <= b1_y - b_vel;
            1: b1_y <= b1_y + b_vel;
            2: b1_x <= b1_x - b_vel;
            3: b1_x <= b1_x + b_vel;
          endcase
        end


        if (shoot_2 && ~b2_fired) begin
          b2_fired <= 1;
          b2_dir <= p2_dir;
          case(b2_dir) 
            0: begin 
              b2_x <= p2_x + 28 ;        
              b2_y <= p2_y;
            end
            1: begin 
              b2_x <= p2_x + 6 ;
              b2_y <= p2_y + p_h;
            end
            2: begin 
              b2_x <= p2_x;
              b2_y <= p2_y + 6;
            end
            default: begin 
              b2_x <= p2_x + p_w - b_w ;
              b2_y <= p2_y + 28;
            end
          endcase
        end else if (b2_fired) begin
          case(b2_dir)
            0: b2_y <= b2_y - b_vel;
            1: b2_y <= b2_y + b_vel;
            2: b2_x <= b2_x - b_vel;
            3: b2_x <= b2_x + b_vel;
          endcase
        end



        if (((b1_x <= 0) || (b1_x >= window_w - b_w)) || ((b1_y <= 0) || (b1_y >= window_h - b_h))) begin
          b1_fired <= 0;
        end

        if ( ( (b2_x <= 0) || (b2_x >= window_w - b_w) ) || ( (b2_y <= 0) || (b2_y >= window_h - b_h) ) ) begin
          b2_fired <= 0;
        end


        if ((((b1_x < p2_x &&  b1_x + b_w > p2_x) || (p2_x < b1_x &&  p2_x + p_w > b1_x)) &&
              ((b1_y < p2_y &&  b1_y + b_h > p2_y) || (p2_y < b1_y &&  p2_y + p_h > b1_y))
            ) && b1_fired ) begin
          p2_health <= p2_health - 1;
          b1_fired <= 0;
        end

        if ((((b2_x < p1_x &&  b2_x + b_w > p1_x) || (p1_x < b2_x &&  p1_x + p_w > b2_x)) &&
              ((b2_y < p1_y &&  b2_y + b_h > p1_y) || (p1_y < b2_y &&  p1_y + p_h > b2_y))
            ) && b2_fired ) begin
          p1_health <= p1_health - 1;
          b2_fired <= 0;
        end


        if (((p1_x < p2_x+2 && p1_x + p_w > p2_x) || (p2_x < p1_x+2 && p2_x + p_w > p1_x)) &&
            ((p1_y < p2_y+2 && p1_y + p_h > p2_y) || (p2_y < p1_y+2 && p2_y + p_h > p1_y))) begin
          if (p1_moving) begin
            case(p1_dir)
              0: p2_y <= p2_y - p_vel;
              1: p2_y <= p2_y + p_vel;
              2: p2_x <= p2_x - p_vel;
              3: p2_x <= p2_x + p_vel;
            endcase
          end
          if (p2_moving) begin
            case(p2_dir)
              0: p1_y <= p1_y - p_vel;
              1: p1_y <= p1_y + p_vel;
              2: p1_x <= p1_x - p_vel;
              3: p1_x <= p1_x + p_vel;
            endcase
          end
        end


        if(p1_x < 0) begin 
          p1_x <= 3;
        end
        if(p1_x > window_w - p_w) begin 
          p1_x <= window_w - p_w ;
        end
        if(p1_y < 0) begin 
          p1_y <= 3 ;
        end
        if(p1_y > window_h - p_h) begin 
          p1_y <= window_h - p_h;
        end


        if(p2_x < 0) begin 
          p2_x <= 3;
        end
        if(p2_x > window_w - p_w) begin 
          p2_x <= window_w - p_w ;
        end
        if(p2_y < 0) begin 
          p2_y <= 3 ;
        end
        if(p2_y > window_h - p_h) begin 
          p2_y <= window_h - p_h;
        end


        if(p1_health == 0) begin
          game_state <= menu_win_p2;
        end
        if(p2_health == 0) begin
          game_state <= menu_win_p1;
        end
        
      end
    end
  end


	assign p1_en = ((column >= p1_x) && (column < p1_x + p_w)) && ((row >= p1_y) && (row < p1_y + p_h));
	assign b1_en = ((column >= b1_x) && (column < b1_x + b_w)) && ((row >= b1_y) && (row < b1_y + b_h)) && b1_fired;
	assign p2_en = ((column >= p2_x) && (column < p2_x + p_w)) && ((row >= p2_y) && (row < p2_y + p_h));
	assign b2_en = ((column >= b2_x) && (column < b2_x + b_w)) && ((row >= b2_y) && (row < b2_y + b_h)) && b2_fired;


  wire [31:0] obj_p1_x;
  wire [31:0] obj_b1_x;
  wire [31:0] obj_b2_x;
  wire [31:0] obj_p1_y;
  wire [31:0] obj_b2_y;
  wire [31:0] obj_b1_y;
  wire [31:0] obj_p2_x;
  wire [31:0] obj_p2_y;
  
  assign obj_p1_x = column - p1_x;
  assign obj_p2_x = column - p2_x;
  assign obj_b1_x = column - b1_x;
  assign obj_b2_x = column - b2_x;
  assign obj_p1_y = row - p1_y;
  assign obj_p2_y = row - p2_y;
  assign obj_b1_y = row - b1_y;
  assign obj_b2_y = row - b2_y;
  obj_p obj_p1(.x(obj_p1_x[5:0]), .y(obj_p1_y[5:0]), .dir(p1_dir), .en(p1_en), .data(p1_data));
  obj_b obj_b1(.x(obj_b1_x[2:0]), .y(obj_b1_y[2:0]) ,  .en(b1_en), .data(b1_data));
  obj_p obj_p2(.x(obj_p2_x[5:0]), .y(obj_p2_y[5:0]), .dir(p2_dir), .en(p2_en), .data(p2_data));
  obj_b obj_b2(.x(obj_b2_x[2:0]), .y(obj_b2_y[2:0]),  .en(b2_en), .data(b2_data));


  assign p1_h_en[0] = ((column >= p1_h_x) && (column < p1_h_x + h_w)) && ((row >= p1_h_y) && (row < p1_h_y + h_h)) && p1_health > 0;
  assign p1_h_en[1] = ((column >= p1_h_x + h_w+5) && (column < p1_h_x + 2*h_w+5)) && ((row >= p1_h_y) && (row < p1_h_y + h_h)) && p1_health > 1;

  assign p2_h_en[0] = ((column >= p2_h_x) && (column < p2_h_x + h_w)) && ((row >= p2_h_y) && (row < p2_h_y + h_h)) && p2_health > 0;
  assign p2_h_en[1] = ((column >= p2_h_x + h_w+5) && (column < p2_h_x + 2*h_w+5)) && ((row >= p2_h_y) && (row < p2_h_y + h_h)) && p2_health > 1;

  wire [31:0]  obj_h11_x;
  wire [31:0]  obj_h12_x;
  wire [31:0]  obj_h22_x;
  wire [31:0]  obj_h21_x;
  wire [31:0]  obj_h11_y;
  wire [31:0]  obj_h12_y;
  wire [31:0]  obj_h22_y;
  wire [31:0]  obj_h21_y;
  
  assign  obj_h11_x = column-p1_h_x;
  assign  obj_h12_x = column-(p1_h_x+h_w+5);
  assign  obj_h22_x = column-(p2_h_x+h_w+5);
  assign  obj_h21_x = column-p2_h_x;
  assign  obj_h11_y = row-p1_h_y;
  assign  obj_h12_y = row-p1_h_y;
  assign  obj_h22_y = row-p2_h_y;
  assign  obj_h21_y = row-p2_h_y;
   
  
  obj_heart obj_h11(.x(obj_h11_x[3:0]), .y(obj_h11_y[3:0]), .en(p1_h_en[0]), .data(p1_h_data[0]));
  obj_heart obj_h12(.x(obj_h12_x[3:0]), .y(obj_h12_y[3:0]), .en(p1_h_en[1]), .data(p1_h_data[1]));
  obj_heart obj_h21(.x(obj_h21_x[3:0]), .y(obj_h22_y[3:0]), .en(p2_h_en[0]), .data(p2_h_data[0]));
  obj_heart obj_h22(.x(obj_h22_x[3:0]), .y(obj_h21_y[3:0]), .en(p2_h_en[1]), .data(p2_h_data[1]));

  always@(*) begin

    if(game_state == menu_win_p1 )begin
      sel_pix = px_menu_p1 ;
    end else if (game_state == menu_win_p2) begin
      sel_pix = px_menu_p2;
    end else if(game_state == game_running) begin
      if(p1_en) sel_pix = px_game_p1;
      else if(p2_en) sel_pix = px_game_p2;
      else if(b1_en) sel_pix = px_game_b1;
      else if(b2_en) sel_pix = px_game_b2;
      else if(p1_h_en[0]) sel_pix = px_game_h11;
      else if(p1_h_en[1]) sel_pix = px_game_h12;
      else if(p2_h_en[0]) sel_pix = px_game_h21;
      else if(p2_h_en[1]) sel_pix = px_game_h22;
      else sel_pix = px_game_bg;
    end else begin
      sel_pix = px_menu_main ;
    end
  end

  always @(*) begin
    case(sel_pix)

      px_menu_main: pix = color_brown;
      px_menu_p1: pix = color_blue;
      px_menu_p2: pix = color_green;

      px_game_h11: pix = p1_h_data[0] ? color_red : color_gray;
      px_game_h12: pix = p1_h_data[1] ? color_red : color_gray;
      px_game_h21: pix = p2_h_data[0] ? color_red : color_gray;
      px_game_h22: pix = p2_h_data[1] ? color_red : color_gray;

      px_game_p1: begin
        case(p1_data)
          2'b00: pix = color_gray;
          2'b01: pix = color_blue;
          2'b10: pix = color_black;
          2'b11: pix = color_brown;
        endcase
      end
      px_game_p2: begin
        case(p2_data)
          2'b00: pix = color_gray;
          2'b01: pix = color_green;
          2'b10: pix = color_black;
          2'b11: pix = color_red;
        endcase
      end

      px_game_b1: pix = b1_data ? color_blue : color_gray;
      px_game_b2: pix = b2_data ? color_green  :color_gray;

      px_game_bg: pix = color_gray;
      default: pix = color_gray;
    endcase
  end

  assign red = disp_en   ? pix[7:5] : 3'b000;
  assign green = disp_en ? pix[4:2] : 3'b000;
  assign blue = disp_en  ? pix[1:0] : 3'b000;

endmodule