SlideShare a Scribd company logo
1 of 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, 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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 },
{ 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
                                   ี

More Related Content

What's hot

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
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام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
 

What's hot (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
 

Viewers also liked

J2 Me Mobile Application
J2 Me Mobile ApplicationJ2 Me Mobile Application
J2 Me Mobile ApplicationImranahmed_19
 
Session10 J2ME Record Management System
Session10 J2ME Record Management SystemSession10 J2ME Record Management System
Session10 J2ME Record Management Systemmuthusvm
 
Session11 J2ME Record Management System
Session11 J2ME Record Management SystemSession11 J2ME Record Management System
Session11 J2ME Record Management Systemmuthusvm
 
Session11 J2ME Record Management System Database
Session11 J2ME Record Management System DatabaseSession11 J2ME Record Management System Database
Session11 J2ME Record Management System Databasemuthusvm
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Session11 J2ME MID-Low Level User Interface(LLUI)-graphics
Session11 J2ME MID-Low Level User Interface(LLUI)-graphicsSession11 J2ME MID-Low Level User Interface(LLUI)-graphics
Session11 J2ME MID-Low Level User Interface(LLUI)-graphicsmuthusvm
 
Session8 J2ME Low Level User Interface
Session8 J2ME Low Level User InterfaceSession8 J2ME Low Level User Interface
Session8 J2ME Low Level User Interfacemuthusvm
 
Session6 J2ME High Level User Interface(HLUI) part1
Session6 J2ME High Level User Interface(HLUI) part1Session6 J2ME High Level User Interface(HLUI) part1
Session6 J2ME High Level User Interface(HLUI) part1muthusvm
 
Java 7 Language Enhancement
Java 7 Language EnhancementJava 7 Language Enhancement
Java 7 Language Enhancementmuthusvm
 
Session5 J2ME High Level User Interface(HLUI) part1
Session5 J2ME High Level User Interface(HLUI) part1Session5 J2ME High Level User Interface(HLUI) part1
Session5 J2ME High Level User Interface(HLUI) part1muthusvm
 
Session12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection FrameworkSession12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection Frameworkmuthusvm
 
Session13 J2ME Timer
Session13  J2ME TimerSession13  J2ME Timer
Session13 J2ME Timermuthusvm
 
Session9 J2ME Record Management System
Session9 J2ME Record Management SystemSession9 J2ME Record Management System
Session9 J2ME Record Management Systemmuthusvm
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedAhsanul Karim
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
Session7 J2ME High Level User Interface(HLUI) part1-2
Session7 J2ME High Level User Interface(HLUI) part1-2Session7 J2ME High Level User Interface(HLUI) part1-2
Session7 J2ME High Level User Interface(HLUI) part1-2muthusvm
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewAhsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedAhsanul Karim
 

Viewers also liked (20)

Android architecture
Android architectureAndroid architecture
Android architecture
 
J2 Me Mobile Application
J2 Me Mobile ApplicationJ2 Me Mobile Application
J2 Me Mobile Application
 
Session10 J2ME Record Management System
Session10 J2ME Record Management SystemSession10 J2ME Record Management System
Session10 J2ME Record Management System
 
Session11 J2ME Record Management System
Session11 J2ME Record Management SystemSession11 J2ME Record Management System
Session11 J2ME Record Management System
 
Session11 J2ME Record Management System Database
Session11 J2ME Record Management System DatabaseSession11 J2ME Record Management System Database
Session11 J2ME Record Management System Database
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Session11 J2ME MID-Low Level User Interface(LLUI)-graphics
Session11 J2ME MID-Low Level User Interface(LLUI)-graphicsSession11 J2ME MID-Low Level User Interface(LLUI)-graphics
Session11 J2ME MID-Low Level User Interface(LLUI)-graphics
 
Session8 J2ME Low Level User Interface
Session8 J2ME Low Level User InterfaceSession8 J2ME Low Level User Interface
Session8 J2ME Low Level User Interface
 
Session6 J2ME High Level User Interface(HLUI) part1
Session6 J2ME High Level User Interface(HLUI) part1Session6 J2ME High Level User Interface(HLUI) part1
Session6 J2ME High Level User Interface(HLUI) part1
 
Java 7 Language Enhancement
Java 7 Language EnhancementJava 7 Language Enhancement
Java 7 Language Enhancement
 
Session5 J2ME High Level User Interface(HLUI) part1
Session5 J2ME High Level User Interface(HLUI) part1Session5 J2ME High Level User Interface(HLUI) part1
Session5 J2ME High Level User Interface(HLUI) part1
 
Session12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection FrameworkSession12 J2ME Generic Connection Framework
Session12 J2ME Generic Connection Framework
 
Session13 J2ME Timer
Session13  J2ME TimerSession13  J2ME Timer
Session13 J2ME Timer
 
Session9 J2ME Record Management System
Session9 J2ME Record Management SystemSession9 J2ME Record Management System
Session9 J2ME Record Management System
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting Started
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
Session7 J2ME High Level User Interface(HLUI) part1-2
Session7 J2ME High Level User Interface(HLUI) part1-2Session7 J2ME High Level User Interface(HLUI) part1-2
Session7 J2ME High Level User Interface(HLUI) part1-2
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick Overview
 
Android programming
Android programmingAndroid programming
Android programming
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
 

Similar to Mobile Game and Application with J2ME - Collision Detection

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
 
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
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview민태 김
 

Similar to Mobile Game and Application with J2ME - Collision Detection (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
 
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
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview
 

More from 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 Lec02
Introduction to On-line Documemt  Lec02Introduction to On-line Documemt  Lec02
Introduction to On-line Documemt Lec02Jenchoke 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
 
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 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08Jenchoke 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
 

More from Jenchoke Tachagomain (20)

Digital Transformation
Digital TransformationDigital Transformation
Digital Transformation
 
Lect 08 Css
Lect 08 CssLect 08 Css
Lect 08 Css
 
Lect07 Page Design
Lect07 Page DesignLect07 Page Design
Lect07 Page Design
 
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 Lec02
Introduction to On-line Documemt  Lec02Introduction to On-line Documemt  Lec02
Introduction to On-line Documemt Lec02
 
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
 
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
 
Lab 2 For Css
Lab 2 For CssLab 2 For Css
Lab 2 For Css
 
Rss
RssRss
Rss
 
Digital Content Business
Digital Content BusinessDigital Content Business
Digital Content Business
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
 
การพัฒนาเอกสารออนไลน์ขั้นสูง 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
 

Mobile Game and Application with J2ME - Collision Detection

  • 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, 0, 0, 0 }, { 0, 0, 4, 2, 2, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 4, 5, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 4, 4, 4, 0, 0, 0, 0, 5, 2, 2, 2, 2, 5, 5, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 2, 5, 3, 0, 0, 0, 2 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2 }, { 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 4, 5 }, { 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, 4, 4, 3, 0, 0, 0, 0, 2, 2, 4 }, { 5, 2, 2, 0, 0, 0, 5, 4, 5, 2, 2, 5, 5, 3, 0, 0, 0, 0, 2, 4 }, { 5, 4, 2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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, 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, 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 ี