home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Hotdog / files / snagpack.exe / KNIGHTRIDER.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-21  |  6.3 KB  |  302 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8.  
  9. public class knightrider extends Applet implements Runnable {
  10.    private Thread engineThread;
  11.    private String lbl;
  12.    private char[] label;
  13.    private int stringLen;
  14.    private int count;
  15.    private int loop;
  16.    private boolean readyToPaint = false;
  17.    private myFont font;
  18.    private boolean toDark = false;
  19.    private boolean userPause = false;
  20.    // $FF: renamed from: x int
  21.    private int field_0;
  22.    private Image offImage;
  23.    private Graphics offGraphics;
  24.    private int bred;
  25.    private int bgreen;
  26.    private int bblue;
  27.    private int fred;
  28.    private int fgreen;
  29.    private int fblue;
  30.    private int red = 255;
  31.    private int blue;
  32.    private int green;
  33.    private int fade;
  34.    private int fadeR;
  35.    private int fadeG;
  36.    private int fadeB;
  37.    private int hiRed;
  38.    private int lowRed;
  39.    private int hiGreen;
  40.    private int lowGreen;
  41.    private int hiBlue;
  42.    private int lowBlue;
  43.    // $FF: renamed from: fm java.awt.FontMetrics
  44.    private FontMetrics field_1;
  45.    private int sleepTime;
  46.    private boolean debug = false;
  47.  
  48.    private void dbg(String var1) {
  49.       if (this.debug) {
  50.          System.out.println(var1);
  51.       }
  52.  
  53.    }
  54.  
  55.    public void init() {
  56.       String var1 = ((Applet)this).getParameter("mydebug");
  57.       if ("myyes".equals(var1)) {
  58.          this.debug = true;
  59.       }
  60.  
  61.       var1 = ((Applet)this).getParameter("fontsize");
  62.       int var2 = var1 == null ? 12 : Integer.valueOf(var1);
  63.       var1 = ((Applet)this).getParameter("style");
  64.       int var3 = myFont.getFontStyle(var1);
  65.       var1 = ((Applet)this).getParameter("font");
  66.       String var4 = myFont.getFontName(var1);
  67.       this.font = new myFont(var4, var3, var2);
  68.       var1 = ((Applet)this).getParameter("text");
  69.       this.lbl = var1 == null ? "Sausage Software" : var1;
  70.       this.label = this.lbl.toCharArray();
  71.       this.stringLen = this.lbl.length();
  72.       var1 = ((Applet)this).getParameter("color");
  73.       if (var1 != null) {
  74.          createColor var5 = new createColor(var1, ",");
  75.          var5.getColor();
  76.          this.red = var5.getRed();
  77.          this.green = var5.getGreen();
  78.          this.blue = var5.getBlue();
  79.       }
  80.  
  81.       var1 = ((Applet)this).getParameter("background");
  82.       if (var1 != null) {
  83.          createColor var14 = new createColor(var1, ",");
  84.          var14.getColor();
  85.          this.bred = var14.getRed();
  86.          this.bgreen = var14.getGreen();
  87.          this.bblue = var14.getBlue();
  88.       }
  89.  
  90.       var1 = ((Applet)this).getParameter("speed");
  91.       this.sleepTime = var1 == null ? 50 : Integer.parseInt(var1);
  92.  
  93.       try {
  94.          this.offImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  95.          this.offGraphics = this.offImage.getGraphics();
  96.       } catch (Exception var6) {
  97.          this.offGraphics = null;
  98.       }
  99.  
  100.       this.hiLowColors();
  101.       this.fadeValue();
  102.       this.dbg("fade " + this.fade + " strLen" + this.stringLen);
  103.    }
  104.  
  105.    private void hiLowColors() {
  106.       if (this.red > this.bred) {
  107.          this.hiRed = this.red;
  108.          this.lowRed = this.bred;
  109.       } else {
  110.          this.hiRed = this.bred;
  111.          this.lowRed = this.red;
  112.       }
  113.  
  114.       if (this.green > this.bgreen) {
  115.          this.hiGreen = this.green;
  116.          this.lowGreen = this.bgreen;
  117.       } else {
  118.          this.hiGreen = this.bgreen;
  119.          this.lowGreen = this.green;
  120.       }
  121.  
  122.       if (this.blue > this.bblue) {
  123.          this.hiBlue = this.blue;
  124.          this.lowBlue = this.bblue;
  125.       } else {
  126.          this.hiBlue = this.bblue;
  127.          this.lowBlue = this.blue;
  128.       }
  129.    }
  130.  
  131.    private void fadeValue() {
  132.       int var1 = Math.abs(this.red - this.bred);
  133.       int var2 = Math.abs(this.green - this.bgreen);
  134.       int var3 = Math.abs(this.blue - this.bblue);
  135.       int var4;
  136.       if (var1 >= var2) {
  137.          if (var1 >= var3) {
  138.             var4 = var1;
  139.          } else {
  140.             var4 = var3;
  141.          }
  142.       } else if (var2 >= var3) {
  143.          var4 = var2;
  144.       } else {
  145.          var4 = var3;
  146.       }
  147.  
  148.       this.fadeR = (this.red - this.bred) / this.stringLen;
  149.       this.fadeG = (this.green - this.bgreen) / this.stringLen;
  150.       this.fadeB = (this.blue - this.bblue) / this.stringLen;
  151.       this.dbg("fadeR " + this.fadeR + " fadeG " + this.fadeG + " fadeB " + this.fadeB);
  152.       this.fade = var4 / this.stringLen;
  153.    }
  154.  
  155.    private synchronized void prePaint(Graphics var1) {
  156.       var1.setColor(new Color(this.bred, this.bgreen, this.bblue));
  157.       var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  158.       var1.setFont(this.font);
  159.       this.field_1 = var1.getFontMetrics();
  160.       this.field_0 = ((Component)this).size().width / 2 - this.field_1.stringWidth(this.lbl) / 2;
  161.  
  162.       for(int var2 = 0; var2 < this.stringLen; ++var2) {
  163.          if (this.loop > 0) {
  164.             --this.loop;
  165.          } else {
  166.             this.colorToHigh();
  167.             this.colorToLow();
  168.             if (this.fred >= this.red && this.fblue >= this.blue && this.fgreen >= this.green) {
  169.                this.toDark = true;
  170.                this.fred = this.red;
  171.                this.fgreen = this.green;
  172.                this.fblue = this.blue;
  173.             }
  174.  
  175.             var1.setColor(new Color(this.fred, this.fgreen, this.fblue));
  176.             var1.drawChars(this.label, var2, 1, this.field_0, ((Component)this).size().height / 2 + this.field_1.getHeight() / 2);
  177.             if (this.toDark) {
  178.                this.fred -= this.fadeR;
  179.                this.fgreen -= this.fadeG;
  180.                this.fblue -= this.fadeB;
  181.             } else {
  182.                this.fred += this.fadeR;
  183.                this.fgreen += this.fadeG;
  184.                this.fblue += this.fadeB;
  185.             }
  186.          }
  187.  
  188.          this.field_0 += this.field_1.charWidth(this.label[var2]);
  189.       }
  190.  
  191.       if (this.count > this.stringLen * 2) {
  192.          this.count = 0;
  193.       }
  194.  
  195.    }
  196.  
  197.    private synchronized void colorToHigh() {
  198.       if (this.fred > this.hiRed) {
  199.          this.fred = this.hiRed;
  200.       }
  201.  
  202.       if (this.fgreen > this.hiGreen) {
  203.          this.fgreen = this.hiGreen;
  204.       }
  205.  
  206.       if (this.fblue > this.hiBlue) {
  207.          this.fblue = this.hiBlue;
  208.       }
  209.  
  210.    }
  211.  
  212.    private synchronized void colorToLow() {
  213.       if (this.fred < this.lowRed) {
  214.          this.fred = this.lowRed;
  215.       }
  216.  
  217.       if (this.fgreen < this.lowGreen) {
  218.          this.fgreen = this.lowGreen;
  219.       }
  220.  
  221.       if (this.fblue < this.lowBlue) {
  222.          this.fblue = this.lowBlue;
  223.       }
  224.  
  225.    }
  226.  
  227.    private synchronized void charSetup() {
  228.       if (this.count >= this.stringLen) {
  229.          this.loop = this.count - this.stringLen;
  230.       }
  231.  
  232.       this.dbg(this.loop + " ");
  233.       this.fred = this.red - this.fadeR * this.count;
  234.       this.fgreen = this.green - this.fadeG * this.count;
  235.       this.fblue = this.blue - this.fadeB * this.count++;
  236.       this.toDark = false;
  237.    }
  238.  
  239.    public void update(Graphics var1) {
  240.       if (this.readyToPaint) {
  241.          this.paint(var1);
  242.       }
  243.  
  244.    }
  245.  
  246.    public void paint(Graphics var1) {
  247.       if (this.engineThread != null && this.readyToPaint) {
  248.          if (this.offGraphics != null) {
  249.             this.prePaint(this.offGraphics);
  250.             var1.drawImage(this.offImage, 0, 0, this);
  251.             return;
  252.          }
  253.  
  254.          this.prePaint(var1);
  255.       }
  256.  
  257.    }
  258.  
  259.    public void start() {
  260.       this.engineThread = new Thread(this);
  261.       this.engineThread.start();
  262.    }
  263.  
  264.    public void stop() {
  265.       this.engineThread.stop();
  266.    }
  267.  
  268.    public void run() {
  269.       Thread.currentThread().setPriority(1);
  270.  
  271.       while(true) {
  272.          ((Component)this).repaint();
  273.  
  274.          try {
  275.             Thread.sleep((long)this.sleepTime);
  276.          } catch (Exception var1) {
  277.          }
  278.  
  279.          this.readyToPaint = false;
  280.          this.charSetup();
  281.          this.readyToPaint = true;
  282.       }
  283.    }
  284.  
  285.    public boolean handleEvent(Event var1) {
  286.       if (var1.id == 501) {
  287.          if (this.userPause) {
  288.             this.engineThread.resume();
  289.          } else {
  290.             this.engineThread.suspend();
  291.          }
  292.  
  293.          this.userPause = !this.userPause;
  294.       } else if (var1.id == 201) {
  295.          this.stop();
  296.          System.exit(0);
  297.       }
  298.  
  299.       return true;
  300.    }
  301. }
  302.