home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Japan / NTT / DM- / hotjava / classes / src / AnimationPlayer.jpp < prev    next >
Encoding:
Text File  |  2017-09-21  |  2.3 KB  |  123 lines

  1. import browser.*;
  2. import browser.audio.*;
  3. import awt.*;
  4. import net.www.html.*;
  5. import java.io.*;
  6. import net.www.*;
  7. import java.util.*;
  8.  
  9. #include "anim.h";
  10.  
  11. class AnimationPlayer extends Applet implements Runnable {
  12.  
  13. // test for MouseMove event
  14. int last_x = -1;
  15. int last_y = -1;
  16.  
  17. static String imgdir = "images";
  18. static String snddir = "audio";
  19.  
  20. boolean    initialized = false;
  21.  
  22. // various image file names
  23.  
  24. // offscreen image & graphic context
  25. Image        im = null;
  26. Graphics    offscreen;
  27. int        width, height;
  28.  
  29. // Various Images
  30. Image        background = null;
  31.  
  32. IDChain        dispobj = null;
  33.  
  34. AnimationData    adList[] = null;
  35. int        maxAnimation = 0;
  36. Schedular    sched[] = null;
  37. int        maxSchedular = 0;
  38.  
  39. public AnimationData getAnimationData(int n) {return adList[n];}
  40.  
  41. void setupDisplayObject() {
  42.     int i;
  43.     for (i = 0; i < maxAnimation; i++) {
  44.     if (adList[i] != null && adList[i].getDepth() >= 0) {
  45.         dispobj.insertByDepth(new IDChain(i, 0, adList[i].getDepth()));
  46.     }
  47.     }
  48. }
  49.  
  50. public void start() {
  51.     startDisplay();
  52.     repaint();
  53. }
  54.  
  55. private void startDisplay() {
  56.     int i;
  57.     AnimationData ad;
  58.  
  59.     sched[ID_AUTO] = new Schedular(this, ID_AUTO);
  60.     for (i = 0; i < maxAnimation; i++) {
  61.     if ((ad=adList[i]) == null) {
  62.         continue;
  63.     }
  64.     if (ad.getType() == TY_AUTO) {
  65.         sched[ID_AUTO].reschedule(i);
  66.     } else if (ad.getCurFrame() == -1) {
  67.         ad.setCurFrame(0);
  68.     }
  69.     }
  70.     sched[ID_AUTO].start();
  71. }
  72.  
  73.  
  74. public void run() {
  75. }
  76.  
  77. public void stop() {
  78.     int i;
  79.     for (i=0; i < maxSchedular; i++) {
  80.     if (sched[i] != null) {
  81.         sched[i].stop();
  82.         sched[i] = null;
  83.     }
  84.     }
  85. }
  86.  
  87. public void paint(Graphics g) {
  88.     update(g);
  89. }
  90.  
  91. public void update(Graphics g) {
  92.     offscreen.setForeground(Color.lightGray);
  93.     offscreen.fillRect(0,0,width,height);
  94.     offscreen.drawImage(background, 0, 0);
  95.  
  96.     IDChain p;
  97.     AnimationData ad;
  98.     Image img;
  99.     for (p = dispobj.getNext(); p != null; p = p.getNext()) {
  100.     ad = adList[p.getID()];
  101.     if ((img=ad.getCurrentImage()) != null) {
  102.         offscreen.drawImage(img, ad.x(), ad.y());
  103.     }    
  104.     }
  105.     g.drawImage(im,0,0);
  106. }
  107.  
  108. public void insertSchedular(int id) {
  109.     sched[id] = new Schedular(this, id);
  110.     sched[id].reschedule(id);
  111.     sched[id].start();
  112. }
  113.  
  114. public void removeSchedular(int id) {
  115.     if (sched[id] != null) {
  116.     sched[id].stop();
  117.     sched[id] = null;
  118.     }
  119. }
  120.  
  121. }
  122.  
  123.