data/full_repos/permissive/14349674/gameFiles/gameLogic.v
[Errno 2] No such file or directory: 'preprocess.output'
1: b'%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:84: Operator ASSIGN expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'7\'h75\' generates 7 bits.\n                                                                            : ... In instance gameLogic\n        reg [7:0] oldPaddleX = 7\'b1110101;\n                               ^~~~~~~~~~\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:114: Operator ASSIGN expects 20 bits on the Assign RHS, but Assign RHS\'s CONST \'?32?h333fffff\' generates 32 or 30 bits.\n                                                                             : ... In instance gameLogic\n    brickLayout = \'b110011001111111111111111111111;\n                ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:116: Operator ASSIGN expects 20 bits on the Assign RHS, but Assign RHS\'s CONST \'?32?h2aaaa955\' generates 32 or 30 bits.\n                                                                             : ... In instance gameLogic\n    brickLayout = \'b101010101010101010100101010101;\n                ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:118: Operator ASSIGN expects 20 bits on the Assign RHS, but Assign RHS\'s CONST \'?32?h3b9ee977\' generates 32 or 30 bits.\n                                                                             : ... In instance gameLogic\n    brickLayout = \'b111011100111101110100101110111;\n                ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:410: Operator ASSIGN expects 4 bits on the Assign RHS, but Assign RHS\'s DIV generates 32 or 7 bits.\n                                                                             : ... In instance gameLogic\n        blockRow = newPosY / boxHeight;\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:412: Operator ADD expects 32 or 15 bits on the RHS, but RHS\'s VARREF \'blockCol\' generates 4 bits.\n                                                                             : ... In instance gameLogic\n       blockAddr = (boxesPerRow * blockRow) + blockCol;\n                                            ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:420: Operator ADD expects 32 or 8 bits on the LHS, but LHS\'s VARREF \'blockCol\' generates 4 bits.\n                                                                             : ... In instance gameLogic\n         if(topRight_X == (boxLength*(blockCol+1)-1)  && ~(blockCol == boxesPerRow-1) && brickLayout[blockAddr+1] == 1\'b1) \n                                              ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:451: Operator ADD expects 32 or 7 bits on the LHS, but LHS\'s VARREF \'blockRow\' generates 4 bits.\n                                                                             : ... In instance gameLogic\n           if(bottomLeft_Y == (boxHeight*(blockRow+1)-1) && ~(blockRow == numRows) && brickLayout[blockAddr+boxesPerRow] == 1\'b1)\n                                                  ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:476: Bit extraction of var[19:0] requires 5 bit index, not 15 bits.\n                                                                             : ... In instance gameLogic\n        brickLayout[blockAddr] = 1\'b0;\n                   ^\n%Warning-WIDTH: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:413: Bit extraction of var[19:0] requires 5 bit index, not 15 bits.\n                                                                             : ... In instance gameLogic\n       if(brickLayout[blockAddr] == 1\'b0) begin\n                     ^\n%Warning-UNSIGNED: data/full_repos/permissive/14349674/gameFiles/gameLogic.v:393: Comparison is constant due to unsigned arithmetic\n                                                                                : ... In instance gameLogic\n     if((newPosY >= 7\'d0 && newPosY <= boxHeight * numRows)) \n                 ^~\n%Error: Exiting due to 11 warning(s)\n'
module gameLogic
        (
                moveLeft,
                moveRight,
                clk,
                newX,
                newY,
                oldX,
                oldY,
                sizeX,
                sizeY,
                startPlot,
                object,
					 userStart,
					 userReset,
					 gameOver,
					 LED
        );
        
        integer ballCyclesToUpdate = 750000;
        integer paddleCyclesToUpdate = 2250000;
        integer brickCyclesToUpdate = 1500000;
        parameter ball_Radius = 2;
        parameter boxesPerRow = 10;
        parameter maxX = 159;
        parameter maxY = 119;
        parameter paddleLength = 20;
        parameter paddleHeight = 1;
        parameter boxLength = 16;
        parameter boxHeight = 8;
			  parameter ballObj = 3'b000;
			  parameter paddleObj = 3'b001;
			  parameter blockObj = 3'b010;
			  parameter noObj = 3'b011;
			  parameter startImgObj = 3'b100;
			  parameter gameOverObj = 3'b101;
		  parameter numRows = 2;
		  parameter paddleSpeedZone = 4;
		  

			parameter 		
							STATE_INITIALIZE = 4'b0000,
							STATE_RESET = 4'b0010,
							STATE_DRAWBLOCKS = 4'b0011,
							STATE_DRAWBALL = 4'b0100,
							STATE_DRAWPADDLE = 4'b0101,
							STATE_IDLE = 4'b0110,
							STATE_START = 4'b0111,
							STATE_WAITRESTART = 4'b1000,
							STATE_DELETESTARTIMG = 4'b1001,
							STATE_DRAWSTARTIMG = 4'b1010;
					  

        input clk;
        input moveLeft;
        input moveRight;
		  input userStart;
		  input gameOver;
		  input userReset;

        
        output reg [7:0] newX = 'b0;
        output reg [6:0] newY = 'b0;
        output reg [7:0] oldX = 'b0;
        output reg [6:0] oldY = 'b0;
        output reg [7:0] sizeX = 'b0;
        output reg [6:0] sizeY = 'b0;
        output reg [2:0] object = 'b11;
        
        output reg startPlot;
		  output [17:14]LED;
		  assign LED = state;

        integer count = 0;
		  integer ballspeed = 0;
        reg [7:0] V_x = 8'b1;
        reg [6:0] V_y = 7'b1;
        reg RIGHT = 1'b1;
        reg DOWN = 1'b0;
        reg [7:0] newPosX = 8'b00110011;
        reg [6:0] newPosY = 7'b1110101;
        reg [7:0] oldPosX = 8'b00110011;
        reg [6:0] oldPosY = 7'b1110101;
        reg [7:0] oldPaddleX = 7'b1110101;
        reg [7:0] paddleX = 'd100;
        reg [6:0] paddleY = 7'b1110101;
        reg [7:0]topLeft_X, topRight_X;
        reg [6:0]topLeft_Y, bottomLeft_Y;
        reg [3:0] blockCol, blockRow;
        reg [14:0] blockAddr;
		  reg [3:0] state;
		  reg collision = 1'b0;
		  reg [2:0] level = 3'b000;
        reg [10:0] score = 'd0;

        reg [7:0] bricksInLevel;
		  
		  reg [boxesPerRow*numRows-1:0] brickLayout = 'b11111111111111111111;
		
				
