data/full_repos/permissive/52706914/background.v
1: b'%Warning-LITENDIAN: data/full_repos/permissive/52706914/background.v:422: Little bit endian vector: MSB < LSB of bit range: 0:6\n output [0:6] Display0;\n        ^\n                    ... Use "/* verilator lint_off LITENDIAN */" and lint_on around source to disable this message.\n%Warning-LITENDIAN: data/full_repos/permissive/52706914/background.v:392: Little bit endian vector: MSB < LSB of bit range: 0:3\n  reg [0:3] fib = 4\'b1111;\n      ^\n%Warning-LITENDIAN: data/full_repos/permissive/52706914/background.v:360: Little bit endian vector: MSB < LSB of bit range: 0:3\n  reg [0:3] fib = 4\'b1111;\n      ^\n%Warning-LITENDIAN: data/full_repos/permissive/52706914/background.v:328: Little bit endian vector: MSB < LSB of bit range: 0:3\n  reg [0:3] fib = 4\'b1111;\n      ^\n%Warning-LITENDIAN: data/full_repos/permissive/52706914/background.v:2: Little bit endian vector: MSB < LSB of bit range: 0:6\n output [9:0] red, output [9:0] green, output [9:0] blue, output [0:6] HEX0, output [0:6] HEX1);\n                                                                 ^\n%Warning-LITENDIAN: data/full_repos/permissive/52706914/background.v:2: Little bit endian vector: MSB < LSB of bit range: 0:6\n output [9:0] red, output [9:0] green, output [9:0] blue, output [0:6] HEX0, output [0:6] HEX1);\n                                                                                    ^\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:140: Operator ASSIGNDLY expects 32 bits on the Assign RHS, but Assign RHS\'s VARREF \'tree1_height_bin\' generates 10 bits.\n                                                                    : ... In instance background\n  tree1_height <= tree1_height_bin;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:141: Operator ASSIGNDLY expects 32 bits on the Assign RHS, but Assign RHS\'s VARREF \'tree2_height_bin\' generates 10 bits.\n                                                                    : ... In instance background\n  tree2_height <= tree2_height_bin;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:142: Operator ASSIGNDLY expects 32 bits on the Assign RHS, but Assign RHS\'s VARREF \'tree3_height_bin\' generates 10 bits.\n                                                                    : ... In instance background\n  tree3_height <= tree3_height_bin; end\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:289: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= tree3_x_left && x <= tree3_x_right && y >= tree3_height && y <= 400) idx <= 3\'d0;  \n             ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:289: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= tree3_x_left && x <= tree3_x_right && y >= tree3_height && y <= 400) idx <= 3\'d0;  \n                                  ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:289: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= tree3_x_left && x <= tree3_x_right && y >= tree3_height && y <= 400) idx <= 3\'d0;  \n                                                        ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:285: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana3_left && x <= banana3_right && y <= banana3_bottom && y >= banana3_top)\n             ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:285: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana3_left && x <= banana3_right && y <= banana3_bottom && y >= banana3_top)\n                                  ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:285: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana3_left && x <= banana3_right && y <= banana3_bottom && y >= banana3_top)\n                                                        ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:285: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana3_left && x <= banana3_right && y <= banana3_bottom && y >= banana3_top)\n                                                                               ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:283: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n    else if (x >= tree2_x_left && x <= tree2_x_right && y >= tree2_height && y <= 400) idx <= 3\'d0;  \n               ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:283: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n    else if (x >= tree2_x_left && x <= tree2_x_right && y >= tree2_height && y <= 400) idx <= 3\'d0;  \n                                    ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:283: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n    else if (x >= tree2_x_left && x <= tree2_x_right && y >= tree2_height && y <= 400) idx <= 3\'d0;  \n                                                          ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:279: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana2_left && x <= banana2_right && y <= banana2_bottom && y >= banana2_top)\n             ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:279: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana2_left && x <= banana2_right && y <= banana2_bottom && y >= banana2_top)\n                                  ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:279: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana2_left && x <= banana2_right && y <= banana2_bottom && y >= banana2_top)\n                                                        ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:279: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana2_left && x <= banana2_right && y <= banana2_bottom && y >= banana2_top)\n                                                                               ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:277: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= tree1_x_left && x <= tree1_x_right && y >= tree1_height && y <= 400) idx <= 3\'d0;  \n             ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:277: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= tree1_x_left && x <= tree1_x_right && y >= tree1_height && y <= 400) idx <= 3\'d0;  \n                                  ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:277: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= tree1_x_left && x <= tree1_x_right && y >= tree1_height && y <= 400) idx <= 3\'d0;  \n                                                        ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:273: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana1_left && x <= banana1_right && y <= banana1_bottom && y >= banana1_top)\n             ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:273: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana1_left && x <= banana1_right && y <= banana1_bottom && y >= banana1_top)\n                                  ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:273: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana1_left && x <= banana1_right && y <= banana1_bottom && y >= banana1_top)\n                                                        ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:273: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= banana1_left && x <= banana1_right && y <= banana1_bottom && y >= banana1_top)\n                                                                               ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:271: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= monkey_x && x <= monkey_x + 30 && y >= monkey -30 && y <= monkey ) idx <= 3\'d5;  \n             ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:271: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'x\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= monkey_x && x <= monkey_x + 30 && y >= monkey -30 && y <= monkey ) idx <= 3\'d5;  \n                              ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:271: Operator GTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= monkey_x && x <= monkey_x + 30 && y >= monkey -30 && y <= monkey ) idx <= 3\'d5;  \n                                                    ^~\n%Warning-WIDTH: data/full_repos/permissive/52706914/background.v:271: Operator LTE expects 32 bits on the LHS, but LHS\'s VARREF \'y\' generates 10 bits.\n                                                                    : ... In instance background\n  else if (x >= monkey_x && x <= monkey_x + 30 && y >= monkey -30 && y <= monkey ) idx <= 3\'d5;  \n                                                                       ^~\n%Warning-UNSIGNED: data/full_repos/permissive/52706914/background.v:265: Comparison is constant due to unsigned arithmetic\n                                                                       : ... In instance background\n  if (x >= 0 && x <= 640 && y >= 0 & y <= 480) idx <= 3\'d6;  \n        ^~\n%Warning-UNSIGNED: data/full_repos/permissive/52706914/background.v:265: Comparison is constant due to unsigned arithmetic\n                                                                       : ... In instance background\n  if (x >= 0 && x <= 640 && y >= 0 & y <= 480) idx <= 3\'d6;  \n                              ^~\n%Warning-UNSIGNED: data/full_repos/permissive/52706914/background.v:267: Comparison is constant due to unsigned arithmetic\n                                                                       : ... In instance background\n  if (x >= 0 && x <= 640 && y >= 400 && y <= 480) idx <= 3\'d2;  \n        ^~\n%Warning-UNSIGNED: data/full_repos/permissive/52706914/background.v:269: Comparison is constant due to unsigned arithmetic\n                                                                       : ... In instance background\n  if (x >= 0 && x <= 640 && y >= 0 && y <= 50) idx <= 3\'d4;  \n        ^~\n%Warning-UNSIGNED: data/full_repos/permissive/52706914/background.v:269: Comparison is constant due to unsigned arithmetic\n                                                                       : ... In instance background\n  if (x >= 0 && x <= 640 && y >= 0 && y <= 50) idx <= 3\'d4;  \n                              ^~\n%Error: Exiting due to 39 warning(s)\n'
module background(input jump, input clk, input reset, input [9:0] x, input [9:0] y,
	output [9:0] red, output [9:0] green, output [9:0] blue, output [0:6] HEX0, output [0:6] HEX1);
	
