com.badlogic.gdx.Game Java Examples

The following examples show how to use com.badlogic.gdx.Game. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AudioGdxMusicTest.java    From gdx-pd with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) 
{
	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	
	new LwjglApplication(new Game(){
		@Override
		public void create() {
			
			// play a music
			Music music = Gdx.audio.newMusic(Gdx.files.classpath("cloudconnected.ogg"));
			music.setVolume(0.3f);
			music.play();
			
			// and a pd patch at the same time
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/test.pd"));
			
		}}, config);
	
}
 
Example #2
Source File: CalibrationScreen.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Screen that only shows the chosen sprites and can be exited with an exit button
 * @param game
 */
public CalibrationScreen( Game game) {
    this.game = game;
    this.cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    if(this.game instanceof OverlayGame) {
        this.renderer = new Renderer(cam, ((OverlayGame) this.game).getSprites());
    }
    else {
        this.renderer = new Renderer(cam, new Sprites());
    }

    this.stage = new Stage();

    // Load UI for buttons if not already loaded
    if(!VisUI.isLoaded())
        VisUI.load();

    // Create back button
    createBackButton();
}
 
Example #3
Source File: MainMenuInterface.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public void init(Game game, Assets assets) {
	hiScoreBuilder = new StringBuilder();
	savedStuff = new SavedStuff();
	skin = new Skin();
	stage = new Stage();
	batch = new SpriteBatch();
	cam = new OrthographicCamera(MainMenuScreen.WIDTH, MainMenuScreen.HEIGHT);
	Gdx.input.setInputProcessor(stage);
	stage.setViewport(new StretchViewport(MainMenuScreen.WIDTH, MainMenuScreen.HEIGHT));
	batch.setProjectionMatrix(cam.combined);
	this.game = game;
	this.assets = assets;
	
	loadMainMenuAssets();
	setUpSkin();
	createTable();
	createStageActors();
	addStageActorsToStage();
	setActorsToDefaults();
	addListenersToActors();
}
 
Example #4
Source File: BeatmapLoadingScreen.java    From SIFTrain with MIT License 6 votes vote down vote up
@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    loadingTime -= delta;
    if (loadingTime <= 0 && !warnings) {
        if (valid) {
            ((Game) Gdx.app.getApplicationListener()).setScreen(new SongScreen());

        }
    }

    stage.act();
    stage.draw();
}
 
Example #5
Source File: BeatmapReloadScreen.java    From SIFTrain with MIT License 6 votes vote down vote up
@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act();
    stage.draw();

    // done loading
    if (Assets.update())
    {

        if (phase == 1) {
            Assets.setSongs();
            ((Game) Gdx.app.getApplicationListener()).setScreen(new SettingsScreen());
        }
        if (phase == 0)
        {
            phase++;
            // this will cause any newly created .rs files to be loaded.
            Assets.reloadBeatmaps();
        }
    }
    loadingProgress.setValue((Assets.getProgress() - 0.5f)* 200f);
    loadingProgress.act(delta);
}
 
Example #6
Source File: AudioGdxSoundTest.java    From gdx-pd with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) 
{
	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	
	new LwjglApplication(new Game(){
		@Override
		public void create() {
			
			// play a pd patch
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/test.pd"));
			
			// and sounds at the same time
			final Sound snd = Gdx.audio.newSound(Gdx.files.classpath("shotgun.wav"));
			snd.play();
			Gdx.input.setInputProcessor(new InputAdapter(){
				@Override
				public boolean touchDown(int screenX, int screenY, int pointer, int button) {
					snd.play();
					return true;
				}
			});
			
		}}, config);
	
}
 
Example #7
Source File: MainMenuScreen.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
public MainMenuScreen (Game game) {
	this.game = game;
	assets = new Assets();
	assets.initMainMenu();
	userInterface = new MainMenuInterface();
	userInterface.init(game, assets);
}
 
