⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.java

📁 一个java的免费游戏引擎,里面有文档,和例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

package com.golden.gamedev;

import com.golden.gamedev.engine.BaseAudio;
import com.golden.gamedev.engine.BaseGraphics;
import com.golden.gamedev.engine.BaseIO;
import com.golden.gamedev.engine.BaseInput;
import com.golden.gamedev.engine.BaseLoader;
import com.golden.gamedev.engine.BaseTimer;
import com.golden.gamedev.engine.audio.MidiRenderer;
import com.golden.gamedev.engine.audio.WaveRenderer;
import com.golden.gamedev.engine.input.AWTInput;
import com.golden.gamedev.engine.timer.SystemTimer;
import com.golden.gamedev.funbox.ErrorNotificationDialog;
import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.GameFont;
import com.golden.gamedev.object.GameFontManager;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.util.ImageUtil;
import com.golden.gamedev.util.Utility;
import java.applet.Applet;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.*;
import java.net.URL;

// Referenced classes of package com.golden.gamedev:
//            GameEngine, GameObject

public abstract class Game
{

    public static final String GTGE_VERSION = "0.2.3";
    public BaseGraphics bsGraphics;
    public BaseIO bsIO;
    public BaseLoader bsLoader;
    public BaseInput bsInput;
    public BaseTimer bsTimer;
    public BaseAudio bsMusic;
    public BaseAudio bsSound;
    public GameFontManager fontManager;
    private boolean k;
    private boolean l;
    protected boolean distribute;
    GameFont fpsFont;
    private boolean o;
    private boolean p;
    static Class a;

    public Game()
    {
    }

    public void stop()
    {
        k = false;
    }

    public void finish()
    {
        l = true;
        stop();
    }

    public boolean isFinish()
    {
        return l;
    }

    public boolean isRunning()
    {
        return k;
    }

    public final void start()
    {
        if(!k && !l)
        {
            k = true;
            URL aurl[] = {
                (a != null ? a : (a = a("com.golden.gamedev.Game"))).getResource("Game.dat"), (a != null ? a : (a = a("com.golden.gamedev.Game"))).getResource("Game.fnt"), (a != null ? a : (a = a("com.golden.gamedev.Game"))).getResource("GameEngine.class"), (a != null ? a : (a = a("com.golden.gamedev.Game"))).getResource("GameObject.class")
            };
            int ai[] = {
                24501, 2107, 2000, 6727
            };
            try
            {
                for(int i = 0; i < aurl.length; i++)
                {
                    if(aurl[i] == null)
                        q();
                    BufferedInputStream bufferedinputstream;
                    if((bufferedinputstream = new BufferedInputStream(aurl[i].openStream())).available() != ai[i])
                        q();
                    bufferedinputstream.close();
                }

            }
            catch(Throwable _ex)
            {
                q();
            }
            if(!p)
                o = !distribute;
            if(!o)
            {
                try
                {
                    if(!p)
                    {
                        p = true;
                        h();
                    }
                    startGameLoop();
                    return;
                }
                catch(Throwable throwable)
                {
                    notifyError(throwable);
                }
                return;
            }
            if(!p)
            {
                p = true;
                h();
            }
            startGameLoop();
        }
    }

    private void h()
    {
        initEngine();
        if(!o)
            showLogo();
        try
        {
            BufferedImage bufferedimage = ImageUtil.getImage((a != null ? a : (a = a("com.golden.gamedev.Game"))).getResource("Game.fnt"));
            fpsFont = fontManager.getFont(bufferedimage);
            fontManager.removeFont(bufferedimage);
            fontManager.putFont("FPS Font", fpsFont);
            if(!o)
                fpsFont = null;
        }
        catch(Exception _ex)
        {
            q();
        }
        System.gc();
        System.runFinalization();
        initResources();
    }

    void startGameLoop()
    {
        System.gc();
        System.runFinalization();
        bsTimer.startTimer();
        bsTimer.refresh();
        long l1 = 0L;
label0:
        do
        {
            update(l1);
            bsInput.update(l1);
            do
            {
                if(!k)
                    break label0;
                Graphics2D graphics2d = bsGraphics.getBackBuffer();
                render(graphics2d);
                if(o)
                {
                    if(graphics2d.getClip() != null)
                        graphics2d.setClip(null);
                    if(graphics2d.getComposite() != null && graphics2d.getComposite() != AlphaComposite.SrcOver)
                        graphics2d.setComposite(AlphaComposite.SrcOver);
                    fpsFont.drawString(graphics2d, "FPS = " + getCurrentFPS() + "/" + getFPS(), 9, getHeight() - 21);
                    fpsFont.drawString(graphics2d, "GTGE", getWidth() - 65, 9);
                }
            } while(!bsGraphics.flip());
            if((l1 = bsTimer.sleep()) > 100L)
                l1 = 100L;
        } while(true);
        bsTimer.stopTimer();
        bsSound.stopAll();
        bsMusic.stopAll();
        if(l)
        {
            bsGraphics.cleanup();
            notifyExit();
        }
    }

