Android Open Source - killingspree on Screen Controls






From Project

Back to project page killingspree.

License

The source code is released under:

MIT License

If you think the Android project killingspree listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sillygames.killingSpree.controls;
/*ww  w  .  j a v  a 2  s .c om*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad.TouchpadStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;

public class onScreenControls extends InputController {
    private Stage stage;
    private Button leftButton;
    private Button rightButton;
    private Button upButton;
    private Button jumpButton;
    private Button shootButton;
    private Button throwBombButton;
    private Button closeButton;
    private Skin skin;
    private boolean createObjectsWasPressed;
    private static float BUTTON_SIZE = 125f;

    public onScreenControls() {
        stage = new Stage();

        skin = new Skin();
        skin.add("buttonA", new Texture("controls/buttonA.png"));
        skin.add("buttonB", new Texture("controls/buttonB.png"));
        skin.add("buttonX", new Texture("controls/buttonX.png"));
        skin.add("buttonLeft", new Texture("controls/buttonLeft.png"));
        skin.add("buttonRight", new Texture("controls/buttonRight.png"));
        skin.add("buttonUp", new Texture("controls/buttonUp.png"));
        skin.add("closeButton", new Texture("controls/closeButton.png"));
        

        Drawable button;


        button = skin.getDrawable("buttonLeft");
        leftButton = new Button(button);
        leftButton.setColor(leftButton.getColor().r, leftButton.getColor().g,
                leftButton.getColor().b, leftButton.getColor().a / 5);
        
        button = skin.getDrawable("buttonRight");
        rightButton = new Button(button);
        rightButton.setColor(rightButton.getColor().r, rightButton.getColor().g,
                rightButton.getColor().b, rightButton.getColor().a / 5);
        
        button = skin.getDrawable("buttonUp");
        upButton = new Button(button);
        upButton.setColor(upButton.getColor().r, upButton.getColor().g,
                upButton.getColor().b, upButton.getColor().a / 5);
        
        button = skin.getDrawable("buttonA");
        jumpButton = new Button(button);
        jumpButton.setColor(jumpButton.getColor().r, jumpButton.getColor().g,
                jumpButton.getColor().b, jumpButton.getColor().a / 5);

        button = skin.getDrawable("buttonX");
        shootButton = new Button(button);
        shootButton.setColor(shootButton.getColor().r,
                shootButton.getColor().g, shootButton.getColor().b,
                shootButton.getColor().a / 5);

        button = skin.getDrawable("buttonB");
        throwBombButton = new Button(button);
        throwBombButton.setColor(throwBombButton.getColor().r,
                throwBombButton.getColor().g,
                throwBombButton.getColor().b,
                throwBombButton.getColor().a / 5);
        
        button = skin.getDrawable("closeButton");
        closeButton = new Button(button);
        closeButton.setColor(closeButton.getColor().r,
                closeButton.getColor().g,
                closeButton.getColor().b,
                closeButton.getColor().a / 5);

        this.stage.addActor(jumpButton);
        this.stage.addActor(shootButton);
        this.stage.addActor(throwBombButton);
        this.stage.addActor(closeButton);
        this.stage.addActor(upButton);
        this.stage.addActor(rightButton);
        this.stage.addActor(leftButton);
        Gdx.input.setInputProcessor(stage);
        resize();
    }

    @Override
    public boolean axisLeft() {
        return (leftButton.isPressed() || (InputController.instance
                    .axisLeft()));
    }

    @Override
    public boolean axisRight() {
        return (rightButton.isPressed() || InputController.instance
                    .axisRight());
    }

    public boolean axisUp() {
        return (upButton.isPressed() || InputController.instance
                    .axisUp());
    }

    @Override
    public boolean axisDown() {
        return false;
    }

    @Override
    public boolean buttonA() {
        return (jumpButton.isPressed() || InputController.instance
                    .buttonA());
    }

    @Override
    public boolean buttonB() {
        return (throwBombButton.isPressed() || InputController.instance
                .buttonB());
    }
    
    @Override
    public boolean closeButton() {
        return (closeButton.isPressed() || InputController.instance
                .closeButton());
    }

    public Stage getStage() {
        return stage;
    }

    public void setStage(Stage stage) {
        this.stage = stage;
    }

    public boolean createObjects() {
        boolean createObjectsStatus = (createObjectsWasPressed || InputController.instance
                .buttonB());
        createObjectsWasPressed = false;
        return createObjectsStatus;
    }

    @Override
    public boolean buttonX() {
        return (shootButton.isPressed() ||
                InputController.instance.buttonX());
    }

    public void render() {
        stage.draw();
    }
    
    public void dispose() {
        skin.dispose();
    }

    public void resize() {
        Preferences prefs = Gdx.app.getPreferences("settings");
        int scaling = prefs.getInteger("scaling");
        if (scaling <= 30 || scaling >= 150) {
            scaling = 100;
            prefs.putInteger("scaling", 100);
            prefs.flush();
        }
        float buttonSize = (BUTTON_SIZE * (float) Gdx.graphics.getWidth() *
                scaling) / (1280f * 100f);
        shootButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
                buttonSize, buttonSize, buttonSize);
        jumpButton.setBounds(Gdx.graphics.getWidth() - 2 * buttonSize, 10,
                buttonSize, buttonSize);
        throwBombButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
                2f * buttonSize  * 1.1f, buttonSize, buttonSize);
        closeButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
                Gdx.graphics.getHeight() - buttonSize * 1.1f, buttonSize,
                buttonSize);
        buttonSize *= 0.8f;
        leftButton.setBounds(buttonSize * 0.1f,
                buttonSize * 0.1f, buttonSize, buttonSize);
        upButton.setBounds(buttonSize * 1.6f / 2,
                buttonSize, buttonSize, buttonSize);
        rightButton.setBounds(buttonSize * 1.6f,
                buttonSize * 0.1f, buttonSize, buttonSize);
    }
}




Java Source Code List

com.sillygames.killingSpree.AndroidLauncher.java
com.sillygames.killingSpree.KillingSpree.java
com.sillygames.killingSpree.PlatformServices.java
com.sillygames.killingSpree.categories.EnemyCategory.java
com.sillygames.killingSpree.categories.ExplodingWeaponCategory.java
com.sillygames.killingSpree.categories.LivingCategory.java
com.sillygames.killingSpree.categories.NonExplodingWeaponCategory.java
com.sillygames.killingSpree.clientEntities.ClientArrow.java
com.sillygames.killingSpree.clientEntities.ClientBlob.java
com.sillygames.killingSpree.clientEntities.ClientBomb.java
com.sillygames.killingSpree.clientEntities.ClientBullet.java
com.sillygames.killingSpree.clientEntities.ClientEntity.java
com.sillygames.killingSpree.clientEntities.ClientFly.java
com.sillygames.killingSpree.clientEntities.ClientFrog.java
com.sillygames.killingSpree.clientEntities.ClientPlayer.java
com.sillygames.killingSpree.clientEntities.ClientTestPlayer.java
com.sillygames.killingSpree.controls.InputController.java
com.sillygames.killingSpree.controls.onScreenControls.java
com.sillygames.killingSpree.desktop.DesktopLauncher.java
com.sillygames.killingSpree.desktop.DesktopServices.java
com.sillygames.killingSpree.helpers.EntityUtils.java
com.sillygames.killingSpree.helpers.Event.java
com.sillygames.killingSpree.helpers.MyButton.java
com.sillygames.killingSpree.helpers.MyConnection.java
com.sillygames.killingSpree.helpers.Utils.java
com.sillygames.killingSpree.managers.LevelLoader.java
com.sillygames.killingSpree.managers.WorldBodyUtils.java
com.sillygames.killingSpree.managers.WorldManager.java
com.sillygames.killingSpree.managers.WorldRenderer.java
com.sillygames.killingSpree.managers.physics.Body.java
com.sillygames.killingSpree.managers.physics.CollisionProcessor.java
com.sillygames.killingSpree.managers.physics.Ray.java
com.sillygames.killingSpree.managers.physics.WorldDebugRenderer.java
com.sillygames.killingSpree.managers.physics.World.java
com.sillygames.killingSpree.networking.ControlsSender.java
com.sillygames.killingSpree.networking.NetworkRegisterer.java
com.sillygames.killingSpree.networking.StateProcessor.java
com.sillygames.killingSpree.networking.messages.AudioMessage.java
com.sillygames.killingSpree.networking.messages.ClientDetailsMessage.java
com.sillygames.killingSpree.networking.messages.ConnectMessage.java
com.sillygames.killingSpree.networking.messages.ControlsMessage.java
com.sillygames.killingSpree.networking.messages.EntityState.java
com.sillygames.killingSpree.networking.messages.GameStateMessage.java
com.sillygames.killingSpree.networking.messages.PlayerNamesMessage.java
com.sillygames.killingSpree.networking.messages.ServerStatusMessage.java
com.sillygames.killingSpree.pool.AssetLoader.java
com.sillygames.killingSpree.pool.EntityPool.java
com.sillygames.killingSpree.pool.MessageObjectPool.java
com.sillygames.killingSpree.pool.Pool.java
com.sillygames.killingSpree.pool.Poolable.java
com.sillygames.killingSpree.renderers.HUDRenderer.java
com.sillygames.killingSpree.screens.AbstractScreen.java
com.sillygames.killingSpree.screens.ClientDiscoveryScreen.java
com.sillygames.killingSpree.screens.GameScreen.java
com.sillygames.killingSpree.screens.LobbyScreen.java
com.sillygames.killingSpree.screens.MainMenuScreen.java
com.sillygames.killingSpree.screens.OptionsScreen.java
com.sillygames.killingSpree.screens.SplashScreen.java
com.sillygames.killingSpree.screens.settings.Constants.java
com.sillygames.killingSpree.serverEntities.ServerArrow.java
com.sillygames.killingSpree.serverEntities.ServerBlob.java
com.sillygames.killingSpree.serverEntities.ServerBomb.java
com.sillygames.killingSpree.serverEntities.ServerBullet.java
com.sillygames.killingSpree.serverEntities.ServerEntity.java
com.sillygames.killingSpree.serverEntities.ServerFly.java
com.sillygames.killingSpree.serverEntities.ServerFrog.java
com.sillygames.killingSpree.serverEntities.ServerPlayer.java
com.sillygames.killingSpree.sound.SFXPlayer.java