Search in sources :

Example 1 with PlayerSoldier

use of me.dumfing.multiplayerTools.PlayerSoldier in project Alkahest-Coffee by AlkahestDev.

the class ClientGameInstance method draw.

public void draw(SpriteBatch batch, ShapeRenderer renderer) {
    batch.begin();
    for (PlayerSoldier p : playWorld.getPlayers().values()) {
        //DrawTools.rec(renderer,p.getRect());
        p.draw(batch, playWorld.getPlayers().get(gameClient.getConnectionID()).equals(p));
    }
    //batch.draw(playWorld.getMap().getVisualComponent(),0,0);
    batch.end();
    playWorld.getMap().draw(batch);
    renderer.begin(ShapeRenderer.ShapeType.Filled);
    for (PlayerSoldier playerSoldier : gameClient.getPlayers().values()) {
        //playerSoldier.getMouseAngle());
        System.out.println(playerSoldier.getX() - playerSoldier.getCenterX());
        renderer.setColor(Color.RED);
        renderer.line(playerSoldier.getCenterX(), playerSoldier.getCenterY(), playerSoldier.getCenterX() + (5 * (float) Math.cos(Math.toRadians(playerSoldier.getMouseAngle()))), playerSoldier.getCenterY() + (5 * (float) Math.sin(Math.toRadians(playerSoldier.getMouseAngle()))));
        renderer.setColor(Color.BLUE);
        DrawTools.rec(renderer, new Rectangle((int) (playerSoldier.getX()), (int) (playerSoldier.getY() + playerSoldier.getvY()), 1, 1));
    }
    renderer.end();
}
Also used : PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) Rectangle(com.badlogic.gdx.math.Rectangle)

Example 2 with PlayerSoldier

use of me.dumfing.multiplayerTools.PlayerSoldier in project Alkahest-Coffee by AlkahestDev.

the class ClientGameInstance method touchDown.

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    PlayerSoldier clientPlayer = getPlayer(gameClient.getConnectionID());
    screenY = Gdx.graphics.getHeight() - screenY;
    if (button == 0) {
        keysDown[MultiplayerTools.Keys.LMB] = new MultiplayerTools.ClientControlObject(true);
        keyUpdate = true;
    }
    if (button == 1) {
        keysDown[MultiplayerTools.Keys.RMB] = new MultiplayerTools.ClientControlObject(true);
        keyUpdate = true;
    }
    keysDown[MultiplayerTools.Keys.ANGLE] = new MultiplayerTools.ClientControlObject(getPointerAngle(screenX, screenY));
    return false;
}
Also used : PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) MultiplayerTools(me.dumfing.multiplayerTools.MultiplayerTools)

Example 3 with PlayerSoldier

use of me.dumfing.multiplayerTools.PlayerSoldier in project Alkahest-Coffee by AlkahestDev.

the class MainGame method create.

