public Allied(GeneralScreen screen, TextureRegion tRegion) { super(tRegion); this.screen = screen; // colocamos la pantalla en el centro inferior de la pantalla // setPosition((GameLogic.getScreenWidth() - getWidth()) / 2, posY); vel = 500; setPosition((GameLogic.getScreenWidth() - getWidth()) / 2, -getHeight()); enter(); setActive(true); setCanShoot(true); }
@Override public void act(float delta) { super.act(delta); dir = -Gdx.input.getAccelerometerX() / 4; if (dir == 0) { if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.isKeyPressed(Input.Keys.D)) { dir = 1; } else if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.isKeyPressed(Input.Keys.A)) { dir = -1; } } if (alive) { if (isActive()) { moveBy(dir * vel * delta, 0); } x = getX(); y = getY(); polygon.setPosition(x - 310, posY + getHeight() - 20); if (isActive()) { // comprobamos que la nave no de salga de la pantalla if (getX() < 5) { setX(10.1f); } else if (getX() > (GameLogic.getScreenWidth() - (getWidth() + 5))) { setX(GameLogic.getScreenWidth() - (getWidth() + 10)); } if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { if (screen._groupAllied.hasChildren()) { if (isCanShoot()) { shoot(); } } } } } }