Example #8
Source File: WorldController.java    From SIFTrain with MIT License 5 votes vote down vote up
@Override
public void onCompletion(Music music) {
    if (isABRepeatMode && !done) {
        resetMarks();
        if (hasMusic) {
            theSong.pause();
            theSong.setPosition(aPosition);
            theSong.play();
            lastmtime = theSong.getPosition();
            time = lastmtime + world.delay;
            timeSyncAcc = 0;
        } else {
            time = aPosition;
        }
        return;
    }

    if (hasMusic) {
        music.dispose();
    }
    done = true;
    if (this.largestCombo < this.combo) {
        this.largestCombo = combo;
    }
    Results.bads = badCount;
    Results.goods = goodCount;
    Results.greats = greatCount;
    Results.perfects = perfectCount;
    Results.miss = missCount;

    Results.combo = largestCombo;
    Results.accuracy = calculateAccuracy();
    Results.normalizedAccuracy = calculateNormalizedAccuracy();
    accuracyMarkers.clear();
    accuracyPopups.clear();
    marks.clear();
    tapZones.clear();
    ((Game) Gdx.app.getApplicationListener()).setScreen(new ResultsScreen());
}
 
Example #9
Source File: SongSelectionScreen.java    From SIFTrain with MIT License 5 votes vote down vote up
@Override
public boolean keyUp(int keycode) {
    if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) {
        Assets.selectedBeatmap = diffList.getSelected();
        Assets.selectedGroup = songList.getSelected();
        stopPreviewSong();
        ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenuScreen());
        // do nothing
        return true;
    }
    return false;
}
 
Example #10
Source File: LiveOptionsScreen.java    From SIFTrain with MIT License 5 votes vote down vote up
@Override
public boolean keyUp(int keycode) {
    if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) {
        if (theSong != null)
        {
            theSong.stop();
            theSong.dispose();
        }
        ((Game) Gdx.app.getApplicationListener()).setScreen(new SongSelectionScreen());
        // do nothing
        return true;
    }
    return false;
}
 
Example #11
Source File: AudioGdxPatchTest.java    From gdx-pd with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	
	new LwjglApplication(new Game(){
		@Override
		public void create() {
			
			// just play a patch
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/test.pd"));
			
		}
		
	}, config);
}
 
Example #12
Source File: SettingsScreen.java    From SIFTrain with MIT License 5 votes vote down vote up
@Override
public boolean keyUp(int keycode) {
    if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) {
        // do nothing
        // Return without saving the changes
        ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenuScreen());
        return true;
    }
    return false;
}
 
Example #13
Source File: SplashScreen.java    From SIFTrain with MIT License 5 votes vote down vote up
@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act();
    stage.draw();

    if (Assets.update()) { // check if all files are loaded

        if (animationDone) { // when the animation is finished, go to MainMenu()
            // load the assets to into the Assets class
            Assets.setMenuSkin();
            Assets.setHitsounds();
            Assets.setTextures();
            Assets.setFonts();
            if (phase == 1)
            {
                Assets.setSongs();
                ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenuScreen());
            }
            if (phase == 0)
            {
                phase++;
                Assets.reloadBeatmaps();
            }
        }
    }
    loadingProgress.setValue(phase == 0 ? Assets.getProgress() * 100f : (Assets.getProgress() - 0.5f)*200f);
    loadingProgress.act(delta);
}
 
Example #14
Source File: MainMenuScreen.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Screen that only shows the chosen sprites and can be exited with an exit button
 * @param game
 */
public MainMenuScreen(Game game) {
    this.game = game;
    this.camera = new OrthographicCamera();
    this.viewport = new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), this.camera);
    this.stage = new Stage(viewport);

    // Load UI for buttons if not already loaded
    if(!VisUI.isLoaded())
        VisUI.load();

    // Create buttons with listeners
    createButtons();
}
 