@Override
public void create() {
    Gdx.graphics.setCursor(Gdx.graphics.newCursor(new Pixmap(Gdx.files.internal("mouseCursorTemp.png")), 0, 0));
    assetManager = new AssetManager();
    queueLoading();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.translate(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    camera.update();
    //viewport = new FitViewport(1920, 1080, camera);
    fontCaches = new Array<BitmapFontCache>();
    BitmapFont dagger20 = new BitmapFont(Gdx.files.internal("fonts/dagger20.fnt"));
    BitmapFont dagger30 = new BitmapFont(Gdx.files.internal("fonts/dagger30.fnt"));
    BitmapFont dagger40 = new BitmapFont(Gdx.files.internal("fonts/dagger40.fnt"));
    BitmapFont dagger50 = new BitmapFont(Gdx.files.internal("fonts/dagger50.fnt"));
    dagger20.getData().markupEnabled = true;
    dagger30.getData().markupEnabled = true;
    dagger40.getData().markupEnabled = true;
    dagger50.getData().markupEnabled = true;
    fontCaches.add(new BitmapFontCache(dagger20));
    fontCaches.add(new BitmapFontCache(dagger30));
    fontCaches.add(new BitmapFontCache(dagger40));
    fontCaches.add(new BitmapFontCache(dagger50));
    shapeRenderer = new ShapeRenderer();
    gameMain = new MainMenu(fontCaches, assetManager, camera);
    loadingMenu = new LoadingMenu(fontCaches, assetManager, camera);
    connectingMenu = new ConnectingMenu(fontCaches, assetManager, camera);
    serverBrowser = new ServerBrowser(fontCaches, assetManager, camera);
    settingsMenu = new SettingsMenu(fontCaches, assetManager, camera);
    pickingInfoMenu = new ClientPickingInfoMenu(fontCaches, assetManager, camera);
    lobbyMenu = new ClientLobbyMenu(fontCaches, assetManager, camera);
    // loadingmenu is the only one that is setup before anything else is loaded, background frames are loaded and added to it here
    setupLoadingMenu();
    scW = Gdx.graphics.getWidth();
    scH = Gdx.graphics.getHeight();
    //System.out.println(new Pixmap(Gdx.files.internal("pixmapTest.png")).getPixel(0,0)>>8);//since gimp doesn't do alpha in a friendly way, I'll bitshift right 8 bits to ignore alpha
    state = GameState.State.LOADINGGAME;
    batch = new SpriteBatch();
    client = new MultiplayerClient();
    clientSoldier = new PlayerSoldier(new Rectangle(0, 0, 1, 2), 0, "");
    client.startClient();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    menu = new UniversalClientMenu(fontCaches, assetManager, camera);
    Gdx.input.setInputProcessor(this);
}
Also used : MultiplayerClient(me.dumfing.multiplayerTools.MultiplayerClient) AssetManager(com.badlogic.gdx.assets.AssetManager) Rectangle(com.badlogic.gdx.math.Rectangle) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 4 with PlayerSoldier

use of me.dumfing.multiplayerTools.PlayerSoldier in project Alkahest-Coffee by AlkahestDev.

the class MainGame method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    for (BitmapFontCache bmfc : fontCaches) {
        // clear bitmap font cache because it doesn't clear itself upon drawing (grumble grumble)
        bmfc.clear();
    }
    if (state == GameState.State.PLAYINGGAME) {
        if (!zoomedIn) {
            System.out.println("CameraZoom " + camera.zoom);
            System.out.println("zoomin");
            zoomCamera(0.025f);
            zoomedIn = true;
        }
    } else {
        if (zoomedIn) {
            camera.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);
            zoomCamera(1);
            //camera.update();
            //shapeRenderer.setProjectionMatrix(camera.combined);
            //batch.setProjectionMatrix(camera.combined);
            zoomedIn = false;
        }
    }
    switch(state) {
        case // we shouldn't ever be going back to LOADINGGAME
        LOADINGGAME:
            //LOADINGGAME just needs to call assetManager.update(), then assign the values
            loadingMenu.update();
            loadingMenu.draw(batch, shapeRenderer);
            if (loadingMenu.doneLoading()) {
                // returns true if done loading
                //assets are assigned to variables here
                assignValues();
                gameMain.init();
                serverBrowser.init();
                settingsMenu.init();
                connectingMenu.init();
                pickingInfoMenu.init(client);
                lobbyMenu.init(client);
                menu.init();
                createWorlds();
                client.pingServers();
            }
            break;
        case MAINMENU:
            if (Gdx.input.getInputProcessor() != gameMain) {
                gameMain.setInputProcessor();
            }
            /*
				if(Gdx.input.getInputProcessor() != menu ){
					menu.setInputProcessor();
				}
				menu.update();
				menu.standardDraw(batch,shapeRenderer);*/
            gameMain.update();
            gameMain.standardDraw(batch, shapeRenderer);
            break;
        case MAINMENUSETTINGS:
            if (Gdx.input.getInputProcessor() != settingsMenu) {
                settingsMenu.setInputProcessor();
            }
            settingsMenu.update();
            settingsMenu.standardDraw(batch, shapeRenderer);
            break;
        case SERVERBROWSER:
            if (Gdx.input.getInputProcessor() != serverBrowser) {
                serverBrowser.setInputProcessor();
                System.out.println("RUN!");
            }
            serverBrowser.update();
            serverBrowser.draw(batch, shapeRenderer);
            break;
        case STARTSERVER:
            break;
        case CONNECTINGTOSERVER:
            connectingMenu.update();
            connectingMenu.standardDraw(batch, shapeRenderer);
            break;
        case GAMELOBBY:
            if (Gdx.input.getInputProcessor() != lobbyMenu) {
                lobbyMenu.setInputProcessor();
            }
            lobbyMenu.update(client);
            lobbyMenu.draw(batch, shapeRenderer);
            break;
        case PICKINGINFO:
            if (Gdx.input.getInputProcessor() != pickingInfoMenu) {
                pickingInfoMenu.setInputProcessor();
            }
            pickingInfoMenu.updateTeamNumbers(client.getRedTeam(), client.getBlueTeam(), client.getrLimit(), client.getbLimit());
            pickingInfoMenu.update();
            pickingInfoMenu.standardDraw(batch, shapeRenderer);
            break;
        case PLAYINGGAME:
            //camera.setToOrtho(true,900,450);
            if (Gdx.input.getInputProcessor() != gameInstance) {
                gameInstance = new ClientGameInstance(client, client.getPlayers(), camera);
                gameInstance.pickWorld(DEBUGWORLD);
                Gdx.input.setInputProcessor(gameInstance);
            }
            gameInstance.update();
            shapeRenderer.setColor(Color.BLUE);
            PlayerSoldier clientSoldierTemp = gameInstance.getPlayer(client.getConnectionID());
            //System.out.println("before "+clientSoldierTemp.getX());
            float deltaX = camera.position.x - clientSoldierTemp.getX();
            float deltaY = camera.position.y - clientSoldierTemp.getY();
            if (deltaX < -3) {
                //camera.position.x = clientSoldierTemp.getX()-5;
                if (Math.abs(deltaX) < 6) {
                    camera.position.x = clientSoldierTemp.getX() - 3;
                } else {
                    camera.position.x += Math.abs(deltaX) / 5f;
                }
            } else if (deltaX > 3) {
                //camera.position.x = clientSoldierTemp.getX()+5;//-=Math.abs(deltaX)/5f;
                if (Math.abs(deltaX) < 6) {
                    camera.position.x = clientSoldierTemp.getX() + 3;
                } else {
                    camera.position.x -= Math.abs(deltaX / 5f);
                }
            }
            if (deltaY < -3f) {
                //Math.min(Math.abs(deltaY)/5f,Math.abs(deltaY));
                camera.position.y += Math.abs(deltaY) / 5f;
            } else if (deltaY > 3f) {
                //Math.min(Math.abs(deltaY)/5f,Math.abs(deltaY));
                camera.position.y -= Math.abs(deltaY) / 5f;
            }
            //camera.position.x = clientSoldierTemp.getX();
            //System.out.println("camera update");
            //System.out.println(camera.position.x-clientSoldierTemp.getX()+" "+deltaX);
            camera.update();
            shapeRenderer.setProjectionMatrix(camera.combined);
            batch.setProjectionMatrix(camera.combined);
            gameInstance.draw(batch, shapeRenderer);
            //System.out.println("after "+clientSoldierTemp.getX());
            break;
        case ROUNDOVER:
            break;
        case QUIT:
            Gdx.app.exit();
            break;
    }
}
Also used : PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache)

