data/full_repos/permissive/141175658/snake_top_level.v
 line:84: before: "."
1: b'%Warning-PINMISSING: data/full_repos/permissive/141175658/snake_top_level.v:116: Cell has missing pin: \'release_direction\'\n  datapath d0(\n           ^~\n                     ... Use "/* verilator lint_off PINMISSING */" and lint_on around source to disable this message.\n%Warning-IMPLICIT: data/full_repos/permissive/141175658/snake_top_level.v:118: Signal definition not found, creating implicitly: \'game_reset\'\n    .game_reset(game_reset),\n                ^~~~~~~~~~\n%Warning-IMPLICIT: data/full_repos/permissive/141175658/snake_top_level.v:123: Signal definition not found, creating implicitly: \'inlevelDisplay\'\n    .inlevelDisplay(inlevelDisplay),\n                    ^~~~~~~~~~~~~~\n%Warning-IMPLICIT: data/full_repos/permissive/141175658/snake_top_level.v:130: Signal definition not found, creating implicitly: \'initial_head\'\n                                                                             : ... Suggested alternative: \'initial_game\'\n    .initial_head(initial_head),\n                  ^~~~~~~~~~~~\n%Warning-IMPLICIT: data/full_repos/permissive/141175658/snake_top_level.v:132: Signal definition not found, creating implicitly: \'finished_displaying_level\'\n    .finished_displaying_level(finished_displaying_level),\n                               ^~~~~~~~~~~~~~~~~~~~~~~~~\n%Warning-IMPLICIT: data/full_repos/permissive/141175658/snake_top_level.v:133: Signal definition not found, creating implicitly: \'continue_reset\'\n    .continue_reset(continue_reset),\n                    ^~~~~~~~~~~~~~\n%Warning-IMPLICIT: data/full_repos/permissive/141175658/snake_top_level.v:134: Signal definition not found, creating implicitly: \'next_level\'\n    .next_level(next_level),\n                ^~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:862: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'x_counter\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.d0.ref0\n  if(x_counter === max_width)\n               ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:872: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'y_counter\' generates 7 bits.\n                                                                          : ... In instance snake_top_level.d0.ref0\n   if(y_counter === max_height)\n                ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:870: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'x_counter\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.d0.ref0\n  if(x_counter === max_width)\n               ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:671: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'rand_X\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.d0.rand2\n  if(rand_X === max_width)\n            ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:681: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'rand_Y\' generates 7 bits.\n                                                                          : ... In instance snake_top_level.d0.rand2\n   if(rand_Y === max_height)\n             ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:679: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'rand_X\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.d0.rand2\n  if(rand_X === max_width)\n            ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:640: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'rand_X\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.d0.rand1\n  if(rand_X === max_width)\n            ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:650: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'rand_Y\' generates 7 bits.\n                                                                          : ... In instance snake_top_level.d0.rand1\n   if(rand_Y === max_height)\n             ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:648: Operator EQCASE expects 32 bits on the LHS, but LHS\'s VARREF \'rand_X\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.d0.rand1\n  if(rand_X === max_width)\n            ^~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:742: Operator NEQ expects 11 bits on the RHS, but RHS\'s CONST \'8\'hf0\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.kbIn\n   if(previousCode != 8\'hF0)begin\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:746: Operator EQ expects 11 bits on the RHS, but RHS\'s CONST \'8\'hf0\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.kbIn\n   if(previousCode == 8\'hF0)begin\n                   ^~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:752: Operator ASSIGN expects 11 bits on the Assign RHS, but Assign RHS\'s SEL generates 8 bits.\n                                                                          : ... In instance snake_top_level.kbIn\n   previousCode = keyCode[8:1];\n                ^\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:809: Operator EQ expects 11 bits on the RHS, but RHS\'s CONST \'8\'hf0\' generates 8 bits.\n                                                                          : ... In instance snake_top_level.kbIn\n  if(previousCode == 8\'hF0) begin\n                  ^~\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:296: Cannot find file containing module: \'logo_text_setter\'\n logo_text_setter logo0(clk, inLogoDisplay,x_pointer, y_pointer, logo_text);\n ^~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/141175658,data/full_repos/permissive/141175658/logo_text_setter\n             data/full_repos/permissive/141175658,data/full_repos/permissive/141175658/logo_text_setter.v\n             data/full_repos/permissive/141175658,data/full_repos/permissive/141175658/logo_text_setter.sv\n             logo_text_setter\n             logo_text_setter.v\n             logo_text_setter.sv\n             obj_dir/logo_text_setter\n             obj_dir/logo_text_setter.v\n             obj_dir/logo_text_setter.sv\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:297: Cannot find file containing module: \'menu_text_setter\'\n menu_text_setter menu0(clk, inmenu, x_pointer, y_pointer, menu_text);\n ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:298: Cannot find file containing module: \'game_text_setter\'\n game_text_setter gametxt0(clk, score, hiscore, ingame, main_difficulty, x_pointer, y_pointer, game_text);\n ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:299: Cannot find file containing module: \'result_text_setter\'\n result_text_setter restxt0(clk, score, inresult, main_difficulty, x_pointer, y_pointer, result_text);\n ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:300: Cannot find file containing module: \'level_text_setter\'\n level_text_setter lvltxt0(clk, game_reset, inlevelDisplay, current_level, main_difficulty, x_pointer, y_pointer, level_text, finished_displaying_level);\n ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:301: Cannot find file containing module: \'game_barrier_setter\'\n game_barrier_setter gamebar0(clk, ingame, current_level, x_pointer, y_pointer, barrier);\n ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:302: Cannot find file containing module: \'level_chooser\'\n level_chooser lvlchoose0(clk, inLevelChooser, release_up, release_down, enter, x_pointer, y_pointer, chooser_text, level_chosen);\n ^~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/141175658/snake_top_level.v:406: Operator SUB expects 32 bits on the LHS, but LHS\'s VARREF \'size\' generates 7 bits.\n                                                                          : ... In instance snake_top_level.d0\n       if(bodycounter2 <= size - 1)begin\n                               ^\n%Error: data/full_repos/permissive/141175658/snake_top_level.v:68: Cannot find file containing module: \'vga_adapter\'\n vga_adapter VGA(\n ^~~~~~~~~~~\n%Error: Exiting due to 8 error(s), 21 warning(s)\n'
module datapath(
   input clk,
	input [3:0] main_difficulty,
	input game_reset,
	input continue_reset,
	output [7:0] x_pointer,
	output [6:0] y_pointer,
	output reg game_over,
	output finished_displaying_level,
	output reg next_level,
	input [4:0] direction,
	input [4:0] release_direction,
	

	input initial_game,
	input allow_moving,
	input initial_head,
	

   input inmenu,
	input ingame,
	input inresult,
	input inlevelDisplay,
	input inLogoDisplay,
	input inLevelChooser,
	input choose_initial_level,
	

	input release_up,
	input release_down,
	input enter,

	output [2:0] RGB
   );
	
	wire R, G, B;
	wire frame_update;
	wire props_update;
	
	wire delayed_clk;
	
	
	wire menu_text;
	wire game_text, result_text, level_text, logo_text, chooser_text;
	wire [3:0] level_chosen;


	reg [12:0] score;
	

	reg [3:0] current_level;
	


	reg [12:0] hiscore;
	

	reg border;
	reg border_collision;
	

	wire barrier;
	

	reg [6:0] size;
	reg [7:0] snake_X[0:1023];
	reg [6:0] snake_Y[0:1023];
	reg found;
	reg found_collidable_body;
	reg snakeHead;
	reg snakeBody;
	
	reg snakeBody_collision;
	reg snakeHead_collision;
	
	reg [1:0]currentDirect;
	integer bodycounter, bodycounter2, bodycounter3, bodycounter4;
	

	reg up,down,left,right;
	

	reg apple, bonus_score, toxic, negative_score;
	reg [7:0] appleX;
	reg [6:0] appleY;
	
	reg [7:0] toxicX;
	reg [6:0] toxicY;
	
	reg [7:0] bonus_score_X;
	reg [6:0] bonus_score_Y;
	
	
	reg [7:0] negative_score_X;
	reg [6:0] negative_score_Y;
	
	reg apple_inX, apple_inY;
	

	wire [7:0]rand_apple_X;
	wire [6:0]rand_apple_Y;
	
	wire [7:0]rand_props_X;
	wire [6:0]rand_props_Y;
	
	wire [3:0] props_choice;

	

	reg lethal, nonLethal;
	reg bad_collision, good_collision;
	

	refresher ref0(clk, x_pointer, y_pointer);
	frame_updater upd0(clk, 1'b1, frame_update);
	props_updater upd1(clk, 1'b1, props_update);
	delay_counter dc0(clk, 1'b1, frame_update,delayed_clk,main_difficulty);
	random_apple rand1(clk, rand_apple_X, rand_apple_Y);
	random_props rand2(clk, rand_props_X, rand_props_Y);
	random_choice rand3(clk, 2, props_choice);
	logo_text_setter logo0(clk, inLogoDisplay,x_pointer, y_pointer, logo_text);
	menu_text_setter menu0(clk, inmenu, x_pointer, y_pointer, menu_text);
	game_text_setter gametxt0(clk, score, hiscore, ingame, main_difficulty, x_pointer, y_pointer, game_text);
	result_text_setter restxt0(clk, score, inresult, main_difficulty, x_pointer, y_pointer, result_text);
	level_text_setter lvltxt0(clk, game_reset, inlevelDisplay, current_level, main_difficulty, x_pointer, y_pointer, level_text, finished_displaying_level);
	game_barrier_setter gamebar0(clk, ingame, current_level, x_pointer, y_pointer, barrier);
	level_chooser lvlchoose0(clk, inLevelChooser, release_up, release_down, enter, x_pointer, y_pointer, chooser_text, level_chosen);
	

	
	always@(posedge clk)
	begin
      
		if(game_reset) begin
			score = 0;
			current_level = 0;
			next_level = 0;
		end
		
		if(continue_reset) begin
			score = 0;
			next_level = 0;
		end
		
		if(choose_initial_level) begin
			current_level = level_chosen;
		end
		
		if(initial_game) begin

			for(bodycounter3 = 1; bodycounter3 <= 1023; bodycounter3 = bodycounter3+1)begin
				snake_X[bodycounter3] = 0;
				snake_Y[bodycounter3] = 0;
			end


			size = 1;
			

			game_over = 0;
			 

			next_level = 0;
		

			appleX = 16;
			appleY = 17;
	

			up = 0;
			down = 0;
			left = 0;
			right = 0;
		end
		
		else if(ingame)begin


				border <= (((x_pointer >= 2) && (x_pointer <= 4)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 155)&& (x_pointer <= 157)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 2) && (y_pointer <= 4))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 110) && (y_pointer <= 112)));


				border_collision <= (((x_pointer >= 0) && (x_pointer <= 3)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 155)&& (x_pointer <= 159)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 0) && (y_pointer <= 3))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 111) && (y_pointer <= 113)));
				




				

				found = 0;
				for(bodycounter = 1; bodycounter <= size; bodycounter = bodycounter + 1)begin
					if(~found)begin				
						snakeBody = ((x_pointer >= snake_X[bodycounter] && x_pointer <= snake_X[bodycounter]+2) 
								  && (y_pointer >= snake_Y[bodycounter] && y_pointer <= snake_Y[bodycounter]+2));
						found = snakeBody;
					end
				end


				found_collidable_body = 0;
				for(bodycounter4 = 1; bodycounter4 <= size; bodycounter4 = bodycounter4 + 1)begin
					if(~found_collidable_body)begin				
						snakeBody_collision = (bodycounter4 >= 5) && ((x_pointer >= snake_X[bodycounter4] && x_pointer <= snake_X[bodycounter4]+2) 
								  && (y_pointer >= snake_Y[bodycounter4] && y_pointer <= snake_Y[bodycounter4]+2));
						found_collidable_body = snakeBody_collision;
					end
				end
				

				snakeHead = (x_pointer >= snake_X[0] && x_pointer <= (snake_X[0]+2))
								&& (y_pointer >= snake_Y[0] && y_pointer <= (snake_Y[0]+2));
				
				
				snakeHead_collision = (x_pointer > snake_X[0] && x_pointer < (snake_X[0]+2))
								&& (y_pointer > snake_Y[0] && y_pointer < (snake_Y[0]+2));

				if(initial_head) begin
					snake_Y[0] = 8;
					snake_X[0] = 8;
				end
				

				if(delayed_clk)begin
					for(bodycounter2 = 1023; bodycounter2 > 0; bodycounter2 = bodycounter2 - 1)begin
							if(bodycounter2 <= size - 1)begin
								snake_X[bodycounter2] = snake_X[bodycounter2 - 1];
								snake_Y[bodycounter2] = snake_Y[bodycounter2 - 1];
							end
					end

						case(direction)


							5'b00010: if(!down)begin
												up = 1;
												down = 0;
												left = 0;
												right = 0;
										 end 

							5'b00100: if(!right)begin
												up = 0;
												down = 0;
												left = 1;
												right = 0;
										 end 

							5'b01000: if(!up)begin
												up = 0;
												down = 1;
												left = 0;
												right = 0;
										 end 

							5'b10000: if(!left)begin
												up = 0;
												down = 0;
												left = 0;
												right = 1;
										 end
							default: begin
											up = up;
											down = down;
											left = left;
											right = right;
										 end
							endcase	
	
					if (allow_moving) begin
						if(up)
							 snake_Y[0] <= (snake_Y[0] - 3);
						else if(left)
							 snake_X[0] <= (snake_X[0] - 3);
						else if(down)
							 snake_Y[0] <= (snake_Y[0] + 3);
						else if(right)
							 snake_X[0] <= (snake_X[0] + 3);
					end
				end
				





				apple_inX <= (x_pointer >= appleX && x_pointer <= (appleX + 2));
				apple_inY <= (y_pointer >= appleY && y_pointer <= (appleY + 2));
				apple = apple_inX && apple_inY;
				



				if(props_update) begin
					toxicX = 0;
					toxicY = 0;
					bonus_score_X = 0;
					bonus_score_Y = 0;
					negative_score_X = 0;
					negative_score_Y = 0;
					if (props_choice == 0)begin
					toxicX = rand_props_X;
					toxicY = rand_props_Y;
					end
					else if (props_choice == 1)begin
					bonus_score_X = rand_props_X;
					bonus_score_Y = rand_props_Y;
					end
					else if (props_choice == 2)begin
					negative_score_X = rand_props_X;
					negative_score_Y = rand_props_Y;
					end
				end
				

				bonus_score = (x_pointer >= bonus_score_X && x_pointer <= (bonus_score_X + 2)) && 
				(y_pointer >= bonus_score_Y && y_pointer <= (bonus_score_Y + 2));
				
				toxic = (x_pointer >= toxicX && x_pointer <= (toxicX + 2)) && 
				(y_pointer >= toxicY && y_pointer <= (toxicY + 2));
				
				negative_score = (x_pointer >= negative_score_X && x_pointer <= (negative_score_X + 2)) && 
				(y_pointer >= negative_score_Y && y_pointer <= (negative_score_Y + 2));


				if(barrier && toxic) begin
					toxicX <= rand_props_X;
					toxicY <= rand_props_Y;
				end
				
				if(barrier && apple) begin
					appleX <= rand_apple_X;
					appleY <= rand_apple_Y;
				end
				
				if(barrier && bonus_score) begin
					bonus_score_X <= rand_props_X;
					bonus_score_Y <= rand_props_Y;
				end
				
				if(barrier && negative_score) begin
					negative_score_X <= rand_props_X;
					negative_score_Y <= rand_props_Y;
				end
				



				lethal = border_collision || snakeBody_collision || barrier;

				if(snakeHead && bonus_score) begin
					bonus_score_X <= 0;
					bonus_score_Y <= 0;
					score = score + 5;
				end
				
				if(snakeHead && toxic) begin
					toxicX <= 0;
					toxicY <= 0;
					if (score <= 5)
						score = 0;
					else 
						score = score - 5;
				end
				
				if(snakeHead && negative_score) begin
					score = score / 2;
					negative_score_X <= 0;
					negative_score_Y <= 0;
				end
	

				if(apple && snakeHead) begin 
					appleX <= rand_apple_X;
					appleY <= rand_apple_Y;
					size = size + 1;

					score = score + 1;

					if (score > hiscore)
						hiscore = score;
					if (current_level < 7) begin
						if (size > 6) begin 
							next_level = 1;
							current_level = current_level + 1;
							up = 0;
							down = 0;
							left = 0;
							right = 0;
						end
					end
				end

			

				if(lethal && snakeHead_collision) begin
					bad_collision<= 1;
					up = 0;
					down = 0;
					left = 0;
					right = 0;
				end
				else begin 
					bad_collision<= 0;
				end

				if(bad_collision) begin
					game_over <= 1;
				end
		end
	end
	

	wire remove = (x_pointer >= 0 && x_pointer <= 2) && (y_pointer >= 0 && y_pointer <= 2);
	

		assign R = (((ingame && apple)
		|| (inmenu && menu_text))
		|| (inresult && result_text)
		|| (ingame && toxic)
		|| (ingame && negative_score)
		|| (inlevelDisplay && level_text)
		|| (inLogoDisplay && logo_text)
		|| (inLevelChooser && chooser_text)) && (!remove);
		assign G = (((ingame && snakeHead) 
		|| (ingame && snakeBody)) 
		|| (inmenu && menu_text) 
		|| (ingame && game_text) 
		|| (inresult && result_text) 
		|| (ingame && bonus_score)  
		|| (ingame && negative_score)
		|| (inlevelDisplay && level_text)
		|| (inLogoDisplay && logo_text)
		|| (inLevelChooser && chooser_text)) && (!remove);
		assign B = ((ingame && border) 
		|| (inmenu && menu_text) 
		|| (inresult && result_text) 
		|| (ingame && toxic) 
		|| (ingame && bonus_score)  
		|| (ingame && negative_score)
		|| (inlevelDisplay && level_text)
		|| (ingame && barrier)
		|| (inLogoDisplay && logo_text)
		|| (inLevelChooser && chooser_text)) && (!remove);
		assign RGB = {R, G, B};
