home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Hotdog / files / snagpack.exe / ANIM3SIMPLE.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-21  |  14.4 KB  |  1,079 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Event;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.MediaTracker;
  9. import java.awt.image.ImageObserver;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12. import java.util.Date;
  13. import java.util.Stack;
  14. import java.util.Vector;
  15.  
  16. public class anim3simple extends Applet implements Runnable {
  17.    private boolean initialized;
  18.    private static final int STARTUP_ID = 0;
  19.    private static final int BACKGROUND_ID = 1;
  20.    private static final int ANIMATION_ID = 2;
  21.    private MediaTracker tracker;
  22.    private Thread engine;
  23.    private int num_sprites;
  24.    private boolean local;
  25.    private Vector[] images;
  26.    private int active_anims;
  27.    private URL baseDir;
  28.    private int[] frameNum;
  29.    private int[] frameNumKey;
  30.    private int[] repeat;
  31.    private int[] currentLoop;
  32.    private int[] priority;
  33.    private int[] maxWidth;
  34.    private int[] maxHeight;
  35.    private int appWidth;
  36.    private int appHeight;
  37.    private Dimension bgSize;
  38.    private boolean error;
  39.    private boolean BigError;
  40.    private boolean loaded;
  41.    private Image startUpImage;
  42.    private URL startUpImageURL;
  43.    private Image endimage;
  44.    private URL endURL;
  45.    private Image backgroundImage;
  46.    private URL backgroundImageURL;
  47.    private Image offScrImage;
  48.    private Graphics offScrGC;
  49.    private int globalPause;
  50.    private boolean[] mousePause;
  51.    private int[] moveEW;
  52.    private int[] moveNS;
  53.    private int[] currentX;
  54.    private int[] currentY;
  55.    private boolean[] bounce;
  56.    private int bgR = 192;
  57.    private int bgG = 192;
  58.    private int bgB = 192;
  59.    private int delay;
  60.    private int[] timeout;
  61.    private long[] wantsecs;
  62.    private URL glob_destination;
  63.    private boolean[] active;
  64.    private String SausCRC = "";
  65.    private int CRCint;
  66.    static final boolean debug = true;
  67.  
  68.    public void stop() {
  69.       this.dbg("Thread stopped");
  70.       if (this.engine != null && this.engine.isAlive()) {
  71.          this.engine.stop();
  72.       }
  73.  
  74.       this.engine = null;
  75.    }
  76.  
  77.    private boolean parsePriority(String var1) {
  78.       int var2 = 0;
  79.       int[] var3 = new int[this.num_sprites];
  80.  
  81.       for(int var4 = 0; var4 < var1.length() && var2 <= this.num_sprites; ++var2) {
  82.          int var5 = var1.indexOf(44, var4);
  83.          if (var5 == -1) {
  84.             var5 = var1.length();
  85.          }
  86.  
  87.          if (var5 == var4) {
  88.             Object var6 = null;
  89.             return false;
  90.          }
  91.  
  92.          var3[var2] = Integer.parseInt(var1.substring(var4, var5).trim());
  93.          var4 = var5 + 1;
  94.       }
  95.  
  96.       for(int var8 = 0; var8 < this.num_sprites; ++var8) {
  97.          this.priority[var8] = var3[this.num_sprites - var8 - 1];
  98.       }
  99.  
  100.       Object var7 = null;
  101.       return true;
  102.    }
  103.  
  104.    private void msg(String var1) {
  105.       ((Applet)this).showStatus(var1);
  106.    }
  107.  
  108.    private boolean parseMovement(String var1, int var2) {
  109.       int var3 = 0;
  110.       int var4 = var1.indexOf(44, 0);
  111.       if (var4 == -1) {
  112.          return false;
  113.       } else {
  114.          this.moveEW[var2] = Integer.parseInt(var1.substring(0, var4).trim());
  115.          var3 = var4 + 1;
  116.          var4 = var1.indexOf(44, var4 + 1);
  117.          if (var4 == -1) {
  118.             var4 = var1.length();
  119.          }
  120.  
  121.          this.moveNS[var2] = Integer.parseInt(var1.substring(var3, var4).trim());
  122.          return true;
  123.       }
  124.    }
  125.  
  126.    private void generateCRC(String var1) {
  127.       int var3 = var1.length();
  128.  
  129.       for(int var2 = 0; var2 < var3; ++var2) {
  130.          this.CRCint += var1.charAt(var2);
  131.       }
  132.  
  133.    }
  134.  
  135.    private boolean parseStartPos(String var1, int var2) {
  136.       int var3 = 0;
  137.       int var4 = var1.indexOf(44, 0);
  138.       if (var4 == -1) {
  139.          return false;
  140.       } else {
  141.          this.currentX[var2] = Integer.parseInt(var1.substring(0, var4).trim());
  142.          var3 = var4 + 1;
  143.          var4 = var1.indexOf(44, var4 + 1);
  144.          if (var4 == -1) {
  145.             var4 = var1.length();
  146.          }
  147.  
  148.          this.currentY[var2] = Integer.parseInt(var1.substring(var3, var4).trim());
  149.          return true;
  150.       }
  151.    }
  152.  
  153.    private Vector parseURLs(String var1) {
  154.       Vector var2 = new Vector(1);
  155.       this.msg("Egor - Fetching URLs");
  156.  
  157.       int var4;
  158.       for(int var5 = 0; var5 < var1.length(); var5 = var4 + 1) {
  159.          var4 = var1.indexOf(44, var5);
  160.          if (var4 == -1) {
  161.             var4 = var1.length();
  162.          }
  163.  
  164.          if (var4 == var5) {
  165.             Object var3 = null;
  166.             var2.addElement((Object)null);
  167.          } else {
  168.             String var8 = var1.substring(var5, var4);
  169.  
  170.             try {
  171.                var2.addElement(new URL((URL)null, var8));
  172.             } catch (MalformedURLException var7) {
  173.                this.dbg("Egor 3.0 - Malformed URL " + var8 + ". Trying to make it absolute");
  174.  
  175.                try {
  176.                   var2.addElement(new URL(this.baseDir, var8));
  177.                } catch (MalformedURLException var6) {
  178.                   this.dbg("Egor 3.0 - Malformed URL " + this.baseDir + var8 + ". Ignoring");
  179.                   var2.addElement((Object)null);
  180.                }
  181.             }
  182.          }
  183.       }
  184.  
  185.       return var2;
  186.    }
  187.  
  188.    private Vector prepareImages(String var1) throws MalformedURLException {
  189.       this.msg("Egor - Fetching images");
  190.       Vector var3 = new Vector(1);
  191.  
  192.       int var5;
  193.       for(int var4 = 0; var4 < var1.length(); var4 = var5 + 1) {
  194.          var5 = var1.indexOf(44, var4);
  195.          if (var5 == -1) {
  196.             var5 = var1.length();
  197.          }
  198.  
  199.          String var6 = var1.substring(var4, var5);
  200.          URL var2 = new URL(this.baseDir, var6);
  201.          var3.addElement(var2);
  202.       }
  203.  
  204.       return var3;
  205.    }
  206.  
  207.    private boolean ptInRect(int var1, int var2, int var3, int var4, int var5, int var6) {
  208.       return var1 <= var5 && var1 >= var3 && var2 <= var6 && var2 >= var4;
  209.    }
  210.  
  211.    public void update(Graphics var1) {
  212.       this.paint(var1);
  213.    }
  214.  
  215.    public void start() {
  216.       this.dbg("Thread started");
  217.       if (this.engine == null) {
  218.          this.engine = new Thread(this);
  219.          this.engine.start();
  220.       }
  221.  
  222.    }
  223.  
  224.    public String getAppletInfo() {
  225.       return "Egor 3.0 animator (c) Sausage Software. Coded by JavaGirl";
  226.    }
  227.  
  228.    public void pause() {
  229.       for(int var1 = 0; var1 < this.num_sprites; ++var1) {
  230.          this.mousePause[var1] = !this.mousePause[var1];
  231.          this.active[var1] = !this.active[var1];
  232.       }
  233.  
  234.    }
  235.  
  236.    boolean fetchImages(Vector[] var1, int var2) {
  237.       this.dbg("Storing images for anim " + var2);
  238.       this.msg("Storing images for anim " + var2);
  239.  
  240.       int var3;
  241.       try {
  242.          var3 = var1[var2].size();
  243.       } catch (NullPointerException var11) {
  244.          this.msg("Egor 3.0 - No images fed in!");
  245.          this.dbg("No images fed in!");
  246.          return false;
  247.       }
  248.  
  249.       Vector var4 = var1[var2];
  250.       Stack var5 = new Stack();
  251.  
  252.       for(int var8 = 0; var8 < var3; ++var8) {
  253.          Object var9 = var4.elementAt(var8);
  254.          if (var9 instanceof URL) {
  255.             URL var6 = (URL)var9;
  256.             Image var7 = ((Applet)this).getImage(var6);
  257.             if (var5.search(var6) == -1) {
  258.                this.tracker.addImage(var7, 2);
  259.                var5.push(var6);
  260.                this.dbg("adding " + var6);
  261.             }
  262.  
  263.             var4.setElementAt(var7, var8);
  264.          }
  265.       }
  266.  
  267.       Object var12 = null;
  268.  
  269.       try {
  270.          this.tracker.waitForID(2);
  271.       } catch (InterruptedException var10) {
  272.       }
  273.  
  274.       if (this.tracker.isErrorID(2)) {
  275.          if ((this.tracker.statusID(2, false) & 4) != 0 || (this.tracker.statusID(2, false) & 2) != 0) {
  276.             this.dbg("Error loading frames - error or abort");
  277.          }
  278.  
  279.          this.msg("Error loading frames - error or abort");
  280.          return false;
  281.       } else {
  282.          for(int var13 = 0; var13 < var3; ++var13) {
  283.             this.updateMaxDims(this.getImageDimensions((Image)var4.elementAt(var13)), var2);
  284.          }
  285.  
  286.          return true;
  287.       }
  288.    }
  289.  
  290.    private Dimension getImageDimensions(Image var1) {
  291.       return new Dimension(var1.getWidth((ImageObserver)null), var1.getHeight((ImageObserver)null));
  292.    }
  293.  
  294.    private boolean updateXY(int var1) {
  295.       int[] var10000 = this.currentX;
  296.       var10000[var1] += this.moveEW[var1];
  297.       var10000 = this.currentY;
  298.       var10000[var1] += this.moveNS[var1];
  299.       boolean var2 = false;
  300.       if (this.bounce[var1]) {
  301.          if (this.currentX[var1] > this.appWidth - this.maxWidth[var1] || this.currentX[var1] < 0) {
  302.             this.moveEW[var1] = -this.moveEW[var1];
  303.             var10000 = this.currentX;
  304.             var10000[var1] += this.moveEW[var1];
  305.             var2 = true;
  306.          }
  307.  
  308.          if (this.currentY[var1] > this.appHeight - this.maxHeight[var1] || this.currentY[var1] < 0) {
  309.             this.moveNS[var1] = -this.moveNS[var1];
  310.             var10000 = this.currentY;
  311.             var10000[var1] += this.moveNS[var1];
  312.             var2 = true;
  313.          }
  314.       } else {
  315.          if (this.currentX[var1] > this.appWidth) {
  316.             this.currentX[var1] = -this.maxWidth[var1] + 1;
  317.             var2 = true;
  318.          } else if (this.currentX[var1] < -this.maxWidth[var1]) {
  319.             this.currentX[var1] = this.appWidth - 1;
  320.             var2 = true;
  321.          }
  322.  
  323.          if (this.currentY[var1] > this.appHeight + this.maxHeight[var1]) {
  324.             this.currentY[var1] = -this.maxHeight[var1] + 1;
  325.             var2 = true;
  326.          } else if (this.currentY[var1] < -this.maxHeight[var1]) {
  327.             this.currentY[var1] = this.appHeight + this.maxHeight[var1];
  328.             var2 = true;
  329.          }
  330.       }
  331.  
  332.       return var2;
  333.    }
  334.  
  335.    private void init_arrays() {
  336.       this.images = new Vector[this.num_sprites];
  337.       this.currentLoop = new int[this.num_sprites];
  338.       this.repeat = new int[this.num_sprites];
  339.       this.maxWidth = new int[this.num_sprites];
  340.       this.maxHeight = new int[this.num_sprites];
  341.       this.globalPause = 10;
  342.       this.mousePause = new boolean[this.num_sprites];
  343.       this.moveEW = new int[this.num_sprites];
  344.       this.moveNS = new int[this.num_sprites];
  345.       this.currentX = new int[this.num_sprites];
  346.       this.currentY = new int[this.num_sprites];
  347.       this.bounce = new boolean[this.num_sprites];
  348.       this.priority = new int[this.num_sprites];
  349.       this.delay = 0;
  350.       this.timeout = new int[this.num_sprites];
  351.       this.wantsecs = new long[this.num_sprites];
  352.       this.frameNum = new int[this.num_sprites];
  353.       this.frameNumKey = new int[this.num_sprites];
  354.       this.active = new boolean[this.num_sprites];
  355.  
  356.       for(int var1 = 0; var1 < this.num_sprites; ++var1) {
  357.          this.images[var1] = new Vector();
  358.          this.currentLoop[var1] = 0;
  359.          this.repeat[var1] = -1;
  360.          this.maxWidth[var1] = 0;
  361.          this.maxHeight[var1] = 0;
  362.          this.moveEW[var1] = 0;
  363.          this.moveNS[var1] = 0;
  364.          this.frameNum[var1] = 0;
  365.          this.frameNumKey[var1] = 0;
  366.          this.currentX[var1] = 0;
  367.          this.currentY[var1] = 0;
  368.          this.timeout[var1] = -1000;
  369.          this.wantsecs[var1] = 0L;
  370.          this.mousePause[var1] = false;
  371.          this.active[var1] = true;
  372.          this.priority[var1] = var1;
  373.          this.bounce[var1] = false;
  374.       }
  375.  
  376.    }
  377.  
  378.    private final int setFrameNum(int var1, int var2) {
  379.       this.frameNumKey[var2] = var1;
  380.       this.frameNum[var2] = var1;
  381.       return var1;
  382.    }
  383.  
  384.    public synchronized void paint(Graphics var1) {
  385.       if (!this.error && this.loaded) {
  386.          if (this.active_anims == 0 && (this.endimage != null || this.endURL != null)) {
  387.             if (this.endimage != null) {
  388.                var1.clearRect(0, 0, this.appWidth, this.appHeight);
  389.                if (this.backgroundImage != null) {
  390.                   var1.drawImage(this.backgroundImage, 0, 0, this);
  391.                }
  392.  
  393.                var1.drawImage(this.endimage, 0, 0, this);
  394.             }
  395.  
  396.             if (this.endURL != null) {
  397.                this.msg("Egor 3.0 - switching pages to " + this.endURL);
  398.                ((Applet)this).getAppletContext().showDocument(this.endURL);
  399.                return;
  400.             }
  401.          }
  402.  
  403.          this.offScrGC.fillRect(0, 0, this.appWidth, this.appHeight);
  404.          if (this.backgroundImage != null) {
  405.             this.offScrGC.drawImage(this.backgroundImage, 0, 0, this);
  406.          }
  407.  
  408.          for(int var3 = 0; var3 < this.num_sprites; ++var3) {
  409.             Image var4 = null;
  410.             int var7 = this.priority[var3];
  411.             if (this.images[var7] != null && this.images[var7].size() > 0) {
  412.                if (this.frameNum[var7] < this.images[var7].size()) {
  413.                   if (this.active[var7]) {
  414.                      boolean var5 = this.updateXY(var7);
  415.                      if (var5 && this.delay > 10) {
  416.                         try {
  417.                            Thread.sleep((long)this.delay);
  418.                         } catch (InterruptedException var6) {
  419.                         }
  420.                      }
  421.                   }
  422.  
  423.                   if (var4 == null) {
  424.                      var4 = (Image)this.images[var7].elementAt(this.frameNum[var7]);
  425.                   }
  426.  
  427.                   this.offScrGC.drawImage(var4, this.currentX[var7], this.currentY[var7], this);
  428.                } else {
  429.                   var4 = (Image)this.images[var7].lastElement();
  430.                   this.offScrGC.drawImage(var4, this.currentX[var7], this.currentY[var7], this);
  431.                }
  432.             }
  433.          }
  434.  
  435.          var1.drawImage(this.offScrImage, 0, 0, this);
  436.       } else {
  437.          Dimension var2 = new Dimension();
  438.          if (this.appWidth != 0) {
  439.             var2.width = this.appWidth;
  440.          }
  441.  
  442.          if (this.appHeight != 0) {
  443.             var2.height = this.appHeight;
  444.          }
  445.  
  446.          var1.clearRect(0, 0, this.appWidth, this.appHeight);
  447.          if (this.backgroundImage != null) {
  448.             if (this.tracker.checkID(1)) {
  449.                var1.clearRect(0, 0, this.appWidth, this.appHeight);
  450.                var1.drawImage(this.backgroundImage, 0, 0, this);
  451.             }
  452.          } else {
  453.             var1.clearRect(0, 0, this.appWidth, this.appHeight);
  454.          }
  455.  
  456.          if (this.startUpImage != null && this.tracker.checkID(0)) {
  457.             var1.drawImage(this.startUpImage, 0, 0, this);
  458.          }
  459.  
  460.       }
  461.    }
  462.  
  463.    private void dbg(String var1) {
  464.       System.out.println(var1);
  465.       ((Applet)this).showStatus(var1);
  466.    }
  467.  
  468.    private boolean checkCRC(String var1) {
  469.       String var2 = Integer.toString(this.CRCint);
  470.       int var4 = var2.length();
  471.       if (var4 > var1.length()) {
  472.          return false;
  473.       } else {
  474.          for(int var3 = 0; var3 < var4; ++var3) {
  475.             this.SausCRC = this.SausCRC + (char)(65 + Integer.parseInt(var2.substring(var3, var3 + 1)));
  476.          }
  477.  
  478.          return this.SausCRC.equals(var1.substring(0, this.SausCRC.length()));
  479.       }
  480.    }
  481.  
  482.    private boolean parseHexBG(String var1) {
  483.       if (var1.length() < 6) {
  484.          return false;
  485.       } else {
  486.          this.bgR = Integer.parseInt(var1.substring(0, 2), 16);
  487.          this.bgG = Integer.parseInt(var1.substring(2, 4), 16);
  488.          this.bgB = Integer.parseInt(var1.substring(4, 6), 16);
  489.          return true;
  490.       }
  491.    }
  492.  
  493.    public void setBehaviour(boolean var1) {
  494.       for(int var2 = 0; var2 < this.num_sprites; ++var2) {
  495.          this.bounce[var2] = var1;
  496.       }
  497.  
  498.    }
  499.  
  500.    public void run() {
  501.       Thread.currentThread();
  502.       if (!this.initialized) {
  503.          this.var_init();
  504.       }
  505.  
  506.       this.dbg("Egor 3.0 animation running");
  507.       Date var1 = new Date();
  508.       long var4 = var1.getTime();
  509.  
  510.       for(int var6 = 0; var6 < this.num_sprites; ++var6) {
  511.          int var3 = this.priority[var6];
  512.          this.currentLoop[var3] = 1;
  513.          int var2 = this.timeout[var3];
  514.          if (var2 > 0) {
  515.             this.wantsecs[var3] = var4 + (long)var2;
  516.          } else {
  517.             this.wantsecs[var3] = var4 - 1000L;
  518.          }
  519.       }
  520.  
  521.       if (!this.loaded) {
  522.          try {
  523.             if (this.BigError) {
  524.                this.msg("Egor - Bad User - Use Egor to change the image list");
  525.                this.error = true;
  526.                return;
  527.             }
  528.  
  529.             Dimension var13 = new Dimension();
  530.             if (this.appWidth != 0) {
  531.                var13.width = this.appWidth;
  532.             }
  533.  
  534.             if (this.appHeight != 0) {
  535.                var13.height = this.appHeight;
  536.             }
  537.  
  538.             ((Component)this).repaint();
  539.             if (this.backgroundImageURL != null) {
  540.                this.backgroundImage = ((Applet)this).getImage(this.backgroundImageURL);
  541.                this.tracker.addImage(this.backgroundImage, 1);
  542.                this.tracker.waitForID(1);
  543.                if (this.tracker.isErrorID(1)) {
  544.                   this.msg("Egor - Error loading background image");
  545.                }
  546.  
  547.                this.bgSize = this.getImageDimensions(this.backgroundImage);
  548.                ((Component)this).repaint();
  549.             }
  550.  
  551.             if (this.error) {
  552.                this.msg("Egor - Can't find images");
  553.                return;
  554.             }
  555.  
  556.             this.offScrImage = ((Component)this).createImage(this.appWidth, this.appHeight);
  557.             this.offScrGC = this.offScrImage.getGraphics();
  558.             Color var7 = new Color(this.bgR, this.bgG, this.bgB);
  559.             this.offScrGC.setColor(var7);
  560.             this.loaded = true;
  561.             this.error = false;
  562.          } catch (Exception var10) {
  563.             this.error = true;
  564.             ((Throwable)var10).printStackTrace();
  565.          }
  566.       }
  567.  
  568.       this.active_anims = this.num_sprites;
  569.  
  570.       while(this.active_anims > 0) {
  571.          for(int var14 = 0; var14 < this.num_sprites; ++var14) {
  572.             int var12 = this.priority[var14];
  573.  
  574.             while(!this.active[var12] && var14 < this.num_sprites) {
  575.                ++var14;
  576.                if (var14 < this.num_sprites) {
  577.                   var12 = this.priority[var14];
  578.                }
  579.             }
  580.  
  581.             if (var14 == this.num_sprites) {
  582.                break;
  583.             }
  584.  
  585.             if (this.images[var12].size() > 0) {
  586.                var1 = new Date();
  587.                long var15 = var1.getTime();
  588.                if (this.frameNum[var12] >= this.images[var12].size()) {
  589.                   if (this.repeat[var12] == 0 || this.currentLoop[var12] >= this.repeat[var12] && this.repeat[var12] > 0 || var15 > this.wantsecs[var12] && this.timeout[var12] > 0) {
  590.                      this.active_anims += -1;
  591.                      this.active[var12] = false;
  592.                      continue;
  593.                   }
  594.  
  595.                   this.setFrameNum(0, var12);
  596.                   if (this.repeat[var12] > 0 && this.currentLoop[var12] < this.repeat[var12]) {
  597.                      int var10002 = this.currentLoop[var12]++;
  598.                   }
  599.                }
  600.             }
  601.  
  602.             this.update(((Component)this).getGraphics());
  603.  
  604.             try {
  605.                Thread.sleep((long)this.globalPause);
  606.             } catch (InterruptedException var9) {
  607.             }
  608.  
  609.             for(int var16 = 0; var16 < this.num_sprites; ++var16) {
  610.                if (this.active[var16]) {
  611.                   this.setFrameNum(this.frameNum[var16] + 1, var16);
  612.                }
  613.             }
  614.          }
  615.       }
  616.  
  617.    }
  618.  
  619.    public void setSound(boolean var1) {
  620.    }
  621.  
  622.    public void changeSpeed(int var1) {
  623.       this.globalPause = var1;
  624.    }
  625.  
  626.    public int getSpeed() {
  627.       return this.globalPause;
  628.    }
  629.  
  630.    private void updateMaxDims(Dimension var1, int var2) {
  631.       this.maxWidth[var2] = Math.max(var1.width, this.maxWidth[var2]);
  632.       this.maxHeight[var2] = Math.max(var1.height, this.maxHeight[var2]);
  633.    }
  634.  
  635.    private boolean parseBackground(String var1) {
  636.       int var2 = 0;
  637.       int var3 = var1.length();
  638.       if (var1.charAt(0) == '#') {
  639.          return this.parseHexBG(var1.substring(1));
  640.       } else {
  641.          int var4 = var1.indexOf(44, 0);
  642.          if (var4 == -1) {
  643.             return false;
  644.          } else {
  645.             this.bgR = Integer.parseInt(var1.substring(0, var4).trim());
  646.             var2 = var4 + 1;
  647.             if (var2 >= var3) {
  648.                return false;
  649.             } else {
  650.                var4 = var1.indexOf(44, var2);
  651.                if (var4 == -1) {
  652.                   return false;
  653.                } else {
  654.                   this.bgG = Integer.parseInt(var1.substring(var2, var4).trim());
  655.                   var2 = var4 + 1;
  656.                   if (var2 >= var3) {
  657.                      return false;
  658.                   } else {
  659.                      var4 = var1.indexOf(44, var2);
  660.                      if (var4 == -1) {
  661.                         this.bgB = Integer.parseInt(var1.substring(var2).trim());
  662.                      }
  663.  
  664.                      return true;
  665.                   }
  666.                }
  667.             }
  668.          }
  669.       }
  670.    }
  671.  
  672.    private void var_init() {
  673.       Object var1 = null;
  674.       Object var2 = null;
  675.       this.initialized = true;
  676.  
  677.       try {
  678.          String var25 = ((Applet)this).getParameter("REGUSER");
  679.          if (var25 == null) {
  680.             this.BigError = true;
  681.             return;
  682.          }
  683.  
  684.          this.dbg("User = " + var25);
  685.          if (var25.equals("Unregistered") && !this.local) {
  686.             this.dbg("Egor 3.0 must be registered to work on the Web");
  687.             this.msg("Egor 3.0 must be registered to work on the Web");
  688.             this.BigError = true;
  689.             return;
  690.          }
  691.  
  692.          this.generateCRC(var25);
  693.          String var11 = ((Applet)this).getParameter("NUM_SPRITES");
  694.          if (var11 == null) {
  695.             this.num_sprites = 1;
  696.          } else {
  697.             this.num_sprites = Integer.parseInt(var11);
  698.          }
  699.  
  700.          this.dbg("NUM_SPRITES = " + this.num_sprites);
  701.          this.init_arrays();
  702.  
  703.          for(int var3 = 0; var3 < this.num_sprites; ++var3) {
  704.             var11 = ((Applet)this).getParameter("REPEAT_" + Integer.toString(var3));
  705.             if (var11 != null) {
  706.                this.repeat[var3] = Integer.parseInt(var11);
  707.             } else {
  708.                this.repeat[var3] = -1;
  709.             }
  710.  
  711.             this.dbg("REPEAT_" + var3 + " = " + this.repeat[var3]);
  712.          }
  713.  
  714.          var11 = ((Applet)this).getParameter("PRIORITY");
  715.          if (var11 != null && !this.parsePriority(var11)) {
  716.             this.msg("Invalid priority. Resetting to default");
  717.  
  718.             for(int var26 = 0; var26 < this.num_sprites; this.priority[var26] = var26++) {
  719.             }
  720.          }
  721.  
  722.          this.dbg("PRIORITY " + var11);
  723.          var11 = ((Applet)this).getParameter("PAUSE");
  724.          this.dbg("PAUSE " + var11);
  725.          if (var11 != null) {
  726.             this.globalPause = Integer.parseInt(var11);
  727.             if (this.globalPause < 0) {
  728.                this.globalPause = 10;
  729.             }
  730.          } else {
  731.             this.globalPause = 10;
  732.          }
  733.  
  734.          this.appWidth = ((Component)this).size().width;
  735.          this.appHeight = ((Component)this).size().height;
  736.  
  737.          for(int var27 = 0; var27 < this.num_sprites; ++var27) {
  738.             var11 = ((Applet)this).getParameter("TIMEOUT_" + Integer.toString(var27));
  739.             Date var4 = new Date();
  740.             int var5 = (int)var4.getTime();
  741.             if (var11 != null) {
  742.                this.timeout[var27] = Integer.parseInt(var11);
  743.                if (this.timeout[var27] <= 0) {
  744.                   this.wantsecs[var27] = (long)(var5 - 1000);
  745.                } else {
  746.                   this.wantsecs[var27] = (long)(var5 + Integer.parseInt(var11));
  747.                }
  748.             } else {
  749.                this.timeout[var27] = -1000;
  750.                this.wantsecs[var27] = (long)(var5 - 1000);
  751.             }
  752.  
  753.             this.dbg("TIMEOUT_" + var27 + " = " + var11);
  754.          }
  755.  
  756.          var11 = ((Applet)this).getParameter("URL");
  757.          if (var11 != null) {
  758.             try {
  759.                this.glob_destination = new URL((URL)null, var11);
  760.             } catch (MalformedURLException var9) {
  761.                this.dbg("Egor 3.0 - Malformed global destination " + this.glob_destination + ". Trying it as a relative reference");
  762.  
  763.                try {
  764.                   this.glob_destination = new URL(this.baseDir, var11);
  765.                } catch (MalformedURLException var8) {
  766.                   this.dbg("Egor 3.0 - Malformed global destination " + this.baseDir + this.glob_destination + ". Ignoring.");
  767.                   this.glob_destination = null;
  768.                }
  769.             }
  770.          }
  771.  
  772.          this.dbg("URL = " + this.glob_destination);
  773.          var11 = ((Applet)this).getParameter("ENDDELAY");
  774.          this.dbg("ENDDELAY " + var11);
  775.          if (var11 != null) {
  776.             this.delay = Integer.parseInt(var11);
  777.          } else {
  778.             this.delay = 0;
  779.          }
  780.  
  781.          var11 = ((Applet)this).getParameter("ENDIMAGE");
  782.          if (var11 != null) {
  783.             try {
  784.                this.endimage = ((Applet)this).getImage(new URL(this.baseDir, var11));
  785.             } catch (MalformedURLException var7) {
  786.                this.msg("Malformed endimage path. Discarding");
  787.                this.endimage = null;
  788.             }
  789.          }
  790.  
  791.          this.dbg("ENDIMAGE = " + this.baseDir + var11);
  792.          var11 = ((Applet)this).getParameter("ENDURL");
  793.          if (var11 != null) {
  794.             try {
  795.                this.endURL = new URL((URL)null, var11);
  796.             } catch (MalformedURLException var6) {
  797.                this.msg("Malformed end URL. Discarding");
  798.                this.endURL = null;
  799.             }
  800.          }
  801.  
  802.          this.dbg("ENDURL = " + this.endURL);
  803.  
  804.          for(int var28 = 0; var28 < this.num_sprites; ++var28) {
  805.             var11 = ((Applet)this).getParameter("IMAGELIST_" + Integer.toString(var28));
  806.             this.dbg("IMAGELIST_" + var28 + " = " + var11);
  807.             if (var11 == null) {
  808.                this.msg("Egor - No image list. Essential!");
  809.                this.error = true;
  810.                return;
  811.             }
  812.  
  813.             this.images[var28] = this.prepareImages(var11);
  814.             this.generateCRC(var11);
  815.          }
  816.  
  817.          var11 = ((Applet)this).getParameter("SERIALID");
  818.          if (var11 == null) {
  819.             this.BigError = true;
  820.             return;
  821.          }
  822.  
  823.          if (!var25.equals("Unregistered") && !this.checkCRC(var11)) {
  824.             this.BigError = true;
  825.             return;
  826.          }
  827.  
  828.          for(int var29 = 0; var29 < this.num_sprites; ++var29) {
  829.             if (!this.fetchImages(this.images, var29)) {
  830.                this.error = true;
  831.             }
  832.          }
  833.  
  834.          for(int var30 = 0; var30 < this.num_sprites; ++var30) {
  835.             if (this.appWidth == 0) {
  836.                if (this.bgSize.width > this.maxWidth[var30]) {
  837.                   this.appWidth = this.bgSize.width;
  838.                } else {
  839.                   this.appWidth = this.maxWidth[var30];
  840.                }
  841.             }
  842.  
  843.             if (this.appHeight == 0) {
  844.                if (this.bgSize.height > this.maxHeight[var30]) {
  845.                   this.appHeight = this.bgSize.height;
  846.                } else {
  847.                   this.appHeight = this.maxHeight[var30];
  848.                }
  849.             }
  850.          }
  851.  
  852.          for(int var31 = 0; var31 < this.num_sprites; ++var31) {
  853.             var11 = ((Applet)this).getParameter("BOUNCE_" + Integer.toString(var31));
  854.             this.bounce[var31] = var11 == null ? true : var11.equalsIgnoreCase("yes") || var11.equalsIgnoreCase("true");
  855.             this.dbg("BOUNCE_" + var31 + " = " + var11);
  856.          }
  857.  
  858.          for(int var32 = 0; var32 < this.num_sprites; ++var32) {
  859.             var11 = ((Applet)this).getParameter("STARTPOS_" + Integer.toString(var32));
  860.             this.dbg("STARTPOS_" + var32 + " =" + var11);
  861.             if (var11 != null) {
  862.                if (!this.parseStartPos(var11, var32)) {
  863.                   this.msg("Egor - Invalid start position");
  864.                   this.currentX[var32] = 0;
  865.                   this.currentY[var32] = 0;
  866.                }
  867.  
  868.                if (this.currentX[var32] > this.appWidth - this.maxWidth[var32]) {
  869.                   this.currentX[var32] = this.appWidth - this.maxWidth[var32];
  870.                } else if (this.currentX[var32] < 0) {
  871.                   this.currentX[var32] = 0;
  872.                }
  873.  
  874.                if (this.currentY[var32] > this.appHeight - this.maxHeight[var32]) {
  875.                   this.currentY[var32] = this.appHeight - this.maxHeight[var32];
  876.                } else if (this.currentY[var32] < 0) {
  877.                   this.currentY[var32] = 0;
  878.                }
  879.             } else {
  880.                this.currentX[var32] = 0;
  881.                this.currentY[var32] = 0;
  882.             }
  883.          }
  884.  
  885.          for(int var33 = 0; var33 < this.num_sprites; ++var33) {
  886.             var11 = ((Applet)this).getParameter("MOVE_" + Integer.toString(var33));
  887.             this.dbg("MOVE_" + Integer.toString(var33) + " = " + var11);
  888.             if (var11 != null) {
  889.                if (!this.parseMovement(var11, var33)) {
  890.                   this.msg("Egor - Invalid movement param");
  891.                   this.moveEW[var33] = 0;
  892.                   this.moveNS[var33] = 0;
  893.                }
  894.             } else {
  895.                this.moveEW[var33] = 0;
  896.                this.moveNS[var33] = 0;
  897.             }
  898.          }
  899.       } catch (MalformedURLException var10) {
  900.       }
  901.  
  902.    }
  903.  
  904.    public void init() {
  905.       this.dbg("Applet starting");
  906.       this.tracker = new MediaTracker(this);
  907.       this.baseDir = ((Applet)this).getDocumentBase();
  908.       this.dbg("BASEDIR = " + this.baseDir);
  909.       String var1 = ((Applet)this).getParameter("BACKGROUND");
  910.       if (var1 != null) {
  911.          try {
  912.             this.backgroundImageURL = new URL((URL)null, var1);
  913.          } catch (MalformedURLException var7) {
  914.             this.dbg("Malformed background image path " + var1 + " Trying to make it absolute");
  915.  
  916.             try {
  917.                this.backgroundImageURL = new URL(this.baseDir, var1);
  918.             } catch (MalformedURLException var6) {
  919.                this.dbg("Malformed background image path " + this.baseDir + var1 + ". Ignoring");
  920.                this.backgroundImageURL = null;
  921.             }
  922.          }
  923.       }
  924.  
  925.       this.dbg("BACKGROUNDIMG = " + this.backgroundImageURL);
  926.       var1 = ((Applet)this).getParameter("BG");
  927.       if (var1 != null && !this.parseBackground(var1)) {
  928.          this.msg("Egor - Background messed up, using default");
  929.          this.bgR = 170;
  930.          this.bgG = 170;
  931.          this.bgB = 170;
  932.       }
  933.  
  934.       Color var2 = new Color(this.bgR, this.bgG, this.bgB);
  935.       ((Component)this).setBackground(var2);
  936.       this.loaded = false;
  937.       this.dbg("BG = " + this.bgR + ", " + this.bgG + ", " + this.bgB);
  938.       this.update(((Component)this).getGraphics());
  939.       var1 = ((Applet)this).getParameter("STARTUP");
  940.       if (var1 != null) {
  941.          try {
  942.             this.startUpImageURL = new URL(this.baseDir, var1);
  943.          } catch (MalformedURLException var5) {
  944.             this.dbg("Malformed startup path " + this.baseDir + var1);
  945.          }
  946.       }
  947.  
  948.       this.dbg("STARTUP = " + this.startUpImageURL);
  949.       if (this.startUpImageURL != null) {
  950.          this.startUpImage = ((Applet)this).getImage(this.startUpImageURL);
  951.          this.tracker.addImage(this.startUpImage, 0);
  952.  
  953.          try {
  954.             this.tracker.waitForID(0);
  955.          } catch (InterruptedException var4) {
  956.          }
  957.  
  958.          if (this.tracker.isErrorID(0)) {
  959.             this.msg("Egor - Load error startup image");
  960.          }
  961.  
  962.          if (this.tracker.checkID(0)) {
  963.             ((Component)this).getGraphics().drawImage(this.startUpImage, 0, 0, this);
  964.          }
  965.       }
  966.  
  967.       for(int var3 = 0; var3 < this.num_sprites; ++var3) {
  968.          this.setFrameNum(0, var3);
  969.       }
  970.  
  971.    }
  972.  
  973.    public boolean handleEvent(Event var1) {
  974.       if (var1.id != 501) {
  975.          if (var1.id == 503) {
  976.             if (this.BigError) {
  977.                this.msg("Egor 3.0 Unrecoverable error (imagelist or timeout)");
  978.             } else {
  979.                this.msg("Egor 3.0 animation");
  980.             }
  981.  
  982.             return true;
  983.          } else {
  984.             return super.handleEvent(var1);
  985.          }
  986.       } else {
  987.          if (this.loaded) {
  988.             boolean var3 = false;
  989.  
  990.             for(int var4 = 0; var4 < this.num_sprites; ++var4) {
  991.                int var2 = this.priority[this.num_sprites - var4 - 1];
  992.                if (this.ptInRect(var1.x, var1.y, this.currentX[var2], this.currentY[var2], this.currentX[var2] + this.maxWidth[var2], this.currentY[var2] + this.maxWidth[var2])) {
  993.                   var3 = true;
  994.                   if (this.engine != null && this.engine.isAlive()) {
  995.                      if (this.glob_destination != null) {
  996.                         this.msg("Egor - Switching pages to " + this.glob_destination);
  997.                         ((Applet)this).getAppletContext().showDocument(this.glob_destination);
  998.                      } else {
  999.                         if (!this.mousePause[var2] && this.active[var2]) {
  1000.                            this.active_anims += -1;
  1001.                            this.active[var2] = false;
  1002.                         } else {
  1003.                            this.active[var2] = true;
  1004.                            ++this.active_anims;
  1005.                            if (this.frameNum[var2] >= this.images[var2].size()) {
  1006.                               this.setFrameNum(0, var2);
  1007.                               this.currentLoop[var2] = 0;
  1008.                            }
  1009.                         }
  1010.  
  1011.                         this.mousePause[var2] = !this.mousePause[var2];
  1012.                      }
  1013.                   } else {
  1014.                      for(int var5 = 0; var5 < this.num_sprites; ++var5) {
  1015.                         this.mousePause[var5] = false;
  1016.                         this.active[var5] = true;
  1017.                         this.setFrameNum(0, var5);
  1018.                      }
  1019.  
  1020.                      this.active_anims = this.num_sprites;
  1021.                      this.engine = new Thread(this);
  1022.                      this.engine.start();
  1023.                   }
  1024.  
  1025.                   return true;
  1026.                }
  1027.             }
  1028.  
  1029.             if (!var3) {
  1030.                this.pause();
  1031.             }
  1032.          }
  1033.  
  1034.          return true;
  1035.       }
  1036.    }
  1037.  
  1038.    public void changeDirection(int var1) {
  1039.       for(int var2 = 0; var2 < this.num_sprites; ++var2) {
  1040.          switch (var1) {
  1041.             case 1:
  1042.                int var12 = this.moveNS[var2]++;
  1043.                break;
  1044.             case 2:
  1045.                int var10 = this.moveEW[var2]++;
  1046.                var10 = this.moveNS[var2]++;
  1047.                break;
  1048.             case 3:
  1049.                int var9 = this.moveEW[var2]++;
  1050.                break;
  1051.             case 4:
  1052.                int[] var7 = this.moveNS;
  1053.                var7[var2] += -1;
  1054.                int var8 = this.moveEW[var2]++;
  1055.                break;
  1056.             case 5:
  1057.                int[] var6 = this.moveNS;
  1058.                var6[var2] += -1;
  1059.                break;
  1060.             case 6:
  1061.                int[] var4 = this.moveEW;
  1062.                var4[var2] += -1;
  1063.                var4 = this.moveNS;
  1064.                var4[var2] += -1;
  1065.                break;
  1066.             case 7:
  1067.                int[] var3 = this.moveEW;
  1068.                var3[var2] += -1;
  1069.                break;
  1070.             case 8:
  1071.                int var10002 = this.moveNS[var2]++;
  1072.                int[] var10000 = this.moveEW;
  1073.                var10000[var2] += -1;
  1074.          }
  1075.       }
  1076.  
  1077.    }
  1078. }
  1079.