Example #15
Source File: Sample.java    From Codelabs with MIT License 5 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
	if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {
		dispose();
		Gdx.input.setCatchBackKey(false);
		((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
	}
	
	return true;
}
 
Example #16
Source File: ScreenManager.java    From Norii with Apache License 2.0 4 votes vote down vote up
public void initialize(Game game) {
	this.game = game;
}
 
Example #17
Source File: SettingsScreen.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
public SettingsScreen(Game game) {

        this.game = game;
        this.camera = new OrthographicCamera();
        this.viewport = new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), this.camera);
        this.stage = new Stage(viewport);

        // Buttons
        this.statusButton = new TextButton("Connect", VisUI.getSkin());
        this.backButton = new TextButton("Back", VisUI.getSkin());

        // IP
        this.ipLabel = new Label("IP Address:", VisUI.getSkin());
        this.ipField = new TextField("", VisUI.getSkin());

        // Port
        this.portLabel = new Label("Port:", VisUI.getSkin());
        this.portField = new TextField("", VisUI.getSkin());

        // Server connection status label
        this.statusLabel = new Label("No Information to see yet.", VisUI.getSkin());

        // BCI Modes

        // Stimuli ON and OFF
        this.stimuliOff = new CheckBox("Stimuli OFF", VisUI.getSkin());
        this.stimuliOn = new CheckBox("Stimuli ON", VisUI.getSkin());

        // Synchronous and asynchronous
        this.synchronous = new CheckBox("Synchronous", VisUI.getSkin());
        this.asynchronous = new CheckBox("Asynchronous", VisUI.getSkin());


        // Controls: direct/sticky keys
        this.gamePlayModeSelectorLabel = new Label("Game play mode", VisUI.getSkin());
        this.gamePlayModeSelector= new SelectBox<>(VisUI.getSkin());
        this.gamePlayModeSelector.setItems("Direct","Sticky");

        // Decay -> Not implemented
        this.keyCommandDecayField = new TextField("", VisUI.getSkin());
        keyCommandDecayField .setMessageText("default : 200 ms ");
        keyCommandDecayField .needsLayout();
        this.keyCommandDecayLabel = new Label("Key command decay (/millisecond):", VisUI.getSkin());

        // File choosers

        // Game stimuli chooser
        this.stimuliLabel = new Label("Stimuli file:", VisUI.getSkin());
        this.fileChooser = new FileChooser("Choose Stimuli File", FileChooser.Mode.OPEN);
        fileChooser.setSize(stage.getWidth(), stage.getHeight());
        this.fileField = new TextField("", VisUI.getSkin() );
        fileField.setMessageText("no file chosen");

        // Calibration stimuli chooser
        this.calibrationLabel = new Label("Calibration file:", VisUI.getSkin() );
        this.calibrationChooser = new FileChooser("Choose Calibration File", FileChooser.Mode.OPEN);
        calibrationChooser.setSize(stage.getWidth(), stage.getHeight());
        this.calibrationField = new TextField("", VisUI.getSkin() );
        calibrationField.setMessageText("no file chosen");

        // Timeout
        this.timeoutField = new TextField("", VisUI.getSkin());
        timeoutField.setMessageText("100");
        timeoutField.needsLayout();
        this.timeoutLabel = new Label("Timeout after (ms):", VisUI.getSkin());

        // Game step
        this.gameStepLabel = new Label("Game step time:", VisUI.getSkin());
        this.gameStepField = new TextField("", VisUI.getSkin());
        gameStepField.setMessageText(""+StandardizedInterface.getInstance().getGameStepLength());
    }
 
Example #18
Source File: GameScreen.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
public GameScreen (Game g) {
	game = g;
	nahwcGame = new NahwcGame();
}
 
Example #19
Source File: SplashScreen.java    From Codelabs with MIT License 4 votes vote down vote up
@Override
public void show() {
	stage = new Stage();

	/* Load splash image */
	codelabsImage = new Image(new Texture(
			Gdx.files.internal("data/images/codelabs_splash.png")));
	
	githubImage = new Image(new Texture(
			Gdx.files.internal("data/images/github_splash.png")));

	/* Set the splash image in the center of the screen */
	float width = Gdx.graphics.getWidth();
	float height = Gdx.graphics.getHeight();

	codelabsImage.setPosition((width - codelabsImage.getWidth()) / 2,
			(height - codelabsImage.getHeight()) / 2);

	/* Fade in the image and then swing it down */
	codelabsImage.getColor().a = 0f;
	codelabsImage.addAction(Actions.sequence(Actions.fadeIn(0.5f), Actions
			.delay(1, Actions.fadeOut(0.5f))));
	
	githubImage.setPosition((width - githubImage.getWidth()) / 2,
			(height - githubImage.getHeight()) / 2);

	/* Fade in the image and then swing it down */
	githubImage.getColor().a = 0f;
	githubImage.addAction(Actions.delay(2, Actions.sequence(Actions.fadeIn(0.5f), Actions
			.delay(1, Actions.moveBy(0,
					-(height - githubImage.getHeight() / 2), 1,
					Interpolation.swingIn)), Actions.run(new Runnable() {
		@Override
		public void run() {

			/* Show main menu after swing out */
			((Game) Gdx.app.getApplicationListener())
					.setScreen(new MainMenu());
		}
	}))));

	stage.addActor(codelabsImage);
	stage.addActor(githubImage);
}
 