endmodule
module datapath(
   input clk,
	input [3:0] main_difficulty,
	input game_reset,
	input continue_reset,
	output [7:0] x_pointer,
	output [6:0] y_pointer,
	output reg game_over,
	output finished_displaying_level,
	output reg next_level,
	input [4:0] direction,
	input [4:0] release_direction,
	

	input initial_game,
	input allow_moving,
	input initial_head,
	

   input inmenu,
	input ingame,
	input inresult,
	input inlevelDisplay,
	input inLogoDisplay,
	input inLevelChooser,
	input choose_initial_level,
	

	input release_up,
	input release_down,
	input enter,

	output [2:0] RGB
   );

	
	wire R, G, B;
	wire frame_update;
	wire props_update;
	
	wire delayed_clk;
	
	
	wire menu_text;
	wire game_text, result_text, level_text, logo_text, chooser_text;
	wire [3:0] level_chosen;


	reg [12:0] score;
	

	reg [3:0] current_level;
	


	reg [12:0] hiscore;
	

	reg border;
	reg border_collision;
	

	wire barrier;
	

	reg [6:0] size;
	reg [7:0] snake_X[0:1023];
	reg [6:0] snake_Y[0:1023];
	reg found;
	reg found_collidable_body;
	reg snakeHead;
	reg snakeBody;
	
	reg snakeBody_collision;
	reg snakeHead_collision;
	
	reg [1:0]currentDirect;
	integer bodycounter, bodycounter2, bodycounter3, bodycounter4;
	

	reg up,down,left,right;
	

	reg apple, bonus_score, toxic, negative_score;
	reg [7:0] appleX;
	reg [6:0] appleY;
	
	reg [7:0] toxicX;
	reg [6:0] toxicY;
	
	reg [7:0] bonus_score_X;
	reg [6:0] bonus_score_Y;
	
	
	reg [7:0] negative_score_X;
	reg [6:0] negative_score_Y;
	
	reg apple_inX, apple_inY;
	

	wire [7:0]rand_apple_X;
	wire [6:0]rand_apple_Y;
	
	wire [7:0]rand_props_X;
	wire [6:0]rand_props_Y;
	
	wire [3:0] props_choice;

	

	reg lethal, nonLethal;
	reg bad_collision, good_collision;
	

	refresher ref0(clk, x_pointer, y_pointer);
	frame_updater upd0(clk, 1'b1, frame_update);
	props_updater upd1(clk, 1'b1, props_update);
	delay_counter dc0(clk, 1'b1, frame_update,delayed_clk,main_difficulty);
	random_apple rand1(clk, rand_apple_X, rand_apple_Y);
	random_props rand2(clk, rand_props_X, rand_props_Y);
	random_choice rand3(clk, 2, props_choice);
	logo_text_setter logo0(clk, inLogoDisplay,x_pointer, y_pointer, logo_text);
	menu_text_setter menu0(clk, inmenu, x_pointer, y_pointer, menu_text);
	game_text_setter gametxt0(clk, score, hiscore, ingame, main_difficulty, x_pointer, y_pointer, game_text);
	result_text_setter restxt0(clk, score, inresult, main_difficulty, x_pointer, y_pointer, result_text);
	level_text_setter lvltxt0(clk, game_reset, inlevelDisplay, current_level, main_difficulty, x_pointer, y_pointer, level_text, finished_displaying_level);
	game_barrier_setter gamebar0(clk, ingame, current_level, x_pointer, y_pointer, barrier);
	level_chooser lvlchoose0(clk, inLevelChooser, release_up, release_down, enter, x_pointer, y_pointer, chooser_text, level_chosen);
	

	
	always@(posedge clk)
	begin
      
		if(game_reset) begin
			score = 0;
			current_level = 0;
			next_level = 0;
		end
		
		if(continue_reset) begin
			score = 0;
			next_level = 0;
		end
		
		if(choose_initial_level) begin
			current_level = level_chosen;
		end
		
		if(initial_game) begin

			for(bodycounter3 = 1; bodycounter3 <= 1023; bodycounter3 = bodycounter3+1)begin
				snake_X[bodycounter3] = 0;
				snake_Y[bodycounter3] = 0;
			end


			size = 1;
			

			game_over = 0;
			 

			next_level = 0;
		

			appleX = 16;
			appleY = 17;
	

			up = 0;
			down = 0;
			left = 0;
			right = 0;
		end
		
		else if(ingame)begin


				border <= (((x_pointer >= 2) && (x_pointer <= 4)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 155)&& (x_pointer <= 157)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 2) && (y_pointer <= 4))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 110) && (y_pointer <= 112)));


				border_collision <= (((x_pointer >= 0) && (x_pointer <= 3)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 155)&& (x_pointer <= 159)&&(y_pointer >= 2) && (y_pointer <=112))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 0) && (y_pointer <= 3))
								||((x_pointer >= 2) && (x_pointer <= 157)&&(y_pointer >= 111) && (y_pointer <= 113)));
				




				

				found = 0;
				for(bodycounter = 1; bodycounter <= size; bodycounter = bodycounter + 1)begin
					if(~found)begin				
						snakeBody = ((x_pointer >= snake_X[bodycounter] && x_pointer <= snake_X[bodycounter]+2) 
								  && (y_pointer >= snake_Y[bodycounter] && y_pointer <= snake_Y[bodycounter]+2));
						found = snakeBody;
					end
				end


				found_collidable_body = 0;
				for(bodycounter4 = 1; bodycounter4 <= size; bodycounter4 = bodycounter4 + 1)begin
					if(~found_collidable_body)begin				
						snakeBody_collision = (bodycounter4 >= 5) && ((x_pointer >= snake_X[bodycounter4] && x_pointer <= snake_X[bodycounter4]+2) 
								  && (y_pointer >= snake_Y[bodycounter4] && y_pointer <= snake_Y[bodycounter4]+2));
						found_collidable_body = snakeBody_collision;
					end
				end
				

				snakeHead = (x_pointer >= snake_X[0] && x_pointer <= (snake_X[0]+2))
								&& (y_pointer >= snake_Y[0] && y_pointer <= (snake_Y[0]+2));
				
				
				snakeHead_collision = (x_pointer > snake_X[0] && x_pointer < (snake_X[0]+2))
								&& (y_pointer > snake_Y[0] && y_pointer < (snake_Y[0]+2));

				if(initial_head) begin
					snake_Y[0] = 8;
					snake_X[0] = 8;
				end
				

				if(delayed_clk)begin
					for(bodycounter2 = 1023; bodycounter2 > 0; bodycounter2 = bodycounter2 - 1)begin
							if(bodycounter2 <= size - 1)begin
								snake_X[bodycounter2] = snake_X[bodycounter2 - 1];
								snake_Y[bodycounter2] = snake_Y[bodycounter2 - 1];
							end
					end

						case(direction)


							5'b00010: if(!down)begin
												up = 1;
												down = 0;
												left = 0;
												right = 0;
										 end 

							5'b00100: if(!right)begin
												up = 0;
												down = 0;
												left = 1;
												right = 0;
										 end 

							5'b01000: if(!up)begin
												up = 0;
												down = 1;
												left = 0;
												right = 0;
										 end 

							5'b10000: if(!left)begin
												up = 0;
												down = 0;
												left = 0;
												right = 1;
										 end
							default: begin
											up = up;
											down = down;
											left = left;
											right = right;
										 end
							endcase	
	
					if (allow_moving) begin
						if(up)
							 snake_Y[0] <= (snake_Y[0] - 3);
						else if(left)
							 snake_X[0] <= (snake_X[0] - 3);
						else if(down)
							 snake_Y[0] <= (snake_Y[0] + 3);
						else if(right)
							 snake_X[0] <= (snake_X[0] + 3);
					end
				end
				





				apple_inX <= (x_pointer >= appleX && x_pointer <= (appleX + 2));
				apple_inY <= (y_pointer >= appleY && y_pointer <= (appleY + 2));
				apple = apple_inX && apple_inY;
				



				if(props_update) begin
					toxicX = 0;
					toxicY = 0;
					bonus_score_X = 0;
					bonus_score_Y = 0;
					negative_score_X = 0;
					negative_score_Y = 0;
					if (props_choice == 0)begin
					toxicX = rand_props_X;
					toxicY = rand_props_Y;
					end
					else if (props_choice == 1)begin
					bonus_score_X = rand_props_X;
					bonus_score_Y = rand_props_Y;
					end
					else if (props_choice == 2)begin
					negative_score_X = rand_props_X;
					negative_score_Y = rand_props_Y;
					end
				end
				

				bonus_score = (x_pointer >= bonus_score_X && x_pointer <= (bonus_score_X + 2)) && 
				(y_pointer >= bonus_score_Y && y_pointer <= (bonus_score_Y + 2));
				
				toxic = (x_pointer >= toxicX && x_pointer <= (toxicX + 2)) && 
				(y_pointer >= toxicY && y_pointer <= (toxicY + 2));
				
				negative_score = (x_pointer >= negative_score_X && x_pointer <= (negative_score_X + 2)) && 
				(y_pointer >= negative_score_Y && y_pointer <= (negative_score_Y + 2));


				if(barrier && toxic) begin
					toxicX <= rand_props_X;
					toxicY <= rand_props_Y;
				end
				
				if(barrier && apple) begin
					appleX <= rand_apple_X;
					appleY <= rand_apple_Y;
				end
				
				if(barrier && bonus_score) begin
					bonus_score_X <= rand_props_X;
					bonus_score_Y <= rand_props_Y;
				end
				
				if(barrier && negative_score) begin
					negative_score_X <= rand_props_X;
					negative_score_Y <= rand_props_Y;
				end
				



				lethal = border_collision || snakeBody_collision || barrier;

				if(snakeHead && bonus_score) begin
					bonus_score_X <= 0;
					bonus_score_Y <= 0;
					score = score + 5;
				end
				
				if(snakeHead && toxic) begin
					toxicX <= 0;
					toxicY <= 0;
					if (score <= 5)
						score = 0;
					else 
						score = score - 5;
				end
				
				if(snakeHead && negative_score) begin
					score = score / 2;
					negative_score_X <= 0;
					negative_score_Y <= 0;
				end
	

				if(apple && snakeHead) begin 
					appleX <= rand_apple_X;
					appleY <= rand_apple_Y;
					size = size + 1;

					score = score + 1;

					if (score > hiscore)
						hiscore = score;
					if (current_level < 7) begin
						if (size > 6) begin 
							next_level = 1;
							current_level = current_level + 1;
							up = 0;
							down = 0;
							left = 0;
							right = 0;
						end
					end
				end

			

				if(lethal && snakeHead_collision) begin
					bad_collision<= 1;
					up = 0;
					down = 0;
					left = 0;
					right = 0;
				end
				else begin 
					bad_collision<= 0;
				end

				if(bad_collision) begin
					game_over <= 1;
				end
		end
	end
	

	wire remove = (x_pointer >= 0 && x_pointer <= 2) && (y_pointer >= 0 && y_pointer <= 2);
	

		assign R = (((ingame && apple)
		|| (inmenu && menu_text))
		|| (inresult && result_text)
		|| (ingame && toxic)
		|| (ingame && negative_score)
		|| (inlevelDisplay && level_text)
		|| (inLogoDisplay && logo_text)
		|| (inLevelChooser && chooser_text)) && (!remove);
		assign G = (((ingame && snakeHead) 
		|| (ingame && snakeBody)) 
		|| (inmenu && menu_text) 
		|| (ingame && game_text) 
		|| (inresult && result_text) 
		|| (ingame && bonus_score)  
		|| (ingame && negative_score)
		|| (inlevelDisplay && level_text)
		|| (inLogoDisplay && logo_text)
		|| (inLevelChooser && chooser_text)) && (!remove);
		assign B = ((ingame && border) 
		|| (inmenu && menu_text) 
		|| (inresult && result_text) 
		|| (ingame && toxic) 
		|| (ingame && bonus_score)  
		|| (ingame && negative_score)
		|| (inlevelDisplay && level_text)
		|| (ingame && barrier)
		|| (inLogoDisplay && logo_text)
		|| (inLevelChooser && chooser_text)) && (!remove);
		assign RGB = {R, G, B};
endmodule