#ff0000 25  2005 . - #000655    .  6
#000655 TiledLayer.     
#0000ff  Carol Hamer 
#00ff00  Tumbleweed
#def     Tumbleweed.java:
package net.frog_parrot.jump;

import java.util.Random;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

/**
 *    ,    .
 *
 * @ Carol Hamer
 */
public class Tumbleweed extends Sprite {

  //---------------------------------------------------------
  //    

  /**
   *  .
   */
  static int WIDTH = 16;

  /**
   *   .
   */
  Random myRandom = new Random();

  /**
   *     .
   *    .
   */
  boolean myJumpedOver;

  /**
   *     .
   */
  boolean myLeft;

  /**
   * Y  .
   */
  int myY;

  //---------------------------------------------------------
  //   

  /**
   *     .
   *  left      .
   */
  public Tumbleweed(boolean left) throws Exception {
    super(Image.createImage("/icons/tumbleweed.png"), 
   WIDTH, WIDTH);
    myY = JumpManager.DISP_HEIGHT - WIDTH - 2;
    myLeft = left;
    if(!myLeft) {
      setTransform(TRANS_MIRROR);
    }
    myJumpedOver = false;
    setVisible(false);
  }

  //---------------------------------------------------------
  //   

  /**
   *      .
   */
  void reset() {
    setVisible(false);
    myJumpedOver = false;
  }

  /**
   *     .
   *  left     
   *     
   */
  int advance(Cowboy cowboy, int tickCount, boolean left,
       int currentLeftBound, int currentRightBound) {
    int retVal = 0;
    //      ,
    //     .
    if((getRefPixelX() + WIDTH <= currentLeftBound) || 
       (getRefPixelX() - WIDTH >= currentRightBound)) {
      setVisible(false);
    } 
    //      
    //      1  100   .
    if(!isVisible()) {
      int rand = getRandomInt(100);
      if(rand == 3) {
 //     ,  
 //     
 myJumpedOver = false;
 setVisible(true);
 //    
 if(myLeft) {
   setRefPixelPosition(currentRightBound, myY);
   move(-1, 0);
 } else {
   setRefPixelPosition(currentLeftBound, myY);
   move(1, 0);
 }
      }
    } else {
      //         .
      if(tickCount % 2 == 0) { // slow the animation down a little
 nextFrame();
      }
      if(myLeft) {
 move(-3, 0);
 //    ,    
 //   myJumpedOver  true,    
 //      
 if((! myJumpedOver) && 
    (getRefPixelX() < cowboy.getRefPixelX())) {
   myJumpedOver = true;
   retVal = cowboy.increaseScoreThisJump();
 }
      } else {
 move(3, 0);
 if((! myJumpedOver) && 
    (getRefPixelX() > cowboy.getRefPixelX() + Cowboy.WIDTH)) {
   myJumpedOver = true;
   retVal = cowboy.increaseScoreThisJump();
 }
      }
    }
    return(retVal);
  }

  /**
   *      0  100
   */
  public int getRandomInt(int upper) {
    int retVal = myRandom.nextInt() % upper;
    if(retVal < 0) {
      retVal += upper;
    }
    return(retVal);
  }

}
   ,  TiledLayers    Sprite,
  ,  TiledLayer     ,
      . 
     TiledLayer, 
  ,   .
!    Sprite   0,   TiledLayer
 1.      (   
   Sprite,    , 
,        TiledLayer.).
        .  
TiledLayer  0    (     
0,       ). Sprite     ,
        ,   
   .     
setVisible(false).       
  .      ,
          
   .   ,  TiledLayer      (tile)      Sprite.
    TiledLayer-      
   .       , 
     .     .        . 
 ()      .
-        , 
      
setCell(int col, int row, int tileIndex).  tileIndex  
    Sprite    .   ,
     ,   
 .      
createAnimatedTile(int staticTileIndex),    
 .       ,
 ,         ,  
      .  
         ,
  ,     .     Grass (  ).            -      ,      .         setAnimatedTile(int animatedTileIndex, int staticTileIndex).       .    ,      animatedTileIndex   
    staticTileIndex.    
       
 (  Grass.advance(int tickCount) 
 ).
package net.frog_parrot.jump;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

/**
 *       .
 *
 * @ Carol Hamer
 */
public class Grass extends TiledLayer {

  //---------------------------------------------------------
  //     

  /**
   *  .
   */
  static int TILE_WIDTH = 20;

  /**
   * ,     
   */
  static int[] FRAME_SEQUENCE = { 2, 3, 2, 4 };

  /**
   *     
   */
  static int COLUMNS;

  /**
   *      
   */
  static int CYCLE = 5;

  /**
   * Y  .
   */
  static int TOP_Y;

  //---------------------------------------------------------
  //    

  /**
   *   .
   */
  int mySequenceIndex = 0;

  /**
   * ,        
   *  .
   */
  int myAnimatedTileIndex;

  //---------------------------------------------------------
  //   gets / sets

