SlideShare ist ein Scribd-Unternehmen logo
1 von 36
J2ME
Mobile games
āļāļēāļĢāļ•āļĢāļ§āļˆāļžāļšāļāļēāļĢāļāļĢāļ°āļ—āļšāļāļąāļ™
   (Collision Detection)
āđ€āļ›āđ‡āļ™āļ§āļīāļ˜āļĩāļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļšāļ§āđˆāļē āļŠāđ„āļ›āļĢāļ•āđŒ (Sprite) āđ€āļ„āļĨāļ·āđˆāļ­āļ™āļ—āļĩāđˆ
āļāļĢāļ°āļ—āļšāļāļąāļš āļŠāđ„āļ›āļĢāļ•āđŒ (Sprite) āļ•āļąāļ§āļ­āļ·āđˆāļ™āļŦāļĢāļ·āļ­āđ„āļĄāđˆ
āļĄāļĩāļ›āļĢāļ°āđ‚āļĒāļŠāļ™āđŒāļĄāļēāļāđƒāļ™āļāļēāļĢāļ™āļģāļēāđ„āļ›āđƒāļŠāđ‰āļāļąāļšāļ āļēāļžāđ€āļ„āļĨāļ·āđˆāļ­āļ™āđ„āļŦāļ§
āļ‚āļ­āļ‡āđ€āļāļĄāļŠāđŒ āđāļ•āđˆāļĨāļ°āļŠāđ„āļ›āļĢāļ•āđŒ (Sprite) āļˆāļ°āļĄāļĩāļ‚āļ­āļšāđ€āļ‚āļ•āđ€āļ›āđ‡āļ™
āļŠāļĩāđ€āļŦāļĨāļĩāđˆāļĒāļĄāļĄāļļāļĄāļ‰āļēāļ āļšāļēāļ‡āļŠāđˆāļ§āļ™āļ‚āļ­āļ‡āļ āļēāļžāļˆāļ°āđ‚āļ›āļĢāđˆāļ‡āđāļŠāļ‡
  āđˆ
āđ€āļĄāļ·āđˆāļ­āđ€āļ„āļĨāļ·āđˆāļ­āļ™āļ—āļĩāđˆāļāļĢāļ°āļ—āļšāļāļąāļ™āļˆāļ°āļ—āļģāļēāđƒāļŦāđ‰āļĄāļļāļĄāļ‚āļ­āļ‡āļŠāļĩāđ€āļŦāļĨāļĩāđˆāļĒāļĄ
                                       āđˆ
āļĄāļļāļĄāļ‰āļēāļāđ€āļŦāļĨāļ·āđˆāļ­āļĄāļĨāļģāļģāļēāļāļąāļ™ āļ—āļģāļēāđƒāļŦāđ‰āļ•āļĢāļ§āļˆāļžāļšāđ„āļ”āđ‰āļ—āļąāļ™āļ—āļĩāļ§āđˆāļēāļĄāļĩ
āļāļēāļĢāļāļĢāļ°āļ—āļšāļāļąāļ™
Collision Detection
   ( āļ‡ Work space āļŠāļ·āđˆāļ­ Sprite)
ïŪ āļŠāļĢāđ‰āļēSprite Vs Collision
ïŪ āļŠāļĢāđ‰āļēāļ‡   J2ME Class āļŠāļ·āļ­
                       āđˆ
    SpriteCollideMIDlet.java
ïŪ āļŠāļĢāđ‰āļēāļ‡ GameCanvas āđ‚āļ”āļĒāđƒāļŦāđ‰āđāļŠāļ”āļ‡ sprite āļŠāļ­āļ‡
  āļ•āļąāļ§
ïŪ āļŦāļēāļ sprite āļŠāļ™ āļ­āļĩāļāļ•āļąāļ§ āđƒāļŦāđ‰āļŦāļĒāļļāļ”āđ€āļ”āļīāļ™
SpriteCollideMIDlet.java
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
public class SpriteCollideMIDlet extends MIDlet {

SpriteCollideCanvas canvas = new SpriteCollideCanvas();
public SpriteCollideMIDlet() {}
protected void destroyApp(boolean arg0) throws
  MIDletStateChangeException {}
protected void pauseApp() {}
protected void startApp() throws MIDletStateChangeException
       {
               Display display = Display.getDisplay(this);
               canvas.start();
               display.setCurrent(canvas);

      }
}
class SpriteCollideCanvas extends GameCanvas implements Runnable {