Example #20
Source File: DefaultScreen.java    From libgdx-demo-pax-britannica with MIT License 4 votes vote down vote up
public DefaultScreen(Game game) {
	this.game = game;
}
 
Example #21
Source File: Settings.java    From libgdx-demo-pax-britannica with MIT License 4 votes vote down vote up
public Settings(Game game) {
	super(game);
	Gdx.input.setCatchBackKey( true );
	Gdx.input.setInputProcessor(this);
}
 
Example #22
Source File: MainMenu.java    From libgdx-demo-pax-britannica with MIT License 4 votes vote down vote up
public MainMenu(Game game) {
	super(game);
	Gdx.input.setInputProcessor(this);
}
 
Example #23
Source File: Help.java    From libgdx-demo-pax-britannica with MIT License 4 votes vote down vote up
public Help(Game game) {
	super(game);
	Gdx.input.setCatchBackKey( true );
	Gdx.input.setInputProcessor(this);
}
 
Example #24
Source File: ScreenSwitcher.java    From ud405 with MIT License 4 votes vote down vote up
public ScreenSwitcher(Game game, Screen screen1, Screen screen2) {
    this.game = game;
    this.screen1 = screen1;
    this.screen2 = screen2;
    currentScreen = 1;
}
 
Example #25
Source File: AudioGdxBakingTest.java    From gdx-pd with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) 
{
	if(args.length > 0 && "remote".equals(args[0])){
		PdConfiguration.remoteEnabled = true;
	}
	new LwjglApplication(new Game() {
		
		private PdAudioBakery bakery;
		private boolean backingComplete = false;
		
		@Override
		public void create() 
		{
			// we first load patch owning destination arrays.
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/runtime.pd"));
			
			// then we schedule baking of our complex patches.
			bakery = new PdAudioBakery();
			
			bakery.addTask(Gdx.files.local("resources/complex-sound.pd"), "baked-sound", 44100, 3);
			
			bakery.start(new BakingListener() {
				@Override
				public void progress(float percents) {
					Gdx.app.log("Baking", "backing progress : " + String.valueOf(percents));
				}
				
				@Override
				public void complete() {
					backingComplete = true;
				}
			});
			
			// finally we playback backed sound when user touch screen
			Gdx.input.setInputProcessor(new InputAdapter(){
				@Override
				public boolean touchDown(int screenX, int screenY, int pointer, int button) {
					if(backingComplete){
						Pd.audio.sendBang("play-backed");
					}
					return true;
				}
			});
			
		}
		@Override
		public void render() {
			if(backingComplete)
				Gdx.gl.glClearColor(0, 0, 0, 0);
			else
				Gdx.gl.glClearColor(1, 0, 0, 0);
			Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		}
	}, new LwjglApplicationConfiguration());
	
}
 
Example #26
Source File: AudioGdxRawTest.java    From gdx-pd with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) 
{
	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	config.audioDeviceBufferSize = 512;
	config.audioDeviceBufferCount = 17;
	new LwjglApplication(new Game(){
		@Override
		public void create() 
		{
			// play a pd patch
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/test.pd"));
			
			// and write on raw device at the same time
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					int channels = 2;
					
					int sampleRate = 44100;
					AudioDevice device = Gdx.audio.newAudioDevice(sampleRate, channels < 2);
					
					// simple sinus
					float duration = 4.f;
					float pitch = 440;
					
					int samples = (int)(duration * sampleRate) * channels;
					float [] data = new float[samples];
					int stride = samples/channels;
					for(int i=0 ; i<stride ; i+=1){
						float s = (float)i/(float)stride;
						float t = s * duration * pitch;
						float value = MathUtils.sin(MathUtils.PI2 * t);
						for(int j=0 ; j<channels ; j++)
							data[i+j*stride] = value;
					}
					device.writeSamples(data, 0, data.length);
					
					device.dispose();
				}
			}).start();
			
			
		}}, config);
	
}