package com.tgs.buah01;  import java.io.IOException;  import org.andengine.audio.sound.Sound; import org.andengine.audio.sound.SoundFactory; import org.andengine.engine.camera.Camera; import org.andengine.engine.options.EngineOptions; import org.andengine.engine.options.ScreenOrientation; import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; import org.andengine.entity.scene.Scene; import org.andengine.entity.sprite.Sprite; import org.andengine.entity.util.FPSLogger; import org.andengine.input.touch.TouchEvent;  import org.andengine.opengl.texture.ITexture; import org.andengine.opengl.texture.TextureOptions; import org.andengine.opengl.texture.bitmap.AssetBitmapTexture; import org.andengine.opengl.texture.region.ITextureRegion; import org.andengine.opengl.texture.region.TextureRegionFactory; import org.andengine.ui.activity.SimpleBaseGameActivity; import org.andengine.util.adt.color.Color; import org.andengine.util.debug.Debug;  import android.widget.Toast;  public class MainActivity extends SimpleBaseGameActivity { 	 	private static final int LEBAR_KAMERA = 510; 	private static final int TINGGI_KAMERA = 800; 	 	 	private ITexture mHewanBirthTexture; 	private ITextureRegion mHewanBirthTextureRegion; 	 	private ITexture mHewanCowTexture; 	private ITextureRegion mHewanCowTextureRegion; 	 	private ITexture mHewanDuckTexture; 	private ITextureRegion mHewanDuckTextureRegion; 	 	private ITexture mHewanGoatTexture; 	private ITextureRegion mHewanGoatTextureRegion; 	 	private ITexture mHewanHorseTexture; 	private ITextureRegion mHewanHorseTextureRegion; 	 	private ITexture mHewanSheepTexture; 	private ITextureRegion mHewanSheepTextureRegion; 	 	private Sound mHewanBirth; 	private Sound mHewanCow; 	private Sound mHewanDuck; 	private Sound mHewanGoat; 	private Sound mHewanHorse; 	private Sound mHewanSheep; 	 	@Override 	public EngineOptions onCreateEngineOptions() { 		Toast.makeText(this, "Sentuh Hewan untuk Mendengar Suara.", Toast.LENGTH_LONG).show();  		final Camera kamera = new Camera(0, 0, LEBAR_KAMERA, TINGGI_KAMERA);  		final EngineOptions PilihanEngine = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(LEBAR_KAMERA, TINGGI_KAMERA), kamera); 		PilihanEngine.getAudioOptions().setNeedsSound(true);  		return PilihanEngine; 	}  	@Override 	protected void onCreateResources() throws IOException { 		this.mHewanBirthTexture = new AssetBitmapTexture(this.getTextureManager(), this.getAssets(), "gfx/birth.png", TextureOptions.BILINEAR); 		this.mHewanBirthTextureRegion = TextureRegionFactory.extractFromTexture(this.mHewanBirthTexture); 		this.mHewanBirthTexture.load(); 		 		this.mHewanCowTexture = new AssetBitmapTexture(this.getTextureManager(), this.getAssets(), "gfx/cow.png", TextureOptions.BILINEAR); 		this.mHewanCowTextureRegion = TextureRegionFactory.extractFromTexture(this.mHewanCowTexture); 		this.mHewanCowTexture.load(); 		 		this.mHewanDuckTexture = new AssetBitmapTexture(this.getTextureManager(), this.getAssets(), "gfx/duck.png", TextureOptions.BILINEAR); 		this.mHewanDuckTextureRegion = TextureRegionFactory.extractFromTexture(this.mHewanDuckTexture); 		this.mHewanDuckTexture.load(); 		 		this.mHewanGoatTexture = new AssetBitmapTexture(this.getTextureManager(), this.getAssets(), "gfx/goat.png", TextureOptions.BILINEAR); 		this.mHewanGoatTextureRegion = TextureRegionFactory.extractFromTexture(this.mHewanGoatTexture); 		this.mHewanGoatTexture.load(); 		 		this.mHewanHorseTexture = new AssetBitmapTexture(this.getTextureManager(), this.getAssets(), "gfx/horse.png", TextureOptions.BILINEAR); 		this.mHewanHorseTextureRegion = TextureRegionFactory.extractFromTexture(this.mHewanHorseTexture); 		this.mHewanHorseTexture.load(); 		 		this.mHewanSheepTexture = new AssetBitmapTexture(this.getTextureManager(), this.getAssets(), "gfx/sheep.png", TextureOptions.BILINEAR); 		this.mHewanSheepTextureRegion = TextureRegionFactory.extractFromTexture(this.mHewanSheepTexture); 		this.mHewanSheepTexture.load(); 		 		SoundFactory.setAssetBasePath("mfx/"); 		try { 			this.mHewanBirth = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "Bird01.mp3"); 			this.mHewanCow = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "Cow.mp3"); 			this.mHewanDuck = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "Duck.wav"); 			this.mHewanGoat = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "Goat.mp3"); 			this.mHewanHorse = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "Horse.wav"); 			this.mHewanSheep = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "Sheep.mp3");   		} catch (final IOException e) { 			Debug.e(e); 		} 		 	}  	@Override 	protected Scene onCreateScene() { 		this.mEngine.registerUpdateHandler(new FPSLogger());  		final Scene Adegan = new Scene(); 		Adegan.getBackground().setColor(Color.WHITE);  		final Sprite birth = new Sprite(150, 700, this.mHewanBirthTextureRegion, this.getVertexBufferObjectManager()){ 		    @Override 		    public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y)  		    { 		        if (pSceneTouchEvent.isActionUp()) 		        { 		        	MainActivity.this.mHewanBirth.play(); 		        } 		        return true; 		    };      		}; 		final Sprite cow = new Sprite(360, 600, this.mHewanCowTextureRegion, this.getVertexBufferObjectManager()){ 		    @Override 		    public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y)  		    { 		        if (pSceneTouchEvent.isActionUp()) 		        { 		        	MainActivity.this.mHewanCow.play(); 		        } 		        return true; 		    };      		}; 		final Sprite duck = new Sprite(150, 500, this.mHewanDuckTextureRegion, this.getVertexBufferObjectManager()){ 		    @Override 		    public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y)  		    { 		        if (pSceneTouchEvent.isActionUp()) 		        { 		        	MainActivity.this.mHewanDuck.play(); 		        } 		        return true; 		    };      		}; 		final Sprite goat = new Sprite(360, 400, this.mHewanGoatTextureRegion, this.getVertexBufferObjectManager()){ 		    @Override 		    public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y)  		    { 		        if (pSceneTouchEvent.isActionUp()) 		        { 		        	MainActivity.this.mHewanGoat.play(); 		        } 		        return true; 		    };      		}; 		final Sprite horse = new Sprite(150, 300, this.mHewanHorseTextureRegion, this.getVertexBufferObjectManager()){ 		    @Override 		    public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y)  		    { 		        if (pSceneTouchEvent.isActionUp()) 		        { 		        	MainActivity.this.mHewanHorse.play(); 		        } 		        return true; 		    };      		}; 		final Sprite sheep = new Sprite(360, 200, this.mHewanSheepTextureRegion, this.getVertexBufferObjectManager()){ 		    @Override 		    public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y)  		    { 		        if (pSceneTouchEvent.isActionUp()) 		        { 		        	MainActivity.this.mHewanSheep.play(); 		        } 		        return true; 		    };      		}; 		 		Adegan.attachChild(birth); 		Adegan.attachChild(cow); 		Adegan.attachChild(duck); 		Adegan.attachChild(goat); 		Adegan.attachChild(horse); 		Adegan.attachChild(sheep); 		 		Adegan.registerTouchArea(birth); 		Adegan.registerTouchArea(cow); 		Adegan.registerTouchArea(duck); 		Adegan.registerTouchArea(goat); 		Adegan.registerTouchArea(horse); 		Adegan.registerTouchArea(sheep); 		 		return Adegan; 	} }