reg [2:0] idx;
reg [25:0] sclk;
reg [25:0] sclkk;
reg [25:0] sclkkk;
reg [25:0] sclkkkk;

reg tree1_clk = 1;
reg tree2_clk = 1;
reg tree3_clk = 1;

reg hit = 0;
reg disappear1;
reg disappear2;
reg disappear3;

wire [9:0] tree1_height_bin;
wire [9:0] tree2_height_bin;
wire [9:0] tree3_height_bin;

integer tree1_height;
integer tree2_height;
integer tree3_height;
integer tree1_x_left;
integer tree1_x_right;
integer tree2_x_left;
integer tree2_x_right;
integer tree3_x_left;
integer tree3_x_right;

integer banana1_left;
integer	banana1_right;
integer	banana1_top;
integer banana1_bottom;

integer banana2_left;
integer banana2_right;
integer banana2_top;
integer banana2_bottom;

integer banana3_left;
integer banana3_right;
integer banana3_top;
integer banana3_bottom;

integer monkey;
integer monkey_x;

reg [3:0] scoreFirst;
reg [3:0] scoreSecond;

initial begin
	tree1_x_left = 120;
	tree1_x_right = 200;
	tree2_x_left = 330;
	tree2_x_right = 410;
	tree3_x_left = 544;
	tree3_x_right = 628;
	tree1_height = 400;
	tree2_height = 300;
	tree3_height = 100;
	monkey = 85;
	monkey_x = 305;
	disappear1 = 0;
	disappear2 = 0;
	disappear3 = 0;
	end

