public static void Update() { // StateGameplay.changeState(StateGameplay.STATE_WINLOSE); switch (stateInGamePlay) { case STATE_IDE: int col = -1; if (StateGameplay.gameMode == 1 || isUserStep) { if (GameLib.isTouchReleaseInRect( BEGIN_X, DEF.BUTTON_IGM_W + 10, BEGIN_X + MAX_COL * ITEM_WIDTH, StateGameplay.SCREEN_HEIGHT)) { col = (GameLib.arraytouchPosX[0] - BEGIN_X) / ITEM_WIDTH; } } else { // col = NewStep1(); // col = NewStep2(); if (StateGameplay.gameDifficult == 0) col = NewStep1(); else if (StateGameplay.gameDifficult == 0) col = NewStep2(); else col = NewStep3(); // col = random.nextInt(MAX_COL); } if (col < MAX_COL && col > -1) { for (int i = MAX_ROW - 1; i >= 0; i--) { if (tableArray[i][col].value == -1) { stateInGamePlay = STATE_DROP; if (isUserStep) tableArray[i][col].value = 0; else tableArray[i][col].value = 1; tableArray[i][col].state = DiamondActor.STATE_DROP; tableArray[i][col].m_x = BEGIN_X + col * ITEM_WIDTH; tableArray[i][col].m_y = 0; tableArray[i][col].targetX = BEGIN_X + col * ITEM_WIDTH; tableArray[i][col].targetY = BEGIN_Y + i * ITEM_HEIGHT; break; } } } break; case STATE_DROP: if (timeEffect++ < 7) break; boolean completeState = true; for (int i = 0; i < MAX_ROW; i++) for (int j = 0; j < MAX_COL; j++) { tableArray[i][j].update(); if (tableArray[i][j].state != DiamondActor.STATE_IDE) { completeState = false; // break; } } if (completeState) { stateInGamePlay = STATE_IDE; // check win } break; } }
public static synchronized boolean loadLayerBG(String path) throws IOException, XmlPullParserException { // listBitmap = new ArrayList<Bitmap>(); // listBitmap.clear(); String directorystr = path.substring(0, path.lastIndexOf("/")); Log.e("Directory : ", directorystr); XmlPullParser xrp = null; InputStream istr = GameLib.mainView.getContext().getAssets().open(path); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(false); xrp = factory.newPullParser(); xrp.setInput(istr, "UTF-8"); if (arrayListBitmap != null) { arrayListBitmap.clear(); } if (arrayListDataMap != null) { arrayListDataMap.clear(); } arrayListBitmap = new ArrayList<Bitmap>(); arrayListDataMap = new ArrayList<int[][]>(); arrayListAObject = new ArrayList<Actor>(); int eventType = 0; eventType = xrp.getEventType(); String tagName = ""; Actor object = null; while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_DOCUMENT: break; case XmlPullParser.START_TAG: tagName = xrp.getName(); if (tagName.equals("map")) { MAX_TILE_COLUMN = Integer.parseInt(xrp.getAttributeValue(null, "width")); MAX_TILE_ROW = Integer.parseInt(xrp.getAttributeValue(null, "height")); TILE_WIDTH = Integer.parseInt(xrp.getAttributeValue(null, "tilewidth")); TILE_HEIGHT = Integer.parseInt(xrp.getAttributeValue(null, "tileheight")); MAP_WIDTH_PIXEL = MAX_TILE_COLUMN * TILE_WIDTH; MAP_HEIGHT_PIXEL = MAX_TILE_ROW * TILE_HEIGHT; } else if (tagName.equals("tileset")) { if (xrp.getAttributeValue(null, "name").equals("physic")) { PHYSIC_INT_NUM_BEGIN = Integer.parseInt(xrp.getAttributeValue(null, "firstgid")) - 1; } } else if (tagName.equals("image")) { Bitmap tempBitmap = GameLib.loadImageFromAsset( directorystr + "/" + xrp.getAttributeValue(null, "source")); int lenBitmapArrayrow = (tempBitmap.getHeight() / TILE_HEIGHT); int lenBitmapArraycol = (tempBitmap.getWidth() / TILE_WIDTH); // arrayBitmap = new // Bitmap[lenBitmapArrayrow*lenBitmapArraycol]; Log.d("lenBitmapArrayrow:", " " + lenBitmapArrayrow); Log.d("lenBitmapArraycol:", " " + lenBitmapArraycol); for (int row = 0; row < lenBitmapArrayrow; row++) { for (int col = 0; col < lenBitmapArraycol; col++) { arrayListBitmap.add( Bitmap.createBitmap( tempBitmap, col * TILE_WIDTH, row * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null, false)); // here } } tempBitmap = null; } else if (tagName.equals("object")) { // <object name="doorright" type="door" x="1374" y="569" // width="47" height="61"> // object = new Actor(); String NAME = xrp.getAttributeValue(null, "name"); String TYPE = xrp.getAttributeValue(null, "type"); int m_x = Integer.parseInt(xrp.getAttributeValue(null, "x")); int m_y = Integer.parseInt(xrp.getAttributeValue(null, "y")); int m_Width = Integer.parseInt(xrp.getAttributeValue(null, "width")); int m_Height = Integer.parseInt(xrp.getAttributeValue(null, "height")); object = Actor.createActor(m_x, m_y, m_Width, m_Height, NAME, TYPE); } else if (tagName.equals("property")) { String name = xrp.getAttributeValue(null, "name"); if (name.equals("level")) { String value = xrp.getAttributeValue(null, "value"); } } break; case XmlPullParser.TEXT: // Log.d("text", xrp.getText()); if (tagName.equals("data")) { int[][] tempArray = new int[MAX_TILE_ROW][MAX_TILE_COLUMN]; String str = xrp.getText(); if (str.charAt(0) == '\n') str = str.substring(1); String[] strArray = str.split("\n"); String[] strTempInt; // = str.split("\n"); for (int row = 0; row < MAX_TILE_ROW; row++) { strTempInt = strArray[row].split(","); for (int col = 0; col < MAX_TILE_COLUMN; col++) { // tempArray[row][col] = new int(); int num = Integer.parseInt(strTempInt[col]); tempArray[row][col] = (num - 1); } } tagName = " "; arrayListDataMap.add(tempArray); } break; case XmlPullParser.END_TAG: tagName = xrp.getName(); if (tagName.equals("object")) { if (object != null) arrayListAObject.add(object); } tagName = " "; break; } eventType = xrp.next(); } return true; }