Animation={}

function Animation.new(fichier,nbframe,x,y,l,h,cadence)
     local animation=nil
	 animation={pic=Image.load(fichier),
	            nb=nbframe,
				x=x,
				y=y,
				l=l,
				h=h,
				n=0,
				cb=cadence,
				c=0,
				lz=l/nbframe,
				etat=true,
				xx=5,
				yy=5}
				
	 function animation:play(img,x,y)
	     --if x<GameMap.lr and y<GameMap.hr then
		  img:blit(x,y,animation.pic,animation.x+(animation.n*animation.lz),animation.y,animation.lz,animation.h)
		-- end
		 animation.c=animation.c+1
		 if animation.c>=animation.cb then
		     animation.c=0
		     animation.n=animation.n+1
		 end
		 
		 if animation.n>=animation.nb then
		     animation.n=0
			 animation.etat=true
			 return false
		 else
		     return true
		 end
	 end
	 
     return animation
end



GlobalAnim={n=0,
            endg=Animation.new("data/image/etoile.png",4,0,0,112,29,2),
			endx=0,
			endy=0}

function GlobalAnim.new(fichier,nbframe,x,y,l,h,cadence)
     GlobalAnim[GlobalAnim.n+1]=Animation.new(fichier,nbframe,x,y,l,h,cadence)
	 GlobalAnim[GlobalAnim.n+1].etat=true
	 GlobalAnim.n=GlobalAnim.n+1
	 return  GlobalAnim.n
end

function GlobalAnim.run(num,x2,y2)
     if num<= GlobalAnim.n then
	     GlobalAnim[num].etat=false
		 GlobalAnim[num].xx=x2
	     GlobalAnim[num].yy=y2
	 end
end


function GlobalAnim.play()
     if GlobalAnim.n>0 then
         for i=1,GlobalAnim.n do
		     if not GlobalAnim[i].etat then
	             if not GlobalAnim[i]:play(screen,GlobalAnim[i].xx,GlobalAnim[i].yy) then
				      GlobalAnim[i].etat=true
			     end
	         end
	     end
	 end
end

function GlobalAnim.playEnd()
     GlobalAnim.endg:play(screen,GameMap.xr+GlobalAnim.endx*20-3,GameMap.yr+GlobalAnim.endy*20-5)
end

function GlobalAnim.defineFinNiveau(x,y)
     GlobalAnim.endx=x
	 GlobalAnim.endy=y
end

 StartAnimation={}
function StartAnimation.new(fichier,x,y,cadence,n)
     StartAnimation.x=x
	 StartAnimation.y=y
	 StartAnimation.n=0
	 StartAnimation.c=0
	 StartAnimation.nb=n
	 StartAnimation.cb=cadence
	 StartAnimation.pic=Image.load(fichier)
	 StartAnimation.l=StartAnimation.pic:width()
	 StartAnimation.h=(StartAnimation.pic:height())/n
end

function StartAnimation.play(img)
		  img:blit(StartAnimation.x,StartAnimation.y,StartAnimation.pic,0,(StartAnimation.n*StartAnimation.h),StartAnimation.l,StartAnimation.h)
		 StartAnimation.c=StartAnimation.c+1
		 if StartAnimation.c>=StartAnimation.cb then
		     StartAnimation.c=0
		     StartAnimation.n=StartAnimation.n+1
		 end
		 
		 if StartAnimation.n>=StartAnimation.nb then
			 return false
		 else
		     return true
		 end
end
	 