music working

master
Jonathan Hager 5 years ago
parent 4d6ed50f42
commit 94f9b95f25

@ -3,6 +3,7 @@ package com.trs.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
@ -45,6 +46,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
Texture textureSolid;
Pixmap pix;
float volume;
Screen screen;
@Override
@ -55,6 +58,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
model = new Model(difficulty);
view = new View();
volume = 0.5f;
wallTimer = new Timer();
wallTimer.scheduleTask(new Timer.Task() {
@Override
@ -63,7 +68,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
if(screen.getId() == 1) {
model.timerStep();
if(model.isToReset()){
screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT,model.getEnding());
screen.dispose();
screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT,model.getEnding(), volume);
}
}
}
@ -83,7 +89,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
//POLYGON STUFF
screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT);
screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT, volume);
Gdx.input.setInputProcessor(this);
}
@ -205,15 +211,18 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
public void ManageButtonEvent(int keycode){
switch(keycode){
case 0: //GOTO MAINMENU
screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT);
screen.dispose();
screen = new MainMenuScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT, volume);
difficulty = 1;
break;
case 1: //NEW GAMESCREEN
model = new Model(difficulty);
screen = new GameScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT);
screen.dispose();
screen = new GameScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT, volume);
break;
case 2: //GOTO ENDSCREEN
screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT, true);
screen.dispose();
screen = new EndScreen(GAME_WORLD_WIDTH,GAME_WORLD_HEIGHT, true, volume);
difficulty = 1;
break;
case 3:

@ -1,5 +1,6 @@
package com.trs.game.view;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@ -15,12 +16,16 @@ public abstract class Screen {
public ArrayList<Button> buttons;
public ArrayList<Text> texts;
public Screen(int SCREEN_WIDTH, int SCREEN_HEIGHT, int id){
protected Music music;
protected float volume;
public Screen(int SCREEN_WIDTH, int SCREEN_HEIGHT, int id, float volume){
buttons = new ArrayList();
texts = new ArrayList();
this.SCREEN_WIDTH = SCREEN_WIDTH;
this.SCREEN_HEIGHT =SCREEN_HEIGHT;
this.id = id;
this.volume = volume;
}
abstract public void timer();
@ -39,4 +44,21 @@ public abstract class Screen {
public int getHeight() {
return SCREEN_HEIGHT;
}
public void startMusic(){
music.play();
}
public void stopMusic(){
music.stop();
}
public void setVolume(float volume){
this.volume = volume;
music.setVolume(volume);
}
public float getVolume(){
return this.volume;
}
}

@ -1,5 +1,6 @@
package com.trs.game.view.Screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -14,10 +15,21 @@ public class EndScreen extends Screen {
boolean lost;
public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT, boolean lost){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 2);
public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT, boolean lost, float volume){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 2, volume);
this.lost = lost;
if(lost){
music = Gdx.audio.newMusic(Gdx.files.internal("lose.ogg"));
}
else{
music = Gdx.audio.newMusic(Gdx.files.internal("victory.mp3"));
}
music.setVolume(volume);
music.setLooping(true);
music.play();
if(lost)
texts.add(new Text(GAME_WORLD_WIDTH/2, (int)((float)GAME_WORLD_HEIGHT * 0.85f), "The monster ate too many doods!", Color.BLACK, 3, 0,0));
else
@ -70,6 +82,6 @@ public class EndScreen extends Screen {
@Override
public void dispose() {
music.dispose();
}
}

@ -1,5 +1,6 @@
package com.trs.game.view.Screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -12,8 +13,12 @@ import com.trs.game.view.Text;
public class GameScreen extends Screen {
public GameScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 1);
public GameScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT, float volume){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 1, volume);
music = Gdx.audio.newMusic(Gdx.files.internal("game.ogg"));
music.setVolume(volume);
music.setLooping(true);
music.play();
}
@Override
@ -46,6 +51,6 @@ public class GameScreen extends Screen {
@Override
public void dispose() {
music.dispose();
}
}

@ -1,5 +1,6 @@
package com.trs.game.view.Screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -12,8 +13,13 @@ import com.trs.game.view.Text;
public class MainMenuScreen extends Screen {
public MainMenuScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 0);
public MainMenuScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT, float volume){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 0, volume);
music = Gdx.audio.newMusic(Gdx.files.internal("menu.ogg"));
music.setVolume(volume);
music.setLooping(true);
music.play();
texts.add(new Text(GAME_WORLD_WIDTH/2, (int)((float)GAME_WORLD_HEIGHT * 0.85f), "Starve the Monster", Color.BLACK, 5, 0,0));
texts.add(new Text(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, "click to start...", Color.BLACK, 2, GAME_WORLD_HEIGHT/2 - 30,GAME_WORLD_HEIGHT/2 + 30));
@ -62,6 +68,6 @@ public class MainMenuScreen extends Screen {
@Override
public void dispose() {
music.dispose();
}
}

Loading…
Cancel
Save