battleplace = 0

counts = nil
p_move = 0
counts = Timer.new()
counts:start()
r =0
t = 0


rbattle = 0

while place == "route1______" do
	CurrentTime = counts:time()
	pad = Controls.read()
		screen:clear()
		screen:blit(BG[7].x, BG[7].y, BG[7].pic)
		screen:blit(BG[4].x, BG[4].y, BG[4].pic)
		screen:blit(BG[9].x, BG[9].y, BG[9].pic)
		screen:blit(240, 135, image[player_direction])
	if pad:l() and oldpad:l() ~= pad:l() then
		dofile("./start_pressed.lua")
	end
	if BG[7].x <= -9 and BG[7].x >= -193 and BG[7].y >= 26 and BG[7].y <= 135  then
		if rbattle >= 990 and rbattle <=1000 then 
			battleplace = "route1 up"
			dofile("./random_battle.lua")
			rbattle = 0
		else 
			if r ==0 then
				rbattle = math.random(1000)		
				r=1
			end	
		end
		if r == 1 and rbattle < 990 then
			r = 0
		end
	end
	if BG[7].x<= 112 and BG[7].y < -7 then
		if rbattle >= 990 and rbattle <=1000 then 
			battleplace = "route1 down"
			dofile("./random_battle.lua")
			rbattle = 0
		else 
			if r ==0 then
				rbattle = math.random(1000)		
				r=1
			end	
		end
		if r == 1 and rbattle < 990 then
			r = 0
		end
	end

	if pad:left() then
	   moveleft()
	
	      Player[1].x = Player[1].x +1
	      chars[1].x = chars[1].x +1
	      for move_slides = 1, 10 do
	       BG[move_slides].x = BG[move_slides].x +1
	    
	      end

-- left screen
		if BG[7].x == 239 and BG[7].y >= -113 and BG[7].y <= 7 then
	      Player[1].x = Player[1].x -1
		     
	
	    	leftmoveboundry()
		    end
	-- left trees
		if BG[7].x == -8 and BG[7].y >=18 then
		
			Player[1].x = Player[1].x -1
	      		leftmoveboundry()
		end
		if BG[7].x == 250 then
	
			place = "neptarento__"
	
		end

	
		
	end
	if pad:right() and BG[7].x >= -226  then
	     moveright()
	      
	      Player[1].x = Player[1].x -1
	      chars[1].x = chars[1].x -1
	      for move_slides = 1, 10 do
	       BG[move_slides].x = BG[move_slides].x -1
	      end     
	
	
		--right bottom trees
		if BG[7].x == 19 and BG[7].y <= -24 and BG[7].y >= -144 then
	
		      Player[1].x = Player[1].x +1
		      rightmoveboundry()
		end
		--right top trees
		if BG[7].x == -194 and BG[7].y <= 135 and BG[7].y >= 7 then
	
			Player[1].x = Player[1].x +1
			rightmoveboundry()
	
		end
		if BG[7].x == -227 then
			place = "plutanium___"
			dofile("./plutanium.lua")
			
		end
	end
	if pad:up() and BG[7].y <= 134 then
   moveup()
   Player[1].y = Player[1].y +1
   chars[1].y = chars[1].y +1
   
   for move_slides = 1, 10 do
    BG[move_slides].y = BG[move_slides].y +1 
   end

-- left trees
if BG[7].y == 13 and BG[7].x<=254 and BG[7].x >= -7 then
upmoveboundry()

end
-- right trees
if BG[7].y == 9 and BG[7].x<=-198 then

upmoveboundry()

end
end
 if pad:down() and BG[7].y >=-113 then
  movedown()
  chars[1].y = chars[1].y -1
   for move_slides = 1, 10 do
    BG[move_slides].y = BG[move_slides].y -1
    Player[1].y = Player[1].y -1
    
   end

--bottom trees
if BG[7].y == -22 and BG[7].x <= 21 then
 downmoveboundry()
end


end

screen:print(100,210, BG[7].x.. "  " .. BG[7].y, blue)
screen:print(15,0,rbattle, blue)
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
