QuatschMIDlet.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 49KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 5
    下载次数
  • 2010-04-15 17:16
    上传日期
j2me game sample, include coalition detection and anemy moving
QuatschMIDlet.rar
  • QuatschMIDlet
  • bin
  • QuatschMIDlet.jar
    19.6KB
  • QuatschMIDlet.jad
    253B
  • MANIFEST.MF
    202B
  • res
  • Thumbs.db
    8.5KB
  • background_tiles.png
    12.5KB
  • quatsch.png
    1.4KB
  • atmosphere.png
    1.4KB
  • classes
  • QuatschMIDlet.class
    2.6KB
  • QuatschCanvas.class
    4.1KB
  • lib
  • tmpclasses
  • QuatschMIDlet.class
    2.5KB
  • QuatschCanvas.class
    3.8KB
  • src
  • QuatschCanvas.java
    5.4KB
  • QuatschMIDlet.java
    2.4KB
  • tmplib
  • project.properties
    47B
内容介绍
import java.io.IOException; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; public class QuatschCanvas extends GameCanvas implements Runnable { private boolean mTrucking; private LayerManager mLayerManager; private TiledLayer mAtmosphere; private TiledLayer mBackground; private int mAnimatedIndex; private Sprite mQuatsch; private int mState, mDirection; private static final int kStanding = 1; private static final int kRunning = 2; private static final int kLeft = 1; private static final int kRight = 2; private static final int[] kRunningSequence = { 0, 1, 2 }; private static final int[] kStandingSequence = { 3 }; public QuatschCanvas(String quatschImageName, String atmosphereImageName, String backgroundImageName) throws IOException { super(true); // Create a LayerManager. mLayerManager = new LayerManager(); int w = getWidth(); int h = getHeight(); mLayerManager.setViewWindow(96, 0, w, h); createBackground(backgroundImageName); createAtmosphere(atmosphereImageName); createQuatsch(quatschImageName); } private void createBackground(String backgroundImageName) throws IOException { // Create the tiled layer. Image backgroundImage = Image.createImage(backgroundImageName); int[] map = { 1, 2, 0, 0, 0, 0, 0, 0, 3, 3, 2, 0, 0, 0, 5, 0, 3, 3, 3, 2, 4, 1, 3, 2, 6, 6, 6, 6, 6, 6, 6, 6 }; mBackground = new TiledLayer(8, 4, backgroundImage, 48, 48); mBackground.setPosition(12, 0); for (int i = 0; i < map.length; i++) { int column = i % 8; int row = (i - column) / 8; mBackground.setCell(column, row, map[i]); } mAnimatedIndex = mBackground.createAnimatedTile(8); mBackground.setCell(3, 0, mAnimatedIndex); mBackground.setCell(5, 0, mAnimatedIndex); mLayerManager.append(mBackground); } private void createAtmosphere(String atmosphereImageName) throws IOException { // Create the atmosphere layer Image atmosphereImage = Image.createImage(atmosphereImageName); mAtmosphere = new TiledLayer(8, 1, atmosphereImage, atmosphereImage.getWidth(), atmosphereImage.getHeight()); mAtmosphere.fillCells(0, 0, 8, 1, 1); mAtmosphere.setPosition(0, 96); mLayerManager.insert(mAtmosphere, 0); } private void createQuatsch(String quatschImageName) throws IOException { // Create the sprite. Image quatschImage = Image.createImage(quatschImageName); mQuatsch = new Sprite(quatschImage, 48, 48); mQuatsch.setPosition(96 + (getWidth() - 48) / 2, 96); mQuatsch.defineReferencePixel(24, 24); setDirection(kLeft); setState(kStanding); mLayerManager.insert(mQuatsch, 1); } public void start() { mTrucking = true; Thread t = new Thread(this); t.start(); } public void run() { int w = getWidth(); int h = getHeight(); Graphics g = getGraphics(); int frameCount = 0; int factor = 2; int animatedDelta = 0; while (mTrucking) { if (isShown()) { int keyStates = getKeyStates(); if ((keyStates & LEFT_PRESSED) != 0) { setDirection(kLeft); setState(kRunning); mBackground.move(3, 0); mAtmosphere.move(3, 0); mQuatsch.nextFrame(); } else if ((keyStates & RIGHT_PRESSED) != 0) { setDirection(kRight); setState(kRunning); mBackground.move(-3, 0); mAtmosphere.move(-3, 0); mQuatsch.nextFrame(); } else { setState(kStanding); } frameCount++; if (frameCount % factor == 0) { int delta = 1; if (frameCount / factor < 10) delta = -1; mAtmosphere.move(delta, 0); if (frameCount / factor == 20) frameCount = 0; mBackground.setAnimatedTile(mAnimatedIndex, 8 + animatedDelta++); if (animatedDelta == 3) animatedDelta = 0; } g.setColor(0x5b1793); g.fillRect(0, 0, w, h); mLayerManager.paint(g, 0, 0); flushGraphics(); } try { Thread.sleep(80); } catch (InterruptedException ie) {} } } public void stop() { mTrucking = false; } public void setVisible(int layerIndex, boolean show) { Layer layer = mLayerManager.getLayerAt(layerIndex); layer.setVisible(show); } public boolean isVisible(int layerIndex) { Layer layer = mLayerManager.getLayerAt(layerIndex); return layer.isVisible(); } private void setDirection(int newDirection) { if (newDirection == mDirection) return; if (mDirection == kLeft) mQuatsch.setTransform(Sprite.TRANS_MIRROR); else if (mDirection == kRight) mQuatsch.setTransform(Sprite.TRANS_NONE); mDirection = newDirection; } private void setState(int newState) { if (newState == mState) return; switch (newState) { case kStanding: mQuatsch.setFrameSequence(kStandingSequence); mQuatsch.setFrame(0); break; case kRunning: mQuatsch.setFrameSequence(kRunningSequence); break; default: break; } mState = newState; } }
评论
    相关推荐
    • ZxingDemo.rar
      android上使用ZXing识别条形码和二维码,代码简单易懂,相信能帮助读者迅速掌握相关的开发
    • android-order-system.rar
      基于Java的android点餐系统--android手机点餐系统,实现基本点菜功能,供大家参考学习
    • MTK-MT6235-USB-driver-2009082823351054.rar
      MTK 6235 USB driver for Nokia N97
    • Mine.zip
      Android 扫雷游戏源代码,代码中附加了详细的注释,另附加Ophone游戏开发文档,有详细搭建开发环境过程,与开发Android类似
    • J2ME_(chinese)api.rar
      J2ME 中文api以及应用 J2ME 中文api以及应用
    • Gallery3D.rar
      安卓系统原生的3D图片浏览器源代码,有兴趣的可以研究一下
    • wpctsc.rar
      wpctsc.exe for windows mobile 可以使WM手机远程登入PC
    • Animation-J2ME.rar
      手机游戏中的动画和CG是怎么做的呢,这个源代码中给了清晰的讲解,此代码是手机游戏巨头智乐(gameloft)公司所使用的引擎,很值得学习
    • androidexample.rar
      androidexample有130多个实例,是现在国内最全的ANDROID实例代码库,希望对大家有用
    • ColorLinez.rar
      用J2ME写的一种五子连线的手机游戏。ColorLinez是一款由玩家通过功能键移动各色小球,把五个及五个以上相同颜色小球移成一横排、一竖列,小球从而消失的游戏,玩家每移动一个小球,就会随机新出现三个随机颜色的小球,小球消失的数量作为玩家得到的分数!