loadmap1 = nil
shop1load = nil
shopmload = nil
collectgarbage()

shop1load,message = loadfile("map2.lua")
if shop1load == nil then
screen:clear()
screen:print(0,0,"LOAD FAILED",Color.new(255,0,0))
screen:print(0,10,message,Color.new(255,255,255))
screen.flip()
end

shopmload,message = loadfile("shopmenu.lua")
if shopmload == nil then
screen:clear()
screen:print(0,0,"LOAD FAILED",Color.new(255,0,0))
screen:print(0,10,message,Color.new(255,255,255))
screen.flip()
end

if bombcounter == 1 then
RupeeCounter = RupeeCounter - 8
end

	status = "game"

--------load map-------

	backgroundCache = Image.load("backgrounds/shop.png")

-----------**Walls**---------

	wall1 = Image.createEmpty(1,60)  -----first vertical wall - left
	wall2 = Image.createEmpty(1,60)  -----first vertical wall - right
	wall3 = Image.createEmpty(70,1)  -----first horizontal wall - left
	wall4 = Image.createEmpty(70,1)  -----first horizontal wall - right
	wall5 = Image.createEmpty(1,1)   -----vertical right wall 1
	wall6 = Image.createEmpty(1,40)  -----vertical right wall 2 - chairs
	wall7 = Image.createEmpty(300,1) -----top horizontal wall
	wall8 = Image.createEmpty(18,1)  -----box next to counter 1
	wall9 = Image.createEmpty(1,60)  -----vertical wall left
	
------------Walls------

   	wall1 = {x = 213, y = 209, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 276, y = 208, height = wall2:height(), width = wall2:width() }
   	wall3 = {x = 120, y = 210, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 276, y = 210, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 347, y = 200, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 329, y = 143, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 158, y = 129, height = wall7:height(), width = wall7:width() }
   	wall8 = {x = 135, y = 138, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 119, y = 149, height = wall9:height(), width = wall9:width() }
   	  
-----------------**Collision Check**---------

function collisionCheck(test)

	if (player.x + playerWidth > test.x) and (player.x < test.x + test.width) and
	(player.y + playerHeight > test.y) and (player.y < test.y + test.height) then

	player.x = oldx
	player.y = oldy
	end
end

--------------**map loading**------

function maps()   ------House

	if player.x>=214 and player.x <=258 and
	player.y >=265 and player.y <=267 then
	player.x = 410
	player.y = 99
	player.img = player10
	shop1load()
	end
end

----------player text---------

	function playertext()
       
---------character conversation-----
  

	if player.x >=222 and player.x <=265 and
	player.y >=128 and player.y <=137 and
	pad:cross() then
	select:play()
    shopmload()
   	end
end

----------start main loop--------

	while true do

    maps()

-------**store players position at beginning of each loop**----

	oldx = player.x
	oldy = player.y
	screen:clear()

-------init controls---------

	pad = Controls.read()

---------init functions-----

	if pad:right() then    -----Right Movement
	moveRight()
	player.x = player.x + 2
 	end

	if pad:left() then    -----Left Movement
	moveLeft()
	player.x = player.x - 2
  	end

	if pad:up() then      -----Up Movement
	moveUp()                                                   
 	player.y = player.y - 2
	end

	if pad:down() then   -----Down Movement
	moveDown()
 	player.y = player.y + 2
	end

------**check collision for wall**-----

	collisionCheck(wall1)
	collisionCheck(wall2)
	collisionCheck(wall3)
	collisionCheck(wall4)
	collisionCheck(wall5)
	collisionCheck(wall6)
	collisionCheck(wall7)
	collisionCheck(wall8)
	collisionCheck(wall9)
	
-------------**Blit To Screen**----

	screen:blit(0, 0, backgroundCache)
	screen:blit(player.x, player.y, player.img)
	screen:blit(245, 78, shopkeeper1)
	screen:blit(400, 10, container)
 	screen:blit(417, 13, triangle)
 	screen:blit(432, 30, circle)
   	screen:blit(403, 30, square)
   	screen:blit(417, 45, cross)
 	screen:blit(404, 32, sword)
 	screen:blit(420, 15, bomb)
 	screen:blit(420, 49, maja)
	screen:blit(0, 0, heart1)
	screen:blit(30, 0, heart2)
	screen:blit(60, 0, heart3)
 	screen:blit(240, 0, rupeess) 
	screen:print(280,10, RupeeCounter, orange)
   	screen.flip()

    playertext()

  screen.waitVblankStart()
  end


