package engine;

import graphics.Circle;
import log.IGLog;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;

/**
 *  The skin class is to handle every buffered image of a given skin.
 */
public class Skin implements Cloneable {

    private BufferedImage[] perso;
    private int animation;
    private int movement;
    private int movementmax;

    public Skin (BufferedImage[] perso, int movementmax){
        this.perso = perso;
        this.animation = 0;
        this.movement = -1;
        if(movementmax > 0)
            this.movementmax = movementmax;
        else
            this.movementmax = 0;
    }

    /**
     * Move an image to show the next animation
     */
    public BufferedImage move(){
        movement++;
        if (movement == movementmax) {
            animation++;
            movement = 0;
        }
        if (animation == perso.length)
            animation=0;
        return this.perso[animation];
    }

    public Skin(int width, int height) {
        Random random = new Random();
        int r = random.nextInt(256);
        int g = random.nextInt(256);
        int b = random.nextInt(256);
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = image.createGraphics();

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setColor(new Color(r, g, b));
        g2d.fill(new Circle(0, 0, width / 2).getShape());

        perso =
                new BufferedImage[] { image };
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Skin s = (Skin) super.clone();

        /*s.left  = left.clone();
        s.right = right.clone();
        s.top   = top.clone();
        s.down  = down.clone();*/
        s.perso = perso.clone();
        s.animation = animation;

        /*s.onDestruct = onDestruct.clone();
        s.onAppears  = onAppears.clone();
*/
        //s.reinit();

        return s;
    }
}

@@ -373,16 +373,75 @@
 ntmax;%0A%0A
+    private boolean oneTime;%0A    private boolean started;%0A%0A
     publ
@@ -701,328 +701,52 @@
     
-%7D%0A%0A
     
-/**%0A     * Move an image to show the next animation%0A     */%0A    public BufferedImage move()%7B%0A        movement++;%0A        if (movement == movementmax) %7B%0A            animation++;%0A            movement = 0;%0A        %7D%0A        if (animation == perso.length)%0A            animation=0;%0A        return this.perso%5Banimation%5D
+started = false;%0A        oneTime = false
 ;%0A  
@@ -1361,357 +1361,879 @@
     
-@Override%0A    protected Object clone() throws CloneNotSupportedException %7B%0A        Skin s = (Skin) super.clone();%0A%0A        /*s.left  = left.clone();%0A        s.right = right.clone();%0A        s.top   = top.clone();%0A        s.down  = down.clone();*/%0A        s.perso = perso.clone();%0A        s.animation = animation;%0A%0A        /*s.onDestruct = onDestruct
+/**%0A     * Move an image to show the next animation%0A     */%0A    public BufferedImage move()%7B%0A        if (started) %7B%0A            movement++;%0A            if (movement == movementmax) %7B%0A                animation++;%0A                movement = 0;%0A            %7D%0A            if (animation == perso.length) %7B%0A                animation = 0;%0A                if (oneTime) %7B%0A                    started = false;%0A                    return null;%0A                %7D%0A            %7D%0A            return this.perso%5Banimation%5D;%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A%0A%0A    public boolean isStarted() %7B%0A        return started;%0A    %7D%0A%0A    public void start() %7B%0A        started = true;%0A    %7D%0A%0A    public void start(boolean oneTime) %7B%0A        this.oneTime = oneTime;%0A        start();%0A    %7D%0A%0A    @Override%0A    public Object clone() throws CloneNotSupportedException %7B%0A        Skin s = (Skin) super
 .clo
@@ -2234,24 +2234,25 @@
 er.clone();%0A
+%0A
         s.on
@@ -2253,30 +2253,29 @@
   s.
-onAp
 pe
-a
 rs
+o       
   = 
-onAp
 pe
-a
 rs
+o
 .clo
@@ -2284,31 +2284,104 @@
 ();%0A
-*/%0A        //s.reinit()
+        s.animation     = 0;%0A        s.movement      = -1;%0A        s.movementmax   = movementmax
 ;%0A%0A 

add possibilities to make only one cycle.