    protected void initEngine()
    {
        if(bsTimer == null)
            bsTimer = new SystemTimer();
        if(bsIO == null)
            bsIO = new BaseIO(getClass());
        if(bsLoader == null)
            bsLoader = new BaseLoader(bsIO, Color.MAGENTA);
        if(bsInput == null)
            bsInput = new AWTInput(bsGraphics.getComponent());
        if(bsMusic == null)
        {
            bsMusic = new BaseAudio(bsIO, new MidiRenderer());
            bsMusic.setExclusive(true);
            bsMusic.setLoop(true);
        }
        if(bsSound == null)
            bsSound = new BaseAudio(bsIO, new WaveRenderer());
        bsTimer.setFPS(100);
        Background.screen = bsGraphics.getSize();
        if(fontManager == null)
            fontManager = new GameFontManager();
    }

    public abstract void initResources();

    public abstract void update(long l1);

    public abstract void render(Graphics2D graphics2d);

    protected void notifyExit()
    {
        Applet applet;
        if(!(bsGraphics instanceof Applet))
            try
            {
                System.exit(0);
                return;
            }
            catch(Exception exception)
            {
                return;
            }
        applet = (Applet)bsGraphics;
        BufferedImage bufferedimage;
        Graphics2D graphics2d = (bufferedimage = ImageUtil.createImage(getWidth(), getHeight())).createGraphics();
        Color.BLACK;
        setColor();
        graphics2d.fillRect(0, 0, getWidth(), getHeight());
        graphics2d.setComposite(AlphaComposite.getInstance(3, 0.8F));
        java.awt.geom.Ellipse2D.Float float1 = new java.awt.geom.Ellipse2D.Float(getWidth() / 10, getHeight() / 10, getWidth() - (getWidth() / 10 << 1), getHeight() - (getHeight() / 10 << 1));
        graphics2d.setClip(float1);
        if(this instanceof GameEngine)
            ((GameEngine)this).getCurrentGame().render(graphics2d);
        render(graphics2d);
        graphics2d.dispose();
        break MISSING_BLOCK_LABEL_187;
        JVM INSTR pop ;
        graphics2d.setColor(Color.BLACK);
        graphics2d.fillRect(0, 0, getWidth(), getHeight());
        ColorSpace colorspace = ColorSpace.getInstance(1003);
        BufferedImage bufferedimage1 = (new ColorConvertOp(colorspace, null)).filter(bufferedimage, null);
        applet.removeAll();
        applet.setIgnoreRepaint(false);
        _cls1 _lcls1;
        (_lcls1 = new _cls1(bufferedimage1)).setSize(applet.getSize());
        _lcls1.addMouseListener(new _cls2(applet));
        applet.add(_lcls1);
        applet.repaint();
        _lcls1.repaint();
        return;
    }

    protected void notifyError(Throwable throwable)
    {
        new ErrorNotificationDialog(throwable, bsGraphics, getClass().getName(), null);
    }

    public final boolean isDistribute()
    {
        return !o;
    }

    public final void showLogo()
    {
label0:
        {
            hideCursor();
            SystemTimer systemtimer;
            (systemtimer = new SystemTimer()).setFPS(20);
            bsInput.refresh();
            BufferedImage bufferedimage = null;
            try
            {
                BufferedImage bufferedimage1;
                bufferedimage = ImageUtil.resize(bufferedimage1 = ImageUtil.getImage((a != null ? a : (a = a("com.golden.gamedev.Game"))).getResource("Game.dat")), getWidth(), getHeight());
                bufferedimage1.flush();
            }
            catch(Exception _ex)
            {
                q();
            }
            try
            {
                p(Color.BLACK);
                Thread.sleep(1000L);
            }
            catch(InterruptedException _ex) { }
            float f = 0.0F;
            systemtimer.startTimer();
            boolean flag = true;
            while(f < 1.0F) 
            {
                do
                {
                    if(!k)
                        break label0;
                    Graphics2D graphics2d;
                    (graphics2d = bsGraphics.getBackBuffer()).setColor(Color.BLACK);
                    graphics2d.fillRect(0, 0, getWidth(), getHeight());
                    java.awt.Composite composite = graphics2d.getComposite();
                    graphics2d.setComposite(AlphaComposite.getInstance(3, f));
                    graphics2d.drawImage(bufferedimage, 0, 0, null);
                    graphics2d.setComposite(composite);
                } while(!bsGraphics.flip());
                if(flag)
                {
                    flag = false;
                    systemtimer.refresh();
                }
                long l1 = systemtimer.sleep();
                double d;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -