home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / Gamelicator / examples / Boink / com / next / gt / Actor.class (.txt) next >
Encoding:
Java Class File  |  1998-04-20  |  3.0 KB  |  154 lines

  1. package com.next.gt;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Image;
  5.  
  6. public abstract class Actor {
  7.    protected Image image;
  8.    protected int numFrames;
  9.    public int width;
  10.    public int height;
  11.    public int currentFrame = 0;
  12.    protected int hFrames;
  13.    // $FF: renamed from: x double
  14.    public double field_0;
  15.    // $FF: renamed from: y double
  16.    public double field_1;
  17.    public double x_old;
  18.    public double y_old;
  19.    public double velocity_x;
  20.    public double velocity_y;
  21.    public Gamelication owner;
  22.    public boolean wrapAround = true;
  23.  
  24.    public void tick() {
  25.       this.calculateCurrentFrame();
  26.       this.calculateNewPosition();
  27.       this.calculateNewVelocity();
  28.    }
  29.  
  30.    protected void setImage(Image var1, int var2, int var3, int var4, int var5) {
  31.       this.width = var2;
  32.       this.height = var3;
  33.       this.numFrames = var5;
  34.       this.hFrames = var4;
  35.       this.image = var1;
  36.    }
  37.  
  38.    protected void setImage(Image var1) {
  39.       int var2;
  40.       do {
  41.          var2 = var1.getHeight(this.owner);
  42.       } while(var2 == -1);
  43.  
  44.       int var3;
  45.       do {
  46.          var3 = var1.getWidth(this.owner);
  47.       } while(var3 == -1);
  48.  
  49.       this.setImage(var1, var3, var2, 1, 1);
  50.    }
  51.  
  52.    protected void setImage(Image var1, int var2, int var3) {
  53.       int var4;
  54.       do {
  55.          var4 = var1.getHeight(this.owner);
  56.       } while(var4 == -1);
  57.  
  58.       int var5;
  59.       do {
  60.          var5 = var1.getWidth(this.owner);
  61.       } while(var5 == -1);
  62.  
  63.       this.setImage(var1, var5 / var2, var4 / (int)Math.ceil((double)var3 / (double)var2), var2, var3);
  64.    }
  65.  
  66.    protected void calculateNewPosition() {
  67.       double var1 = this.owner.deltaTickTimeMillis() / (double)1000.0F;
  68.       this.x_old = this.field_0;
  69.       this.y_old = this.field_1;
  70.       this.field_0 += this.velocity_x * var1;
  71.       this.field_1 += this.velocity_y * var1;
  72.       if (this.wrapAround) {
  73.          this.checkForOutOfBounds();
  74.       }
  75.  
  76.    }
  77.  
  78.    protected void calculateNewVelocity() {
  79.    }
  80.  
  81.    protected void calculateCurrentFrame() {
  82.       if (++this.currentFrame >= this.numFrames) {
  83.          this.currentFrame = 0;
  84.       }
  85.  
  86.    }
  87.  
  88.    protected void checkForOutOfBounds() {
  89.       if (this.field_0 > (double)(this.owner.getSize().width + this.width + this.width)) {
  90.          this.field_0 = (double)(-this.width);
  91.       } else if (this.field_0 < (double)(-this.width)) {
  92.          this.field_0 = (double)(this.owner.getSize().width + this.width + this.width);
  93.       }
  94.  
  95.       if (this.field_1 > (double)(this.owner.getSize().height + this.height + this.height)) {
  96.          this.field_1 = (double)(-this.height);
  97.       } else {
  98.          if (this.field_1 < (double)(-this.height)) {
  99.             this.field_1 = (double)(this.owner.getSize().height + this.height + this.height);
  100.          }
  101.  
  102.       }
  103.    }
  104.  
  105.    public void draw(Graphics var1) {
  106.       double var2 = (double)(-(this.currentFrame % this.hFrames) * this.width);
  107.       double var4 = -Math.floor((double)(this.currentFrame / this.hFrames)) * (double)this.height;
  108.       Graphics var6 = var1.create((int)this.field_0, (int)this.field_1, this.width, this.height);
  109.       var6.drawImage(this.image, (int)var2, (int)var4, this.owner);
  110.       var6.dispose();
  111.    }
  112.  
  113.    protected void collideWithActor(Actor var1) {
  114.    }
  115.  
  116.    public void bounceOff(Actor var1) {
  117.       double var2 = (double)(this.width / 2) + this.x_old;
  118.       double var4 = (double)(this.height / 2) + this.y_old;
  119.       double var6 = (double)(var1.width / 2) + var1.field_0;
  120.       double var8 = (double)(var1.height / 2) + var1.field_1;
  121.       double var10 = (var4 - var8) / (var2 - var6);
  122.       double var12 = var4 - var10 * var2;
  123.       if (var1.field_0 >= var2) {
  124.          double var14 = var10 * var1.field_0 + var12;
  125.          if (var14 >= var1.field_1 && var14 <= var1.field_1 + (double)var1.height) {
  126.             this.velocity_x = var1.velocity_x - this.velocity_x;
  127.             this.field_0 = this.x_old;
  128.             return;
  129.          }
  130.       } else if (var1.field_0 + (double)var1.width <= var2) {
  131.          double var18 = var10 * (var1.field_0 + (double)var1.width) + var12;
  132.          if (var18 >= var1.field_1 && var18 <= var1.field_1 + (double)var1.height) {
  133.             this.velocity_x = var1.velocity_x - this.velocity_x;
  134.             this.field_0 = this.x_old;
  135.             return;
  136.          }
  137.       } else if (var1.field_1 >= var4) {
  138.          double var16 = (var1.field_1 - var12) / var10;
  139.          if (var16 >= var1.field_0 && var16 <= var1.field_0 + (double)var1.width) {
  140.             this.velocity_y = var1.velocity_y - this.velocity_y;
  141.             this.field_1 = this.y_old;
  142.             return;
  143.          }
  144.       } else if (var1.field_1 + (double)var1.height <= var4) {
  145.          double var19 = (var1.field_1 + (double)var1.height - var12) / var10;
  146.          if (var19 >= var1.field_0 && var19 <= var1.field_0 + (double)var1.width) {
  147.             this.velocity_y = var1.velocity_y - this.velocity_y;
  148.             this.field_1 = this.y_old;
  149.          }
  150.       }
  151.  
  152.    }
  153. }
  154.