  static int FRONT_DIRECTION = 0;
  static int LEFT_DIRECTION = 1;
  static int RIGHT_DIRECTION = 2;
  static int BACK_DIRECTION = 3;
  Sprite hero,hero2;
  boolean running;
  int[][] sequence = {{0,1,2,3},            //front
                        {4,5,6,7},          //left
                        {8,9,10,11},        //right
                        {12,13,14,15}};     //back
  int s2[] ={8,9,10,11};
  int w, h;
  Image img_bg = null;
  int cx,cy,cx2,cy2;
  int currentDirection = FRONT_DIRECTION;
protected SpriteCollideCanvas() {
  super(true);
  Image im = null, hm2 = null;
  try {
               im = Image.createImage("/sprites/c1.png");
               hm2 = Image.createImage("/sprites/c4.png");
               img_bg = Image.createImage("/world/roundedbg.png");

       } catch (IOException e) {}

       hero = new Sprite(im,32,48);
       hero2 = new Sprite(hm2,32,48);
       w = getWidth();
       h = getHeight();
       cx = w/2;
       cy = h/2;
       hero.setFrameSequence(sequence[0]);
       hero2.setFrameSequence(s2);
}
public void start(){
      running = true;
      Thread t = new Thread(this);
      t.start();
}
public void run() {
      Graphics g = getGraphics();
      int delay = 100;
      while(running) {
              moving();
              getInput();
              hero2.nextFrame();
              drawScreen(g);
              try {Thread.sleep(delay);}
              catch (InterruptedException e) {}
      }
}
void moving() {
    if (cx2 > getWidth()) {
           cx2 = 0;
    }
    if ( ! hero2.collidesWith(hero, false))
    cx2++;
}
void getInput(){
   int keyState = getKeyStates();
   int cDirection = currentDirection; // then we know current direction
        if(keyState== LEFT_PRESSED) {
                 if( ! hero.collidesWith(hero2, false)) {
                          cx = cx - 5; cx = Math.max (0, cx);
                          currentDirection= LEFT_DIRECTION;
                 } hero.nextFrame();
        } else if(keyState== RIGHT_PRESSED){
                 cx = cx + 5; cx = Math.min (cx, w-32);
                 currentDirection= RIGHT_DIRECTION;
                 hero.nextFrame();
        } else if(keyState== UP_PRESSED) {
                 cy = cy - 5; cy = Math.max (0, cy);
                 currentDirection= BACK_DIRECTION;
                 hero.nextFrame();
        } else if(keyState== DOWN_PRESSED){
                 cy = cy + 5; cy = Math.min(cy, h - 50);
                 currentDirection= FRONT_DIRECTION;
                 hero.nextFrame();
        }
        if(cDirection != currentDirection){
                 hero.setFrameSequence(sequence[currentDirection]);
        }
void drawScreen(Graphics g){
        g.drawImage(img_bg, 0 - cx,0 - cy, Graphics.TOP | Graphics.LEFT);
        hero2.setPosition(cx2, cy2 + 20);
        hero2.paint(g);
        hero.setPosition(cx, cy);
        hero.paint(g);
        flushGraphics();
    }
}
LayerManager
LayerManager methods
void append(Layer l)
Layer getLayerAt(int index)
int  getSize()
void insert(Layer l, int index)
void paint(Graphics g, int x, int y)
void remove(Layer l)
void setViewWindow(int x, int y, int w, int h)

** leyer āļ—āđˆāļĩ append āļāđˆāļ­āļ™ āļˆāļ°āļ­āļĒāđˆāđˆāļ”āđ‰āļēāļ™āļšāļ™āļŠāļļāļ”
LayerManager and Scrolling
            background
ïŪ Idea āļ‚āļ­āļ‡āļāļēāļĢāļ—āļģāļē scrolling background āļ„āļ·āļ­āđƒāļŠāđ‰
  method setViewWindow(sx,sy,w,h)
ïŪ āđ‚āļ”āļĒ sx, sy āļ„āļ·āļ­āļ•āļģāļēāđāļŦāļ™āđˆ āļ‡ viewpoint āļšāļ™
  background āļ—āđˆāļ•āđ‰āļ­āļ‡āļāļēāļĢāđāļŠāļ”āļ‡āļšāļ™ screen.
                 āļĩ
LayerManager
ïŪ   āļŠāļĢāđ‰āļēāļ‡ work space āļŠāļ·āļ­ LayerManagerDemo
                       āđˆ
ïŪ āļŠāļĢāđ‰āļēāļ‡J2ME Class āļŠāļ·āđˆāļ­
 LayerManagerMIDlet.java
āđ‚āļ”āļĒ āļĄāļĩāļ•āļąāļ§ Sprite āđ€āļ›āđ‡āļ™ hero 2 āļ•āļąāļ§āđāļĨāļ°āļĄāļĩ Sprite 1
 āļ•āļąāļ§āđ€āļ›āđ‡āļ™ background
āđāļĨāļ°āđƒāļŦāđ‰āđƒāļŠāđ‰āļŠāļ‡ setViewWindow āđƒāļ™āļāļēāļĢāđ€āļĨāļ·āļ­āļ™āļŦāļ™āđ‰āļē
          āļą
 āļˆāļ­āđ„āļ›āļ‹āđ‰āļēāļĒāđāļĨāļ°āļ‚āļēāļ§
LayerManagerMIDlet.java
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;

public class LayerManagerMIDlet extends MIDlet {
  CanvasLayerManager canvas = new CanvasLayerManager ();
public LayerManagerMIDlet() {}
protected void destroyApp(boolean arg0) throws
  MIDletStateChangeException {}
protected void pauseApp() {}
protected void startApp() throws MIDletStateChangeException {
        Display display = Display.getDisplay(this);
        canvas.start();
        display.setCurrent(canvas);
  }
}
class CanvasLayerManager extends
  GameCanvas implements Runnable {
         Sprite hero;
         Sprite hero2;
         Sprite bg;
         boolean running;
         LayerManager layerManager;
         int sx,sy;
protected CanvasLayerManager() {
        super(true);
        Image img_boy = null;
        Image img_man = null;
        Image img_bg = null;
        try {
               img_boy = Image.createImage("/res/boy.png");
               img_man = Image.createImage("/res/man.png");
               img_bg = Image.createImage("/res/bg.jpg");
        } catch (IOException e) {}
hero = new Sprite(img_boy,img_boy.getWidth()/4,img_boy.getHeight()/4);
hero2 = new
   Sprite(img_man,img_man.getWidth()/4,img_man.getHeight()/4);

       bg = new Sprite(img_bg);
       layerManager = new LayerManager();
       layerManager.append(hero);
       layerManager.append(hero2);
       layerManager.append(bg);
}
public void start() {
      running = true;
      Thread t = new Thread(this);
      t.start();
}
public void run() {
      Graphics g = getGraphics();
      int delay = 50;
      while(running){
              input();
              drawScreen(g);
              try {
                     Thread.sleep(delay);
                     } catch (InterruptedException e) {
              e.printStackTrace();
              }
  }
}
private void input() {
        int keyState = getKeyStates();
        if(keyState== LEFT_PRESSED){
               sx = sx - 5;
               }else if(keyState== RIGHT_PRESSED){
                       sx = sx + 5;
               }
    }
    private void drawScreen(Graphics g) {
        int w = getWidth();
        int h = getHeight();
        hero.setPosition(w/2 + sx, h/2 );
        hero2.setPosition(w/2 + 50, h/2 - 20);
        bg.setPosition(-50, -50);
        layerManager.setViewWindow(sx,sy,w,h);
        layerManager.paint(g,0,0);
        flushGraphics();
    }
}
āđƒāļŠāđ‰ TiledLayer āļ—āļģāļē background
TiledLayer
TiledLayer

map[] ={
4,5,5,5,5,5,5,4,4,4,
4,5,5,5,5,5,5,5,5,4,
4,5,5,5,2,2,5,5,5,4,
4,5,5,5,2,2,5,5,5,4,
4,4,5,5,2,2,5,5,5,4,
4,4,4,5,5,2,2,2,5,4,
1,1,3,3,5,5,2,2,5,4,
3,1,3,3,3,5,5,5,5,4,
3,1,1,3,3,3,5,5,1,1,
3,3,1,1,1,1,1,1,1,3,
3,3,3,3,3,3,3,3,3,3}
āļŠāļĢāđ‰āļēāļ‡āđāļœāļ™āļ—āļĩāđˆ (world)
ïŪ   āđ€āļĢāļēāļŠāļēāļĄāļēāļĢāļ–āļŠāļĢāđ‰āļēāļ‡ world āļŦāļĢāļ·āļ­ map āđ‚āļ”āļĒāđƒāļŠāđ‰
    Mappy win32
āļœāļĨāļˆāļēāļ export text file āđƒāļ™āļĢāļđāļ›āđāļšāļš array

