private void onCheckIsLaserSightEnabled() { if (StaticData.laserSightItems[this.pPlayer.getWeaponIndex()]) { if (this.sLaserSight == null) { this.sLaserSight = new Sprite( 0f, 0f, MiscRegions.region_empty, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); this.sLaserSight.setShaderProgram(this.LASER_SIGHT_SHADER); this.sLaserSight.setZIndex(-1); this.sLaserSight.setScaleCenter(0, 0); this.sLaserSight.setScale(16f, 0.5f); this.sLaserSight.setRotationCenter(0f, this.sLaserSight.getHeightScaled() / 2f); this.resetLaserSightShader(); if (SessionScene.USE_LASER_CROSSHAIR) { this.sLaserCrosshair = new Sprite( 0f, 0f, HudRegions.region_laser_crosshair, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); this.sLaserCrosshair.setZIndex(this.lLevel.getMapHeight()); this.sLaserCrosshair.setScaleCenter(0, 0); this.sLaserCrosshair.setScale(2f); } } this.transformLaserSight(); try { if (SessionScene.USE_LASER_CROSSHAIR) { ResourceManager.btLaserCrosshair.load(); this.attachChild(this.sLaserCrosshair); } this.pPlayer.attachChild(this.sLaserSight); this.pPlayer.sortChildren(); } catch (final IllegalStateException ex) { } } else { if (this.sLaserSight == null) return; if (SessionScene.USE_LASER_CROSSHAIR) { ResourceManager.btLaserCrosshair.unload(); this.sLaserCrosshair.detachSelf(); } this.sLaserSight.detachSelf(); } }
/** Occurs when all fields have been initialised. */ public void onStart() { this.fFade.hide(); this.loadTextures(); this.registerUpdateHandler(this.eysEntityYSorter); this.onStartRound(); this.showSurviveNotification(); this.playSirenSound(); SessionScene.AMBIENCE.play(); EnvironmentVars.MAIN_CONTEXT.registerSound(SessionScene.AMBIENCE); this.registerFloatValueModifier( true, new OnValueChangeListener() { @Override public void valueChanged(float value) { EnvironmentVars.MAIN_CONTEXT.getSoundManager().setMasterVolume(value); } }, new Runnable() { @Override public void run() { SessionScene.AMBIENCE.setVolume(SessionScene.AMBIENCE_VOLUME); } }); }
protected void createExplosionMark(float x, float y) { final Sprite MARK = new TextureManagedSprite( 0, 0, HudRegions.region_explosion_mark, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()) { private float elapsedAliveTime; @Override protected void onManagedUpdate(float pSecondsElapsed) { this.elapsedAliveTime += pSecondsElapsed; if (this.elapsedAliveTime >= SessionScene.TARGET_ALIVE_EXPLOSION_MARK_TIME) { this.setAlpha(this.getAlpha() - 0.002f); if ((int) (this.getAlpha() * 1000) <= 0) EntityUtils.safetlyDetachAndDispose(this); } super.onManagedUpdate(pSecondsElapsed); } }; MARK.setScale(2f); MARK.setX(x - MARK.getWidth() / 2f); MARK.setY(y - MARK.getHeight() / 2f); this.attachChild(MARK); }
@Override protected void onDialogAccept() { super.onDialogAccept(); // User chose to sign in EnvironmentVars.MAIN_CONTEXT.getGoogleApiClient().connect(); }
private void initRotateChar() { this.sRotateChar = new Sprite( 0f, 0f, StoreTextureRegions.region_rotate_char, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()) { @Override public void setAlpha(float pAlpha) { super.setAlpha( pAlpha * ((MainMenuEditPlayer.this.isRotatingSkin) ? MainMenuEditPlayer.ROTATE_PRESSED_ALPHA : MainMenuEditPlayer.ROTATE_IDLE_ALPHA)); } }; this.sRotateChar.setScale(4f); this.sRotateChar.setPosition( this.sPlayerSkinGradient.getX() + (this.sPlayerSkinGradient.getWidthScaled() - this.sRotateChar.getWidth()) / 2f, this.sPlayerSkinGradient.getY() + this.sPlayerSkinGradient.getHeightScaled() * 0.875f); super.afeContainer.attachChild(this.sRotateChar); // @formatter:off this.baPlayerBoundary = new BoundaryAdapter( this.sPlayerSkinGradient.getX(), this.sPlayerSkinGradient.getY(), Math.max(this.sPlayerSkinGradient.getWidthScaled(), this.sRotateChar.getWidthScaled()), this.sPlayerSkinGradient.getHeightScaled()); // @formatter:on }
/** * Detaches and disposes all Entities that does not have the tag <em>TAG_PRESERVE</em> ({@value * #TAG_PRESERVE}) in the HUD and in this scene. */ public void detachAndDisposeNonPreservedEntities() { EnvironmentVars.MAIN_CONTEXT.runOnUpdateThread( new Runnable() { @Override public void run() { SessionScene.this.detachAndDisposeEntities(true); } }); }
protected void initComboTracker() { this.ctComboTracker = new ComboTracker(0, 0, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager(), this); this.ctComboTracker.setComponentListener( new ComponentAdapter() { @Override public void onComponentReleased(BaseScreenComponent component, float x, float y) { SessionScene.this.getRewardGuide().show(); } }); }
protected void initFade() { this.fFade = new LoadingSpriteFade(EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()) { @Override protected void onFadeOut() { super.onFadeOut(); EntityUtils.safetlyDetach(this); } }; this.fFade.setAlpha(1f); }
protected void createAmmoText() { this.stAmmoText = new ShadowedText( this.sAmmoIcon.getWidth() + 4f, 0f, ResourceManager.fFontMain, "XXXX", EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); this.stAmmoText.setY((this.sAmmoIcon.getHeight() - this.stAmmoText.getHeight()) / 2f); this.stAmmoText.setScale(1f); }
@SuppressWarnings("unused") private void clampLaserCrosshair() { if (this.sLaserCrosshair == null || !SessionScene.USE_LASER_CROSSHAIR) return; final float LASER_CROSSHAIR_X = this.getLaserCrosshairX(); final float LASER_CROSSHAIR_Y = this.getLaserCrosshairY(); this.sLaserCrosshair.setPosition(LASER_CROSSHAIR_X, LASER_CROSSHAIR_Y); if (false) { if (this.pPlayer.getX() + this.sLaserCrosshair.getX() * this.pPlayer.getScaleX() < EnvironmentVars.MAIN_CONTEXT.getCamera().getXMin()) this.sLaserCrosshair.setX( LASER_CROSSHAIR_X - (this.pPlayer.getX() + LASER_CROSSHAIR_X * this.pPlayer.getScaleX() - EnvironmentVars.MAIN_CONTEXT.getCamera().getXMin()) / this.pPlayer.getScaleX()); if (this.pPlayer.getX() + this.sLaserCrosshair.getX() * this.pPlayer.getScaleX() > this.lLevel.getMapWidth() - EnvironmentVars.MAIN_CONTEXT.getCamera().getXMin() - this.sLaserCrosshair.getWidthScaled()) this.sLaserCrosshair.setX( LASER_CROSSHAIR_X - (this.pPlayer.getX() + LASER_CROSSHAIR_X * this.pPlayer.getScaleX()) / this.pPlayer.getScaleX()); if (this.pPlayer.getY() + this.sLaserCrosshair.getY() * this.pPlayer.getScaleY() < EnvironmentVars.MAIN_CONTEXT.getCamera().getYMin()) this.sLaserCrosshair.setY( LASER_CROSSHAIR_Y - (this.pPlayer.getY() + LASER_CROSSHAIR_Y * this.pPlayer.getScaleY() - EnvironmentVars.MAIN_CONTEXT.getCamera().getYMin()) / this.pPlayer.getScaleY()); } }
@Override protected void postInitialized() { super.postInitialized(); this.pcsPlayerSkinPreview = new PlayerCharacterSkin(); this.pcsPlayerSkinPreview.setScaleCenter(0, 0); this.pcsPlayerSkinPreview.setScale(9f); this.pcsPlayerSkinPreview.setX(EnvironmentVars.MAIN_CONTEXT.width() - 32f * 9f - 64f); this.pcsPlayerSkinPreview.setY( (EnvironmentVars.MAIN_CONTEXT.height() + Button.BUTTON_HEIGHT - 32f * 9f) / 2f); this.pcsPlayerSkinPreview.loadTextures(); this.directPlayerSkin(); this.sPlayerSkinGradient = new Sprite( this.pcsPlayerSkinPreview.getX() - 24f, this.pcsPlayerSkinPreview.getY() - 24f, MiscRegions.region_empty, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); this.sPlayerSkinGradient.setScaleCenter(0, 0); this.sPlayerSkinGradient.setScale(32f * 9f + 48f); this.sPlayerSkinGradient.setColor(Color.WHITE); this.sPlayerSkinGradient.setShaderProgram(RadialGradientShaderProgram.getInstance()); super.afeContainer.attachChild(this.sPlayerSkinGradient); super.afeContainer.attachChild(this.pcsPlayerSkinPreview); this.sPlayerSkinGradient.setAlpha(0); this.pcsPlayerSkinPreview.setAlpha(0); this.initRotateChar(); this.initButtons(); super.tmButtonTouchManager.setComponents( this.bBack, this.bHair, this.bLegs, this.bSkin, this.bTorso); }
@Override protected void onContainerAttached() { this.purchaseCanceled = false; this.needsPurchaseConfirmation = false; ResourceManager.btStroke2.load(); ResourceManager.btStroke6.load(); ResourceManager.btRotateChar.load(); if (EnvironmentVars.MAIN_CONTEXT.isAdVisible()) this.pushEntities(); this.scLeftSideContainer.onTouchRelease(false); this.revalidatePlayerSkinBodyParts(); }
protected void createInvSprite(ITiledTextureRegion sheet) { final float w = this.getWidth(); final float h = this.getHeight(); final float sw = sheet.getWidth(); final float sh = sheet.getHeight(); this.sInvSprite = new TiledSprite( (w - sw) / 2f, (h - sh) / 2f, sheet, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); this.sInvSprite.setRotationCenter(sw / 2f, sh / 2f); this.sInvSprite.setRotation(Inventory.INVENTORY_ICON_ROTATION); }
protected void createAmmoIcon() { final float h = this.getHeight(); this.sAmmoIcon = new Sprite( 0f, h - 6f, HudRegions.region_ammo_icon, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()) { @Override public void setAlpha(float pAlpha) { super.setAlpha(pAlpha); Inventory.this.stAmmoText.setAlpha(pAlpha); } }; this.sAmmoIcon.setRotation(10f); }
/** Closes this game session and returns to the main menu. */ public void toMainMenu(final String optionalMessage) { EnvironmentVars.MAIN_CONTEXT.runOnUpdateThread( new Runnable() { @Override public void run() { for (final BaseAudioEntity audio : EnvironmentVars.MAIN_CONTEXT.getAudioRegistered()) { audio.pause(); EnvironmentVars.MAIN_CONTEXT.unregisterSound(audio); } ResourceManager.btScrapPartsBig.unload(); SessionScene.this.setIgnoreUpdate(false); SessionScene.this.detachAndDisposeEntities(false); SessionScene.HUD.setOnSceneTouchListener(null); EnvironmentVars.MAIN_CONTEXT .getCamera() .setCenter( EnvironmentVars.MAIN_CONTEXT.width() / 2f, EnvironmentVars.MAIN_CONTEXT.height() / 2f); final MainMenuScene SCENE = new MainMenuScene() { @Override public void init() { super.init(); if (!optionalMessage.contentEquals("")) this.showDialog(optionalMessage); } }; EnvironmentVars.MAIN_CONTEXT.getEngine().setScene(SCENE); if (!SessionScene.this.isDisposed()) SessionScene.this.dispose(); System.gc(); SCENE.init(); } }); }
static { HUD = EnvironmentVars.MAIN_CONTEXT.getCamera().getHUD(); }
protected void playSirenSound() { ResourceManager.sSiren.setVolume(1); ResourceManager.sSiren.play(); EnvironmentVars.MAIN_CONTEXT.registerSound(ResourceManager.sSiren); }
protected void showFirstWave() { if (this.rsRoundSystem.getStartRound() != 1) return; // @formatter:off this.sFirstWave = new Sprite( (EnvironmentVars.MAIN_CONTEXT.width() - HudRegions.region_wave_1[0].getWidth()) / 2f, (EnvironmentVars.MAIN_CONTEXT.height() - HudRegions.region_wave_1[0].getHeight()) / 2f, HudRegions.region_wave_1[0], EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); this.sFirstWave.setScale(4f); this.sFirstWaveSub = new Sprite( (EnvironmentVars.MAIN_CONTEXT.width() - HudRegions.region_wave_1[1].getWidth()) / 2f, this.sFirstWave.getY() + this.sFirstWave.getHeightScaled() + 4f, HudRegions.region_wave_1[1], EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()) { @Override public void dispose() { ResourceManager.btWave1.unload(); super.dispose(); } }; this.sFirstWaveSub.setScale(1.5f); // @formatter:on final Music FIRST_WAVE_MUSIC = ResourceManager.mFirstWave; EnvironmentVars.MAIN_CONTEXT.registerSound(FIRST_WAVE_MUSIC); FIRST_WAVE_MUSIC.seekTo(0); FIRST_WAVE_MUSIC.play(); SessionScene.HUD.attachChild(SessionScene.this.sFirstWave); SessionScene.HUD.attachChild(SessionScene.this.sFirstWaveSub); ResourceManager.btWave1.load(); final DelayModifier DELAY_LIFETIME = new DelayModifier(3f) { @Override protected void onModifierFinished(IEntity pItem) { super.onModifierFinished(pItem); SessionScene.this.rsRoundSystem.start(); final FlashUpdateHandler FLASH = new FlashUpdateHandler(0.05f, 2); FLASH.runOnSwitch( new Runnable() { @Override public void run() { final boolean VISIBLE = SessionScene.this.sFirstWave.isVisible(); SessionScene.this.sFirstWave.setVisible(!VISIBLE); } }); FLASH.runOnFinish( new Runnable() { @Override public void run() { SessionScene.this.unregisterUpdateHandler(FLASH); SessionScene.this.sFirstWave.setVisible(true); EntityUtils.animateEntity( SessionScene.this.sFirstWave, 0.25f, EntityUtils.ANIMATION_JUMP_OUT_MEDIUM_INTESTIVITY, EaseLinear.getInstance(), EntityUtils.getDetachDisposeListener()); EntityUtils.animateEntity( SessionScene.this.sFirstWaveSub, 1f, EntityUtils.ANIMATION_FADE_OUT, EaseCubicInOut.getInstance(), EntityUtils.getDetachDisposeListener()); } }); SessionScene.this.registerUpdateHandler(FLASH); } }; DELAY_LIFETIME.setAutoUnregisterWhenFinished(true); this.registerEntityModifier(DELAY_LIFETIME); EntityUtils.animateEntity(this.sFirstWave, 1f, EntityUtils.ANIMATION_FADE_IN); EntityUtils.animateEntity(this.sFirstWaveSub, 1f, EntityUtils.ANIMATION_FADE_IN); }
public void showPowerupIcon(Powerup powerup) { Sprite icon = null; final float ANIMATION_DELTA_Y = 96f; ITextureRegion iconTextureRegion = null; switch (powerup.getId()) { case Powerups.ID_SPEED_BOOST: iconTextureRegion = HudRegions.region_boost_icon; break; default: Log.e("Mortal Showdown", powerup.getId() + " is an invalid power-up id!"); break; } if (iconTextureRegion != null) icon = new Sprite( 16f * this.powerupIconCount, 20, iconTextureRegion, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); if (icon != null) { final DelayModifier[] ICON_DELAYS = new DelayModifier[2]; ICON_DELAYS[0] = new DelayModifier(powerup.getDuration() * 0.8f); ICON_DELAYS[1] = new DelayModifier(powerup.getDuration() * 0.2f); final Sprite ICON = icon; // @formatter:off ICON_DELAYS[0].addModifierListener( new IModifierListener<IEntity>() { @Override public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) { EnvironmentVars.MAIN_CONTEXT.runOnUpdateThread( new Runnable() { @Override public void run() { ICON.registerEntityModifier(ICON_DELAYS[1]); } }); } @Override public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {} }); ICON_DELAYS[0].setAutoUnregisterWhenFinished(true); ICON_DELAYS[1].addModifierListener( new IModifierListener<IEntity>() { final FlashUpdateHandler FLASH = new FlashUpdateHandler(0.2f, -1); @Override public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) { EnvironmentVars.MAIN_CONTEXT.runOnUpdateThread( new Runnable() { @Override public void run() { Inventory.this.powerupIconCount--; ICON.unregisterUpdateHandler(FLASH); ICON.detachSelf(); ICON.dispose(); } }); } @Override public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) { this.FLASH.runOnSwitch( new Runnable() { @Override public void run() { ICON.setVisible(!ICON.isVisible()); } }); ICON.registerUpdateHandler(this.FLASH); } }); ICON_DELAYS[1].setAutoUnregisterWhenFinished(true); // @formatter:on // @formatter:off final ParallelEntityModifier ICON_MOD = new ParallelEntityModifier( new AlphaModifier(Inventory.POWERUP_ICON_ANIMATION_DURATION, 0f, 1f), new MoveYModifier( Inventory.POWERUP_ICON_ANIMATION_DURATION, icon.getY() + ANIMATION_DELTA_Y, icon.getY(), EaseCubicOut.getInstance()), ICON_DELAYS[0]); icon.setAlpha(0f); icon.setY(icon.getY() + ANIMATION_DELTA_Y); icon.registerEntityModifier(ICON_MOD); this.sAmmoIcon.attachChild(icon); // @formatter:on this.powerupIconCount++; } }
@Override protected void onManagedUpdate(float pSecondsElapsed) { super.onManagedUpdate(pSecondsElapsed); super.setRotation(EnvironmentVars.MAIN_CONTEXT.getEngine().getSecondsElapsedTotal() * 480); }
public void createExplosion(float x, float y, float radius, float damage, boolean harmPlayer) { final float X = x, Y = y; final HashMap<Character, Float> CHARACTERS_IN_RANGE = new HashMap<Character, Float>(); for (final Zombie z : Zombie.getAliveZombies()) this.onExplosionCheckCharacterCollision(x, y, radius, z, CHARACTERS_IN_RANGE); if (harmPlayer) this.onExplosionCheckCharacterCollision(x, y, radius, this.pPlayer, CHARACTERS_IN_RANGE); final Iterator<Character> CHARACTER_ITERATOR = CHARACTERS_IN_RANGE.keySet().iterator(); final Iterator<Float> DAMAGE_ITERATOR = CHARACTERS_IN_RANGE.values().iterator(); while (CHARACTER_ITERATOR.hasNext()) { final Character CHAR = CHARACTER_ITERATOR.next(); final Float DAMAGE = DAMAGE_ITERATOR.next(); CHAR.setHealthAmount((int) (CHAR.getHealthAmount() - damage * DAMAGE)); if (CHAR.getHealthAmount() <= 0) AchievementsManager.incrementZombiesKilledByExplosion(); } final ITiledTextureRegion EXPLOSION_TEXTURE = HudRegions.region_explosion; final AnimatedSprite EXPLOSION = new AnimatedSprite( x, y, EXPLOSION_TEXTURE, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); if (this.explosionCount == 0) EXPLOSION_TEXTURE.getTexture().load(); EXPLOSION.setScaleCenter(0, 0); EXPLOSION.setScale(2f); EXPLOSION.setPosition( EXPLOSION.getX() - EXPLOSION.getWidthScaled() / 2f, EXPLOSION.getY() - EXPLOSION.getHeightScaled() / 2f); EXPLOSION.setZIndex(this.getLevel().getMapHeight()); this.attachChild(EXPLOSION); this.explosionCount++; EXPLOSION.animate( 30L, false, new IAnimationListener() { private boolean usedEffects; @Override public void onAnimationFinished(AnimatedSprite pAnimatedSprite) { EnvironmentVars.MAIN_CONTEXT.runOnUpdateThread( new Runnable() { @Override public void run() { SessionScene.this.explosionCount--; if (SessionScene.this.explosionCount == 0) EXPLOSION_TEXTURE.getTexture().unload(); EXPLOSION.detachSelf(); EXPLOSION.dispose(); } }); } @Override public void onAnimationFrameChanged( AnimatedSprite pAnimatedSprite, int pOldFrameIndex, int pNewFrameIndex) { if (pNewFrameIndex >= 3) if (!this.usedEffects) { SessionScene.this.createExplosionMark(X, Y); SessionScene.this.onExplosionCreateSmoke(X, Y); this.usedEffects = true; } } @Override public void onAnimationLoopFinished( AnimatedSprite pAnimatedSprite, int pRemainingLoopCount, int pInitialLoopCount) {} @Override public void onAnimationStarted(AnimatedSprite pAnimatedSprite, int pInitialLoopCount) {} }); this.getCameraManager().shakeRandomDirection(); SessionScene.EXPLOSION_SOUND.play(); }
protected void initHudRewardGuide() { this.rgsRewardGuide = new RewardGuideStructure(this, EnvironmentVars.MAIN_CONTEXT.getVertexBufferObjectManager()); }
protected void initCameraManager() { this.cmCameraManager = new CameraManager(EnvironmentVars.MAIN_CONTEXT.getCamera(), this.lLevel, this); this.cmCameraManager.setShakeForce(4f); }