private void handleInput() { if (Gdx.input.isButtonPressed(Buttons.LEFT)) { if (isSelected) { SoundManager.getInstance().playSound(SoundManager.getInstance().mSoundSelectMenu); switch (menuIndex) { case 0: // Easy GameUtils.getInstance().levelIndex = 0; goToGame(); break; case 1: // Normal GameUtils.getInstance().levelIndex = 1; goToGame(); break; case 2: // Hard GameUtils.getInstance().levelIndex = 2; goToGame(); break; case 3: // Back this.mGame.setScreen(new MainMenuScreen(mGame)); break; default: break; } } } }
@Override public void run() { while (mRun) { Canvas c = null; try { c = mSurfaceHolder.lockCanvas(null); synchronized (mSurfaceHolder) { long currentTime = System.currentTimeMillis(); long delta = (long) (currentTime - lastUpdateTime); lastUpdateTime = currentTime; processInput(); updatePhysics(delta); SoundManager.update(delta); doDraw(c); } } finally { // do this in a finally so that if an exception is thrown // during the above, we don't leave the Surface in an // inconsistent state if (c != null) { mSurfaceHolder.unlockCanvasAndPost(c); } } } }
public static void init() { DiamondActor.sprite = StateGameplay.spriteFruit; ITEM_WIDTH = StateGameplay.spriteFruit.getFrameWidth(0); ITEM_HEIGHT = StateGameplay.spriteFruit.getFrameHeight(0); DiamondActor.speed = ITEM_HEIGHT / 2; BEGIN_X = (FourInALine.SCREEN_WIDTH - MAX_COL * ITEM_WIDTH) / 2; BEGIN_Y = (int) (306 * StateGameplay.SCREEN_HEIGHT * 1.0f / 1280); // BEGIN_Y = (Diamond.SCREEN_HEIGHT - MAX_ROW * ITEM_HEIGHT) / 2; for (int i = 0; i < MAX_ROW; i++) for (int j = 0; j < MAX_COL; j++) { // int tempValue = random.nextInt(MAX_ITEM); tableArray[i][j] = null; tableArray[i][j] = new DiamondActor( -1, i, j, BEGIN_X + j * ITEM_WIDTH, (i) * ITEM_HEIGHT - (MAX_ROW + j) * ITEM_HEIGHT, BEGIN_X + j * ITEM_WIDTH, BEGIN_Y + i * ITEM_HEIGHT, DiamondActor.STATE_IDE); tableArray[i][j].state = DiamondActor.STATE_IDE; } stateInGamePlay = STATE_IDE; Map.targetScore = (3000 + StateGameplay.mcurrentlevel * 1000); SoundManager.playSound(SoundManager.SOUND_START, 1); isUserStep = random.nextBoolean(); }
public void update() { final SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); if (this.activeSound != null) { if (handler.isSoundPlaying(this.activeSound)) return; ModLog.debug("FADE: " + this.activeSound.toString()); this.activeSound.fadeAway(); this.activeSound = null; this.repeatDelay = this.effect.getRepeat(RANDOM); if (this.repeatDelay > 0) return; } else if (this.repeatDelay > 0) { if (--this.repeatDelay > 0) return; } // If the volume is turned off don't send // down a sound. if (SoundSystemConfig.getMasterGain() <= 0) return; final PlayerSound theSound = new PlayerSound(effect); if (this.effect.type == SoundType.PERIODIC) { this.repeatDelay = this.effect.getRepeat(RANDOM); } else { this.activeSound = theSound; } try { SoundManager.playSound(theSound); } catch (final Throwable t) {; } }
/** * Initiate the Caster Activity, load the sounds up, set up touch listener, vibrator, sensor * manager, and accelerometer sensor * * @param savedInstanceState */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.caster); castDistance = 0; casterBackground = (ImageView) findViewById(R.id.caster_background); casterBackground.setOnTouchListener(this); audioTask = new AudioTask(); soundManager = SoundManager.getInstance(); // TODO: background animation once we get the assets. vibrotron = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); sensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); }
public void render(Application app) { if (BattleBeasties3d.manager.isLoaded("data/jet.png")) { // if base asstest for load screen havent been loaded if (!texturesUnbound) { texturesUnbound = true; // load them bindTextures(); } // render load anim renderInsideStation(app); } if (BattleBeasties3d.manager.update()) { // we are done loading everything } // display loading information progress = BattleBeasties3d.manager.getProgress(); // check if music has loaded if (BattleBeasties3d.manager.isLoaded("sound/movement_proposition.mp3") && musicPlaying == false) { // music is available, let's play it musicPlaying = true; SoundManager.music = BattleBeasties3d.manager.get("sound/movement_proposition.mp3", Music.class); SoundManager.playmusic(); } }
LevelModel(ModelController theModelController, String fileLocation) { modelController = theModelController; levelFile = loadToJson(fileLocation); tileMap = new TileMap(levelFile); playerModel = new PlayerModel(this); theModelController .getViewController() .getDrawPanel() .getInputHandler() .registerInputResponder(playerModel); distanceScrolled = 0.0f; scrollVelocity = 0.05f; scrollDelta = 0; queuedEnemies = new ArrayList<EnemyModel>(); activeEnemies = new ArrayList<EnemyModel>(); activeBullets = new ArrayList<Bullet>(); levelPickups = new ArrayList<Pickup>(); // Retrieves Enemies, pickups, and tileMap loadObjects(levelFile, queuedEnemies, levelPickups); paused = false; deathTimer = null; SoundManager.get().playSound("music"); mapWidthInPixels = tileMap.getTileMapWidth() * tileMap.getTileWidth(); }
/** * Called once per frame from {@link FrameRate}'s loop. Calls tick on the soundManager, and the * current game. (This will in turn call the tick of the Director, the SceneDirector and all * Actor's roles. * * @priority 3 */ public static void tick() { try { soundManager.tick(); currentGame.tick(); } catch (Exception e) { handleException(e); } }
@Override public void onResume() { super.onResume(); soundManager.loadSounds(SoundManager.CASTABLE); audioTask.execute(); }
/** * Creates an AudioSource which can be to manipulate a Sound buffer. An AudioSource can be created * multiple times and use the same Sound buffer. */ public AudioSource createAudioSource(final String _file, final StreamType _type) { final AudioBuffer<AndroidSound> buffer = (AudioBuffer<AndroidSound>) staticSoundManager.get(_file); if (buffer == null) { System.out.println("Sound Doesn't exist."); return null; } final AndroidSound sound = buffer.getBuffer(); return new AndroidSource(sound.getBuffer()); }
/** * At the end of the cast, analyze the data associated with it and determine a cast distance (or * failure if too short) Launch the Reeler activity if the distance was large enough */ public void endCast() { castDistance = 0; // We're going to do some really inaccurate numerical integration for these readings. Rough // results work well enough for this purpose on tested devices. // TODO: Test more devices. Currently used EVO4G, EVO3D, Galaxy Nexus, and older Nexus model. for (SensorEvent event : readings) { Long timeDelta = (long) ((event.timestamp - lastTimestamp) * 10E-9); castDistance += timeDelta * Math.abs(event.values[0]) + timeDelta * Math.abs(event.values[1]); lastTimestamp = event.timestamp; } Log.d(TAG, "Cast Distance: " + castDistance); // check for a weak cast and try again if it was really bad. if (castDistance < 25) { // TODO: play an audio track about not casting far enough. We need that asset still. casting = false; return; } vibrotron.vibrate(castPattern, -1); // play the casting audio. soundManager.playSound(1, 1); // kill the audio task if (audioTask != null) audioTask.cancel(true); // TODO: launch a cast animation/video when we get it, wait for it to finish before doing the // following try block // Free up listeners, hardware, etc. and launch the Reeler Activity. try { Intent ourIntent = new Intent(Caster.this, Class.forName("org.MAG.Reeler")); ourIntent.putExtra("CastDistance", castDistance); sensorManager.unregisterListener(this); vibrotron = null; sensorManager = null; casterBackground.setOnTouchListener(null); ourIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(ourIntent); casting = false; finish(); } catch (ClassNotFoundException ex) { Log.e(TAG, "Failed to jump to another activity"); } }
/** * Called when a {@link Game} ends. If there is another game on the stack, then continues to run, * otherwise terminates. * * <p>Itchy. * * @priority 5 */ public static void endGame() { currentGame.onDeactivate(); soundManager.stopAll(); if (gameStack.isEmpty()) { terminate(); } else { currentGame = gameStack.pop(); try { setScreenMode(currentGame); } catch (Exception e) { e.printStackTrace(); } currentGame.onActivate(); mainLoop(); } }
// The case Volume button has been clicked by user public void volumeClicked(View View) { // Testing playing Sound // playSound(soundSpeed , soundVolume); snd.play(bellSound); snd.play(drumSound); if (volcontrolVisible) { findViewById(R.id.volbar).setVisibility(View.GONE); // findViewById(R.id.optionSub1).setVisibility(View.GONE); // findViewById(R.id.optionSub2).setVisibility(View.GONE); } else { findViewById(R.id.volbar).setVisibility(View.VISIBLE); // findViewById(R.id.optionSub1).setVisibility(View.VISIBLE); // findViewById(R.id.optionSub2).setVisibility(View.VISIBLE); } volcontrolVisible = !volcontrolVisible; }
// Configurations for player upon death public void playerDeath() { SoundManager.get().playSound("death"); deathTimer = new MillisecTimer(); playerModel.death(); distanceScrolled = 0.0f; scrollDelta = 0; activeBullets.clear(); activeEnemies.clear(); loadObjects(levelFile, queuedEnemies, levelPickups); // Game Over if player runs out of lives if (playerModel.getLives() < 0) { modelController.setMainModel(new GameOverModel(modelController)); modelController .getViewController() .setMainView(new GameOverView(modelController.getViewController())); } }
/* * (non-Javadoc) * * @see com.badlogic.gdx.ApplicationListener#create() */ @Override public void create() { // TODO: Put this in a better place, remove the method CoreLogic.setGame(this); exitBuffer = 1; multiplayer = false; bounds = .25f; // max of .5 gameSize = 0; font = new BitmapFont( Gdx.files.internal(Settings.data_path + "smallfonts.fnt"), Gdx.files.internal(Settings.data_path + "smallfonts_0.png"), false); Gdx.input.setCatchBackKey(true); Settings.init(this); try { Net.init(this); SoundManager.init(this); TextureManager.init(this); ScoresManager.init(this); } catch (FileNotFoundException e) { e.printStackTrace(); } screens = new HashMap<String, Screen>(); screens.put("splash", new SplashScreen(this)); screens.put("main", new MainMenu(this)); screens.put("settings", new SettingsScreen(this)); if (connected) { screens.put("host", new MultiHost(this)); screens.put("lobby", new MultiLobby(this)); } screens.put("scores", new ScoresScreen(this)); this.setScreen(BaseGame.screens.get("splash")); }
public void loadLevel(Level level) { levelFile = loadToJson(level); tileMap = new TileMap(levelFile); distanceScrolled = 0.0f; scrollVelocity = 0.05f; scrollDelta = 0; queuedEnemies = new ArrayList<EnemyModel>(); activeEnemies = new ArrayList<EnemyModel>(); activeBullets = new ArrayList<Bullet>(); levelPickups = new ArrayList<Pickup>(); // Retrieves Enemies, pickups, and tileMap loadObjects(levelFile, queuedEnemies, levelPickups); SoundManager.get().playSound("music"); mapWidthInPixels = tileMap.getTileMapWidth() * tileMap.getTileWidth(); }
@Override public boolean mouseMoved(int screenX, int screenY) { // TODO Auto-generated method stub isSelected = false; // Easy if (screenX > 65 && screenX < 200 && screenY > 160 && screenY < 190) { SoundManager.getInstance().playSound(SoundManager.getInstance().mSoundSwitchMenu); menuIndex = 0; selector_Y = 600 - 185; isSelected = true; } // Normal if (screenX > 65 && screenX < 200 && screenY > 210 && screenY < 240) { selector_Y = 600 - 235; menuIndex = 1; isSelected = true; SoundManager.getInstance().playSound(SoundManager.getInstance().mSoundSwitchMenu); } // Hard if (screenX > 65 && screenX < 200 && screenY > 260 && screenY < 290) { selector_Y = 600 - 285; menuIndex = 2; isSelected = true; SoundManager.getInstance().playSound(SoundManager.getInstance().mSoundSwitchMenu); } // Back if (screenX > 65 && screenX < 200 && screenY > 310 && screenY < 340) { selector_Y = 600 - 335; menuIndex = 3; isSelected = true; SoundManager.getInstance().playSound(SoundManager.getInstance().mSoundSwitchMenu); } return false; }
public boolean startGenerator() { final ManagerInterface.ResourceLoader<AudioBuffer> loader = staticSoundManager.getResourceLoader(); loader.add( new ManagerInterface.ResourceDelegate<AudioBuffer>() { public boolean isLoadable(final String _file) { return GlobalFileSystem.isExtension(_file, ".wav", ".WAV"); } public AudioBuffer load(final String _file, final Settings _settings) { final byte[] buffer = ByteReader.readBytes(_file); if (buffer == null) { return null; } return new AudioBuffer<AndroidSound>(new AndroidSound(buffer)); } }); return true; }
public GameThread(SurfaceHolder surfaceHolder, Context context, Handler handler) { // get handles to some important objects mSurfaceHolder = surfaceHolder; mContext = context; lastUpdateTime = 0; Resources res = context.getResources(); bullets = new ArrayList<FunctionalBullet>(); aircrafts = new ArrayList<FunctionalAircraft>(); newaircraftimer = 0; // we don't need to transform it and it's faster to draw this way mBackgroundImage = BitmapFactory.decodeResource(res, R.drawable.background); tankImg = BitmapFactory.decodeResource(res, R.drawable.tank); gunBarrelImg = BitmapFactory.decodeResource(res, R.drawable.cannon); aircraftImg = BitmapFactory.decodeResource(res, R.drawable.aircraft); aircraftDownImg = BitmapFactory.decodeResource(res, R.drawable.aircraftdown); vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); SoundManager.loadSound(mContext); }
@Override public void onRestart() { SoundManager.playEffect("menu"); runFadeInAnimation(); super.onRestart(); }
@Override public boolean onTouchEvent(MotionEvent event) { // Only process if game is active if (GameActive && !GamePaused) { // If the next obstacle is not a tap type check for swipe if (nearestObstacle.getType() != Obstacle.TYPE.T_TAP && FingerDown == false) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { InitialPos.Set(event.getX(), event.getY()); } break; case MotionEvent.ACTION_MOVE: LastPos.Set(event.getX(), event.getY()); break; case MotionEvent.ACTION_UP: DirectionVector.Set(LastPos.operatorMinus(InitialPos)); break; } } // else check for tap else { if (event.getAction() == MotionEvent.ACTION_DOWN) { FingerDown = true; Tapped = true; } else if (event.getAction() == MotionEvent.ACTION_UP) { FingerDown = false; } } // Check if touch pause button if (event.getAction() == MotionEvent.ACTION_DOWN) { // If touch pause button if (CheckTouch( event.getX(), event.getY(), Pause_button.getPosX(), Pause_button.getPosY(), (int) Pause_button.getPosX() + Pause_button.getImgWidth(), (int) Pause_button.getPosY() + Pause_button.getImgHeight())) { GamePaused = true; } } return true; } else if (GameActive && GamePaused) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (CheckTouch( event.getX(), event.getY(), Unpause_button.getPosX(), Unpause_button.getPosY(), (int) Unpause_button.getPosX() + Unpause_button.getImgWidth(), (int) Unpause_button.getPosY() + Unpause_button.getImgHeight())) { GamePaused = false; } } return true; } // To process other taps while game is not active else { if (event.getAction() == MotionEvent.ACTION_DOWN) { // If touch restart button if (CheckTouch( event.getX(), event.getY(), Restart_button.getPosX(), Restart_button.getPosY(), (int) Restart_button.getPosX() + Restart_button.getImgWidth(), (int) Restart_button.getPosY() + Restart_button.getImgHeight())) { // Restart the game soundManager.PlaySFX(); Reset(); } // If touch mainmenu button else if (CheckTouch( event.getX(), event.getY(), Mainmenu_button.getPosX(), Mainmenu_button.getPosY(), (int) Mainmenu_button.getPosX() + Mainmenu_button.getImgWidth(), (int) Mainmenu_button.getPosY() + Mainmenu_button.getImgHeight())) { soundManager.PlaySFX(); Intent intent = new Intent(); intent.setClass(getContext(), Mainmenu.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); getContext().startActivity(intent); } } return true; } }
public void run() { SoundManager.playClickSound(4, 1); Log.i("TIMER_SAMPLE", "Timer updated "); mHandler.postDelayed(this, 1000); }
public List<Food> update( List<Conveyer> conveyerList, List<Arrow> arrowList, List<Target> targetList, SoundManager soundManager) { this.scoreUpList = new ArrayList(); this.explodeList = new ArrayList(); this.requestedFoods_added_byExplode = new ArrayList(); this.score = 0; // ====== <INIT: EXPLODECHECK ARRAY> ========// int[][] explodecheck = new int[22][22]; for (int j = 0; j <= 20; j++) { for (int k = 0; k <= 20; k++) { explodecheck[j][k] = 0; } } // ====== </INIT: EXPLODECHECK ARRAY> ========// // ============= MAIN UPDATE (set x,y,remove from list....) for (i = 0; i < foodList.size(); i++) { Food tem = foodList.get(i); int[] nextCell = tem.getNextCell(); Converter converter = new Converter(nextCell[0], nextCell[1]); int nextCellX = converter.getX(); int nextCellY = converter.getY(); int[] currentCell = tem.getCurrentCell(); Converter converter1 = new Converter(currentCell[0], currentCell[1]); int currentCellX = converter1.getX(); int currentCellY = converter1.getY(); if (!tem.getStay()) { tem.setX( currentCellX + (int) ((float) ((float) ((float) (nextCellX - currentCellX) / (float) tem.getCountDown()) * (tem.getCountDown() - tem.getCurrentCountDown() + 1)))); tem.setY( currentCellY + (int) ((float) ((float) ((float) (nextCellY - currentCellY) / (float) tem.getCountDown()) * (tem.getCountDown() - tem.getCurrentCountDown() + 1)))); } if (tem.getCurrentCountDown() > 0) { tem.setCurrentCountDown(tem.getCurrentCountDown() - 1); } if (tem.getCurrentCountDown() == 0) { tem.setXx(nextCell[0]); tem.setYy(nextCell[1]); int j; for (j = 0; j < targetList.size(); j++) { Target temTarget = targetList.get(j); if ((temTarget.getXx() == tem.getXx()) && (temTarget.getYy() == tem.getYy())) { if (tem.getDeathCountDown() == 0) { foodList.remove(i); i--; } else { tem.setDeathCountDown(tem.getDeathCountDown() - 1); tem.imgArr.decreaseOpacity((float) (tem.imgArr.getOpacity() * 0.25)); tem.setStay(true); } break; } } if (!tem.getStay()) { tem.setCurrentCountDown(tem.getCountDown()); currentCell[0] = tem.getXx(); currentCell[1] = tem.getYy(); tem.setCurrentCell(currentCell); tem.setX(nextCellX); tem.setY(nextCellY); for (j = 0; j < conveyerList.size(); j++) { Conveyer temConveyer = conveyerList.get(j); if ((temConveyer.getXx() == tem.getXx()) && (temConveyer.getYy() == tem.getYy())) { tem.setDirection(temConveyer.getDirection()); } } for (j = 0; j < arrowList.size(); j++) { Arrow temArrow = arrowList.get(j); if ((temArrow.getXx() == tem.getXx()) && (temArrow.getYy() == tem.getYy())) { tem.setDirection(temArrow.getDirection()); } } switch (tem.getDirection()) { case 1: if (nextCell[0] < 20) { nextCell[0]++; } break; case 2: if (nextCell[1] < 20) { nextCell[1]++; } break; case 3: if (nextCell[0] > 1) { nextCell[0]--; } break; case 4: if (nextCell[1] > 1) { nextCell[1]--; } break; } tem.setNextCell(nextCell); } } // end of if tem.getCurrentCountDown==0 explodecheck[tem.getXx()][tem.getYy()]++; } // ====== <CHECK AND SOLVE: EXPLODE> ========// int j, k; for (j = 1; j <= 20; j++) { for (k = 1; k <= 20; k++) { if (explodecheck[j][k] > 1) { int l; long scoreuptem = 0; for (l = 0; l < foodList.size(); l++) { Food tem = foodList.get(l); if ((tem.getXx() == j) && (tem.getYy() == k)) { int scoretem = (int) ((float) 1 / (float) 3 * tem.getScore()); scoreuptem += scoretem; score -= scoretem; foodList.remove(l); requestedFoods_added_byExplode.add(tem.getId()); l--; } } scoreUpList.add(new ScoreUp(j, k, -scoreuptem)); explodeList.add(new Explode(j, k)); soundManager.explode(); } } } for (j = 0; j < foodList.size(); j++) { boolean collision = false; long scoreuptem = 0; Food tem1 = foodList.get(j); for (k = j + 1; k < foodList.size(); k++) { Food tem2 = foodList.get(k); if ((Math.abs(tem1.getX() - tem2.getX()) < 13) && (Math.abs(tem1.getY() - tem2.getY()) < 13) && (((tem1.getYy() == tem2.getYy() && (tem1.getDirection() + tem2.getDirection() == 4) || (tem1.getXx() == tem2.getXx() && (tem1.getDirection() + tem2.getDirection() == 6)) || (Math.abs(tem1.getDirection() - tem2.getDirection()) == 1) || (Math.abs(tem1.getDirection() - tem2.getDirection()) == 3))))) { int scoretem = (int) ((float) 1 / (float) 3 * tem2.getScore()); scoreuptem += scoretem; score -= scoretem; foodList.remove(k); requestedFoods_added_byExplode.add(tem2.getId()); k--; collision = true; } } if (collision == true) { foodList.remove(j); j--; requestedFoods_added_byExplode.add(tem1.getId()); scoreuptem += (int) ((float) 1 / (float) 3 * tem1.getScore()); scoreUpList.add(new ScoreUp(tem1.getXx(), tem1.getYy(), -scoreuptem)); score -= scoreuptem; explodeList.add(new Explode(tem1.getXx(), tem1.getYy())); soundManager.explode(); } } // ====== </CHECK AND SOLVE: EXPLODE> ========// return foodList; }
// Initialization of the Battle State public BattleState(Framework framework, BattleEnemy enemy) { windowWidth = framework.getWidth(); windowHeight = framework.getHeight(); this.enemy = enemy; turn = 0; turnState = 0; Font buttonFont = new Font("Arial", Font.BOLD, 15); int xButtonSpacing = 40; int yButtonSpacing = 35; cardButton = new MenuButton( "Cast Card", xButtonSpacing, 3 * windowHeight / 4 + yButtonSpacing, buttonFont, (Graphics2D) framework.getGraphics(), 5, 5); itemButton = new MenuButton( "Use Item", xButtonSpacing, cardButton.getY() + cardButton.getHeight() + yButtonSpacing, buttonFont, (Graphics2D) framework.getGraphics(), 5, 5); drawButton = new MenuButton( "Draw Card", cardButton.getX() + cardButton.getWidth() + xButtonSpacing, cardButton.getY(), buttonFont, (Graphics2D) framework.getGraphics(), 5, 5); runButton = new MenuButton( "Run", cardButton.getX() + cardButton.getWidth() + xButtonSpacing, cardButton.getY() + cardButton.getHeight() + yButtonSpacing, buttonFont, (Graphics2D) framework.getGraphics(), 5, 5); buttonWidth = drawButton.getWidth(); int buttonHeight = drawButton.getHeight(); cardButton.setWidth(buttonWidth); itemButton.setWidth(buttonWidth); runButton.setWidth(buttonWidth); drawButton.setPosition( cardButton.getX() + cardButton.getWidth() + xButtonSpacing, drawButton.getY()); runButton.setPosition( cardButton.getX() + cardButton.getWidth() + xButtonSpacing, runButton.getY()); int scrollerBuffer = 5; BufferedImage scrollerImage = null; // Load the Scroller Image try { scrollerImage = ImageIO.read(this.getClass().getResource("/resources/images/pointerFinger.png")); } catch (IOException ex) { Logger.getLogger(Framework.class.getName()).log(Level.SEVERE, null, ex); } actionScroller = new MenuScroller2D( scrollerImage, cardButton.getX() - scrollerBuffer, cardButton.getY(), buttonWidth + xButtonSpacing, buttonHeight + yButtonSpacing, 2, 2, 4, 1, 1); actionScroller.setWidth(cardButton.getHeight()); actionScroller.setHeight(cardButton.getHeight()); actionScroller.setPosition( cardButton.getX() - actionScroller.getWidth() - scrollerBuffer, cardButton.getY()); enemyImage = enemy.getBattleImage(); mainCharacterImage = StartGameState.character.getBattleImage(); SoundManager.add( "BattleMusic", new Sound(this.getClass().getResource("/resources/sounds/Woodland_Fantasy_0.wav"), 0)); hand = new IndexedLinkedHashMap<>(); deckCount = 0; if (MainCharacter.maxHand <= MainCharacter.deck.size()) { for (int i = 0; i < MainCharacter.maxHand; i++) { hand.put(i, MainCharacter.deck.get(i)); deckCount++; } } else { for (int i = 0; i < MainCharacter.deck.size(); i++) { hand.put(i, MainCharacter.deck.get(i)); deckCount++; } } try { cardBack = ImageIO.read( this.getClass() .getResource("/resources/images/Cards/40X56 Card Frames Revised/Card_Back.png")); } catch (IOException ex) { Logger.getLogger(Framework.class.getName()).log(Level.SEVERE, null, ex); } int x = drawButton.getX() + drawButton.getWidth() + 40; cardWidth = 3 * windowWidth / 4 - 2 * 15 - cardBack.getWidth() - x; int cardSpacing = cardWidth / hand.size(); cardScroller = new MenuScroller2D( scrollerImage, drawButton.getX() + drawButton.getWidth() + 10, drawButton.getY() + hand.getIndexed(0).getHeight() / 2 - 10, cardSpacing, 0, deckCount, 1, deckCount, 1, 1); cardScroller.setWidth(actionScroller.getWidth()); cardScroller.setHeight(actionScroller.getHeight()); deckScroller = new MenuScroller2D( scrollerImage, 3 * windowWidth / 4 - 15 - cardBack.getWidth() - 10 - actionScroller.getWidth(), drawButton.getY() + hand.getIndexed(0).getHeight() / 2 - 10, 0, 0, 1, 1, 1, 1, 1); deckScroller.setWidth(actionScroller.getWidth()); deckScroller.setHeight(actionScroller.getHeight()); shouldWait = false; drawNoMana = false; drawNoCards = false; drawItemUsed = false; drawParalyzed = false; enemyMoveChosen = false; itemMenu = new ItemsMenu(framework); }
public static void shootBullet(float angle, int power, int x, int y) { bullets.add(new FunctionalBullet(power, angle, x, y)); SoundManager.playShoot(); }
private void handleSubMenuClick(int i) { if (i == 0) { // back button centralBox.setFinalPos(new Vector2D(boxs[0].getPos().x, boxs[0].getPos().y + Box.size)); centralBox.setFinalSize(Box.size, Box.size); centralBox.setImageVisible(true); // No longer draw submenu drawSubmenuScreen = -1; setTextBoxesVisible(false); // Special text cases i.e. depending on logged in/out // TODO: set up arrays for altTxt in different languages if (currSubMenu == Menu.CONNECTIVITY && DBClient.loggedIn) { subBoxs[0].setText("Sign out"); } // If going back from find opponent screen then remove player from waiting table if (currSubMenu == Menu.MAIN) { DBClient.removeFromWaitingTable(); } } else { switch (currMenu) { case MAIN: // Find opponent 'play' button pressed DBClient.createNewGame(); game.gameType = Game.ONLINE_MULTI; game.rPlayerTurn = true; game.startNewGame(); break; case OPTIONS: switch (currSubMenu) { case GENERAL: switch (drawSubmenuScreen) { // Sound case 0: switch (i) { case 1: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.sound = true; SoundManager.unmute(); break; case 2: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.sound = false; SoundManager.mute(); break; } break; // Language case 1: switch (i) { case 1: txt = english; break; case 2: txt = french; break; } changeLanguage(); break; // Animation case 2: switch (i) { case 1: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.animation = true; break; case 2: subMenuBoxs[1].invertChecked(); subMenuBoxs[2].invertChecked(); game.animation = false; } break; } break; case CONNECTIVITY: switch (drawSubmenuScreen) { // Login case 0: // TODO: encrpyt pass in db switch (i) { // Checkbox case 1: subMenuBoxs[1].invertChecked(); break; case 2: if (subMenuBoxs[1].isChecked()) { if (DBClient.newUser(textFields[0].getText(), textFields[1].getText())) handleSubMenuClick(0); } else { if (DBClient.tryLogin(textFields[0].getText(), textFields[1].getText())) handleSubMenuClick(0); } break; } break; } break; } break; } } }
/** * manages the boss. Checks if boss is dead and goes to next level, Check if boss is shot. Flips * boss image as necessary and finally handles the boss shooting */ private void updateBoss(float dt) { if (boss != null) { // Check if boss needs flipped (Boss cannot access the player to get his x and y position so I // calculate this here) if (playerModel.getXPos() > boss.getXPos() + 30 && boss.direction == false) { boss.direction = true; if (boss.curFrame == 2) { boss.curFrame = 1; } else { boss.curFrame = 0; } } else if (playerModel.getXPos() < boss.getXPos() + 30 && boss.direction == true) { boss.direction = false; if (boss.curFrame == 1) { boss.curFrame = 2; } else { boss.curFrame = 3; } } // // Check if boss gets shot ArrayList<Bullet> bulletsToRemove = new ArrayList<Bullet>(); for (Bullet b : playerModel.getBulletList()) { if (boss.checkBullet(b)) { bulletsToRemove.add(b); } } playerModel.getBulletList().removeAll(bulletsToRemove); // Check if player is hit by spinning arm // Here I check each piece of arm individually for (int i = 0; i < boss.armPieces.size(); i++) { // Player dies if he collides with arm if (Utils.boxCollision( new Rectangle(boss.armPieces.get(i).x, boss.armPieces.get(i).y, 32, 32), playerModel.getBoundingBox())) { boss.setXPos(300); boss.theta = 0; playerDeath(); } } // check if boss is dead (Boss doesn't have enough access to change to a new test level) if (boss.health <= 0) { modelController.setMainModel(new LevelModel(modelController, "assets/underworld.json")); modelController .getViewController() .setMainView(new LevelView(modelController.getViewController(), "next")); SoundManager sm = SoundManager.get(); sm.playSound("underworld"); sm.stopSound("music"); } // boss shoots 3 bullets at a time if (boss.shootBullet()) { if (boss.direction == false) { Vector2 playerPos = new Vector2( playerModel.getXPos(), playerModel .getYPos()); // Obtains player's location to shoot towards that direction Vector2 enemyPos = new Vector2(boss.xPos + 8, boss.yPos + 19); Vector2 dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 8, boss.yPos + 19, dir)); enemyPos = new Vector2(boss.xPos + 5, boss.yPos + 47); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 5, boss.yPos + 47, dir)); enemyPos = new Vector2(boss.xPos + 8, boss.yPos + 72); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 8, boss.yPos + 72, dir)); } else { Vector2 playerPos = new Vector2( playerModel.getXPos(), playerModel .getYPos()); // Obtains player's location to shoot towards that direction Vector2 enemyPos = new Vector2(boss.xPos + 84, boss.yPos + 19); Vector2 dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 84, boss.yPos + 19, dir)); enemyPos = new Vector2(boss.xPos + 88, boss.yPos + 47); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 88, boss.yPos + 47, dir)); enemyPos = new Vector2(boss.xPos + 84, boss.yPos + 72); dir = playerPos.sub(enemyPos); activeBullets.add(new EnemyBullet(boss.xPos + 84, boss.yPos + 72, dir)); } } boss.update(dt); } }
@Override public void onClick(View v) { Intent i = new Intent(v.getContext(), DrillActivity.class); /* This is probably a good candidate for refactoring: * */ switch (v.getId()) { case R.id.button_numbers: i.putExtra("word_list", R.raw.wl_numbers); break; case R.id.button_colors: i.putExtra("word_list", R.raw.wl_colors); break; case R.id.button_daysmonths: i.putExtra("word_list", R.raw.wl_daysmonths); break; case R.id.button_body: i.putExtra("word_list", R.raw.wl_body); break; case R.id.button_countries: i.putExtra("word_list", R.raw.wl_countries); break; case R.id.button_drinks: i.putExtra("word_list", R.raw.wl_drinks); break; case R.id.button_family: i.putExtra("word_list", R.raw.wl_family); break; case R.id.button_food: i.putExtra("word_list", R.raw.wl_generalfood); break; case R.id.button_kfood: i.putExtra("word_list", R.raw.wl_koreanfood); break; case R.id.button_fruit: i.putExtra("word_list", R.raw.wl_fruit); break; case R.id.button_home: i.putExtra("word_list", R.raw.wl_home); break; case R.id.button_kitchen: i.putExtra("word_list", R.raw.wl_kitchen); break; case R.id.button_school: i.putExtra("word_list", R.raw.wl_school); break; case R.id.button_seasonings: i.putExtra("word_list", R.raw.wl_seasonings); break; case R.id.button_shopping: i.putExtra("word_list", R.raw.wl_shopping); break; case R.id.button_transportation: i.putExtra("word_list", R.raw.wl_transportation); break; case R.id.button_vegetables: i.putExtra("word_list", R.raw.wl_vegetables); break; case R.id.button_weather: i.putExtra("word_list", R.raw.wl_weather); break; case R.id.button_pet_farm: i.putExtra("word_list", R.raw.wl_pet_farm); break; case R.id.button_zoo: i.putExtra("word_list", R.raw.wl_zoo); break; default: break; } SoundManager.playEffect("menu"); startActivity(i); }
public void clear() { staticSoundManager.clear(); }
// called when application is first run, long running methods should not go here but should be // placed in threads that are called from here, as this thread delays the UI thread @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Sound files loading part snd = new SoundManager(getApplicationContext()); // Create an instance of our sound manager this.setVolumeControlStream( AudioManager.STREAM_MUSIC); // Set volume rocker mode to media volume bellSound = snd.load(R.raw.gong_burmese); drumSound = snd.load(R.raw.bowla_emoto); // Background music load // mp = new MediaPlayer(); //Create Mediaplayer object // mp = MediaPlayer.create(getBaseContext(), R.raw.substancesuperslow); mp = MediaPlayer.create(getBaseContext(), R.raw.bowla_emoto); // mp.setDataSource(); // mp.prepare(); // mp.seekTo(0); mp.setLooping(true); mp.start(); // Seekbar listener, This will detect moving signal by seekbar barChange = new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) {} @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { switch (seekBar.getId()) { case R.id.volbar: snd.setVolume((float) progress / 100.0f); break; } } }; seekvolbar = (SeekBar) findViewById(R.id.volbar); seekvolbar.setOnSeekBarChangeListener(barChange); // soundEffects = new SoundPool(5, AudioManager.STREAM_MUSIC, 100); GLSurfaceView glView = (GLSurfaceView) findViewById(R.id.surfaceview); openGLRenderer = new OpenGLRenderer(this, glView, backend); // imageView = (ImageView)findViewById(R.id.image); // Bitmap bm3 = BitmapFactory.decodeFile(backend.getImagePath()); // imageView.setImageBitmap(bm); /*new Thread(new Runnable(){ @Override public void run(){ while (true){ backend.getServerUpdates(); } } });*/ shouldGetImage = true; shouldUpdateData = true; spawnerToggle = true; updatedCount = 0; // new BackendThreadSpawner().execute(); // new MapUpdater().execute(); // setContentView(openGLRenderer); // glView.setRenderer(openGLRenderer); }