always @(posedge clk)
	begin
		sclk = sclk + 1;
		if (sclk == 26'h7A120)
			begin
				sclk = 0;
				if (tree1_x_left <= 0) 
					begin 
					tree1_clk = 1;
					tree1_x_left = 640;
					end
				else if (tree1_x_right <= 0) 
					begin
					tree1_clk = 0;
					tree1_x_right = 640;
					end
				else begin
					tree1_clk = 0;
					tree1_x_left = tree1_x_left - 1;
					tree1_x_right = tree1_x_right - 1; end
	end end
	

	random1 tree1 (tree1_clk, tree1_height_bin);
	
	always @(posedge clk)
	begin
		sclkk = sclkk + 1;
		if (sclkk == 26'h7A120)
			begin
				sclkk = 0;
				if (tree2_x_left <= 0) begin 
					tree2_x_left = 640;
					tree2_clk = 1; end
				else if (tree2_x_right <= 0) begin
					tree2_x_right = 640;
					tree2_clk = 0; end
				else begin
					tree2_x_left = tree2_x_left - 1;
					tree2_x_right = tree2_x_right - 1; 
					tree2_clk = 0; end
	end end
	

	random2 tree2 (tree2_clk, tree2_height_bin);
	
	always @(posedge clk)
	begin
		sclkkk = sclkkk + 1;
		if (sclkkk == 26'h7A120)
			begin
				sclkkk = 0;
				if (tree3_x_left <= 0) begin
					tree3_x_left = 640;
					tree3_clk = 1; end
				else if (tree3_x_right <= 0) begin
					tree3_x_right = 640;
					tree3_clk = 0; end
				else begin
					tree3_x_left = tree3_x_left - 1;
					tree3_x_right = tree3_x_right - 1; 
					tree3_clk = 0; end
	end end
	

	random3 tree3 (tree3_clk, tree3_height_bin);
	

	always begin
		tree1_height <= tree1_height_bin;
		tree2_height <= tree2_height_bin;
		tree3_height <= tree3_height_bin; end
	
	always @(posedge clk) begin
		sclkkkk = sclkkkk + 1;
			if (sclkkkk == 26'h2DC6C0)
				begin
				sclkkkk = 0;
				if (!jump && !hit)
					monkey = monkey - 10;

				else if (!reset) begin
					monkey = 85;
					hit <= 0;
					scoreFirst <= 0; 
					scoreSecond <= 0;
					monkey_x = 305; end
				else if (monkey - 30 <= 50) begin
					monkey = 80;
					hit <= 1; end
				else if (monkey >= 400) begin
					monkey = 400;
					hit <= 1; end
				else if (tree1_x_left <= monkey_x && tree1_x_right >= monkey_x + 30 && tree1_height <= monkey) begin
					monkey = monkey;
					monkey_x = tree1_x_left -30;
					hit <= 1; end
				else if (tree2_x_left <= monkey_x && tree2_x_right >= monkey_x + 30 && tree2_height <= monkey) begin
					monkey = monkey;
					monkey_x = tree2_x_left -30;
					hit <= 1; end
				else if (tree3_x_left <= monkey_x && tree3_x_right >= monkey_x + 30 && tree3_height <= monkey) begin
					monkey = monkey;
					monkey_x = tree3_x_left -30;
					hit <= 1; end
				else
					monkey = monkey + 5;
				
				
				if (tree1_x_right > 5)
					if (!hit && banana1_left <= monkey_x && banana1_right >= monkey_x + 30 && monkey >= banana1_top && !disappear1) begin
						disappear1 = 1;
						scoreFirst <= scoreFirst + 1'b1;
						if (scoreFirst == 4'b1010) begin
							scoreSecond <= scoreSecond + 1'b1;
							scoreFirst <= 0; end end

				if (tree1_x_right < 5)
					disappear1 = 0;
				
				if (tree2_x_right > 5 )
					if ( !hit && banana2_left <= monkey_x && banana2_right >= monkey_x + 30 && monkey >= banana2_top && !disappear2) begin
						disappear2 = 1;
						scoreFirst <= scoreFirst + 1'b1;
						if (scoreFirst == 4'b1010) begin
							scoreSecond <= scoreSecond + 1'b1;
							scoreFirst <= 0; end end

				if (tree2_x_right < 5)
					disappear2 = 0;


				if (tree3_x_right > 5)
					if (!hit &&  banana3_left <= monkey_x && banana3_right >= monkey_x + 30 && monkey >= banana3_top && !disappear3) begin
						disappear3 = 1;
						scoreFirst <= scoreFirst + 1'b1;
						if (scoreFirst == 4'b1010) begin
							scoreSecond <= scoreSecond + 1'b1;
							scoreFirst <= 0; end end

				if (tree3_x_right < 5)
					disappear3 = 0;

				end
		end	


	


	BCD DisplayScoreFirst(scoreFirst, HEX0);
	BCD DisplayScoreSecond(scoreSecond, HEX1);
	

	always begin
		banana1_left = tree1_x_left + 20;
		banana1_right = tree1_x_right - 20;
		banana1_bottom = tree1_height - 30;
		banana1_top = tree1_height - 60;
		
		banana2_left = tree2_x_left + 20;
		banana2_right = tree2_x_right - 20;
		banana2_bottom = tree2_height - 30;
		banana2_top = tree2_height - 60;
		
		banana3_left = tree3_x_left + 20;
		banana3_right = tree3_x_right - 20;
		banana3_bottom = tree3_height - 30;
		banana3_top = tree3_height - 60;
	end
	
	always @(x && y)
	begin
		if (x >= 0 && x <= 640 && y >= 0 & y <= 480) idx <= 3'd6;
		
		if (x >= 0 && x <= 640 && y >= 400 && y <= 480) idx <= 3'd2;

		if (x >= 0 && x <= 640 && y >= 0 && y <= 50) idx <= 3'd4;
		
		else if (x >= monkey_x && x <= monkey_x + 30 && y >= monkey -30 && y <= monkey ) idx <= 3'd5;
		
		else if (x >= banana1_left && x <= banana1_right && y <= banana1_bottom && y >= banana1_top)
			if (disappear1) idx <= 3'd6;
			else idx <= 3'd3;
		
		else if (x >= tree1_x_left && x <= tree1_x_right && y >= tree1_height && y <= 400) idx <= 3'd0;
		
		else if (x >= banana2_left && x <= banana2_right && y <= banana2_bottom && y >= banana2_top)
			if (disappear2) idx <= 3'd6;
			else idx <= 3'd3;
			
	   else if (x >= tree2_x_left && x <= tree2_x_right && y >= tree2_height && y <= 400) idx <= 3'd0;
		
		else if (x >= banana3_left && x <= banana3_right && y <= banana3_bottom && y >= banana3_top)
			if (disappear3) idx <= 3'd6;
			else idx <= 3'd3;
		
		else if (x >= tree3_x_left && x <= tree3_x_right && y >= tree3_height && y <= 400) idx <= 3'd0;
		
		if (hit) begin
			if (x >= 30 && x <= 610 && y >= 50 && y <= 450) idx <= 3'd0;
			if (x >= 130 && x <=510 && y <= 400 && y >= 100) begin
				idx <= 3'd7; 
				if (x >= 130 && x <= 170 && y <= 350 && y >= 100) idx <= 3'd0;
				if (x >= 240 && x <= 410 && y >= 200 && y <= 250) idx <= 3'd0;
				if (x >= 290 && x <= 337 && y >= 150 && y <= 350) idx <= 3'd0;
				if (x >= 460 && x <= 560 && y <= 350 && y >= 100) idx <= 3'd0; end
			end
	end



assign red = (idx[0]? 10'h3ff: 10'h000);
assign green = (idx[1]? 10'h3ff: 10'h000);
assign blue = (idx[2]? 10'h3ff: 10'h000);

endmodule
module background(input jump, input clk, input reset, input [9:0] x, input [9:0] y,
	output [9:0] red, output [9:0] green, output [9:0] blue, output [0:6] HEX0, output [0:6] HEX1);

	
reg [2:0] idx;
reg [25:0] sclk;
reg [25:0] sclkk;
reg [25:0] sclkkk;
reg [25:0] sclkkkk;

reg tree1_clk = 1;
reg tree2_clk = 1;
reg tree3_clk = 1;

reg hit = 0;
reg disappear1;
reg disappear2;
reg disappear3;

wire [9:0] tree1_height_bin;
wire [9:0] tree2_height_bin;
wire [9:0] tree3_height_bin;

integer tree1_height;
integer tree2_height;
integer tree3_height;
integer tree1_x_left;
integer tree1_x_right;
integer tree2_x_left;
integer tree2_x_right;
integer tree3_x_left;
integer tree3_x_right;

integer banana1_left;
integer	banana1_right;
integer	banana1_top;
integer banana1_bottom;

integer banana2_left;
integer banana2_right;
integer banana2_top;
integer banana2_bottom;

integer banana3_left;
integer banana3_right;
integer banana3_top;
integer banana3_bottom;

integer monkey;
integer monkey_x;

reg [3:0] scoreFirst;
reg [3:0] scoreSecond;

initial begin
	tree1_x_left = 120;
	tree1_x_right = 200;
	tree2_x_left = 330;
	tree2_x_right = 410;
	tree3_x_left = 544;
	tree3_x_right = 628;
	tree1_height = 400;
	tree2_height = 300;
	tree3_height = 100;
	monkey = 85;
	monkey_x = 305;
	disappear1 = 0;
	disappear2 = 0;
	disappear3 = 0;
	end

always @(posedge clk)
	begin
		sclk = sclk + 1;
		if (sclk == 26'h7A120)
			begin
				sclk = 0;
				if (tree1_x_left <= 0) 
					begin 
					tree1_clk = 1;
					tree1_x_left = 640;
					end
				else if (tree1_x_right <= 0) 
					begin
					tree1_clk = 0;
					tree1_x_right = 640;
					end
				else begin
					tree1_clk = 0;
					tree1_x_left = tree1_x_left - 1;
					tree1_x_right = tree1_x_right - 1; end
	end end
	

	random1 tree1 (tree1_clk, tree1_height_bin);
	
	always @(posedge clk)
	begin
		sclkk = sclkk + 1;
		if (sclkk == 26'h7A120)
			begin
				sclkk = 0;
				if (tree2_x_left <= 0) begin 
					tree2_x_left = 640;
					tree2_clk = 1; end
				else if (tree2_x_right <= 0) begin
					tree2_x_right = 640;
					tree2_clk = 0; end
				else begin
					tree2_x_left = tree2_x_left - 1;
					tree2_x_right = tree2_x_right - 1; 
					tree2_clk = 0; end
	end end
	

	random2 tree2 (tree2_clk, tree2_height_bin);
	
	always @(posedge clk)
	begin
		sclkkk = sclkkk + 1;
		if (sclkkk == 26'h7A120)
			begin
				sclkkk = 0;
				if (tree3_x_left <= 0) begin
					tree3_x_left = 640;
					tree3_clk = 1; end
				else if (tree3_x_right <= 0) begin
					tree3_x_right = 640;
					tree3_clk = 0; end
				else begin
					tree3_x_left = tree3_x_left - 1;
					tree3_x_right = tree3_x_right - 1; 
					tree3_clk = 0; end
	end end
	

	random3 tree3 (tree3_clk, tree3_height_bin);
	

	always begin
		tree1_height <= tree1_height_bin;
		tree2_height <= tree2_height_bin;
		tree3_height <= tree3_height_bin; end
	
	always @(posedge clk) begin
		sclkkkk = sclkkkk + 1;
			if (sclkkkk == 26'h2DC6C0)
				begin
				sclkkkk = 0;
				if (!jump && !hit)
					monkey = monkey - 10;

				else if (!reset) begin
					monkey = 85;
					hit <= 0;
					scoreFirst <= 0; 
					scoreSecond <= 0;
					monkey_x = 305; end
				else if (monkey - 30 <= 50) begin
					monkey = 80;
					hit <= 1; end
				else if (monkey >= 400) begin
					monkey = 400;
					hit <= 1; end
				else if (tree1_x_left <= monkey_x && tree1_x_right >= monkey_x + 30 && tree1_height <= monkey) begin
					monkey = monkey;
					monkey_x = tree1_x_left -30;
					hit <= 1; end
				else if (tree2_x_left <= monkey_x && tree2_x_right >= monkey_x + 30 && tree2_height <= monkey) begin
					monkey = monkey;
					monkey_x = tree2_x_left -30;
					hit <= 1; end
				else if (tree3_x_left <= monkey_x && tree3_x_right >= monkey_x + 30 && tree3_height <= monkey) begin
					monkey = monkey;
					monkey_x = tree3_x_left -30;
					hit <= 1; end
				else
					monkey = monkey + 5;
				
				
				if (tree1_x_right > 5)
					if (!hit && banana1_left <= monkey_x && banana1_right >= monkey_x + 30 && monkey >= banana1_top && !disappear1) begin
						disappear1 = 1;
						scoreFirst <= scoreFirst + 1'b1;
						if (scoreFirst == 4'b1010) begin
							scoreSecond <= scoreSecond + 1'b1;
							scoreFirst <= 0; end end

				if (tree1_x_right < 5)
					disappear1 = 0;
				
				if (tree2_x_right > 5 )
					if ( !hit && banana2_left <= monkey_x && banana2_right >= monkey_x + 30 && monkey >= banana2_top && !disappear2) begin
						disappear2 = 1;
						scoreFirst <= scoreFirst + 1'b1;
						if (scoreFirst == 4'b1010) begin
							scoreSecond <= scoreSecond + 1'b1;
							scoreFirst <= 0; end end

				if (tree2_x_right < 5)
					disappear2 = 0;


				if (tree3_x_right > 5)
					if (!hit &&  banana3_left <= monkey_x && banana3_right >= monkey_x + 30 && monkey >= banana3_top && !disappear3) begin
						disappear3 = 1;
						scoreFirst <= scoreFirst + 1'b1;
						if (scoreFirst == 4'b1010) begin
							scoreSecond <= scoreSecond + 1'b1;
							scoreFirst <= 0; end end

				if (tree3_x_right < 5)
					disappear3 = 0;

				end
		end	


	


	BCD DisplayScoreFirst(scoreFirst, HEX0);
	BCD DisplayScoreSecond(scoreSecond, HEX1);
	

	always begin
		banana1_left = tree1_x_left + 20;
		banana1_right = tree1_x_right - 20;
		banana1_bottom = tree1_height - 30;
		banana1_top = tree1_height - 60;
		
		banana2_left = tree2_x_left + 20;
		banana2_right = tree2_x_right - 20;
		banana2_bottom = tree2_height - 30;
		banana2_top = tree2_height - 60;
		
		banana3_left = tree3_x_left + 20;
		banana3_right = tree3_x_right - 20;
		banana3_bottom = tree3_height - 30;
		banana3_top = tree3_height - 60;
	end
	
	always @(x && y)
	begin
		if (x >= 0 && x <= 640 && y >= 0 & y <= 480) idx <= 3'd6;
		
		if (x >= 0 && x <= 640 && y >= 400 && y <= 480) idx <= 3'd2;

		if (x >= 0 && x <= 640 && y >= 0 && y <= 50) idx <= 3'd4;
		
		else if (x >= monkey_x && x <= monkey_x + 30 && y >= monkey -30 && y <= monkey ) idx <= 3'd5;
		
		else if (x >= banana1_left && x <= banana1_right && y <= banana1_bottom && y >= banana1_top)
			if (disappear1) idx <= 3'd6;
			else idx <= 3'd3;
		
		else if (x >= tree1_x_left && x <= tree1_x_right && y >= tree1_height && y <= 400) idx <= 3'd0;
		
		else if (x >= banana2_left && x <= banana2_right && y <= banana2_bottom && y >= banana2_top)
			if (disappear2) idx <= 3'd6;
			else idx <= 3'd3;
			
	   else if (x >= tree2_x_left && x <= tree2_x_right && y >= tree2_height && y <= 400) idx <= 3'd0;
		
		else if (x >= banana3_left && x <= banana3_right && y <= banana3_bottom && y >= banana3_top)
			if (disappear3) idx <= 3'd6;
			else idx <= 3'd3;
		
		else if (x >= tree3_x_left && x <= tree3_x_right && y >= tree3_height && y <= 400) idx <= 3'd0;
		
		if (hit) begin
			if (x >= 30 && x <= 610 && y >= 50 && y <= 450) idx <= 3'd0;
			if (x >= 130 && x <=510 && y <= 400 && y >= 100) begin
				idx <= 3'd7; 
				if (x >= 130 && x <= 170 && y <= 350 && y >= 100) idx <= 3'd0;
				if (x >= 240 && x <= 410 && y >= 200 && y <= 250) idx <= 3'd0;
				if (x >= 290 && x <= 337 && y >= 150 && y <= 350) idx <= 3'd0;
				if (x >= 460 && x <= 560 && y <= 350 && y >= 100) idx <= 3'd0; end
			end
	end



assign red = (idx[0]? 10'h3ff: 10'h000);
assign green = (idx[1]? 10'h3ff: 10'h000);
assign blue = (idx[2]? 10'h3ff: 10'h000);

endmodule