--Loading

load = image.load("loading/loading.png")
tile=image.load("loading/lo.png")
loadtop=image.load("loading/loadingG.png")

loadingimg=image.load("loading/loading1.png")
loading2img=image.load("loading/loading3.png")

tplayer={}
tplayer.x=64
tplayer.y=-30
tplayer.timer=0
tplayer.play="false"

gravity=2

tplayerright = image.load("loading/right/stand.png")


tplayerspin = {
image.load("loading/right/crouch.png"), 
image.load("loading/right/sspin1.png"),
image.load("loading/right/sspin2.png"),
image.load("loading/right/sspin3.png"),
image.load("loading/right/sspin4.png"),
image.load("loading/right/sspin5.png"),
image.load("loading/right/sspin6.png"),
image.load("loading/right/sspin7.png"),
image.load("loading/right/sspin8.png"),
image.load("loading/right/sspin9.png"),
image.load("loading/right/sspin10.png"),
image.load("loading/right/sspin11.png"),
image.load("loading/right/sspin12.png")

}
tplayer.img=tplayerright

--Animation function--
function animate(imgtable,interval, object) 
	
	 local numFrames = table.getn(imgtable) 
	 if object.timer >= numFrames*interval then object.timer = 0 end 
	 object.timer = object.timer + 1 
	 for i = 1, numFrames do 
		 if object.timer > interval*(i-1) and object.timer <= interval*i then 
			 object.img = imgtable[i] 
			 break 
		 end
	 end
	 return object.img
end

--Load stuff
function loadstuff()
bg = image.load("img/bg.jpg")
white = color.new(255,255,255) 
red = color.new(255,0,0)
blue = color.new(0,0,255)
dofile("player.txt")
dofile("enemy.txt")
dofile("diamonds.txt")
dofile("functions.lua")
end

t=0
while true do

screen:clear()

image.blit(100,61,load)
image.blit(323,93,loadtop)

image.blit(323,125,loadingimg)


if t>40 then
t=0
end


t=t+1
if t>10 then
a=1
image.blit(343+((a-1)*14),125,loading2img)
end
if t>20 then
b=2
image.blit(343+((b-1)*14),125,loading2img)
end
if t>30 then
c=3
image.blit(343+((c-1)*14),125,loading2img)
end



for i=1, 15 do
image.blit((32*(i-1)),224,tile)
end

if tplayer.y~=192 then
gravity=gravity+1
tplayer.y=tplayer.y+gravity
end
if tplayer.y>192 then
tplayer.y=192
end
if tplayer.y==192 then
animate(tplayerspin,10,tplayer)
end

if tplayer.timer>90 then
tplayer.play="true"
end

if tplayer.play=="true" then
tplayer.x=tplayer.x+10
end

image.blit(tplayer.x, tplayer.y, tplayer.img)

if tplayer.x>=480 then
collectgarbage("collect")
loadstuff()
dofile("game.lua")
end


 screen.flip()
 screen.waitvblankstart()
end