always @ (posedge clk) begin
	case (state)
	

		STATE_INITIALIZE : begin
			newPosX = 8'b01010011;
			newPosY = 7'b1110000;
			oldPosX = 8'b01010011;
			oldPosY = 7'b1110000;
			oldPaddleX = 'd69;
			paddleX = 'd69;
			paddleY = 7'b1110101;
			if (level == 'd0)
				brickLayout = 'b110011001111111111111111111111;
			else if (level == 'd1)
				brickLayout = 'b101010101010101010100101010101;
			else if (level == 'd2)
				brickLayout = 'b111011100111101110100101110111;
			RIGHT = 1'b1;
			DOWN = 1'b0;
			count <= 0;
			state <= STATE_RESET;		
		end



		STATE_RESET : begin
			if (count == 0) begin
				count <= count + 1;

				newX = 0;
				newY = 0;
				oldX = 0;
				oldY = 0;
				sizeX = maxX + 1;
				sizeY = maxY + 1;
				object = noObj;
				startPlot <= 1;

			end else if (count == 'd50000) begin
				newX = 0;
				newY = 0;
				oldX = 0;
				oldY = 0;
				sizeX = 1;
				sizeY = 1;
				object = noObj;
				startPlot <= 1;
				count <= count + 1;

			end else if (count == 'd100000) begin
				state <= STATE_DRAWBLOCKS;
				count <= 0;
				blockCol <= 0;
				blockRow <= 0;
			end else begin
				count <= count + 1'b1;
				startPlot <= 0;
			end
		end

		

		STATE_DRAWBLOCKS : begin
			if (count == 0) begin
				count <= count + 1;
				newX = boxLength * (blockCol);
				newY = boxHeight * (blockRow);
				oldX = boxLength * (blockCol);
				oldY = boxHeight * (blockRow);
				sizeX = boxLength;
				sizeY = boxHeight;
				if (brickLayout[blockCol + (blockRow * boxesPerRow)] == 1'b1)
					object = blockObj;
				else
					object = noObj;
				startPlot <= 1;
			end else if (count == 'd1000) begin
				if (blockCol == boxesPerRow - 1) begin
					blockCol = 0;
					if (blockRow >= numRows)
						state <= STATE_DRAWBALL;
					else
						blockRow = blockRow + 1;
				end
				else
					blockCol = blockCol + 1;
				count <= 0;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end
		end
		

		STATE_DRAWBALL : begin
			if (count == 0) begin
				 object = ballObj;
				 newX = newPosX;
				 newY = newPosY;
				 oldX = oldPosX;
				 oldY = oldPosY;
				 sizeX = 2 * ball_Radius;
				 sizeY = 2 * ball_Radius;
				 startPlot <= 1;
				count <= count + 1;
			end else if (count == 'd100) begin
				count <= 0;
				state <= STATE_DRAWPADDLE;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end	
		end
		

		STATE_DRAWPADDLE : begin
			if (count == 0) begin
				 newX = paddleX;
				 newY = paddleY;
				 oldX = oldPaddleX;
				 oldY = paddleY;
				 sizeX = paddleLength;
				 sizeY = paddleHeight;
				 object = paddleObj;
				 startPlot <= 1;
				 count <= count + 1;

			end else if (count == 'd200) begin
				state <= STATE_DRAWSTARTIMG;
				count <= 0;
			end else begin
				count <= count + 1;
				startPlot <= 0;
				end
		end
		

		STATE_DRAWSTARTIMG : begin
			if (count == 0) begin
				 newX = 9;
				 newY = 40;
				 oldX = 9;
				 oldY = 40;
				 sizeX = 140;
				 sizeY = 70;
				 object = startImgObj;
				 startPlot <= 1;
				 count <= count + 1;		
			end else if (count == 'd50000) begin
				state <= STATE_IDLE;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end
		end
		

		STATE_IDLE: begin 
			if (userStart) begin
				state <= STATE_DELETESTARTIMG;
				count <= 0;
			end
		end

		STATE_DELETESTARTIMG :  begin
			if (count == 0) begin
				 newX = 9;
				 newY = 40;
				 oldX = 9;
				 oldY = 40;
				 sizeX = 140;
				 sizeY = 70;
				 object = noObj;
				 startPlot <= 1;
				 count <= count + 1;			
			end else if (count == 'd50000) begin
				count <= 0;
				state <= STATE_START;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end
		end
	
	

		STATE_START: begin
			

			if (newPosY > maxY || (brickLayout == 'd0)) begin 
				state <= STATE_WAITRESTART;
				count <= 0;
			end else if (userStart) begin

				if(count == ballCyclesToUpdate) begin
						object = ballObj;

						count = count + 1;
						ballspeed <= ballspeed + 1;

						if((newPosX) >= (maxX - (2*ball_Radius + V_x - 1)-1))
							RIGHT <= 1'b0;
							

						if((newPosX) <= V_x)
							RIGHT <= 1'b1;
							

						if((newPosY) == (paddleY-1-(2*ball_Radius))) begin 
							if ( (newPosX >= paddleX + paddleSpeedZone) && ((newPosX + 2*ball_Radius) < (paddleX + paddleLength-paddleSpeedZone))) 
							begin
								DOWN <= 1'b0;
								V_x = 8'd1;
							end
							else if((newPosX + 2*ball_Radius) >= paddleX-1 && newPosX < (paddleX + paddleSpeedZone))
							begin
								DOWN <= 1'b0;
								RIGHT <= 1'b0;
								V_x = 8'd1;
							end
							else if((newPosX + 2*ball_Radius) >= (paddleX + paddleLength - paddleSpeedZone) && newPosX <= (paddleX + paddleLength))
							begin
								DOWN <= 1'b0;
								RIGHT <= 1'b1;
								V_x = 8'd1;
							end
						end
						

						if((newPosY) <= V_y+1)
							DOWN <= 1'b1;
						

						if(RIGHT) begin
							oldPosX <= newPosX;
							newPosX <= newPosX + V_x;				
						end else begin
							oldPosX <= newPosX;
							newPosX <= newPosX - V_x;
						end if(DOWN) begin
							oldPosY <= newPosY;
							newPosY <= newPosY + V_y;
						end else begin
							oldPosY <= newPosY;
							newPosY <= newPosY - V_y;
						end
						
						if(ballspeed == 1000 && ballCyclesToUpdate > 350000) begin
							ballCyclesToUpdate <= ballCyclesToUpdate - 1;
							paddleCyclesToUpdate <= paddleCyclesToUpdate -1;
							brickCyclesToUpdate <= brickCyclesToUpdate - 1;
							ballspeed <= 0;
						end
						startPlot <= 1'b1;
				end
				

				else if (count == paddleCyclesToUpdate)
					begin
					  count = 0;
					  object = paddleObj;
					  

					  if (moveLeft) begin
						 if (!(paddleX < V_x)) begin
									oldPaddleX <= paddleX;
									paddleX <= paddleX - V_x;
									startPlot <= 1'b1;
						 end
					  end else if (moveRight) begin 
						 if ((maxX >= (paddleX + paddleLength) ) ) begin
									oldPaddleX <= paddleX;
									paddleX <= paddleX + V_x;
									startPlot <= 1'b1;
						 end
					  end

					end
				

				else if (count == brickCyclesToUpdate)
				begin
					count = count + 1;
					object = noObj;

					topLeft_X = newPosX;
					topRight_X = newPosX + (2*ball_Radius) - 1;
					topLeft_Y = newPosY;
					bottomLeft_Y = newPosY + (2*ball_Radius) - 1;
					

					if((newPosY >= 7'd0 && newPosY <= boxHeight * numRows)) 
						begin
					
							blockCol = newPosX[7:4];
							collision = 1'b0;












								blockRow = newPosY / boxHeight;
								
							blockAddr = (boxesPerRow * blockRow) + blockCol;
							if(brickLayout[blockAddr] == 1'b0) begin


							case(RIGHT)
								1'b1: begin


									if(topRight_X == (boxLength*(blockCol+1)-1)  && ~(blockCol == boxesPerRow-1) && brickLayout[blockAddr+1] == 1'b1) 
									begin
										RIGHT = 1'b0;
										blockCol = blockCol+1;
										brickLayout[blockAddr+1] = 1'b0;
										startPlot <= 1'b1;
										score <= score + 1;
										collision = 1'b1;
									end
								end
								1'b0: begin

									if(topLeft_X == boxLength*(blockCol) && ~(blockCol == 4'd0) && brickLayout[blockAddr-1] == 1'b1) 
									begin
										RIGHT = 1'b1;
										blockCol = blockCol-1;
										brickLayout[blockAddr-1] = 1'b0;
										startPlot <= 1'b1;
										score <= score + 1;
										collision = 1'b1;
									end
								end
							endcase
							


							if(collision == 1'b0) begin
							case(DOWN)
								1'b1: 
									begin

										 if(bottomLeft_Y == (boxHeight*(blockRow+1)-1) && ~(blockRow == numRows) && brickLayout[blockAddr+boxesPerRow] == 1'b1)
										 begin
											 DOWN = 1'b0;
											 blockRow = blockRow+1;
											 brickLayout[blockAddr+boxesPerRow] = 1'b0;
											 startPlot <= 1'b1;
											 score <= score + 1;
										 end
									end
								1'b0: 
									begin

										 if(topLeft_Y == boxHeight*(blockRow) && ~(blockRow == 4'd0) && brickLayout[blockAddr-boxesPerRow] == 1'b1)
										 begin
											 DOWN = 1'b1;
											 blockRow = blockRow-1;
											 brickLayout[blockAddr-boxesPerRow] = 1'b0;
											 startPlot <= 1'b1;
											 score <= score + 1;
										 end
									end
							endcase
							end
							end
							else begin
								brickLayout[blockAddr] = 1'b0;
								startPlot <= 1'b1;
								score <= score + 1;
							end
					end
				end
			
			else 	

				begin
					startPlot <= 1'b0;
					count = count + 1;
				end
			
			
			

				if (object == ballObj) begin
					 newX = newPosX;
					 newY = newPosY;
					 oldX = oldPosX;
					 oldY = oldPosY;
					 sizeX = 2 * ball_Radius;
					 sizeY = 2 * ball_Radius;
				end else if (object == paddleObj) begin
					 newX = paddleX;
					 newY = paddleY;
					 oldX = oldPaddleX;
					 oldY = paddleY;
					 sizeX = paddleLength;
					 sizeY = paddleHeight;
				end else if (object == noObj) begin		
					newX = boxLength * (blockCol);
					newY = boxHeight * (blockRow);
					oldX = boxLength * (blockCol);
					oldY = boxHeight * (blockRow);
					sizeX = boxLength;
					sizeY = boxHeight;
				end

							
		end
	
		end
		
		STATE_WAITRESTART : begin
			if (count == 0) begin
				 newX = 9;
				 newY = 40;
				 oldX = 9;
				 oldY = 40;
				 sizeX = 140;
				 sizeY = 70;
				 object = gameOverObj;
				 startPlot <= 1;
				 count <= count + 1;
			end else if (count > 'd50000) begin
				if(gameOver) begin
					if(brickLayout != 'd0)
						score <= 0;
					level <= level + 1;
					state <= STATE_INITIALIZE;
				end
				else if (userReset)
					state <= STATE_INITIALIZE;
			end else begin
				count <= count + 1;
				startPlot <= 0;	
			end
				
		end
		
	endcase
	
end

endmodule
module gameLogic
        (
                moveLeft,
                moveRight,
                clk,
                newX,
                newY,
                oldX,
                oldY,
                sizeX,
                sizeY,
                startPlot,
                object,
					 userStart,
					 userReset,
					 gameOver,
					 LED
        );

        
        integer ballCyclesToUpdate = 750000;
        integer paddleCyclesToUpdate = 2250000;
        integer brickCyclesToUpdate = 1500000;
        parameter ball_Radius = 2;
        parameter boxesPerRow = 10;
        parameter maxX = 159;
        parameter maxY = 119;
        parameter paddleLength = 20;
        parameter paddleHeight = 1;
        parameter boxLength = 16;
        parameter boxHeight = 8;
			  parameter ballObj = 3'b000;
			  parameter paddleObj = 3'b001;
			  parameter blockObj = 3'b010;
			  parameter noObj = 3'b011;
			  parameter startImgObj = 3'b100;
			  parameter gameOverObj = 3'b101;
		  parameter numRows = 2;
		  parameter paddleSpeedZone = 4;
		  

			parameter 		
							STATE_INITIALIZE = 4'b0000,
							STATE_RESET = 4'b0010,
							STATE_DRAWBLOCKS = 4'b0011,
							STATE_DRAWBALL = 4'b0100,
							STATE_DRAWPADDLE = 4'b0101,
							STATE_IDLE = 4'b0110,
							STATE_START = 4'b0111,
							STATE_WAITRESTART = 4'b1000,
							STATE_DELETESTARTIMG = 4'b1001,
							STATE_DRAWSTARTIMG = 4'b1010;
					  

        input clk;
        input moveLeft;
        input moveRight;
		  input userStart;
		  input gameOver;
		  input userReset;

        
        output reg [7:0] newX = 'b0;
        output reg [6:0] newY = 'b0;
        output reg [7:0] oldX = 'b0;
        output reg [6:0] oldY = 'b0;
        output reg [7:0] sizeX = 'b0;
        output reg [6:0] sizeY = 'b0;
        output reg [2:0] object = 'b11;
        
        output reg startPlot;
		  output [17:14]LED;
		  assign LED = state;

        integer count = 0;
		  integer ballspeed = 0;
        reg [7:0] V_x = 8'b1;
        reg [6:0] V_y = 7'b1;
        reg RIGHT = 1'b1;
        reg DOWN = 1'b0;
        reg [7:0] newPosX = 8'b00110011;
        reg [6:0] newPosY = 7'b1110101;
        reg [7:0] oldPosX = 8'b00110011;
        reg [6:0] oldPosY = 7'b1110101;
        reg [7:0] oldPaddleX = 7'b1110101;
        reg [7:0] paddleX = 'd100;
        reg [6:0] paddleY = 7'b1110101;
        reg [7:0]topLeft_X, topRight_X;
        reg [6:0]topLeft_Y, bottomLeft_Y;
        reg [3:0] blockCol, blockRow;
        reg [14:0] blockAddr;
		  reg [3:0] state;
		  reg collision = 1'b0;
		  reg [2:0] level = 3'b000;
        reg [10:0] score = 'd0;

        reg [7:0] bricksInLevel;
		  
		  reg [boxesPerRow*numRows-1:0] brickLayout = 'b11111111111111111111;
		
				
always @ (posedge clk) begin
	case (state)
	

		STATE_INITIALIZE : begin
			newPosX = 8'b01010011;
			newPosY = 7'b1110000;
			oldPosX = 8'b01010011;
			oldPosY = 7'b1110000;
			oldPaddleX = 'd69;
			paddleX = 'd69;
			paddleY = 7'b1110101;
			if (level == 'd0)
				brickLayout = 'b110011001111111111111111111111;
			else if (level == 'd1)
				brickLayout = 'b101010101010101010100101010101;
			else if (level == 'd2)
				brickLayout = 'b111011100111101110100101110111;
			RIGHT = 1'b1;
			DOWN = 1'b0;
			count <= 0;
			state <= STATE_RESET;		
		end



		STATE_RESET : begin
			if (count == 0) begin
				count <= count + 1;

				newX = 0;
				newY = 0;
				oldX = 0;
				oldY = 0;
				sizeX = maxX + 1;
				sizeY = maxY + 1;
				object = noObj;
				startPlot <= 1;

			end else if (count == 'd50000) begin
				newX = 0;
				newY = 0;
				oldX = 0;
				oldY = 0;
				sizeX = 1;
				sizeY = 1;
				object = noObj;
				startPlot <= 1;
				count <= count + 1;

			end else if (count == 'd100000) begin
				state <= STATE_DRAWBLOCKS;
				count <= 0;
				blockCol <= 0;
				blockRow <= 0;
			end else begin
				count <= count + 1'b1;
				startPlot <= 0;
			end
		end

		

		STATE_DRAWBLOCKS : begin
			if (count == 0) begin
				count <= count + 1;
				newX = boxLength * (blockCol);
				newY = boxHeight * (blockRow);
				oldX = boxLength * (blockCol);
				oldY = boxHeight * (blockRow);
				sizeX = boxLength;
				sizeY = boxHeight;
				if (brickLayout[blockCol + (blockRow * boxesPerRow)] == 1'b1)
					object = blockObj;
				else
					object = noObj;
				startPlot <= 1;
			end else if (count == 'd1000) begin
				if (blockCol == boxesPerRow - 1) begin
					blockCol = 0;
					if (blockRow >= numRows)
						state <= STATE_DRAWBALL;
					else
						blockRow = blockRow + 1;
				end
				else
					blockCol = blockCol + 1;
				count <= 0;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end
		end
		

		STATE_DRAWBALL : begin
			if (count == 0) begin
				 object = ballObj;
				 newX = newPosX;
				 newY = newPosY;
				 oldX = oldPosX;
				 oldY = oldPosY;
				 sizeX = 2 * ball_Radius;
				 sizeY = 2 * ball_Radius;
				 startPlot <= 1;
				count <= count + 1;
			end else if (count == 'd100) begin
				count <= 0;
				state <= STATE_DRAWPADDLE;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end	
		end
		

		STATE_DRAWPADDLE : begin
			if (count == 0) begin
				 newX = paddleX;
				 newY = paddleY;
				 oldX = oldPaddleX;
				 oldY = paddleY;
				 sizeX = paddleLength;
				 sizeY = paddleHeight;
				 object = paddleObj;
				 startPlot <= 1;
				 count <= count + 1;

			end else if (count == 'd200) begin
				state <= STATE_DRAWSTARTIMG;
				count <= 0;
			end else begin
				count <= count + 1;
				startPlot <= 0;
				end
		end
		

		STATE_DRAWSTARTIMG : begin
			if (count == 0) begin
				 newX = 9;
				 newY = 40;
				 oldX = 9;
				 oldY = 40;
				 sizeX = 140;
				 sizeY = 70;
				 object = startImgObj;
				 startPlot <= 1;
				 count <= count + 1;		
			end else if (count == 'd50000) begin
				state <= STATE_IDLE;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end
		end
		

		STATE_IDLE: begin 
			if (userStart) begin
				state <= STATE_DELETESTARTIMG;
				count <= 0;
			end
		end

		STATE_DELETESTARTIMG :  begin
			if (count == 0) begin
				 newX = 9;
				 newY = 40;
				 oldX = 9;
				 oldY = 40;
				 sizeX = 140;
				 sizeY = 70;
				 object = noObj;
				 startPlot <= 1;
				 count <= count + 1;			
			end else if (count == 'd50000) begin
				count <= 0;
				state <= STATE_START;
			end else begin
				count <= count + 1;
				startPlot <= 0;
			end
		end
	
	

		STATE_START: begin
			

			if (newPosY > maxY || (brickLayout == 'd0)) begin 
				state <= STATE_WAITRESTART;
				count <= 0;
			end else if (userStart) begin

				if(count == ballCyclesToUpdate) begin
						object = ballObj;

						count = count + 1;
						ballspeed <= ballspeed + 1;

						if((newPosX) >= (maxX - (2*ball_Radius + V_x - 1)-1))
							RIGHT <= 1'b0;
							

						if((newPosX) <= V_x)
							RIGHT <= 1'b1;
							

						if((newPosY) == (paddleY-1-(2*ball_Radius))) begin 
							if ( (newPosX >= paddleX + paddleSpeedZone) && ((newPosX + 2*ball_Radius) < (paddleX + paddleLength-paddleSpeedZone))) 
							begin
								DOWN <= 1'b0;
								V_x = 8'd1;
							end
							else if((newPosX + 2*ball_Radius) >= paddleX-1 && newPosX < (paddleX + paddleSpeedZone))
							begin
								DOWN <= 1'b0;
								RIGHT <= 1'b0;
								V_x = 8'd1;
							end
							else if((newPosX + 2*ball_Radius) >= (paddleX + paddleLength - paddleSpeedZone) && newPosX <= (paddleX + paddleLength))
							begin
								DOWN <= 1'b0;
								RIGHT <= 1'b1;
								V_x = 8'd1;
							end
						end
						

						if((newPosY) <= V_y+1)
							DOWN <= 1'b1;
						

						if(RIGHT) begin
							oldPosX <= newPosX;
							newPosX <= newPosX + V_x;				
						end else begin
							oldPosX <= newPosX;
							newPosX <= newPosX - V_x;
						end if(DOWN) begin
							oldPosY <= newPosY;
							newPosY <= newPosY + V_y;
						end else begin
							oldPosY <= newPosY;
							newPosY <= newPosY - V_y;
						end
						
						if(ballspeed == 1000 && ballCyclesToUpdate > 350000) begin
							ballCyclesToUpdate <= ballCyclesToUpdate - 1;
							paddleCyclesToUpdate <= paddleCyclesToUpdate -1;
							brickCyclesToUpdate <= brickCyclesToUpdate - 1;
							ballspeed <= 0;
						end
						startPlot <= 1'b1;
				end
				

				else if (count == paddleCyclesToUpdate)
					begin
					  count = 0;
					  object = paddleObj;
					  

					  if (moveLeft) begin
						 if (!(paddleX < V_x)) begin
									oldPaddleX <= paddleX;
									paddleX <= paddleX - V_x;
									startPlot <= 1'b1;
						 end
					  end else if (moveRight) begin 
						 if ((maxX >= (paddleX + paddleLength) ) ) begin
									oldPaddleX <= paddleX;
									paddleX <= paddleX + V_x;
									startPlot <= 1'b1;
						 end
					  end

					end
				

				else if (count == brickCyclesToUpdate)
				begin
					count = count + 1;
					object = noObj;

					topLeft_X = newPosX;
					topRight_X = newPosX + (2*ball_Radius) - 1;
					topLeft_Y = newPosY;
					bottomLeft_Y = newPosY + (2*ball_Radius) - 1;
					

					if((newPosY >= 7'd0 && newPosY <= boxHeight * numRows)) 
						begin
					
							blockCol = newPosX[7:4];
							collision = 1'b0;












								blockRow = newPosY / boxHeight;
								
							blockAddr = (boxesPerRow * blockRow) + blockCol;
							if(brickLayout[blockAddr] == 1'b0) begin


							case(RIGHT)
								1'b1: begin


									if(topRight_X == (boxLength*(blockCol+1)-1)  && ~(blockCol == boxesPerRow-1) && brickLayout[blockAddr+1] == 1'b1) 
									begin
										RIGHT = 1'b0;
										blockCol = blockCol+1;
										brickLayout[blockAddr+1] = 1'b0;
										startPlot <= 1'b1;
										score <= score + 1;
										collision = 1'b1;
									end
								end
								1'b0: begin

									if(topLeft_X == boxLength*(blockCol) && ~(blockCol == 4'd0) && brickLayout[blockAddr-1] == 1'b1) 
									begin
										RIGHT = 1'b1;
										blockCol = blockCol-1;
										brickLayout[blockAddr-1] = 1'b0;
										startPlot <= 1'b1;
										score <= score + 1;
										collision = 1'b1;
									end
								end
							endcase
							


							if(collision == 1'b0) begin
							case(DOWN)
								1'b1: 
									begin

										 if(bottomLeft_Y == (boxHeight*(blockRow+1)-1) && ~(blockRow == numRows) && brickLayout[blockAddr+boxesPerRow] == 1'b1)
										 begin
											 DOWN = 1'b0;
											 blockRow = blockRow+1;
											 brickLayout[blockAddr+boxesPerRow] = 1'b0;
											 startPlot <= 1'b1;
											 score <= score + 1;
										 end
									end
								1'b0: 
									begin

										 if(topLeft_Y == boxHeight*(blockRow) && ~(blockRow == 4'd0) && brickLayout[blockAddr-boxesPerRow] == 1'b1)
										 begin
											 DOWN = 1'b1;
											 blockRow = blockRow-1;
											 brickLayout[blockAddr-boxesPerRow] = 1'b0;
											 startPlot <= 1'b1;
											 score <= score + 1;
										 end
									end
							endcase
							end
							end
							else begin
								brickLayout[blockAddr] = 1'b0;
								startPlot <= 1'b1;
								score <= score + 1;
							end
					end
				end
			
			else 	

				begin
					startPlot <= 1'b0;
					count = count + 1;
				end
			
			
			

				if (object == ballObj) begin
					 newX = newPosX;
					 newY = newPosY;
					 oldX = oldPosX;
					 oldY = oldPosY;
					 sizeX = 2 * ball_Radius;
					 sizeY = 2 * ball_Radius;
				end else if (object == paddleObj) begin
					 newX = paddleX;
					 newY = paddleY;
					 oldX = oldPaddleX;
					 oldY = paddleY;
					 sizeX = paddleLength;
					 sizeY = paddleHeight;
				end else if (object == noObj) begin		
					newX = boxLength * (blockCol);
					newY = boxHeight * (blockRow);
					oldX = boxLength * (blockCol);
					oldY = boxHeight * (blockRow);
					sizeX = boxLength;
					sizeY = boxHeight;
				end

							
		end
	
		end
		
		STATE_WAITRESTART : begin
			if (count == 0) begin
				 newX = 9;
				 newY = 40;
				 oldX = 9;
				 oldY = 40;
				 sizeX = 140;
				 sizeY = 70;
				 object = gameOverObj;
				 startPlot <= 1;
				 count <= count + 1;
			end else if (count > 'd50000) begin
				if(gameOver) begin
					if(brickLayout != 'd0)
						score <= 0;
					level <= level + 1;
					state <= STATE_INITIALIZE;
				end
				else if (userReset)
					state <= STATE_INITIALIZE;
			end else begin
				count <= count + 1;
				startPlot <= 0;	
			end
				
		end
		
	endcase
	
end

endmodule