  /**
   *        .
   */
  static int setColumns(int screenWidth) {
    COLUMNS = ((screenWidth / 20) + 1)*3;
    return(COLUMNS);
  }

  //---------------------------------------------------------
  //   

  /**
   *    .
   */
  public Grass() throws Exception {
    super(setColumns(JumpCanvas.DISP_WIDTH), 1, 
   Image.createImage("/icons/grass.png"), 
   TILE_WIDTH, TILE_WIDTH);
    TOP_Y = JumpManager.DISP_HEIGHT - TILE_WIDTH;
    setPosition(0, TOP_Y);
    myAnimatedTileIndex = createAnimatedTile(2);
    for(int i = 0; i < COLUMNS; i++) {
      if((i % CYCLE == 0) || (i % CYCLE == 2)) {
 setCell(i, 0, myAnimatedTileIndex);
      } else {
 setCell(i, 0, 1);
      }
    }
  }

  //---------------------------------------------------------
  //   

  /**
   *     ..
   */
  void reset() {
    setPosition(-(TILE_WIDTH*CYCLE), TOP_Y);
mySequenceIndex = 0;
    setAnimatedTile(myAnimatedTileIndex, FRAME_SEQUENCE[mySequenceIndex]);
  }

  /**
   *  ..
   */
  void advance(int tickCount) {
    if(tickCount % 2 == 0) { // slow the animation down a little
      mySequenceIndex++;
      mySequenceIndex %= 4;
      setAnimatedTile(myAnimatedTileIndex, FRAME_SEQUENCE[mySequenceIndex]);
    }
  }

}
  
,           
.    ,     jar .
(    J2ME ,   
  ,      
 .)   ,       jar
.     cowboy.png    grass.png  
  icons  jar ,   
Layer   ,     :
Image.createImage("/icons/grass.png"), .    
     MANIFEST.MF.    .
MIDlet-1: Hello World, /icons/hello.png, net.frog_parrot.hello.Hello
MIDlet-2: Tumbleweed, /icons/boot.png, net.frog_parrot.jump.Jump
MMIDlet-Description: Example games for MIDP
MIDlet-Name: Example Games
MIDlet-Permissions: 
MIDlet-Vendor: frog-parrot.net
MIDlet-Version: 2.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
,       jar    
 ,     
 m.
,    jar ,   jad .   
 jump.jad,   :
MIDlet-1: Hello, /icons/hello.png, net.frog_parrot.hello.Hello
MIDlet-2: Tumbleweed, /icons/boot.png, net.frog_parrot.jump.Jump
MMIDlet-Description: Example games for MIDP
MIDlet-Jar-URL: jump.jar
MIDlet-Name: Example Games
MIDlet-Permissions: 
MIDlet-Vendor: frog-parrot.net
MIDlet-Version: 2.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
MIDlet-Jar-Size: 17259
   jad  ,     , 
MIDlet-Jar-Size  .  ,   jad 
  : /icons/boot.png.    
  jar .
  jar  jad  ,    . 
        runmidlet, 
   WTK2.0.
       !
 :  
         .
    bin      WTK2.0.
  ./bin/emulator    jad  
.       :
./bin/emulator -Xdescriptor:/home/carol/j2me/book/ch02/bin/games.jad
     WTK2.0   D.
      MIDlet-Jar-Size  jad
 .        jar
.
        ,  
    :    
  bin(   ,    jad ),
tempclasses (  ), classes (  images    )  scr (   
).
#      
#    .
#     javac   :
JAVA4_HOME=/usr/java/j2sdk1.4.0_01/bin
#  ,   WTK2.0
WTK2_HOME=../../../../WTK2.0

echo "clear directories"
#   
rm ../tmpclasses/net/frog_parrot/hello/*.class
rm ../classes/net/frog_parrot/hello/*.class
rm ../tmpclasses/net/frog_parrot/jump/*.class
rm ../classes/net/frog_parrot/jump/*.class

echo "Compiling source files"

$JAVA4_HOME/javac -bootclasspath $WTK2_HOME/lib/midpapi.zip -
d ../tmpclasses -classpath ../tmpclasses ../src/net/frog_parrot/hello/*.java 
../src/net/frog_parrot/jump/*.java

echo "Preverifying class files"

$WTK2_HOME/bin/preverify -classpath $WTK2_HOME/lib/midpapi.zip:
../tmpclasses -d ../classes ../tmpclasses

echo "Jarring preverified class files"
$JAVA4_HOME/jar cmf MANIFEST.MF jump.jar -C ../classes .

echo "Updating JAR size info in JAD file..."

NB=`wc -l jump.jad | awk '{print $1}'`
head --lines=$(($NB-1)) jump.jad > jump.jad1
echo "MIDlet-Jar-Size:" `stat -c '%s' jump.jar`>> jump.jad1
cp jump.jad1 jump.jad
         .  , 
       /dev/null.   
     ,   >/dev/null  
.
 :   Gimp
   ?      ,   .        Gimp.  
 : http://www.gimp.org/download.html.    .
           .            .
#0000ff : Alex.
#ff0000          : http://www.mobilab.ru