@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() != Sensor.TYPE_ROTATION_VECTOR) return; rotation -= event.values[1]; // it's dumb, just go with it. score.setText("" + rotation); bar.setRotation(rotation); ballX += rotation / 100; ball.setPosition(ballX, ball.getY()); }
public void addFace(final int pID, final float pX, final float pY) { final Scene scene = this.mEngine.getScene(); /* Create the face and add it to the scene. */ final Sprite face = new Sprite(0, 0, this.mFaceTextureRegion); face.setPosition(pX - face.getWidth() * 0.5f, pY - face.getHeight() * 0.5f); face.setUserData(pID); this.mFaces.put(pID, face); scene.registerTouchArea(face); scene.attachChild(face); }
public void moveFace(final int pID, final float pX, final float pY) { /* Find and move the face. */ final Sprite face = this.mFaces.get(pID); face.setPosition(pX - face.getWidth() * 0.5f, pY - face.getHeight() * 0.5f); }
public TowerUpgraderBack show(final Tower pTowerBase) { // Debug.i("TowerUpgrader :: show :: type=" + pTowerBase.getTowerType()); // disable tower interaction TowerManager.ENABLE_TOWER_INTERACTION = false; // set our current tower base mCurrentTowerBase = pTowerBase; // update our sell text mTowerSellText.setText(Integer.toString(pTowerBase.getTowerType().getCost())); // set our current row/col, make sure to account for our cancel + // sell button int currentCol = 0; int currentRow = 0; // find the coords final int[] coords = Registry.sMap.getCoordsFromTiles(pTowerBase.mTowerCol, pTowerBase.mTowerRow); // update the position mPositionMarker.setPosition(coords[0], coords[1]); mPositionMarker.setColor(1, 1, 1, 1.0f); // turn on updates and visibility mPositionMarker.setIgnoreUpdate(false); mPositionMarker.setVisible(true); // setup the radius marker mRadiusMarker.setIgnoreUpdate(false); mRadiusMarker.setVisible(true); mRadiusMarker.setWidth(pTowerBase.getTowerRange() * 2); mRadiusMarker.setHeight(pTowerBase.getTowerRange() * 2); // set the position of the marker mRadiusMarker.setPosition( (-pTowerBase.getTowerRange()) + (TowerManager.TOWER_WIDTH / 2), (-pTowerBase.getTowerRange()) + (TowerManager.TOWER_HEIGHT / 2)); // attach the radius marker to the position marker, then to the scene Registry.sSceneLayerTowers.attachChild(mPositionMarker); // get this towers upgrade types for (final TowerTypes tt : pTowerBase.getTowerUpgradeTypes()) { /** * final TiledSprite upgradableTower = new TiledSprite(this.mBoxX + TOWERS_UI_SPACER + * (TOWERS_UI_SPACER * currentCol) + (TOWERS_UI_ITEM_WIDTH * currentCol), mBoxY + * TOWERS_UI_SPACER + (TOWERS_UI_SPACER * currentRow) + (TOWERS_UI_ITEM_WIDTH * currentRow), * mTowerManager.getTowerMenuTiledTextureRegionClone()) { */ // PUT BORDERS ABOVE THESE FROM THE UI SPRITES THEY COME IN LARGE SIZE final float lX = mBoxX + TOWERS_UI_SPACER + (TOWERS_UI_SPACER * currentCol) + (TOWERS_UI_ITEM_WIDTH * currentCol); final float lY = mBoxY + TOWERS_UI_SPACER + (TOWERS_UI_SPACER * currentRow) + (TOWERS_UI_ITEM_HEIGHT * currentRow); final float placeX = (TOWERS_UI_ITEM_WIDTH / 2) + (lX - tt.getTowerTileCenterX()); final float placeY = (TOWERS_UI_ITEM_HEIGHT - TOWERS_UI_SPACER) + (lY - tt.getTowerTileCenterY()); final TiledSprite upgradableTower = new TiledSprite( placeX, placeY, Registry.sTowerTextureRegions[tt.getTowerTopSprite().getId()].deepCopy()); upgradableTower.setScale(.90f); if (null == tt.getPlayerRewardType() || Registry.sPlayerRewards.isRewardEarned(tt.getPlayerRewardType())) { upgradableTower.setAlpha(1f); } else { upgradableTower.setAlpha(.25f); } if (null != tt.getTowerBaseSprite()) { upgradableTower.setCurrentTileIndex(tt.getTowerBaseSprite().getInitialTileIndex()); // Debug.i("getTowerBaseSprite=" + tt.getTowerBaseSprite().getInitialTileIndex()); } if (null != tt.getTowerTopSprite()) { upgradableTower.setCurrentTileIndex(tt.getTowerTopSprite().getInitialTileIndex()); // Debug.i("getTowerTopSprite=" + tt.getTowerTopSprite().getInitialTileIndex()); } upgradableTower.setZIndex(100); attachChild(upgradableTower); registerTouchArea(upgradableTower); mUpgradeSprites.add(upgradableTower); final Rectangle rect = new Rectangle(lX, lY, TOWERS_UI_ITEM_WIDTH, TOWERS_UI_ITEM_HEIGHT) { @Override public boolean onAreaTouched( TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { if (null == tt.getPlayerRewardType() || Registry.sPlayerRewards.isRewardEarned(tt.getPlayerRewardType())) { this.setAlpha(1f); if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) { TowerUpgraderBack.this.isValidClick = true; } if (TowerUpgraderBack.this.isValidClick && pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP && GameActivity.SCROLL_MODE_DISABLED == Registry.sGameActivity.getScrollMode()) { Registry.sGameActivity.runOnUpdateThread( new Runnable() { @Override public void run() { TowerUpgraderBack.this.upgrade(pTowerBase, tt); TowerUpgraderBack.this.isValidClick = false; } }); } return true; } else { this.setAlpha(.25f); Registry.sGameActivity.userNotifyShort( "This tower requires the \"" + tt.getPlayerRewardType() + "\" reward to be unlocked. Visit the Game Points section from the main menu for more information about earning and spending Game Points (The currency \"GP\" you see above)."); return false; } } }; rect.setZIndex(90); attachChild(rect); if (++currentCol >= mTotalColumns) { currentRow++; currentCol = 0; } } sortChildren(); Debug.i("SpriteSheets.UI_128x128_01.ordinal()=" + SpriteSheets.UI_128x128_01.ordinal()); final TiledSprite ts = new TiledSprite( 25, 25, Registry.sSpriteTextureRegions[SpriteSheets.UI_128x128_01.ordinal()].deepCopy()); // final TiledSprite ts = new TiledSprite(25, 25, // Registry.sTowerTextureRegions[TowerTypes.ARCH_MAGE.getTowerTopSprite().getId()].deepCopy()); ts.setZIndex(110); ts.setCurrentTileIndex(0); attachChild(ts); Registry.sGameActivity.setScrollMode(GameActivity.SCROLL_MODE_DISABLED); Registry.sGameActivity.getCamera().setHUD(TowerUpgraderBack.this); return this; }
public GameOverScreen(Camera pCamera, LineikiActivity pActivity, int pScore, int pHighscore) { super(pCamera); this.setBackgroundEnabled(false); /*final SpriteMenuItem resetMenuItem = new SpriteMenuItem(MENU_RESET, this.mMenuNewGame); resetMenuItem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); this.mMenuthis.addMenuItem(resetMenuItem);*/ // mGameOverthis.setBackground(new ColorBackground(0.5f, 0.1f, 0.1f, 0.5f)); Rectangle r = new Rectangle(0, 0, pActivity.getScreenWidth(), pActivity.getScreenHeight()); r.setColor(0, 0, 0, 0.0f); r.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); r.setAlpha(0.5f); // r.registerEntityModifier(new AlphaModifier(1.0f, 0.0f, 0.5f)); this.attachChild(r); int w = pActivity.getTileSize(); final Sprite game_over = new Sprite(w * .5f, w * 2, pActivity.getGameOverTexture()); this.attachChild(game_over); /*mScoreDisplay = new ScoreDisplay(pActivity, 3); mScoreDisplay.setPosition(w*3, w*4); mScoreDisplay.setScore(pScore); this.attachChild(mScoreDisplay);*/ final TextMenuItem resetMenuItem = new TextMenuItem(LineikiActivity.MENU_RESET, pActivity.mFont, "New Game"); this.addMenuItem(resetMenuItem); final TextMenuItem quitMenuItem = new TextMenuItem(LineikiActivity.MENU_QUIT, pActivity.mFont, "Quit"); this.addMenuItem(quitMenuItem); // this.buildAnimations(); float scoreTop; float scoreLeft; // manually override menu items position if (pActivity.getIsTablet()) { // TABLET game_over.setPosition(w * 1.0f, w * 1.5f); resetMenuItem.setPosition(w * 10.5f, w * 6.5f); quitMenuItem.setPosition(w * 10.5f, w * 8.5f); scoreTop = w * 6.5f; scoreLeft = w * 0.5f; } else { // PHONE game_over.setPosition(w * .5f, w * 2); resetMenuItem.setPosition(w * 1, w * 11); quitMenuItem.setPosition(w * 5, w * 11); scoreTop = w * 6; scoreLeft = 0; } this.setBackgroundEnabled(false); Text t; t = new Text( 100, 60, pActivity.getFont(), "Your score: " + Integer.valueOf(pScore).toString(), HorizontalAlign.CENTER); this.attachChild(t); t.setPosition(scoreLeft + (w * 9 - t.getWidth()) / 2, scoreTop); if (pHighscore > 0) { // highscore is zero initially t = new Text( 100, 60, pActivity.getFont(), "Personal best: " + Integer.valueOf(pHighscore).toString(), HorizontalAlign.CENTER); this.attachChild(t); t.setPosition(scoreLeft + (w * 9 - t.getWidth()) / 2, scoreTop + w); if (pScore > pHighscore) { t = new Text(100, 60, pActivity.getFont(), "YOU WIN!!!", HorizontalAlign.CENTER); this.attachChild(t); t.setPosition(scoreLeft + (w * 9 - t.getWidth()) / 2, scoreTop + w * 2); } } this.setOnMenuItemClickListener(pActivity); }