j2me to achieve classic case of people moving, one-dimensional array to achieve – iteye technology website
August 1, 2011
j2me people move to implement the classic case study
/ / bottom of the screen class package com.canvas.image02; import java.io.IOException; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; public class ExCanvas extends Canvas {/ / used to achieve one-dimensional array of images of people walking around public Image imbg; / / background Image public Image imPlayer; / / images of people / / define action figures based on the direction of the image array public int upImage [] = {12, 13, 14, 15}; / / the public int downImage [] = {0, 1, 2 , 3}; / / The following public int leftImage [] = {4, 5, 6, 7}; / / left public int rightImage [] = {8, 9, 10, 11}; / / right / / initialization character of the current frame public int nowPlayer = 0; / / define the character direction: public static final int DIR_UP = 1; / / the public static final int DIR_DOWN = 2; / / The following public static final int DIR_LEFT = 3; / / left public static final int DIR_RIGHT = 4; / / Right public static final int DIR_STOP = -1; / / stop / / initialize the first character in the direction public int dir = DIR_STOP; / / initialize the character coordinates public int px = 80, py = 80; / / create the content type of the thread: class Mythread extends Thread {public void run () {while (true) {if (dir> = 1