Internet Start Page  TOP  
 Road of Developers
 
 


DownLoad Nstower.lzh(ソースコード付き)


import java.awt.*;
import java.applet.AudioClip;

public class Nstower extends java.applet.Applet implements Runnable {

  MainScreen can = new MainScreen(this);
  PowerMeter powmeter = new PowerMeter(this);
  FloorNumber fln = new FloorNumber(this);
  MediaTracker mt = new MediaTracker(this);
  Image nekopics[] = new Image[24];
  String images[] = { "1", "2", "3", "4", "5", "6", "7", "8",
                       "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12",
                       "floors", "floorl", "wall"};
  AudioClip clip[] = new AudioClip[16];
  String sounds[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
                       "bgm", "gameover", "floor", "jump"};
  Image currentimg;
  Thread runner;
  int xpos, ypos, xp, yp, pow, objn, scr;
  boolean isMouse, isJump;
  int objsign[] = new int[14];
  int objxpos[] = new int[14];
  int objypos[] = new int[14];

  public void start() {
    xpos = 16; ypos = 288; xp = 1; yp = 0; pow = 0; objn = 11;
    scr = 0; isMouse = false; isJump = false; can.isScroll = true;
    fln.flnum = 1;
    // オブジェクトセット
    for (int i = 0; i < 11; i++) {
      objsign[i] = 0;
      objxpos[i] = floorlocation(12 - i);
      objypos[i] = i*32 - 32;
    }
    objsign[11] = 1;
    objxpos[11] = 16;
    objypos[11] = 320;
    objsign[12] = objsign[13] = 2;
    objxpos[12] = 0; objxpos[13] = 400;
    objypos[12] = objypos[13] = -32;    
  
    if (runner == null) {
      runner = new Thread(this);
      runner.start();
    }
  }

  public void stop() {
    if (runner != null) {
      if (clip[12] != null)
        clip[12].stop();
      runner.stop();
      runner = null;
    }
  }

  public void init() {
    for (int i=0; i < nekopics.length; i++) {
      nekopics[i] = getImage(getCodeBase(), "images/" + images[i] + ".gif");
      mt.addImage(nekopics[i], 0);
    }
    for (int i=0; i < clip.length; i++) {
      clip[i] = getAudioClip(getCodeBase(), "sounds/" + sounds[i] + ".au");
    }
    can.offscreenImg = createImage(32, 32);
    can.offscreenG = can.offscreenImg.getGraphics();
    
    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints gc = new GridBagConstraints();
    setLayout(gb);
    gc.fill = GridBagConstraints.BOTH;
    gc.insets = new Insets(4, 4, 4, 4);
    gc.gridx = 0; gc.gridy = 0;
    powmeter.resize(204, 32);
    gb.setConstraints(powmeter, gc);
    add(powmeter);
    gc.gridx = 1; gc.gridy = 0;
    fln.resize(204, 32);
    gb.setConstraints(fln, gc);
    add(fln);
    gc.gridx = 0; gc.gridy = 1; gc.gridwidth = 2;
    //can = new MainScreen(this);
    can.resize(416, 352);
    gb.setConstraints(can, gc);
    add(can);
    gc.gridx = 0; gc.gridy = 2; gc.gridwidth = 1;
    Button b3 = new Button("START");
    gb.setConstraints(b3, gc);
    add(b3);
    gc.gridx = 1; gc.gridy = 2;
    Button b4 = new Button("SCORE");
    gb.setConstraints(b4, gc);
    add(b4);
    
    // 初期化
  }
  
  public void run() {
    while(mt.checkID(0, true) == false)
      pause(100);
    clip[12].loop();
    nekorun();
  }

  void nekorun() {
    int step = 0;
    can.isScroll = true;
    while (true) {
      this.xpos += xp*4;
      if (this.xpos <= 16 || this.xpos >= 368) xp = -xp;
      step = (step + 1)%4;
      if (this.isJump) {
        if ((this.ypos <= 68) && (this.yp < 0)) {
          floorup(-this.yp*2);
          can.isScroll = true;
        } else
          this.ypos += this.yp*2;
        objn = isfloor();
        if (yp > 0 && objn != -1) {
          this.ypos = objypos[objn] - 32;
          this.pow = 0;
          this.isJump = false;
          clip[14].play();
        } else
          this.yp += 1;
      } else {
        objn = isfloor();
        if (objn == -1) {
          isJump = true;
          yp = 1;
        }
        if (this.isMouse) {
          this.pow = this.pow%12 + 1;
          clip[this.pow - 1].play();
        }
      }
      if (ypos >= 352) {
        can.repaint();
        if (clip[12] != null)
          clip[12].stop();
        clip[13].play();
        stop();
      }
      
      currentimg = nekopics[(xp + 1)*2 + (isJump ? 0 : step)];
      can.repaint();
      powmeter.repaint();
      pause(50);
     }
  }

