Main.java :  » Game » easy-game-client » frame » Java Open Source

Java Open Source » Game » easy game client 
easy game client » frame » Main.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frame;

import j2se.org.easy.gui.AWTComponent;
import j2se.org.easy.gui.AWTImageFactory;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import norg.easy.ani.animator.ImageCollectionAnimator;
import norg.easy.ani.animator.ImageSprite;
import norg.easy.ani.animator.WilResourceAnimator;
import org.easy.gui.Image;
import org.easy.gui.ImageFactory;
import org.easy.mir2.action.ActionInfo;
import org.easy.mir2.action.BaseHumanActions;
import org.easy.mir2.res.Directory;
import org.easy.mir2.res.WilImageReadOnlyResource;
import org.easy.mir2.res.WilResource;
import org.easy.util.Converter;

/**
 *
 * @author Administrator
 */
public class Main {

    public static WilResourceAnimator createAnimator(ImageSprite s, WilResource res, int index, ActionInfo info, Directory dir, boolean loop) {
        int start = info.start + index * 600;
        int[] indexes = new int[info.frame];
        long[] periods = new long[info.frame];
        int l = info.frame + info.skip;
        for (int i = 0; i < info.frame; i++) {
            indexes[i] = start + l * (dir.getDir() - 1) + i;
            periods[i] = TimeUnit.MILLISECONDS.toNanos(info.ftime);
        }
        return new WilResourceAnimator(s, res, indexes, periods);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Throwable {
        File dir = new File("D:\\\\\\Data");
        File humWil = new File(dir, "hum.wil");
        File humWix = new File(dir, "hum.wix");
        WilResource res = createResource(humWil, humWix);
        WilResourceAnimator ani = createAnimator(new ImageSprite(), res, 0, BaseHumanActions.WALK, Directory.UP, true);
        ani.setLoop(true);

        System.out.println(ani.getNewPaintBounds());

        ImageCollectionAnimator as = new ImageCollectionAnimator();
        as.add(ani);

        for (int i = 0; i < 10; i++) {
            as.setX(100);
            as.setY(100);
            as.update(new AWTComponent(new JPanel()));
            System.out.println("--");
            Thread.sleep(100);
        }

    }

    static WilResource createResource(File wil, File wix) {
        final ImageFactory f = new AWTImageFactory();
        try {
            return new WilImageReadOnlyResource(new Converter<ByteBuffer, Image>() {

                public Image convert(ByteBuffer arg0) {
                    return f.create(arg0.array());
                }
            }, wil, wix);
        } catch (IOException ex) {
            Logger.getLogger(CanvasPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.