www.pudn.com > 3dtennis.rar > C3D.java


// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2007-5-8 ÏÂÎç 09:17:04 
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version! 
// Decompiler options: packimports(3)  
 
import com.mascotcapsule.micro3d.v3.*; 
import java.io.*; 
import java.util.Date; 
import java.util.Random; 
import javax.microedition.lcdui.*; 
import javax.microedition.lcdui.game.GameCanvas; 
import javax.microedition.rms.RecordStore; 
 
abstract class C3D extends GameCanvas 
    implements CommandListener 
{ 
 
    C3D(Tennis tennis) 
    { 
        super(true); 
        SndMgr.SoundInit(this); 
        NowSw = 0; 
        NowSwStack = 0; 
        ClickSw = 0; 
        OldClickSw = 0; 
        ClickSwStack = 0; 
        RepeatSw = 0; 
        setCommandListener(this); 
        Parent = tennis; 
        Width = getWidth(); 
        Height = getHeight(); 
        Width = 176; 
        Height = 175; 
        for(int i = 0; i < 6; i++) 
            CVecs[i] = new Vector3D(); 
 
        CVecs[5].set(0, 4096, 0); 
        for(int j = 0; j < TmpMat.length; j++) 
            TmpMat[j] = new CMat(); 
 
        for(int k = 0; k < TmpV.length; k++) 
            TmpV[k] = new Vector3D(); 
 
        InitSaveData(); 
        if(!Load()) 
        { 
            NeedSave = true; 
            Save(); 
        } 
        if(SaveData[0] >= Tennis.NumOfLanguages) 
            SaveData[0] = 0; 
        tennis.LanguageChange(SaveData[0]); 
        TimeLockTournamentCheck(SaveData[4]); 
        SetCom(-1, -1); 
        ReMakeCommandValue(); 
        SetCom(-1, -1); 
        (new Thread() { 
 
            public void run() 
            { 
                do 
                { 
                    do 
                    { 
                        C3D.NowSwStack = C3D.NowSw; 
                        C3D.NowSw = 0; 
                        C3D.OldClickSw = C3D.ClickSw; 
                        C3D.ClickSw = C3D.ClickSwStack; 
                        C3D.ClickSwStack = 0; 
                        KeyCheckForGameCanvas(); 
                        try 
                        { 
                            Thread.sleep(C3D.Sleep); 
                            Thread.yield(); 
                        } 
                        catch(InterruptedException interruptedexception) { } 
                    } while(C3D.InComingCall); 
                    run_paint(); 
                } while(true); 
            } 
 
        }).start(); 
    } 
 
    abstract void run_paint(); 
 
    boolean TimeLockTournamentCheck(int i) 
    { 
        if(i > 5) 
            return false; 
        if(i != SaveData[3]) 
        { 
            SaveData[3] = (byte)i; 
            SetSaveData(7, i); 
            return true; 
        } else 
        { 
            return false; 
        } 
    } 
 
    void PaintYesNoWindow(Graphics g, String s, int i) 
    { 
        int j1 = Fonts[0].stringWidth(s); 
        int l; 
        if(j1 + 10 <= 100) 
        { 
            l = 100; 
        } else 
        { 
            l = j1 + 10; 
            if(l > Width - 2) 
                l = Width - 2; 
        } 
        byte byte0 = 45; 
        int j = (Width - l) / 2; 
        int k = (Height - byte0) / 2; 
        g.setColor(0x888888); 
        for(int i1 = 0; i1 < byte0; i1 += 2) 
            g.fillRect(j, k + i1, l, 1); 
 
        g.setColor(0xffffff); 
        g.drawRect(j, k, l, byte0); 
        k -= 2 * Tennis.ChineseFont; 
        PaintBold(g, s, j + (l - j1) / 2, k + 7, 0, 0, 0xffffff, 157); 
        l = (l - 100) / 2 + 16; 
        if(i == 0) 
        { 
            PaintBold(g, PrStr[2], j + l, k + 27, 0, 0, 0xffffff, 157); 
            PaintBold(g, PrStr[3], j + l + 48, k + 27, 0, 0, 0x888888, 157); 
        } else 
        { 
            PaintBold(g, PrStr[2], j + l, k + 27, 0, 0, 0x888888, 157); 
            PaintBold(g, PrStr[3], j + l + 48, k + 27, 0, 0, 0xffffff, 157); 
        } 
    } 
 
    void InitSaveData() 
    { 
        SaveData[1] = 3; 
        SaveData[2] = 0; 
        SaveData[3] = 0; 
        SaveData[4] = 0; 
        SaveData[5] = 0; 
        SaveData[6] = 10; 
        SaveData[7] = -1; 
        for(int i = 0; i < 5; i++) 
            SaveData[8 + i] = 0; 
 
        for(int j = 22; j < 52; j++) 
            if(j < 37) 
                SaveData[j] = 1; 
            else 
                SaveData[j] = 0; 
 
        SaveData[22] = 1; 
        l2b(GetNowTime(), SaveData, 13); 
    } 
 
    void SetSaveData(int i, int j) 
    { 
        if(SaveData[i] != j) 
        { 
            SaveData[i] = (byte)j; 
            NeedSave = true; 
        } 
    } 
 
    void Save() 
    { 
        WriteRS(SaveData, "SAVE"); 
    } 
 
    boolean Load() 
    { 
        byte abyte0[] = ReadRS("SAVE"); 
        if(abyte0 != null) 
        { 
            SaveData = abyte0; 
            return true; 
        } else 
        { 
            return false; 
        } 
    } 
 
    protected void SetLoadingBar(int i) 
    { 
        LoadingBar = i; 
    } 
 
    protected void PaintLoadingBar(Graphics g, int i, boolean flag) 
    { 
        int j = (Width - Spr[0].getWidth()) / 2; 
        g.drawImage(Spr[0], j, i, 0x10 | 4); 
        g.setClip(j + 4, i + 3, 94, 4); 
        g.drawImage(Spr[1], (j + 4 + 94) - ((100 - LoadingBar) * 94) / 100, i + 3, 0x10 | 8); 
        g.setClip(0, 0, Width, Height); 
        g.setColor(0); 
        String s = PrStr[58]; 
        int k = Fonts[0].stringWidth(s); 
        g.setFont(Fonts[0]); 
        g.drawString(s, (Width - k) / 2, i + 16, 0x10 | 4); 
        if(flag) 
        { 
            byte byte1 = 100; 
            int l = i - 20; 
            byte byte0 = byte1; 
            i = l - LoadingBar_BallS; 
            LoadingBar_BallS += LoadingBar_BallV; 
            LoadingBar_BallV--; 
            if(LoadingBar_BallS < 0) 
            { 
                LoadingBar_BallS = 0; 
                LoadingBar_BallV = (LoadingBar_BallV * -80) / 100; 
            } 
            g.setClip(byte1, l, 13, 13); 
            int i1 = LoadingBar_BallS / 20; 
            if(i1 > 2) 
                i1 = 2; 
            g.drawImage(Spr[2], byte1 - 13 * i1, l - 13, 0x10 | 4); 
            byte0 = byte1; 
            i = l - LoadingBar_BallS; 
            g.setClip(byte0, i, 13, 13); 
            g.drawImage(Spr[2], byte0 - LoadinbBar_ballTable[Counter % 4], i, 0x10 | 4); 
            g.setColor(0); 
            g.setClip(0, 0, Width, Height); 
            g.setFont(Fonts[0]); 
        } 
    } 
 
    static void PerticleErace() 
    { 
        EffectiveNumPerticle = 0; 
        NumPerticle = 0; 
    } 
 
    static void PerticleStart1(int i, int j, int k, int l, int i1, int j1, int k1, int l1) 
    { 
        Vector3D vector3d = new Vector3D(l, i1, j1); 
        vector3d.unit(); 
        NumPerticle = l1; 
        for(int i2 = 0; i2 < 200; i2++) 
            if(i2 < l1) 
            { 
                PerV[i2 * 3] = i; 
                PerV[i2 * 3 + 1] = j; 
                PerV[i2 * 3 + 2] = k; 
                int j2 = abs(Rnd.nextInt()) % 80; 
                PerS[i2 * 3] = ((l * j2) / 100 + abs(Rnd.nextInt()) % 20) - 10; 
                PerS[i2 * 3 + 1] = ((i1 * j2) / 100 + abs(Rnd.nextInt()) % 20) - 10; 
                PerS[i2 * 3 + 2] = ((j1 * j2) / 100 + abs(Rnd.nextInt()) % 20) - 10; 
                Per[i2] = true; 
            } 
 
        PerticlePat = k1; 
        EffectiveNumPerticle = l1; 
    } 
 
    static void PerticleStart2(int i, int j, int k, int l, int i1, int j1) 
    { 
        EffectiveNumPerticle = 200; 
        NumPerticle = 200; 
        for(int k1 = i1; k1 < i1 + j1; k1++) 
        { 
            PerV[k1 * 3] = i; 
            PerV[k1 * 3 + 1] = j; 
            PerV[k1 * 3 + 2] = k; 
            int l1 = Rnd(4096); 
            int i2 = Rnd(15); 
            PerS[k1 * 3] = (Util3D.sin(l1) * i2) / 1024; 
            PerS[k1 * 3 + 1] = (Util3D.cos(l1) * i2) / 1024; 
            PerS[k1 * 3 + 2] = 0; 
            Per[k1] = true; 
        } 
 
        PerticlePat = l; 
    } 
 
    void PerticleCalc() 
    { 
        for(int i = 0; i < NumPerticle; i++) 
            if(PerV[i * 3 + 1] < 0 && Per[i]) 
            { 
                PerV[i * 3 + 0] = 30000; 
                PerV[i * 3 + 1] = -100; 
                PerV[i * 3 + 2] = 0; 
                EffectiveNumPerticle--; 
                Per[i] = false; 
            } else 
            { 
                PerV[i * 3 + 0] += PerS[i * 3 + 0]; 
                PerV[i * 3 + 1] += PerS[i * 3 + 1]; 
                PerV[i * 3 + 2] += PerS[i * 3 + 2]; 
                PerS[i * 3 + 1] -= 5; 
            } 
 
        PerT[PerticlePat % 4][2] = (PerT[PerticlePat % 4][2] + 768) % 4096; 
    } 
 
    void PerticleCalc2() 
    { 
        for(int i = 0; i < 200; i++) 
        { 
            PerV[i * 3 + 0] += PerS[i * 3 + 0]; 
            PerV[i * 3 + 1] += PerS[i * 3 + 1]; 
            PerV[i * 3 + 2] += PerS[i * 3 + 2]; 
            PerS[i * 3 + 1] += 10; 
        } 
 
        PerT[0][2] = (PerT[0][2] + 768) % 4096; 
    } 
 
    void PerticlePaint() 
    { 
        if(EffectiveNumPerticle <= 0) 
            return; 
        if(PerticlePat >= 4) 
        { 
            g3.renderPrimitives(Tex[1], 0, 0, C3DObj.Layout, C3DObj.Effect[2], 0x5000000 | 0 | 0x1000 | 0x10 | 8 | 0x20, NumPerticle, PerV, Normals, PerT[PerticlePat % 4], Colors); 
        } else 
        { 
            g3.renderPrimitives(Tex[1], 0, 0, C3DObj.Layout, C3DObj.Effect[2], 0x5000000 | 0 | 0x1000 | 0x10 | 8 | 0x40, NumPerticle, PerV, Normals, PerT[PerticlePat % 4], Colors); 
        } 
    } 
 
    static byte[] ISCatRead(InputStream inputstream, int i) 
        throws Exception 
    { 
        byte abyte0[]; 
        DataInputStream datainputstream = new DataInputStream(inputstream); 
        datainputstream.skipBytes(8 * i); 
        int j = 8 * i; 
        int l = datainputstream.readInt(); 
        j += 4; 
        int i1 = datainputstream.readInt(); 
        j += 4; 
        abyte0 = new byte[i1]; 
        datainputstream.skipBytes(l - j); 
        for(int k = 0; k < i1; k++) 
            abyte0[k] = datainputstream.readByte(); 
 
        inputstream.close(); 
        inputstream = null; 
        if(inputstream != null) 
            inputstream.close(); 
        if(inputstream != null) 
            inputstream.close(); 
        return abyte0; 
    } 
 
    boolean MarkRead(String s, Image aimage[]) 
    { 
        boolean flag1; 
        DataInputStream datainputstream; 
        datainputstream = null; 
        flag1 = true; 
        datainputstream = new DataInputStream(getClass().getResourceAsStream(s)); 
        int ai[] = new int[30]; 
        int ai1[] = new int[30]; 
        int i = 0; 
        try { 
			for(int j = 0; j < 30; j++) 
			{ 
			    ai[j] = datainputstream.readInt(); 
			    i += 4; 
			    ai1[j] = datainputstream.readInt(); 
			    i += 4; 
			} 
		} catch (IOException e1) { 
			// TODO Auto-generated catch block 
			e1.printStackTrace(); 
		} 
 
        for(int k = 0; k < 30; k++) 
        { 
            byte abyte0[] = new byte[ai1[k]]; 
            try { 
				datainputstream.readFully(abyte0, 0, ai1[k]); 
			} catch (IOException e) { 
				// TODO Auto-generated catch block 
				e.printStackTrace(); 
			} 
            aimage[k] = Image.createImage(abyte0, 0, abyte0.length); 
        } 
 
        try { 
			datainputstream.close(); 
		} catch (IOException e) { 
			// TODO Auto-generated catch block 
			e.printStackTrace(); 
		} 
        datainputstream = null; 
        if(datainputstream != null) 
            try 
            { 
                datainputstream.close(); 
            } 
            catch(Exception exception2) 
            { 
                flag1 = false; 
            } 
        flag1 = false; 
        if(datainputstream != null) 
            try 
            { 
                datainputstream.close(); 
            } 
            catch(Exception exception3) 
            { 
                flag1 = false; 
            } 
        if(datainputstream != null) 
            try 
            { 
                datainputstream.close(); 
            } 
            catch(Exception exception4) 
            { 
                flag1 = false; 
            } 
        return flag1; 
    } 
 
    protected void ResRelease() 
    { 
        for(int i = 0; i < 10; i++) 
            Fig[i] = null; 
 
        for(int j = 0; j < 5; j++) 
            Tex[j] = null; 
 
        for(int k = 0; k < 19; k++) 
            Anm[k] = null; 
 
        for(int l = 0; l < 5; l++) 
            SndMgr.Phr[l] = null; 
 
        System.gc(); 
    } 
 
    protected void ResDownLoad(int i, int j) 
    { 
        int k = NowNumRequests; 
        byte abyte0[] = null; 
        String s = ""; 
        for(int l = 0; l < 100; l++) 
        { 
            if(ForceExit) 
                return; 
            Thread.yield(); 
            String s1 = ""; 
            if(DLReqBuf_Type[l] == 0) 
                continue; 
            switch(DLReqBuf_Geo[l]) 
            { 
            case 1: // '\001' 
                switch(DLReqBuf_Type[l]) 
                { 
                case 1: // '\001' 
                    s = "mbac"; 
                    break; 
 
                case 2: // '\002' 
                case 3: // '\003' 
                    s = "bmp"; 
                    break; 
 
                case 4: // '\004' 
                    s = "png"; 
                    break; 
 
                case 5: // '\005' 
                    s = "mtra"; 
                    break; 
 
                case 7: // '\007' 
                    s = "wav"; 
                    break; 
 
                case 8: // '\b' 
                    s = "amr"; 
                    break; 
 
                case 11: // '\013' 
                    s = "imy"; 
                    break; 
 
                case 9: // '\t' 
                    s = "mid"; 
                    break; 
 
                case 12: // '\f' 
                    s = ""; 
                    break; 
                } 
                if(s.equals("")) 
                    s1 = DLReqBuf_Name[l]; 
                else 
                    s1 = DLReqBuf_Name[l] + "." + s; 
                if(DLReqBuf_Type[l] != 7 && DLReqBuf_Type[l] != 8 && DLReqBuf_Type[l] != 9 && DLReqBuf_Type[l] != 10 && DLReqBuf_Type[l] != 11) 
                    try 
                    { 
                        if(DLReqBuf_Arg0[l] < 0) 
                            abyte0 = ISRead(getClass().getResourceAsStream(s1), 0); 
                        else 
                            abyte0 = ISCatRead(getClass().getResourceAsStream(s1), DLReqBuf_Arg0[l]); 
                    } 
                    catch(Exception exception) { } 
                break; 
            } 
            short word0 = DLReqBuf_ArrayNo[l]; 
            switch(DLReqBuf_Type[l]) 
            { 
            case 6: // '\006' 
            default: 
                break; 
 
            case 1: // '\001' 
                try 
                { 
                    Fig[word0] = new Figure(abyte0); 
                } 
                catch(Exception exception1) { } 
                break; 
 
            case 2: // '\002' 
                Tex[word0] = new Texture(abyte0, true); 
                break; 
 
            case 3: // '\003' 
                Tex[word0] = new Texture(abyte0, false); 
                break; 
 
            case 4: // '\004' 
                Spr[word0] = Image.createImage(abyte0, 0, abyte0.length); 
                break; 
 
            case 5: // '\005' 
                Anm[word0] = new ActionTable(abyte0); 
                break; 
 
            case 7: // '\007' 
                SndMgr.Phr[word0] = new Phrase(word0, getClass().getResourceAsStream(s1), "audio/x-wav"); 
                break; 
 
            case 8: // '\b' 
                SndMgr.Phr[word0] = new Phrase(word0, getClass().getResourceAsStream(s1), "audio/amr"); 
                break; 
 
            case 9: // '\t' 
                SndMgr.Phr[word0] = new Phrase(word0, getClass().getResourceAsStream(s1), "audio/midi"); 
                break; 
 
            case 10: // '\n' 
                SndMgr.Phr[word0] = new Phrase(word0, getClass().getResourceAsStream(s1), "audio/x-tone-seq"); 
                break; 
 
            case 11: // '\013' 
                SndMgr.Phr[word0] = new Phrase(word0, getClass().getResourceAsStream(s1), "audio/imelody"); 
                break; 
 
            case 12: // '\f' 
                Dat[word0] = abyte0; 
                break; 
            } 
            DLReqBuf_Type[l] = 0; 
            DLReqBuf_ArrayNo[l] = -1; 
            DLReqBuf_Name[l] = ""; 
            DLReqBuf_Arg0[l] = -1; 
            DLReqBuf_Geo[l] = 0; 
            NowNumRequests--; 
            int i1; 
            if(k == 0) 
            { 
                i1 = j; 
            } else 
            { 
                i1 = ((k - NowNumRequests) * (j - i)) / k; 
                i1 += i; 
            } 
            if(i1 > j) 
                i1 = j; 
            SetLoadingBar(i1); 
        } 
 
        DLReqBufP = 0; 
    } 
 
    protected boolean ResGetReq(int i, int j, String s, int k, int l) 
    { 
        DLReqBuf_Type[DLReqBufP] = (byte)i; 
        DLReqBuf_ArrayNo[DLReqBufP] = (short)j; 
        DLReqBuf_Name[DLReqBufP] = s; 
        DLReqBuf_Arg0[DLReqBufP] = (byte)k; 
        DLReqBuf_Geo[DLReqBufP] = (byte)l; 
        DLReqBufP++; 
        NowNumRequests++; 
        return true; 
    } 
 
    static byte[] ReadRS(String s) 
    { 
        byte abyte0[] = null; 
        try 
        { 
            RecordStore recordstore = RecordStore.openRecordStore(s, true); 
            abyte0 = recordstore.getRecord(1); 
            if(recordstore != null) 
                recordstore.closeRecordStore(); 
        } 
        catch(Exception exception) 
        { 
            return null; 
        } 
        return abyte0; 
    } 
 
    public static void WriteRS(byte abyte0[], String s) 
    { 
        try 
        { 
            RecordStore recordstore = RecordStore.openRecordStore(s, true); 
            if(recordstore.getNumRecords() == 0) 
                recordstore.addRecord(abyte0, 0, abyte0.length); 
            else 
                recordstore.setRecord(1, abyte0, 0, abyte0.length); 
            recordstore.closeRecordStore(); 
        } 
        catch(Exception exception) { } 
    } 
 
    static byte[] ISRead(InputStream inputstream, int i) 
        throws Exception 
    { 
        ByteArrayOutputStream bytearrayoutputstream; 
        bytearrayoutputstream = null; 
        byte abyte0[]; 
        System.gc(); 
        bytearrayoutputstream = new ByteArrayOutputStream(1024); 
        if(i > 0) 
            inputstream.skip(i); 
        byte abyte1[] = new byte[1024]; 
        int j; 
        while((j = inputstream.read(abyte1)) > 0)  
            bytearrayoutputstream.write(abyte1, 0, j); 
        System.gc(); 
        abyte0 = bytearrayoutputstream.toByteArray(); 
        bytearrayoutputstream.close(); 
        bytearrayoutputstream = null; 
        inputstream.close(); 
        inputstream = null; 
        if(bytearrayoutputstream != null) 
            bytearrayoutputstream.close(); 
        if(inputstream != null) 
            inputstream.close(); 
        if(bytearrayoutputstream != null) 
            bytearrayoutputstream.close(); 
        if(inputstream != null) 
            inputstream.close(); 
        return abyte0; 
    } 
 
    static String pack0str(int i, int j) 
    { 
        String s = ""; 
        if(i < 0) 
            return "" + i; 
        int k = 1; 
        for(int l = i; l >= 10; l /= 10) 
            k++; 
 
        for(int i1 = 0; i1 < j - k; i1++) 
            s = s + "0"; 
 
        return s + i; 
    } 
 
    public static void l2b(long l, byte abyte0[], int i) 
    { 
        abyte0[i + 0] = (byte)(int)(255L & l >> 56); 
        abyte0[i + 1] = (byte)(int)(255L & l >> 48); 
        abyte0[i + 2] = (byte)(int)(255L & l >> 40); 
        abyte0[i + 3] = (byte)(int)(255L & l >> 32); 
        abyte0[i + 4] = (byte)(int)(255L & l >> 24); 
        abyte0[i + 5] = (byte)(int)(255L & l >> 16); 
        abyte0[i + 6] = (byte)(int)(255L & l >> 8); 
        abyte0[i + 7] = (byte)(int)(255L & l); 
    } 
 
    public static long b2l(byte abyte0[], int i) 
    { 
        return (long)(abyte0[i + 0] & 0xff) << 56 | (long)(abyte0[i + 1] & 0xff) << 48 | (long)(abyte0[i + 2] & 0xff) << 40 | (long)(abyte0[i + 3] & 0xff) << 32 | (long)(abyte0[i + 4] & 0xff) << 24 | (long)(abyte0[i + 5] & 0xff) << 16 | (long)(abyte0[i + 6] & 0xff) << 8 | (long)(abyte0[i + 7] & 0xff) << 0; 
    } 
 
    static long GetNowTime() 
    { 
        Date date = new Date(); 
        return date.getTime(); 
    } 
 
    static int Rnd(int i) 
    { 
        return abs(Rnd.nextInt()) % i; 
    } 
 
    static int clip(int i, int j, int k) 
    { 
        if(i < j) 
            return j; 
        if(i > k) 
            return k; 
        else 
            return i; 
    } 
 
    static int abs(int i) 
    { 
        if(i < 0) 
            return -i; 
        else 
            return i; 
    } 
 
    static int len_pow(Vector3D vector3d, Vector3D vector3d1) 
    { 
        int i = vector3d.x - vector3d1.x; 
        int j = vector3d.y - vector3d1.y; 
        int k = vector3d.z - vector3d1.z; 
        int l = i * i + j * j + k * k; 
        return l; 
    } 
 
    static int sign(int i) 
    { 
        return i >= 0 ? 1 : -1; 
    } 
 
    static boolean between(int i, int j, int k) 
    { 
        if(i < j) 
        { 
            if(i <= k && k <= j) 
                return true; 
        } else 
        if(i >= k && k >= j) 
            return true; 
        return false; 
    } 
 
    static int GetAngleSpeed(int i, int j) 
    { 
        int k = j - i & 0xfff; 
        if(k > 2048) 
            return k - 4096; 
        else 
            return k; 
    } 
 
    static int GetAngle(int i, int j) 
    { 
        if(i == 0) 
            return j < 0 ? 2048 : 0; 
        if(i > 0) 
            if(j > 0) 
            { 
                long l = i * 256; 
                l /= j; 
                if(l > 256L) 
                    return 1024 - GetAngle(j, i); 
                else 
                    return AtanTbl[(int)l]; 
            } else 
            { 
                return 1024 + GetAngle(-j, i); 
            } 
        if(j > 0) 
            return 4096 - GetAngle(-i, j); 
        else 
            return 2048 + GetAngle(-i, -j); 
    } 
 
    public static int CalcXPos(int i, int j, int k, int l, int i1, int j1) 
    { 
        i /= 10; 
        k /= 10; 
        j /= 10; 
        l /= 10; 
        i1 /= 10; 
        j1 /= 10; 
        int k1 = k - i; 
        int l1 = l - j; 
        if(k1 == 0 && l1 == 0) 
        { 
            retX = 0; 
            retZ = 0; 
            return 0; 
        } else 
        { 
            int i2 = k1 * (i1 - i) + l1 * (j1 - j); 
            i2 = (i2 * 1000) / (k1 * k1 + l1 * l1); 
            retX = (i2 * k1) / 1000 + i; 
            retZ = (i2 * l1) / 1000 + j; 
            retX *= 10; 
            retZ *= 10; 
            return i2; 
        } 
    } 
 
    void Set_LookAt(int i, int j, int k, int l, int i1, int j1, int k1) 
    { 
        CVecs[2].set(i, j, k); 
        CVecs[3].set(l, i1, j1); 
        CDelta = k1; 
    } 
 
    void CamCalc() 
    { 
        CVecs[0].x += (CVecs[2].x - CVecs[0].x) / CDelta; 
        CVecs[0].y += (CVecs[2].y - CVecs[0].y) / CDelta; 
        CVecs[0].z += (CVecs[2].z - CVecs[0].z) / CDelta; 
        CVecs[1].x += (CVecs[3].x - CVecs[1].x) / CDelta; 
        CVecs[1].y += (CVecs[3].y - CVecs[1].y) / CDelta; 
        CVecs[1].z += (CVecs[3].z - CVecs[1].z) / CDelta; 
        CVecs[4].set(CVecs[1].x - CVecs[0].x, CVecs[1].y - CVecs[0].y, CVecs[1].z - CVecs[0].z); 
        gCam.lookAt(CVecs[0], CVecs[4], CVecs[5]); 
    } 
 
    static void PaintBold(Graphics g, String s, int i, int j, int k, int l, int i1, int j1) 
    { 
        g.setFont(Fonts[k]); 
        if(j1 >= 0) 
        { 
            g.setColor(j1); 
            g.drawString(s, i + 1 + 1, j + 1 + 1, 0x10 | 4); 
        } 
        if(i1 >= 0) 
        { 
            g.setColor(i1); 
            for(int k1 = -1; k1 <= 1; k1++) 
            { 
                for(int l1 = -1; l1 <= 1; l1++) 
                    if((k1 == 0 || l1 == 0) && (k1 != 0 || l1 != 0)) 
                    { 
                        g.drawString(s, i + k1, j + l1, 0x10 | 4); 
                    } 
 
            } 
 
        } 
        g.setColor(l); 
        g.drawString(s, i, j, 0x10 | 4); 
    } 
 
    void ClipPut(Graphics g, int i, int j, int k, int l, int i1, int j1,  
            int k1) 
    { 
        g.setClip(j, k, j1, k1); 
        g.drawImage(Spr[i], j - l, k - i1, 0x10 | 4); 
    } 
 
    void CenterPutX(Graphics g, Image image, int i) 
    { 
        int j = image.getWidth(); 
        g.drawImage(image, (Width - j) / 2, i, 4 | 0x10); 
    } 
 
    void BmpPatWrite(byte abyte0[], int i, int j, byte abyte1[], int k, int l, int i1,  
            int j1) 
    { 
        int k1 = 1078; 
        int l1 = 0; 
        k1 += i * j1; 
        for(int j2 = 0; j2 < l; j2++) 
        { 
            for(int i2 = 0; i2 < k; i2++) 
                abyte0[k1 + i1 + i2] = abyte1[l1 + i2]; 
 
            k1 += i; 
            l1 += k; 
        } 
 
    } 
 
    void BmpPalWrite(byte abyte0[], byte abyte1[], int i, int j) 
    { 
        int k = 54; 
        k += j * 4; 
        for(int l = 0; l < i; l++) 
        { 
            abyte0[k + 0] = abyte1[l * 3 + 0]; 
            abyte0[k + 1] = abyte1[l * 3 + 1]; 
            abyte0[k + 2] = abyte1[l * 3 + 2]; 
            k += 4; 
        } 
 
    } 
 
    void ReMakeCommandValue() 
    { 
        for(int i = 0; i < KeyCom.length; i++) 
            KeyCom[i] = new Command(PrStr[CommandTable[i][0]], CommandTable[i][1], CommandTable[i][2]); 
 
    } 
 
    void ReMakeCommandKey() 
    { 
        int i = Com[0]; 
        int j = Com[1]; 
        SetCom(-1, -1); 
        ReMakeCommandValue(); 
        SetCom(i, j); 
    } 
 
    void SetCom(int i, int j) 
    { 
        boolean flag = false; 
        if(Com[0] == i && Com[1] == j) 
            return; 
        for(int k = 1; k >= 0; k--) 
            if(Com[k] != -1) 
                flag = true; 
 
        if(flag) 
        { 
            for(int l = 1; l >= 0; l--) 
                if(Com[l] != -1) 
                    removeCommand(KeyCom[Com[l]]); 
 
        } 
        Com[0] = i; 
        if(i != -1) 
            addCommand(KeyCom[i]); 
        Com[1] = j; 
        if(j != -1) 
            addCommand(KeyCom[j]); 
    } 
 
    public static void VibrationOn(int i) 
    { 
        if(SaveData[2] == 1) 
            Tennis.gDisplay.vibrate(i * 100); 
    } 
 
    public static void VibrationOff() 
    { 
        Tennis.gDisplay.vibrate(0); 
    } 
 
    private static int AscByteToI(byte byte0) 
    { 
        if((byte0 & 0xff) <= 57) 
            return (byte0 & 0xff) - 48; 
        else 
            return ((byte0 & 0xff) - 65) + 10; 
    } 
 
    public void KeyCheckForGameCanvas() 
    { 
        int i = getKeyStates(); 
        if((i & 4) != 0) 
        { 
            if((NowSwStack & 0x2010) == 0) 
                ClickSw |= 0x2010; 
            NowSw |= 0x2010; 
        } else 
        { 
            NowSw &= 0xffffdfef; 
        } 
        if((i & 0x20) != 0) 
        { 
            if((NowSwStack & 0x4040) == 0) 
                ClickSw |= 0x4040; 
            NowSw |= 0x4040; 
        } else 
        { 
            NowSw &= 0xffffbfbf; 
        } 
        if((i & 2) != 0) 
        { 
            if((NowSwStack & 0x1004) == 0) 
                ClickSw |= 0x1004; 
            NowSw |= 0x1004; 
        } else 
        { 
            NowSw &= 0xffffeffb; 
        } 
        if((i & 0x40) != 0) 
        { 
            if((NowSwStack & 0x8100) == 0) 
                ClickSw |= 0x8100; 
            NowSw |= 0x8100; 
        } else 
        { 
            NowSw &= 0xffff7eff; 
        } 
        if((i & 0x100) != 0) 
        { 
            if((NowSwStack & 0x10000) == 0) 
                ClickSw |= 0x10000; 
            NowSw |= 0x10000; 
        } else 
        { 
            NowSw &= 0xfffeffff; 
        } 
        if((i & 0x200) != 0) 
        { 
            if((NowSwStack & 0x80) == 0) 
                ClickSw |= 0x80; 
            NowSw |= 0x80; 
        } else 
        { 
            NowSw &= 0xffffff7f; 
        } 
        if((i & 0x400) != 0) 
        { 
            if((NowSwStack & 0x200) == 0) 
                ClickSw |= 0x200; 
            NowSw |= 0x200; 
        } else 
        { 
            NowSw &= 0xfffffdff; 
        } 
        if((i & 0x800) != 0) 
        { 
            if((NowSwStack & 0x400) == 0) 
                ClickSw |= 0x400; 
            NowSw |= 0x400; 
        } else 
        { 
            NowSw &= 0xfffffbff; 
        } 
        if((i & 0x1000) != 0) 
        { 
            if((NowSwStack & 0x400) == 0) 
                ClickSw |= 0x400; 
            NowSw |= 0x400; 
        } else 
        { 
            NowSw &= 0xfffffbff; 
        } 
        if(NowSwStack == NowSw && NowSw != 0) 
            KeyRepeatCounter++; 
        else 
            KeyRepeatCounter = 0; 
        if(KeyRepeatCounter > 7) 
            RepeatSw = NowSw; 
        else 
            RepeatSw = 0; 
    } 
 
    public void commandAction(Command command, Displayable displayable) 
    { 
        int i = 0; 
        if(Com[0] != -1 && KeyCom[Com[0]] == command) 
            i = 0x20000; 
        if(Com[1] != -1 && KeyCom[Com[1]] == command) 
            i = 0x40000; 
        ClickSwStack |= i; 
    } 
 
    protected static Tennis Parent; 
    protected static Graphics3D g3; 
    protected static int Width; 
    protected static int Height; 
    public static int Seq = 0; 
    public static int Counter = 0; 
    public static int Sleep = 2; 
    protected static boolean SeqWait = false; 
    static byte SaveData[] = new byte[128]; 
    static boolean NeedSave = false; 
    protected static CMat TmpMat[] = new CMat[10]; 
    protected static Vector3D TmpV[] = new Vector3D[10]; 
    static String PrStr[]; 
    static String MenuStr[]; 
    static Random Rnd = new Random(); 
    static Font Fonts[] = new Font[3]; 
    static int FontHeights[] = new int[3]; 
    static boolean ForceExit = false; 
    static int Normals[] = { 
        0, 0, 1 
    }; 
    static int Colors[] = { 
        0, 0, 255 
    }; 
    static boolean InComingCall = false; 
    static int LoadingBar = 0; 
    static int LoadingBar_BallS = 0; 
    static int LoadingBar_BallV = 10; 
    static int LoadinbBar_ballTable[] = { 
        0, 13, 26, 13 
    }; 
    private static boolean Per[] = new boolean[200]; 
    private static int PerV[] = new int[600]; 
    private static int PerS[] = new int[600]; 
    private static int PerticlePat; 
    private static int EffectiveNumPerticle = 0; 
    private static int NumPerticle = 0; 
    static int PerT[][]; 
    protected static Figure Fig[] = new Figure[10]; 
    protected static Texture Tex[] = new Texture[5]; 
    protected static Image Spr[] = new Image[15]; 
    protected static ActionTable Anm[] = new ActionTable[19]; 
    protected static byte Dat[][] = new byte[11][]; 
    private static int NowNumRequests = 0; 
    private static int DLReqBufP = 0; 
    private static byte DLReqBuf_Type[] = new byte[100]; 
    private static short DLReqBuf_ArrayNo[] = new short[100]; 
    private static String DLReqBuf_Name[] = new String[100]; 
    private static byte DLReqBuf_Geo[] = new byte[100]; 
    private static byte DLReqBuf_Arg0[] = new byte[100]; 
    static short AtanTbl[] = { 
        1, 3, 6, 8, 11, 14, 16, 19, 21, 24,  
        26, 29, 31, 34, 36, 39, 41, 44, 47, 49,  
        52, 54, 57, 59, 62, 64, 67, 69, 72, 74,  
        77, 79, 82, 84, 87, 89, 92, 94, 97, 99,  
        102, 104, 107, 109, 112, 114, 117, 119, 122, 124,  
        126, 129, 131, 134, 136, 139, 141, 144, 146, 148,  
        151, 153, 156, 158, 160, 163, 165, 168, 170, 172,  
        175, 177, 179, 182, 184, 186, 189, 191, 193, 196,  
        198, 200, 203, 205, 207, 210, 212, 214, 216, 219,  
        221, 223, 226, 228, 230, 232, 234, 237, 239, 241,  
        243, 246, 248, 250, 252, 254, 257, 259, 261, 263,  
        265, 267, 269, 272, 274, 276, 278, 280, 282, 284,  
        286, 288, 290, 293, 295, 297, 299, 301, 303, 305,  
        307, 309, 311, 313, 315, 317, 319, 321, 323, 325,  
        327, 329, 331, 333, 334, 336, 338, 340, 342, 344,  
        346, 348, 350, 352, 353, 355, 357, 359, 361, 363,  
        365, 366, 368, 370, 372, 374, 375, 377, 379, 381,  
        383, 384, 386, 388, 390, 391, 393, 395, 396, 398,  
        400, 402, 403, 405, 407, 408, 410, 412, 413, 415,  
        417, 418, 420, 421, 423, 425, 426, 428, 429, 431,  
        433, 434, 436, 437, 439, 440, 442, 444, 445, 447,  
        448, 450, 451, 453, 454, 456, 457, 459, 460, 462,  
        463, 464, 466, 467, 469, 470, 472, 473, 475, 476,  
        477, 479, 480, 482, 483, 484, 486, 487, 488, 490,  
        491, 493, 494, 495, 497, 498, 499, 500, 502, 503,  
        504, 506, 507, 508, 510, 511, 512, 513 
    }; 
    static int retX; 
    static int retZ; 
    static AffineTrans gCam = new AffineTrans(); 
    static int CDelta = 1; 
    static Vector3D CVecs[] = new Vector3D[6]; 
    private static Command KeyCom[] = new Command[4]; 
    private static int Com[] = new int[2]; 
    private static int CommandTable[][] = { 
        { 
            4, 2, 1 
        }, { 
            5, 2, 1 
        }, { 
            6, 1, 1 
        }, { 
            7, 2, 1 
        } 
    }; 
    public static int NowSw = 0; 
    public static int NowSwStack = 0; 
    public static int RepeatSw = 0; 
    public static int ClickSw = 0; 
    public static int ClickSwStack = 0; 
    public static int OldClickSw = 0; 
    public static int KeyRepeatCounter = 0; 
 
    static  
    { 
        g3 = new Graphics3D(); 
        int ai[][] = new int[4][]; 
        ai[0] = (new int[] { 
            40, 40, 0, 180, 0, 195, 15, 0 
        }); 
        ai[1] = (new int[] { 
            20, 20, 0, 180, 0, 195, 15, 0 
        }); 
        ai[2] = (new int[] { 
            20, 20, 0, 160, 0, 175, 15, 0 
        }); 
        ai[3] = (new int[] { 
            100, 100, 0, 160, 0, 175, 15, 0 
        }); 
        PerT = ai; 
    } 
}