Selasa, 04 Mei 2010

TUTORIAL GAME DARTS

Nama : Aristo Oktobrian (50407155)
 
Pada pertemuan kali ini, saya akan menerangkan tentang code-code dalam pembuatan game Darts dan tahap-tahap pembuatannya.
Game Darts ini merupakan jenis game yang mengutamakan ketepatan dalam melemparkan anak panah/biduk panah.
Pada tahap pertama kali adalah membuat source code untuk membangun struktur pada game ini :

package darts;
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * This is the main class of the mini games.
 *
 * @author Jeremiah McLeod
 */
public class darts extends MIDlet implements CommandListener {



  private Command myExitCommand = new Command("Exit", Command.EXIT, 99);

  private Command myPauseCommand = new Command("Pause", Command.SCREEN, 1);
 
  private Command myGoCommand = new Command ("Go",Command.SCREEN, 1);
 
  private Command myNewGameCommand = new Command ("New Game",Command.SCREEN,1);
 
  private long pauseTime;
 
 
   //* the the canvas that all of the game will be drawn on.
   //*/
 
  dartsCanvas myDartsCanvas;
 
 
  /**
   * the thread that advances the animation
   */
  GameThread myGameThread;

  //-----------------------------------------------------
  //    initialization and game state changes

  /**
   * Initialize the canvas and the commands.
   */
  public darts () {
    pauseTime=0;
          myDartsCanvas = new dartsCanvas(this);
          myDartsCanvas.addCommand(myExitCommand);
              myDartsCanvas.addCommand(myNewGameCommand);
              myDartsCanvas.setCommandListener(this);
   
  }

 
 
  //----------------------------------------------------------------
  //  implementation of MIDlet

  /**
   * Start the application.
   */
  public void startApp() throws MIDletStateChangeException {
    myGameThread = new GameThread(myDartsCanvas);
    myDartsCanvas.start();
  
    myGameThread.go();


  }

  /**
   * stop and throw out the garbage.
   */
  public void destroyApp(boolean unconditional)
      throws MIDletStateChangeException {
    myGameThread.requestStop();
    myGameThread = null;
    myDartsCanvas=null;
    System.gc();
  }

  public void pauseApp() {

    myGameThread.pause();
  }

public void setMyPauseCommand () {
    myDartsCanvas.removeCommand (myNewGameCommand);
    myDartsCanvas.addCommand (myPauseCommand);


}


public void setMyGoCommand () {

myDartsCanvas.removeCommand (myPauseCommand);
myDartsCanvas.addCommand (myGoCommand);

}

public void setMyNewGameCommand () {
    myDartsCanvas.removeCommand (myPauseCommand);
    myDartsCanvas.addCommand (myNewGameCommand);

}
  //----------------------------------------------------------------
  //  implementation of CommandListener

  /*
   * Respond to a command issued on the Canvas.
   */
  public void commandAction(Command c, Displayable s) {
    int p,t;

 

   if (c == myExitCommand) {
      try {
    destroyApp(false);
    notifyDestroyed();
      } catch (MIDletStateChangeException ex) {
      }
    }
 
    else if (c==myGoCommand) {
        myDartsCanvas.paused=false;
          myDartsCanvas.removeCommand(myGoCommand);
          myDartsCanvas.addCommand(myPauseCommand);
          myDartsCanvas.pausedAbouted=false;

    }
  
    else if (c==myPauseCommand) {
    pauseTime=System.currentTimeMillis();
        myDartsCanvas.paused=true;
        myDartsCanvas.removeCommand (myPauseCommand);
        myDartsCanvas.addCommand (myGoCommand);
  
  }
  else if (c==myNewGameCommand) {
          myDartsCanvas.newGame();

  }//if mynewgame
}//commandlistener

Setelah itu buat gambar papan sasaran Darts tersebut seperti ini :

 
Setelah semua disusun maka tampilan dari game ini yaitu :




0 komentar:

Posting Komentar