Example 5 with PlayerSoldier

use of me.dumfing.multiplayerTools.PlayerSoldier in project Alkahest-Coffee by AlkahestDev.

the class ClientLobbyMenu method update.

public void update(MultiplayerClient client) {
    chatBox.clearText();
    connectedPlayers.clearText();
    int textLevel = 0;
    for (String text : client.getMessages()) {
        MenuTools.QueueText tempMessage = new MenuTools.QueueText(5, 75 + (textLevel * 32), 0, 0);
        tempMessage.setText(text, getFonts());
        tempMessage.setFont(DAGGER30);
        chatBox.addQueueText(tempMessage);
        textLevel++;
    }
    textLevel = 0;
    for (PlayerSoldier player : client.getPlayers().values()) {
        MenuTools.QueueText tempName = new MenuTools.QueueText(5, 45 + (textLevel * 42), 0, 0);
        tempName.setText(player.getName(), getFonts());
        connectedPlayers.addQueueText(tempName);
        textLevel++;
    }
    if (client.getGameStarted() > -1) {
        if (barOut) {
            countdown.setText("" + MainGame.client.getGameStarted(), getFonts());
        } else {
            // extend bar
            countDownBar.setVelocity(-13.9f, 0);
            barOut = true;
        }
    } else if (barOut) {
        // the bar is out but doesn't show any useful info
        //retract bar
        countDownBar.setVelocity(13.9f, 0);
        barOut = false;
    }
    super.update();
}
Also used : PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) MenuTools(me.dumfing.gdxtools.MenuTools)

Aggregations

PlayerSoldier (me.dumfing.multiplayerTools.PlayerSoldier)5 BitmapFontCache (com.badlogic.gdx.graphics.g2d.BitmapFontCache)2 Rectangle (com.badlogic.gdx.math.Rectangle)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 MenuTools (me.dumfing.gdxtools.MenuTools)1 MultiplayerClient (me.dumfing.multiplayerTools.MultiplayerClient)1 MultiplayerTools (me.dumfing.multiplayerTools.MultiplayerTools)1