Code
Code
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- import javax.microedition.lcdui.game.GameCanvas;
- import java.io.IOException;
- public class bs extends MIDlet implements CommandListener {
- public myCanvas ggc = new myCanvas();
- public bs() { }
- protected void startApp()
- {
- ggc.start();
- Display.getDisplay(this).setCurrent(ggc);
- }
- protected void pauseApp()
- {
- }
- protected void destroyApp(boolean unconditional)
- {
- }
- public void commandAction(Command c, Displayable d)
- {
- }
- /******************************************
- ******************************************/
- class myCanvas extends GameCanvas implements Runnable {
- public Graphics graph = getGraphics();
- public bs BS;
- public boolean running;
- public Image[] mlvblocks, mptank;
- public Image lvlblocks, ptank, title;
- public myCanvas ggc;
- public Thread mthread;
- public int width, height;
- public myCanvas()
- {
- super(false);
- setFullScreenMode(true);
- try{
- if(lvlblocks == null) lvlblocks = Image.createImage("/bloks.png");
- if(ptank == null) ptank = Image.createImage("/p_tank.png");
- if (title == null) title = Image.createImage("/title.png");
- } catch(IOException ioe) {}
- running = true;
- }
- public void start()
- {
- Thread mthread = new Thread(this);
- mthread.start();
- }
- public void imagesPrepare()
- {
- }
- /* public final Image getImageRegion(Image source, int x, int y, int width, int
- height)
- {
- Image result = Image.createImage(width, height);
- result.getGraphics().drawImage(source, -x, -y, Graphics.TOP|Graphics.LEFT);
- return result;
- }
- public final Image[] extractFrames(Image sourceImage, int sourceX,
- int sourceY,
- int framesWide, int framesHigh,
- int frameWidth, int frameHeight)
- {
- Image[] frames = new Image[framesWide * framesHigh];
- int frameCount = 0;
- for (int fy = 0; fy < framesHigh; fy++)
- for (int fx = 0; fx < framesWide; fx++)
- frames[frameCount++] =
- getImageRegion(sourceImage, sourceX + (fx * frameWidth),
- sourceY + (fy * frameHeight),
- frameWidth, frameHeight);
- return frames;
- }
- */
- public void tsleep(long millisec)
- {
- try {
- mthread.sleep(millisec);
- } catch(InterruptedException ie) {}
- }
- /*
- private void spritesPrepare()
- {
- for(int i=1, ii=0; i<16; i+=1) {
- mlvblocks[i] = getImageRegion(lvlblocks, ii, 0, 16, 16);
- ii=+16;
- }
- mptank = extractFrames(ptank, 0, 0, 2, 1, 15, 15);
- }
- */
- public void painting()
- {
- graph.setColor(0x000000);
- graph.fillRect(0, 0, getWidth(), getHeight());
- graph.setColor(0xFFFFFF);
- }
- public void run()
- {
- painting();
- graph.drawImage(title, 15, 0, Graphics.TOP);
- while(running)
- {
- flushGraphics();
- tsleep(1000);
- }
- }
- }
- }