  int floorlocation(int i)
  {
    return (int)(Math.random()*4)*16 + ((i%4)/2)*80 + (i%2)*160 + 16;
  }

  int isfloor()
  {
    for (int i = 0; i < 12; i++)
      if (xpos+4 < objxpos[i]+(objsign[i] == 0 ? 96 : 384) && xpos+28 > objxpos[i] && ypos-yp*2+32 < objypos[i]+1 && ypos+33 > objypos[i])
        return i;
    return -1;
  }

  void floorup(int v)
  {
    int prescr;
    
    for (int i = 0; i < 14; i++) {
      if (objsign[i] == 2) {
        if ((objypos[i] + v) >= 0)
          objypos[i] = objypos[i] + v - 32;
        else
          objypos[i] = objypos[i] + v;
      } else {
        if ((objypos[i] + v) >= 352) {
          prescr = scr;
          scr = (scr + 1) % 4;
          objsign[i] = 0;
          objxpos[i] = floorlocation(scr);
          objypos[i] = objypos[i] + v - 384;
          if (prescr == 3 && scr == 0)
            fln.plus();
        } else
          objypos[i] = objypos[i] + v;
      }		
    }
  }

  void pause(int time) {
    try { Thread.sleep(time); }
    catch (InterruptedException e) { }
  }
  
  public boolean action(Event evt, Object arg) {
    if (evt.target instanceof Button)
      if (arg == "START") {
        stop();
        start();
      }
    return true;
  }
}

class MainScreen extends Canvas {

  Image offscreenImg;
  Graphics offscreenG;
  boolean isScroll = false;
  int prexpos = 16;
  int preypos = 288;
  Nstower outerparent;
  
  MainScreen(Nstower nst) {
    this.outerparent = nst;
    setBackground(Color.black);
  }
 
    public void update(Graphics g) {
    paint(g);
  }

  public void paint(Graphics g) {
    if (isScroll) {
      g.setColor(getBackground());
      g.fillRect(0, 0, 416, 352);
      g.setColor(getForeground());
      for (int i = 0; i < 14; i++)
        g.drawImage(outerparent.nekopics[21 + outerparent.objsign[i]], outerparent.objxpos[i], outerparent.objypos[i], this);
      isScroll = false;
    } else {
      offscreenG.setColor(getBackground());
      offscreenG.fillRect(0, 0, 32, 32);
      offscreenG.setColor(getForeground());
      for (int i = 0; i < 12; i++)
        if (prexpos < outerparent.objxpos[i]+96 && prexpos+32 > outerparent.objxpos[i] && preypos < outerparent.objypos[i]+16 && preypos+32 > outerparent.objypos[i])
          offscreenG.drawImage(outerparent.nekopics[21 + outerparent.objsign[i]], outerparent.objxpos[i] - prexpos, outerparent.objypos[i] - preypos, this);
      offscreenG.drawImage(outerparent.currentimg, outerparent.xpos - prexpos, outerparent.ypos - preypos,this);
      g.drawImage(offscreenImg, prexpos, preypos,this);
    }
    g.drawImage(outerparent.currentimg, outerparent.xpos, outerparent.ypos,this);
    prexpos = outerparent.xpos; preypos = outerparent.ypos;
  }

  public boolean mouseDown(Event evt, int x, int y) {
    outerparent.isMouse = true;
    return true;
  }

  public boolean mouseUp(Event evt, int x, int y) {
  outerparent.isMouse = false;
    if (outerparent.isJump == false) {
      outerparent.yp = - outerparent.pow;
      outerparent.isJump = true;
      outerparent.clip[15].play();
    }
    return true;
  }
}

class PowerMeter extends Canvas {
  Nstower outerparent;

  PowerMeter (Nstower nst) {
    this.outerparent = nst;
    setBackground(Color.black);
  }

  public void update(Graphics g) {
    paint(g);
  }

  public void paint(Graphics g) {
    if (outerparent.isMouse) {
      g.drawImage(outerparent.nekopics[8 + outerparent.pow], 32, 8, this);
    }
  }
}

class FloorNumber extends Canvas {
  Nstower outerparent;
  int flnum = 1;
  Font f = new Font("TimesRoman", Font.BOLD, 36);
  Color c = new Color(127, 255, 127);
  String s = new String();

  FloorNumber (Nstower nst) {
    this.outerparent = nst;
    setBackground(Color.black);
  }

  public void plus() {
    flnum++;
    repaint();
  }

  public void paint(Graphics g) {
    g.setFont(f);
    g.setColor(c);
    s = "000" + String.valueOf(flnum) + "F";
    g.drawString(s.substring(s.length() - 5, s.length()), 8, 28);
  }
}
  













インターネットスタートページ 鈴木維一郎 石橋三重子
        
         
               
                   


©2000 kg-group Inc.