  const short mymap_map0[10][10] = {
  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
  { 2, 4, 4, 4, 4, 4, 4, 4, 4, 2 },
  { 2, 4, 4, 3, 5, 5, 5, 3, 4, 2 },
  { 2, 5, 4, 3, 3, 3, 5, 3, 4, 2 },
  { 2, 1, 4, 4, 4, 3, 5, 3, 4, 2 },
  { 2, 1, 1, 1, 4, 3, 5, 3, 4, 2 },
  { 2, 1, 1, 1, 4, 3, 3, 3, 4, 2 },
  { 2, 1, 1, 1, 4, 3, 3, 3, 4, 2 },
  { 2, 1, 1, 1, 4, 4, 5, 4, 4, 2 },
  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }};
āļāļēāļĢāđƒāļŠāđ‰āļ‡āļēāļ™ TiledLayer
TiledLayer background, land;
       int[][] map = {
       { 5, 5, 5, 4, 4, 4, 5, 5, 5, 2, 2, 2, 2, 2, 5, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
       { 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 2, 5, 2,
       2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2 },
       { 5, 5, 5, 5, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}

background = new TiledLayer(30, 30, img_bg,
  img_bg.getWidth()/5,img_bg.getHeight());

background.setCell(i, j, map[i][j]);
TiledLayerMIDlet
ïŪ āđƒāļŦāđ‰āļŠāļĢāđ‰āļēāļ‡ work space āļŠāļ·āļ­āļ§āđˆāļē TiledLayerDemo
                          āđˆ
ïŪ āđƒāļŦāđ‰āļŠāļĢāđ‰āļēāļ‡ J2ME Class āļŠāļ·āļ­āļ§āđˆāļē
                        āđˆ
   TiledLayerMIDlet.java




āđƒāļŠāđ‰ TiledLayer āļ—āļģāļē background
TiledLayerMIDlet.java
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;

public class TiledLayerMIDlet extends MIDlet {
  CanvasTiledLayer canvas = new CanvasTiledLayer();
  public TiledLayerMIDlet() {}
  protected void destroyApp(boolean arg0) throws
  MIDletStateChangeException {}
  protected void pauseApp() {}
  protected void startApp() throws MIDletStateChangeException {
       Display display = Display.getDisplay(this);
       canvas.start();
       display.setCurrent(canvas);
  }
}
class CanvasTiledLayer extends GameCanvas implements
  Runnable {
      static int FRONT_DIRECTION = 0;
      static int LEFT_DIRECTION = 1;
      static int RIGHT_DIRECTION = 2;
      static int BACK_DIRECTION = 3;
      Sprite ship;
      TiledLayer waster, land;
      LayerManager layerManager;
      int w, h;
      int cx,cy;
      int currentDirection = FRONT_DIRECTION;
      boolean running;
      int[][] sequence = {{0,1,2,3},       //front
                           {4,5,6,7},      //left
                           {8,9,10,11},    //right
                           {12,13,14,15}}; //back
int[][] obstruction_land = {
{ 2, 2, 0, 0, 0, 0, 0, 0, 0, 4, 4, 2, 2, 2, 2, 5, 0, 0, 2, 2 },
{ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 2, 2, 5, 5, 0, 0, 0, 2 },
{ 0, 0, 0, 2, 4, 0, 0, 0, 0, 0, 0, 3, 2, 5, 3, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 2, 5, 5, 3, 0, 0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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }};
protected CanvasTiledLayer() {
super(true);
Image img_ship = null; Image img_bg = null;
w = getWidth(); h = getHeight(); cx = w/2; cy = h/2;
         try {
                   img_ship = Image.createImage("/res/Ship.png");
                   img_bg = Image.createImage("/res/bgtiles.png");
         } catch (IOException e) {}
   ship = new Sprite(img_ship,img_ship.getWidth()/4,img_ship.getHeight()/4);
   land = new TiledLayer(20, 20, img_bg, img_bg.getWidth()/5,img_bg.getHeight());
   waster = new TiledLayer(20, 20, img_bg,
   img_bg.getWidth()/5,img_bg.getHeight());
   for (int i = 0; i < 20;i++) {
         for (int j = 0; j <20;j++) {
                   land.setCell(i, j, obstruction_land[i][j]); }}
   for (int i = 0; i < 20;i++) {
         for (int j = 0; j < 20;j++) {
                   waster.setCell(i, j, waster_map[i][j]); }}
         ship.setFrameSequence(sequence[0]);
         layerManager = new LayerManager();
         layerManager.append(ship); layerManager.append(land);
         layerManager.append(waster);
}
public void run() {
   Graphics g = getGraphics();
   int delay = 100;
   while(running){
                 getInput();
                 drawScreen(g);
                 try {Thread.sleep(delay);} catch (InterruptedException e) {}
   }
}
void drawScreen(Graphics g) {
        int w = getWidth();
        int h = getHeight();
        int xpoint = 120;
        int ypoint = 70;
        g.setColor(0);
        g.fillRect(0, 0, w, h);
   ship.setPosition((w/2) + xpoint + (cx /2) - 12, (h/2)+ ypoint + (cy/2) - 24 );
   layerManager.paint(g, -(xpoint) - (cx/2) , -(ypoint) - (cy/2));
   g.setColor(255,255,255);
   g.drawString(" ["+cx+","+cy+"]", 0, getHeight()- 20, g.TOP | g.LEFT);
   flushGraphics();
}
void getInput() {
int keyState = getKeyStates();
int cDirection = currentDirection;
       if(keyState== LEFT_PRESSED){
              currentDirection= LEFT_DIRECTION;
              if(!ship.collidesWith(land, true)){
                      cx = cx - 10;
              } else {cx = cx + 20;}
              ship.nextFrame();
       }
       else if(keyState== RIGHT_PRESSED){
              currentDirection= RIGHT_DIRECTION;
              if(!ship.collidesWith(land, true)){
              cx = cx + 10;
              } else {cx = cx - 20;}
              ship.nextFrame();
}
else if (keyState== UP_PRESSED) {
       currentDirection= BACK_DIRECTION;
              if(!ship.collidesWith(land, true)){
                      cy = cy - 10;
              }else{cy = cy + 20;}
              ship.nextFrame();
       }
       else if(keyState== DOWN_PRESSED){
              currentDirection= FRONT_DIRECTION;
              if(!ship.collidesWith(land, true)){
                      cy = cy + 10;
              }else{cy = cy - 20;}
              ship.nextFrame();
              }
       if(cDirection != currentDirection){
       ship.setFrameSequence(sequence[currentDirection]);
       }
}
public void start() {
      running = true;
      Thread t = new Thread(this);
      t.start();
    }
}
āđāļ™āļ°āļ™āļģāļēāļŦāļ™āļąāļ‡āļŠāļ·āļ­ J2ME
ïŪ āļŠāļĢāđ‰āļēāļ‡āđ€āļāļĄāđāļĨāļ°āđ‚āļ›āļĢāđāļāļĢāļĄāļ”āđ‰āļ§āļĒ J2ME āļ„āļļāļ“āļāđ‡āļ—āļģāļēāđ„āļ”āđ‰
ïŪ āđ€āļ‚āļĩāļĒāļ™āđ€āļāļĄāđāļĨāļ°āđ‚āļ›āļĢāđāļāļĢāļĄāđāļšāļšāļĄāļ·āļ­āļ–āļ·āļ­ J2ME + CD
ïŪ J2ME āļ„āđˆāđˆāļĄāļ·āļ­āļŠāļģāļēāļŦāļĢāļąāļšāđ€āļĢāđˆāļĄāļ•āđ‰āļ™ āļžāļąāļ’āļ™āļēāļˆāļēāļ§āļēāļšāļ™āļĄāļ·āļ­
                       āļī
ïŪ āđ€āļāđˆāļ‡ J2ME āđƒāļŦāđ‰āļ„āļĢāļšāļŠāđˆāļ•āļĢ + CD
ïŪ āđ€āļ‚āļĩāļĒāļ™āđ‚āļ›āļĢāđāļāļĢāļĄāļšāļ™āđ‚āļ—āļĢāļĻāļąāļžāļ—āđŒāđ€āļ„āļĨāđˆ āļ·āļ­āļ™āļ—āđˆāļ”āđ‰āļ§āļĒ J2ME
                                   āļĩ

Weitere ÃĪhnliche Inhalte

Was ist angesagt?

Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineersvarun arora
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmKapil Pandit
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautifulmonikagupta18jan
 
Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…
Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…
Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…Aram Jamal
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202Mahmoud Samir Fayed
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneBhavesh Shah
 
Hypercritical C++ Code Review
Hypercritical C++ Code ReviewHypercritical C++ Code Review
Hypercritical C++ Code ReviewAndrey Karpov
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconftutorialsruby
 
Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1Raphael Marques
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slidesMitchell Wand
 

Was ist angesagt? (19)

Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
OOXX
OOXXOOXX
OOXX
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithm
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…
Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…
Ų…Ø§ØŠØąÛŽÚĐØģ ØĻŲ‡â€Œ ÚĐŲˆØąØŊی ØĶØ§ØąØ§Ų…
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
662305 LAB12
662305 LAB12662305 LAB12
662305 LAB12
 
Graphics point clipping c program
Graphics point clipping c programGraphics point clipping c program
Graphics point clipping c program
 
Hypercritical C++ Code Review
Hypercritical C++ Code ReviewHypercritical C++ Code Review
Hypercritical C++ Code Review
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 

Andere mochten auch

āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Intro
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ IntroāļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Intro
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ IntroJenchoke Tachagomain
 
Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4Jenchoke Tachagomain
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision DetectionJenchoke Tachagomain
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08Jenchoke Tachagomain
 
Introduction to On-line Documemt Lec02
Introduction to On-line Documemt  Lec02Introduction to On-line Documemt  Lec02
Introduction to On-line Documemt Lec02Jenchoke Tachagomain
 

Andere mochten auch (9)

āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Intro
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ IntroāļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Intro
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Intro
 
Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
Lect07 Page Design
Lect07 Page DesignLect07 Page Design
Lect07 Page Design
 
Android programming
Android programmingAndroid programming
Android programming
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 08
 
Introduction to On-line Documemt Lec02
Introduction to On-line Documemt  Lec02Introduction to On-line Documemt  Lec02
Introduction to On-line Documemt Lec02
 
Lab 2 For Css
Lab 2 For CssLab 2 For Css
Lab 2 For Css
 
Android architecture
Android architectureAndroid architecture
Android architecture
 

Ähnlich wie Mobile Game and Application with J2ME

Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfapexcomputer54
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfanjandavid
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfanyacarpets
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfanwarsadath111
 
Creating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdfCreating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdfShaiAlmog1
 
Mashup caravan android-talks
Mashup caravan android-talksMashup caravan android-talks
Mashup caravan android-talkshonjo2
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212Mahmoud Samir Fayed
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxTashiBhutia12
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Palak Sanghani
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfarcotstarsports
 
Creating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdfCreating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdfShaiAlmog1
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfanithareadymade
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overviewëŊžíƒœ ęđ€
 

Ähnlich wie Mobile Game and Application with J2ME (20)

Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 
Aditazz 01-ul
Aditazz 01-ulAditazz 01-ul
Aditazz 01-ul
 
Creating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdfCreating an Uber Clone - Part VIII.pdf
Creating an Uber Clone - Part VIII.pdf
 
Mashup caravan android-talks
Mashup caravan android-talksMashup caravan android-talks
Mashup caravan android-talks
 
MIDP: Game API
MIDP: Game APIMIDP: Game API
MIDP: Game API
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 
Clock For My
Clock For MyClock For My
Clock For My
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
 
Creating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdfCreating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdf
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdf
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview
 

Mehr von Jenchoke Tachagomain

Introduction to On-line Documemt Lect05 Web Process
Introduction to On-line Documemt  Lect05 Web ProcessIntroduction to On-line Documemt  Lect05 Web Process
Introduction to On-line Documemt Lect05 Web ProcessJenchoke Tachagomain
 
Introduction to On-line Documemt Lect03 E Commerce
Introduction to On-line Documemt  Lect03 E CommerceIntroduction to On-line Documemt  Lect03 E Commerce
Introduction to On-line Documemt Lect03 E CommerceJenchoke Tachagomain
 
Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3Jenchoke Tachagomain
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09Jenchoke Tachagomain
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07Jenchoke Tachagomain
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06Jenchoke Tachagomain
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05Jenchoke Tachagomain
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04Jenchoke Tachagomain
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03Jenchoke Tachagomain
 

Mehr von Jenchoke Tachagomain (20)

Digital Transformation
Digital TransformationDigital Transformation
Digital Transformation
 
Lect 08 Css
Lect 08 CssLect 08 Css
Lect 08 Css
 
Lect06 Web Design
Lect06 Web DesignLect06 Web Design
Lect06 Web Design
 
Introduction to On-line Documemt Lect05 Web Process
Introduction to On-line Documemt  Lect05 Web ProcessIntroduction to On-line Documemt  Lect05 Web Process
Introduction to On-line Documemt Lect05 Web Process
 
Introduction to On-line Documemt Lect03 E Commerce
Introduction to On-line Documemt  Lect03 E CommerceIntroduction to On-line Documemt  Lect03 E Commerce
Introduction to On-line Documemt Lect03 E Commerce
 
Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3
 
Rss
RssRss
Rss
 
Digital Content Business
Digital Content BusinessDigital Content Business
Digital Content Business
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 09
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 07
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 06
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 05
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 04
 
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03
āļāļēāļĢāļžāļąāļ’āļ™āļēāđ€āļ­āļāļŠāļēāļĢāļ­āļ­āļ™āđ„āļĨāļ™āđŒāļ‚āļąāđ‰āļ™āļŠāļđāļ‡ Lect 03
 
Communication Concept
Communication ConceptCommunication Concept
Communication Concept
 
Communication Concept 3
Communication Concept 3Communication Concept 3
Communication Concept 3
 
Communication Concept
Communication ConceptCommunication Concept
Communication Concept
 
Communication Concept
Communication ConceptCommunication Concept
Communication Concept
 
J2ME Game Concept
J2ME  Game ConceptJ2ME  Game Concept
J2ME Game Concept
 
J2ME Game Concept
J2ME  Game ConceptJ2ME  Game Concept
J2ME Game Concept
 

Mobile Game and Application with J2ME

  • 2. āļāļēāļĢāļ•āļĢāļ§āļˆāļžāļšāļāļēāļĢāļāļĢāļ°āļ—āļšāļāļąāļ™ (Collision Detection) āđ€āļ›āđ‡āļ™āļ§āļīāļ˜āļĩāļāļēāļĢāļ•āļĢāļ§āļˆāļŠāļ­āļšāļ§āđˆāļē āļŠāđ„āļ›āļĢāļ•āđŒ (Sprite) āđ€āļ„āļĨāļ·āđˆāļ­āļ™āļ—āļĩāđˆ āļāļĢāļ°āļ—āļšāļāļąāļš āļŠāđ„āļ›āļĢāļ•āđŒ (Sprite) āļ•āļąāļ§āļ­āļ·āđˆāļ™āļŦāļĢāļ·āļ­āđ„āļĄāđˆ āļĄāļĩāļ›āļĢāļ°āđ‚āļĒāļŠāļ™āđŒāļĄāļēāļāđƒāļ™āļāļēāļĢāļ™āļģāļēāđ„āļ›āđƒāļŠāđ‰āļāļąāļšāļ āļēāļžāđ€āļ„āļĨāļ·āđˆāļ­āļ™āđ„āļŦāļ§ āļ‚āļ­āļ‡āđ€āļāļĄāļŠāđŒ āđāļ•āđˆāļĨāļ°āļŠāđ„āļ›āļĢāļ•āđŒ (Sprite) āļˆāļ°āļĄāļĩāļ‚āļ­āļšāđ€āļ‚āļ•āđ€āļ›āđ‡āļ™ āļŠāļĩāđ€āļŦāļĨāļĩāđˆāļĒāļĄāļĄāļļāļĄāļ‰āļēāļ āļšāļēāļ‡āļŠāđˆāļ§āļ™āļ‚āļ­āļ‡āļ āļēāļžāļˆāļ°āđ‚āļ›āļĢāđˆāļ‡āđāļŠāļ‡ āđˆ āđ€āļĄāļ·āđˆāļ­āđ€āļ„āļĨāļ·āđˆāļ­āļ™āļ—āļĩāđˆāļāļĢāļ°āļ—āļšāļāļąāļ™āļˆāļ°āļ—āļģāļēāđƒāļŦāđ‰āļĄāļļāļĄāļ‚āļ­āļ‡āļŠāļĩāđ€āļŦāļĨāļĩāđˆāļĒāļĄ āđˆ āļĄāļļāļĄāļ‰āļēāļāđ€āļŦāļĨāļ·āđˆāļ­āļĄāļĨāļģāļģāļēāļāļąāļ™ āļ—āļģāļēāđƒāļŦāđ‰āļ•āļĢāļ§āļˆāļžāļšāđ„āļ”āđ‰āļ—āļąāļ™āļ—āļĩāļ§āđˆāļēāļĄāļĩ āļāļēāļĢāļāļĢāļ°āļ—āļšāļāļąāļ™
  • 3. Collision Detection ( āļ‡ Work space āļŠāļ·āđˆāļ­ Sprite) ïŪ āļŠāļĢāđ‰āļēSprite Vs Collision ïŪ āļŠāļĢāđ‰āļēāļ‡ J2ME Class āļŠāļ·āļ­ āđˆ SpriteCollideMIDlet.java ïŪ āļŠāļĢāđ‰āļēāļ‡ GameCanvas āđ‚āļ”āļĒāđƒāļŦāđ‰āđāļŠāļ”āļ‡ sprite āļŠāļ­āļ‡ āļ•āļąāļ§ ïŪ āļŦāļēāļ sprite āļŠāļ™ āļ­āļĩāļāļ•āļąāļ§ āđƒāļŦāđ‰āļŦāļĒāļļāļ”āđ€āļ”āļīāļ™
  • 4. SpriteCollideMIDlet.java import java.io.IOException; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import javax.microedition.midlet.*; public class SpriteCollideMIDlet extends MIDlet { SpriteCollideCanvas canvas = new SpriteCollideCanvas(); public SpriteCollideMIDlet() {} protected void destroyApp(boolean arg0) throws MIDletStateChangeException {} protected void pauseApp() {} protected void startApp() throws MIDletStateChangeException { Display display = Display.getDisplay(this); canvas.start(); display.setCurrent(canvas); } }
  • 5. class SpriteCollideCanvas extends GameCanvas implements Runnable { static int FRONT_DIRECTION = 0; static int LEFT_DIRECTION = 1; static int RIGHT_DIRECTION = 2; static int BACK_DIRECTION = 3; Sprite hero,hero2; boolean running; int[][] sequence = {{0,1,2,3}, //front {4,5,6,7}, //left {8,9,10,11}, //right {12,13,14,15}}; //back int s2[] ={8,9,10,11}; int w, h; Image img_bg = null; int cx,cy,cx2,cy2; int currentDirection = FRONT_DIRECTION;
  • 6. protected SpriteCollideCanvas() { super(true); Image im = null, hm2 = null; try { im = Image.createImage("/sprites/c1.png"); hm2 = Image.createImage("/sprites/c4.png"); img_bg = Image.createImage("/world/roundedbg.png"); } catch (IOException e) {} hero = new Sprite(im,32,48); hero2 = new Sprite(hm2,32,48); w = getWidth(); h = getHeight(); cx = w/2; cy = h/2; hero.setFrameSequence(sequence[0]); hero2.setFrameSequence(s2); }
  • 7. public void start(){ running = true; Thread t = new Thread(this); t.start(); } public void run() { Graphics g = getGraphics(); int delay = 100; while(running) { moving(); getInput(); hero2.nextFrame(); drawScreen(g); try {Thread.sleep(delay);} catch (InterruptedException e) {} } }
  • 8. void moving() { if (cx2 > getWidth()) { cx2 = 0; } if ( ! hero2.collidesWith(hero, false)) cx2++; }
  • 9. void getInput(){ int keyState = getKeyStates(); int cDirection = currentDirection; // then we know current direction if(keyState== LEFT_PRESSED) { if( ! hero.collidesWith(hero2, false)) { cx = cx - 5; cx = Math.max (0, cx); currentDirection= LEFT_DIRECTION; } hero.nextFrame(); } else if(keyState== RIGHT_PRESSED){ cx = cx + 5; cx = Math.min (cx, w-32); currentDirection= RIGHT_DIRECTION; hero.nextFrame(); } else if(keyState== UP_PRESSED) { cy = cy - 5; cy = Math.max (0, cy); currentDirection= BACK_DIRECTION; hero.nextFrame(); } else if(keyState== DOWN_PRESSED){ cy = cy + 5; cy = Math.min(cy, h - 50); currentDirection= FRONT_DIRECTION; hero.nextFrame(); } if(cDirection != currentDirection){ hero.setFrameSequence(sequence[currentDirection]); }
  • 10. void drawScreen(Graphics g){ g.drawImage(img_bg, 0 - cx,0 - cy, Graphics.TOP | Graphics.LEFT); hero2.setPosition(cx2, cy2 + 20); hero2.paint(g); hero.setPosition(cx, cy); hero.paint(g); flushGraphics(); } }
  • 12. LayerManager methods void append(Layer l) Layer getLayerAt(int index) int getSize() void insert(Layer l, int index) void paint(Graphics g, int x, int y) void remove(Layer l) void setViewWindow(int x, int y, int w, int h) ** leyer āļ—āđˆāļĩ append āļāđˆāļ­āļ™ āļˆāļ°āļ­āļĒāđˆāđˆāļ”āđ‰āļēāļ™āļšāļ™āļŠāļļāļ”
  • 13. LayerManager and Scrolling background ïŪ Idea āļ‚āļ­āļ‡āļāļēāļĢāļ—āļģāļē scrolling background āļ„āļ·āļ­āđƒāļŠāđ‰ method setViewWindow(sx,sy,w,h) ïŪ āđ‚āļ”āļĒ sx, sy āļ„āļ·āļ­āļ•āļģāļēāđāļŦāļ™āđˆ āļ‡ viewpoint āļšāļ™ background āļ—āđˆāļ•āđ‰āļ­āļ‡āļāļēāļĢāđāļŠāļ”āļ‡āļšāļ™ screen. āļĩ
  • 14. LayerManager ïŪ āļŠāļĢāđ‰āļēāļ‡ work space āļŠāļ·āļ­ LayerManagerDemo āđˆ ïŪ āļŠāļĢāđ‰āļēāļ‡J2ME Class āļŠāļ·āđˆāļ­ LayerManagerMIDlet.java āđ‚āļ”āļĒ āļĄāļĩāļ•āļąāļ§ Sprite āđ€āļ›āđ‡āļ™ hero 2 āļ•āļąāļ§āđāļĨāļ°āļĄāļĩ Sprite 1 āļ•āļąāļ§āđ€āļ›āđ‡āļ™ background āđāļĨāļ°āđƒāļŦāđ‰āđƒāļŠāđ‰āļŠāļ‡ setViewWindow āđƒāļ™āļāļēāļĢāđ€āļĨāļ·āļ­āļ™āļŦāļ™āđ‰āļē āļą āļˆāļ­āđ„āļ›āļ‹āđ‰āļēāļĒāđāļĨāļ°āļ‚āļēāļ§
  • 15. LayerManagerMIDlet.java import java.io.IOException; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import javax.microedition.midlet.*; public class LayerManagerMIDlet extends MIDlet { CanvasLayerManager canvas = new CanvasLayerManager (); public LayerManagerMIDlet() {} protected void destroyApp(boolean arg0) throws MIDletStateChangeException {} protected void pauseApp() {} protected void startApp() throws MIDletStateChangeException { Display display = Display.getDisplay(this); canvas.start(); display.setCurrent(canvas); } }
  • 16. class CanvasLayerManager extends GameCanvas implements Runnable { Sprite hero; Sprite hero2; Sprite bg; boolean running; LayerManager layerManager; int sx,sy;
  • 17. protected CanvasLayerManager() { super(true); Image img_boy = null; Image img_man = null; Image img_bg = null; try { img_boy = Image.createImage("/res/boy.png"); img_man = Image.createImage("/res/man.png"); img_bg = Image.createImage("/res/bg.jpg"); } catch (IOException e) {} hero = new Sprite(img_boy,img_boy.getWidth()/4,img_boy.getHeight()/4); hero2 = new Sprite(img_man,img_man.getWidth()/4,img_man.getHeight()/4); bg = new Sprite(img_bg); layerManager = new LayerManager(); layerManager.append(hero); layerManager.append(hero2); layerManager.append(bg); }
  • 18. public void start() { running = true; Thread t = new Thread(this); t.start(); } public void run() { Graphics g = getGraphics(); int delay = 50; while(running){ input(); drawScreen(g); try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } }
  • 19. private void input() { int keyState = getKeyStates(); if(keyState== LEFT_PRESSED){ sx = sx - 5; }else if(keyState== RIGHT_PRESSED){ sx = sx + 5; } } private void drawScreen(Graphics g) { int w = getWidth(); int h = getHeight(); hero.setPosition(w/2 + sx, h/2 ); hero2.setPosition(w/2 + 50, h/2 - 20); bg.setPosition(-50, -50); layerManager.setViewWindow(sx,sy,w,h); layerManager.paint(g,0,0); flushGraphics(); } }
  • 23. āļŠāļĢāđ‰āļēāļ‡āđāļœāļ™āļ—āļĩāđˆ (world) ïŪ āđ€āļĢāļēāļŠāļēāļĄāļēāļĢāļ–āļŠāļĢāđ‰āļēāļ‡ world āļŦāļĢāļ·āļ­ map āđ‚āļ”āļĒāđƒāļŠāđ‰ Mappy win32
  • 24. āļœāļĨāļˆāļēāļ export text file āđƒāļ™āļĢāļđāļ›āđāļšāļš array const short mymap_map0[10][10] = { { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 4, 4, 4, 4, 4, 4, 4, 4, 2 }, { 2, 4, 4, 3, 5, 5, 5, 3, 4, 2 }, { 2, 5, 4, 3, 3, 3, 5, 3, 4, 2 }, { 2, 1, 4, 4, 4, 3, 5, 3, 4, 2 }, { 2, 1, 1, 1, 4, 3, 5, 3, 4, 2 }, { 2, 1, 1, 1, 4, 3, 3, 3, 4, 2 }, { 2, 1, 1, 1, 4, 3, 3, 3, 4, 2 }, { 2, 1, 1, 1, 4, 4, 5, 4, 4, 2 }, { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }};
  • 25. āļāļēāļĢāđƒāļŠāđ‰āļ‡āļēāļ™ TiledLayer TiledLayer background, land; int[][] map = { { 5, 5, 5, 4, 4, 4, 5, 5, 5, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 2, 5, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2 }, { 5, 5, 5, 5, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}} background = new TiledLayer(30, 30, img_bg, img_bg.getWidth()/5,img_bg.getHeight()); background.setCell(i, j, map[i][j]);
  • 26. TiledLayerMIDlet ïŪ āđƒāļŦāđ‰āļŠāļĢāđ‰āļēāļ‡ work space āļŠāļ·āļ­āļ§āđˆāļē TiledLayerDemo āđˆ ïŪ āđƒāļŦāđ‰āļŠāļĢāđ‰āļēāļ‡ J2ME Class āļŠāļ·āļ­āļ§āđˆāļē āđˆ TiledLayerMIDlet.java āđƒāļŠāđ‰ TiledLayer āļ—āļģāļē background
  • 27. TiledLayerMIDlet.java import java.io.IOException; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import javax.microedition.midlet.*; public class TiledLayerMIDlet extends MIDlet { CanvasTiledLayer canvas = new CanvasTiledLayer(); public TiledLayerMIDlet() {} protected void destroyApp(boolean arg0) throws MIDletStateChangeException {} protected void pauseApp() {} protected void startApp() throws MIDletStateChangeException { Display display = Display.getDisplay(this); canvas.start(); display.setCurrent(canvas); } }
  • 28. class CanvasTiledLayer extends GameCanvas implements Runnable { static int FRONT_DIRECTION = 0; static int LEFT_DIRECTION = 1; static int RIGHT_DIRECTION = 2; static int BACK_DIRECTION = 3; Sprite ship; TiledLayer waster, land; LayerManager layerManager; int w, h; int cx,cy; int currentDirection = FRONT_DIRECTION; boolean running; int[][] sequence = {{0,1,2,3}, //front {4,5,6,7}, //left {8,9,10,11}, //right {12,13,14,15}}; //back
  • 29. int[][] obstruction_land = { { 2, 2, 0, 0, 0, 0, 0, 0, 0, 4, 4, 2, 2, 2, 2, 5, 0, 0, 2, 2 }, { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 2, 2, 5, 5, 0, 0, 0, 2 }, { 0, 0, 0, 2, 4, 0, 0, 0, 0, 0, 0, 3, 2, 5, 3, 0, 0, 0, 0, 0 }, { 0, 0, 0, 2, 5, 5, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }};
  • 31. protected CanvasTiledLayer() { super(true); Image img_ship = null; Image img_bg = null; w = getWidth(); h = getHeight(); cx = w/2; cy = h/2; try { img_ship = Image.createImage("/res/Ship.png"); img_bg = Image.createImage("/res/bgtiles.png"); } catch (IOException e) {} ship = new Sprite(img_ship,img_ship.getWidth()/4,img_ship.getHeight()/4); land = new TiledLayer(20, 20, img_bg, img_bg.getWidth()/5,img_bg.getHeight()); waster = new TiledLayer(20, 20, img_bg, img_bg.getWidth()/5,img_bg.getHeight()); for (int i = 0; i < 20;i++) { for (int j = 0; j <20;j++) { land.setCell(i, j, obstruction_land[i][j]); }} for (int i = 0; i < 20;i++) { for (int j = 0; j < 20;j++) { waster.setCell(i, j, waster_map[i][j]); }} ship.setFrameSequence(sequence[0]); layerManager = new LayerManager(); layerManager.append(ship); layerManager.append(land); layerManager.append(waster); }
  • 32. public void run() { Graphics g = getGraphics(); int delay = 100; while(running){ getInput(); drawScreen(g); try {Thread.sleep(delay);} catch (InterruptedException e) {} } } void drawScreen(Graphics g) { int w = getWidth(); int h = getHeight(); int xpoint = 120; int ypoint = 70; g.setColor(0); g.fillRect(0, 0, w, h); ship.setPosition((w/2) + xpoint + (cx /2) - 12, (h/2)+ ypoint + (cy/2) - 24 ); layerManager.paint(g, -(xpoint) - (cx/2) , -(ypoint) - (cy/2)); g.setColor(255,255,255); g.drawString(" ["+cx+","+cy+"]", 0, getHeight()- 20, g.TOP | g.LEFT); flushGraphics(); }
  • 33. void getInput() { int keyState = getKeyStates(); int cDirection = currentDirection; if(keyState== LEFT_PRESSED){ currentDirection= LEFT_DIRECTION; if(!ship.collidesWith(land, true)){ cx = cx - 10; } else {cx = cx + 20;} ship.nextFrame(); } else if(keyState== RIGHT_PRESSED){ currentDirection= RIGHT_DIRECTION; if(!ship.collidesWith(land, true)){ cx = cx + 10; } else {cx = cx - 20;} ship.nextFrame(); }
  • 34. else if (keyState== UP_PRESSED) { currentDirection= BACK_DIRECTION; if(!ship.collidesWith(land, true)){ cy = cy - 10; }else{cy = cy + 20;} ship.nextFrame(); } else if(keyState== DOWN_PRESSED){ currentDirection= FRONT_DIRECTION; if(!ship.collidesWith(land, true)){ cy = cy + 10; }else{cy = cy - 20;} ship.nextFrame(); } if(cDirection != currentDirection){ ship.setFrameSequence(sequence[currentDirection]); } }
  • 35. public void start() { running = true; Thread t = new Thread(this); t.start(); } }
  • 36. āđāļ™āļ°āļ™āļģāļēāļŦāļ™āļąāļ‡āļŠāļ·āļ­ J2ME ïŪ āļŠāļĢāđ‰āļēāļ‡āđ€āļāļĄāđāļĨāļ°āđ‚āļ›āļĢāđāļāļĢāļĄāļ”āđ‰āļ§āļĒ J2ME āļ„āļļāļ“āļāđ‡āļ—āļģāļēāđ„āļ”āđ‰ ïŪ āđ€āļ‚āļĩāļĒāļ™āđ€āļāļĄāđāļĨāļ°āđ‚āļ›āļĢāđāļāļĢāļĄāđāļšāļšāļĄāļ·āļ­āļ–āļ·āļ­ J2ME + CD ïŪ J2ME āļ„āđˆāđˆāļĄāļ·āļ­āļŠāļģāļēāļŦāļĢāļąāļšāđ€āļĢāđˆāļĄāļ•āđ‰āļ™ āļžāļąāļ’āļ™āļēāļˆāļēāļ§āļēāļšāļ™āļĄāļ·āļ­ āļī ïŪ āđ€āļāđˆāļ‡ J2ME āđƒāļŦāđ‰āļ„āļĢāļšāļŠāđˆāļ•āļĢ + CD ïŪ āđ€āļ‚āļĩāļĒāļ™āđ‚āļ›āļĢāđāļāļĢāļĄāļšāļ™āđ‚āļ—āļĢāļĻāļąāļžāļ—āđŒāđ€āļ„āļĨāđˆ āļ·āļ­āļ™āļ—āđˆāļ”āđ‰āļ§āļĒ J2ME āļĩ