예제 #1
0
  public void drawDebug(SpriteBatch batch) {
    if (debugRenderer == null) {
      if (Gdx.graphics.isGL20Available())
        debugRenderer = new ImmediateModeRenderer20(64, false, true, 0);
      else debugRenderer = new ImmediateModeRenderer10(64);
    }

    float x = getX(), y = getY();

    debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);

    float x1 = x;
    float y1 = y;
    float x2 = x1 + getPrefWidth();
    float y2 = y1 + getPrefHeight();
    drawDebugItem(x1, y1, x2, y2, 1, 0, 0);

    for (Actor a : getChildren()) {
      if (debugRenderer.getNumVertices() == 64) {
        debugRenderer.end();
        debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);
      }

      x1 = x + a.getX();
      y1 = y + a.getY();
      x2 = x1 + a.getWidth();
      y2 = y1 + a.getHeight();
      drawDebugItem(x1, y1, x2, y2, 0, 1, 0);
    }

    debugRenderer.end();
  }
예제 #2
0
  public void drawDebug(SpriteBatch batch) {
    if (getDebug() == Debug.none || debugRects == null) return;
    if (debugRenderer == null) {
      if (Gdx.graphics.isGL20Available())
        debugRenderer = new ImmediateModeRenderer20(64, false, true, 0);
      else debugRenderer = new ImmediateModeRenderer10(64);
    }

    float x = 0, y = 0;
    Actor parent = getTable();
    while (parent != null) {
      if (parent instanceof Group) {
        x += parent.getX();
        y += parent.getY();
      }
      parent = parent.getParent();
    }

    debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);
    for (int i = 0, n = debugRects.size; i < n; i++) {
      DebugRect rect = debugRects.get(i);
      float x1 = x + rect.x;
      float y1 = y + rect.y - rect.height;
      float x2 = x1 + rect.width;
      float y2 = y1 + rect.height;
      float r = rect.type == Debug.cell ? 1 : 0;
      float g = rect.type == Debug.widget ? 1 : 0;
      float b = rect.type == Debug.table ? 1 : 0;

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y1, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y2, 0);

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y2, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y2, 0);

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y2, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y1, 0);

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y1, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y1, 0);

      if (debugRenderer.getNumVertices() == 64) {
        debugRenderer.end();
        debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);
      }
    }
    debugRenderer.end();
  }
예제 #3
0
    @Override
    public void render() {
      Gdx.gl.glClearColor(1, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      sharedSpriteBatch
          .getProjectionMatrix()
          .setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
      sharedSpriteBatch.begin();
      sharedSpriteBatch.draw(
          sharedTexture, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY() - 1);
      sharedSpriteBatch.end();

      if (Gdx.input.justTouched()) {
        Lwjgl3Application app = (Lwjgl3Application) Gdx.app;
        Lwjgl3WindowConfiguration config = new Lwjgl3WindowConfiguration();
        DisplayMode mode = Gdx.graphics.getDisplayMode();
        config.setWindowPosition(
            MathUtils.random(0, mode.width - 640), MathUtils.random(0, mode.height - 480));
        config.setTitle("Child window");
        Class clazz = childWindowClasses[MathUtils.random(0, childWindowClasses.length - 1)];
        ApplicationListener listener = null;
        try {
          listener = (ApplicationListener) clazz.newInstance();
        } catch (Throwable t) {
          new GdxRuntimeException("Couldn't instantiate app listener", t);
        }
        Lwjgl3Window window = app.newWindow(listener, config);
      }
    }
예제 #4
0
  @Override
  public void render() {
    // Update
    //		Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    world.step(1 / 60f, 10, 10);
    for (int i = 0; i < MAX_BALL_COUNT; i++) {
      Vector2 pos =
          ballModels[i]
              .getPosition()
              .sub(ballSprites[i].getWidth() / 2, ballSprites[i].getHeight() / 2);
      float angleDeg = ballModels[i].getAngle() * MathUtils.radiansToDegrees;

      ballSprites[i].setPosition(pos.x, pos.y);
      ballSprites[i].setRotation(angleDeg);
    }

    // Render
    //		GL10 gl = Gdx.gl10;
    //		gl.glClearColor(1, 1, 1, 1);
    //		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    spriteBatch.setProjectionMatrix(camera.combined);
    spriteBatch.begin();
    vialSprite.draw(spriteBatch);
    for (int i = 0; i < MAX_BALL_COUNT; i++) ballSprites[i].draw(spriteBatch);
    spriteBatch.end();

    spriteBatch
        .getProjectionMatrix()
        .setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    spriteBatch.begin();
    font.draw(spriteBatch, "Touch the screen to restart", 5, 25);
    spriteBatch.end();
  }
예제 #5
0
 /** sets batch to game units to draw and then back to screen */
 @Override
 public void draw(SpriteBatch batch, float parentAlpha) {
   tmpMatrix4.set(batch.getProjectionMatrix());
   batch.setProjectionMatrix(cam.combined);
   super.draw(batch, parentAlpha);
   batch.setProjectionMatrix(tmpMatrix4);
 }
예제 #6
0
 @Override
 public void show() {
   title =
       new TextureRegion(
           new Texture(Gdx.files.internal("data/textures/mockup.jpg")), 0, 0, 512, 512);
   batch = new SpriteBatch();
   batch.getProjectionMatrix().setToOrtho2D(0, 0, 960, 640);
 }
예제 #7
0
 @Override
 public void show() {
   loadAssets();
   batch = new SpriteBatch();
   // batch.getProjectionMatrix().setToOrtho2D(0, 0, 800, 480);
   batch
       .getProjectionMatrix()
       .setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
 }
예제 #8
0
  @Override
  public void render() {
    Gdx.gl.glClearColor(
        background.rgb.getRed() / 255f,
        background.rgb.getGreen() / 255f,
        background.rgb.getBlue() / 255f,
        background.rgb.getAlpha() / 255f);

    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    boolean hasUserInput = false;
    if (input.getText() != null && input.getText().length() != 0) hasUserInput = true;
    final String text =
        hasUserInput ? input.getText() : "The quick brown fox jumps over the lazy dog";

    float scale = scaleSlider.getValue();

    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.setProjectionMatrix(cam.combined);

    batch.getProjectionMatrix().scale(scale, scale, 0.0f);

    //		batch.getTransformMatrix().scale(scale, scale, 0.0f);

    if (fonts != null) {
      batch.begin();

      int x = 5;
      int y = 0;

      for (FontElement e : fonts) {
        y += e.font.getLineHeight() + 5;
        String str = hasUserInput ? text : e.name + " " + e.size + ": " + text;
        e.font.draw(batch, str, x, y);
      }

      batch.end();
    }

    input.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);
    labelInput.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);

    labelScale.setY(labelInput.getY() - labelInput.getHeight() - 5);
    scaleSlider.setY(input.getY() - input.getHeight() - 5);
    scaleAmt.setY(scaleSlider.getY());

    linearFiltering.setY(scaleSlider.getY() - scaleSlider.getHeight() - 10);

    stage.act();
    stage.draw();
  }
예제 #9
0
  public void drawDebug(SpriteBatch batch) {
    batch.end();

    ShapeRenderer renderer = DebugRendererManager.instance.debugRenderer;

    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());
    renderer.translate(getX(), getY(), 0);

    renderer.begin(ShapeRenderer.ShapeType.Line);
    renderer.setColor(new Color(Color.RED));
    renderer.rect(0, 0, getWidth(), getHeight());
    renderer.end();

    batch.begin();
  }
예제 #10
0
파일: Bdx.java 프로젝트: colepram/bdx
  public static void resize(int width, int height) {
    spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);

    if (frameBuffer != null) frameBuffer.dispose();
    if (tempBuffer != null) tempBuffer.dispose();

    frameBuffer =
        new RenderBuffer(
            spriteBatch); // Have to recreate all render buffers and adjust the projection matrix as
                          // the window size has changed
    tempBuffer = new RenderBuffer(spriteBatch);
    for (Scene scene : scenes) {

      if (scene.lastFrameBuffer != null) scene.lastFrameBuffer.dispose();

      scene.lastFrameBuffer = new RenderBuffer(null);
    }
  }
 public void render() {
   spriteBatch
       .getProjectionMatrix()
       .setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
   float delta = Gdx.graphics.getDeltaTime();
   GL10 gl = Gdx.graphics.getGL10();
   gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
   spriteBatch.begin();
   effect.draw(spriteBatch, delta);
   spriteBatch.end();
   fpsCounter += delta;
   if (fpsCounter > 3) {
     fpsCounter = 0;
     int activeCount = emitters.get(emitterIndex).getActiveCount();
     System.out.println(
         activeCount
             + "/"
             + particleCount
             + " particles, FPS: "
             + Gdx.graphics.getFramesPerSecond());
   }
 }
예제 #12
0
  @Override
  public void render() {

    updatePhysics();
    // System.out.println("render");

    Gdx.graphics.getGL20().glClearColor(1, 1, 1, 1); // White color
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    backgroundSprite.draw(batch);
    planetCoreSprite.draw(batch);
    planetSprite.draw(batch);
    for (int i = 0; i < MAX_BALLS; i++) ballSprites[i].draw(batch);
    batch.end();

    batch.getProjectionMatrix().setToOrtho2D(0, 0, WIDTH_DEVICE, HEIGHT_DEVICE);
    batch.begin();
    font.draw(batch, "Touch the screen to restart", 5, HEIGHT_DEVICE - 5);
    batch.end();
  }
예제 #13
0
  @Override
  public void draw(SpriteBatch batch, float parentAlpha) {
    stateTime += Gdx.graphics.getDeltaTime();
    drawable.setRegion(character.getAnimation().getKeyFrame(stateTime));

    super.draw(batch, parentAlpha);

    if (selected) {
      batch.end();
      ShapeRenderer shape = new ShapeRenderer();
      shape.setProjectionMatrix(batch.getProjectionMatrix());
      shape.begin(ShapeType.Line);
      shape.setColor(Color.YELLOW);
      shape.rect(
          getX() + getParent().getParent().getX(),
          getY() + getParent().getParent().getY(),
          getPrefWidth(),
          getPrefHeight());
      shape.end();
      batch.begin();
    }
  }
예제 #14
0
파일: HUD.java 프로젝트: Stalf/droid-wars
  public void resize(int width, int height) {
    this.width = width;
    this.height = height;

    HUDBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
  }
예제 #15
0
  @Override
  public void render() {
    // first we update the world. For simplicity
    // we use the delta time provided by the Graphics
    // instance. Normally you'll want to fix the time
    // step.
    long start = TimeUtils.nanoTime();
    world.step(Gdx.graphics.getDeltaTime(), 8, 3);
    float updateTime = (TimeUtils.nanoTime() - start) / 1000000000.0f;

    // next we clear the color buffer and set the camera
    // matrices
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();

    // next we render the ground body
    renderBox(groundBody, 50, 1);

    // next we render each box via the SpriteBatch.
    // for this we have to set the projection matrix of the
    // spritebatch to the camera's combined matrix. This will
    // make the spritebatch work in world coordinates
    batch.getProjectionMatrix().set(camera.combined);
    batch.begin();
    for (int i = 0; i < boxes.size(); i++) {
      Body box = boxes.get(i);
      Vector2 position = box.getPosition(); // that's the box's center position
      float angle =
          MathUtils.radiansToDegrees * box.getAngle(); // the rotation angle around the center
      batch.draw(
          textureRegion,
          position.x - 1,
          position.y - 1, // the bottom left corner of the box, unrotated
          1f,
          1f, // the rotation center relative to the bottom left corner of the box
          2,
          2, // the width and height of the box
          1,
          1, // the scale on the x- and y-axis
          angle); // the rotation angle
    }
    batch.end();

    // next we use the debug renderer. Note that we
    // simply apply the camera again and then call
    // the renderer. the camera.apply() call is actually
    // not needed as the opengl matrices are already set
    // by the spritebatch which in turn uses the camera matrices :)
    debugRenderer.render(world, camera.combined);

    // finally we render all contact points
    renderer.setProjectionMatrix(camera.combined);
    renderer.begin(ShapeType.Point);
    renderer.setColor(0, 1, 0, 1);
    for (int i = 0; i < world.getContactCount(); i++) {
      Contact contact = world.getContactList().get(i);
      // we only render the contact if it actually touches
      if (contact.isTouching()) {
        // get the world manifold from which we get the
        // contact points. A manifold can have 0, 1 or 2
        // contact points.
        WorldManifold manifold = contact.getWorldManifold();
        int numContactPoints = manifold.getNumberOfContactPoints();
        for (int j = 0; j < numContactPoints; j++) {
          Vector2 point = manifold.getPoints()[j];
          renderer.point(point.x, point.y, 0);
        }
      }
    }
    renderer.end();

    // finally we render the time it took to update the world
    // for this we have to set the projection matrix again, so
    // we work in pixel coordinates
    batch
        .getProjectionMatrix()
        .setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.begin();
    font.draw(
        batch, "fps: " + Gdx.graphics.getFramesPerSecond() + " update time: " + updateTime, 0, 20);
    batch.end();
  }
예제 #16
0
  public GameScreen(Game game, Array<Integer> playerList, Array<Integer> cpuList) {
    super(game);
    Gdx.input.setCatchBackKey(true);
    Gdx.input.setInputProcessor(this);

    cam = new OrthographicCamera(width, height);

    cam.position.x = 400;
    cam.position.y = 240;
    cam.update();

    numPlayers = playerList.size;

    if (numPlayers == 1) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width),
                  -((this.height - 480) / 2) + this.height,
                  0));
    } else if (numPlayers == 2) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));
    } else if (numPlayers == 3) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));
    } else if (numPlayers == 4) {
      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP4 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));
    }

    //		camera = new OrthographicCamera(800, 480);
    //		camera.translate(400, 240, 0);

    if (playerList.size + cpuList.size != 3) {
      POSITIONS.add(new Vector2(150, 180));
      POSITIONS.add(new Vector2(450, 180));
      POSITIONS.add(new Vector2(300, 335));
      POSITIONS.add(new Vector2(300, 25));
    } else {
      POSITIONS.add(new Vector2(170, 92));
      POSITIONS.add(new Vector2(432, 100));
      POSITIONS.add(new Vector2(300, 335));
    }

    // Fade
    blackFade = Resources.getInstance().blackFade;
    fadeBatch = new SpriteBatch();
    fadeBatch.getProjectionMatrix().setToOrtho2D(0, 0, 2, 2);

    stouchAreaP1 = Resources.getInstance().touchArea1;
    stouchAreaP2 = Resources.getInstance().touchArea2;
    stouchAreaP3 = Resources.getInstance().touchArea3;
    stouchAreaP4 = Resources.getInstance().touchArea4;

    if (playerList.size > 0 && playerList.get(0) == 1) {
      p1 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 0 && playerList.get(0) == 2) {
      p1 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 0 && playerList.get(0) == 3) {
      p1 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 0 && playerList.get(0) == 4) {
      p1 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 1 && playerList.get(1) == 1) {
      p2 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 1 && playerList.get(1) == 2) {
      p2 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 1 && playerList.get(1) == 3) {
      p2 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 1 && playerList.get(1) == 4) {
      p2 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 2 && playerList.get(2) == 1) {
      p3 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 2 && playerList.get(2) == 2) {
      p3 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 2 && playerList.get(2) == 3) {
      p3 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 2 && playerList.get(2) == 4) {
      p3 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 3 && playerList.get(3) == 1) {
      p4 = Resources.getInstance().factoryP1Small;
    } else if (playerList.size > 3 && playerList.get(3) == 2) {
      p4 = Resources.getInstance().factoryP2Small;
    } else if (playerList.size > 3 && playerList.get(3) == 3) {
      p4 = Resources.getInstance().factoryP3Small;
    } else if (playerList.size > 3 && playerList.get(3) == 4) {
      p4 = Resources.getInstance().factoryP4Small;
    }

    if (playerList.size > 0) p1.setScale(.2f);
    if (playerList.size > 1) p2.setScale(.2f);
    if (playerList.size > 2) p3.setScale(.2f);
    if (playerList.size > 3) p4.setScale(.2f);

    if (playerList.size > 0) p1.rotate(-90);
    if (playerList.size > 1) p2.rotate(90);
    if (playerList.size > 2) p3.rotate(-90);
    if (playerList.size > 3) p4.rotate(90);

    stouchAreaP1.setRotation(-90);
    stouchAreaP2.setRotation(90);
    stouchAreaP1.setRotation(-90);
    stouchAreaP2.setRotation(90);

    gameBatch = new SpriteBatch();
    gameBatch.getProjectionMatrix().set(cam.combined);

    // init player positions
    //		Array<Vector2> positons = generatePositions(numPlayers + 1);

    int currentPos = 0;

    for (int i = 0; i < playerList.size; ++i) {
      Vector2 temp1 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 temp2 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
      playerProduction = new PlayerProduction(playerList.get(i), POSITIONS.get(currentPos), facing);
      GameInstance.getInstance().factorys.add(playerProduction);
      ++currentPos;
    }

    for (int i = 0; i < cpuList.size; ++i) {
      Vector2 temp1 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 temp2 = new Vector2(POSITIONS.get(currentPos).x, POSITIONS.get(currentPos).y);
      Vector2 facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
      if (GameInstance.getInstance().difficultyConfig == 0) {
        enemyProduction =
            new EasyEnemyProduction(cpuList.get(i), POSITIONS.get(currentPos), facing);
      } else if (GameInstance.getInstance().difficultyConfig == 1) {
        enemyProduction =
            new MediumEnemyProduction(cpuList.get(i), POSITIONS.get(currentPos), facing);
      } else {
        enemyProduction =
            new HardEnemyProduction(cpuList.get(i), POSITIONS.get(currentPos), facing);
      }
      GameInstance.getInstance().factorys.add(enemyProduction);
      ++currentPos;
    }

    //		// add cpu if only one player plays
    //		if (idP2 == -1) {
    //			temp1 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			temp2 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			if(GameInstance.getInstance().difficultyConfig == 0) {
    //				enemyProduction = new EasyEnemyProduction((idP1+1)%4, POSITIONS.get(1), facing);
    //			} else if(GameInstance.getInstance().difficultyConfig == 1) {
    //				enemyProduction = new MediumEnemyProduction((idP1+1)%4, POSITIONS.get(1), facing);
    //			} else {
    //				enemyProduction = new HardEnemyProduction((idP1+1)%4, POSITIONS.get(1), facing);
    //			}
    //			GameInstance.getInstance().factorys.add(enemyProduction);
    //			touchedP2 = true;
    //			touchFadeP2 = 0;
    //
    //			temp1 = new Vector2(POSITIONS.get(2).x, POSITIONS.get(2).y);
    //			temp2 = new Vector2(POSITIONS.get(2).x, POSITIONS.get(2).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			if(GameInstance.getInstance().difficultyConfig == 0) {
    //				enemyProduction = new EasyEnemyProduction((idP1+2)%4, POSITIONS.get(2), facing);
    //			} else if(GameInstance.getInstance().difficultyConfig == 1) {
    //				enemyProduction = new MediumEnemyProduction((idP1+2)%4, POSITIONS.get(2), facing);
    //			} else {
    //				enemyProduction = new HardEnemyProduction((idP1+2)%4, POSITIONS.get(2), facing);
    //			}
    //			GameInstance.getInstance().factorys.add(enemyProduction);
    //			touchedP2 = true;
    //			touchFadeP2 = 0;
    //
    //			temp1 = new Vector2(POSITIONS.get(3).x, POSITIONS.get(3).y);
    //			temp2 = new Vector2(POSITIONS.get(3).x, POSITIONS.get(3).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			if(GameInstance.getInstance().difficultyConfig == 0) {
    //				enemyProduction = new EasyEnemyProduction((idP1+3)%4, POSITIONS.get(3), facing);
    //			} else if(GameInstance.getInstance().difficultyConfig == 1) {
    //				enemyProduction = new MediumEnemyProduction((idP1+3)%4, POSITIONS.get(3), facing);
    //			} else {
    //				enemyProduction = new HardEnemyProduction((idP1+3)%4, POSITIONS.get(3), facing);
    //			}
    //			GameInstance.getInstance().factorys.add(enemyProduction);
    //			touchedP2 = true;
    //			touchFadeP2 = 0;
    //		} else {
    //			temp1 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			temp2 = new Vector2(POSITIONS.get(1).x, POSITIONS.get(1).y);
    //			facing = new Vector2(-temp1.sub(CENTER).y, temp2.sub(CENTER).x).nor();
    //			playerProduction = new PlayerProduction(idP2, POSITIONS.get(1), facing);
    //			GameInstance.getInstance().factorys.add(playerProduction);
    //		}

    Gdx.gl.glDisable(GL20.GL_CULL_FACE);
    Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
  }
예제 #17
0
  @Override
  public void resize(int width, int height) {
    this.width = width;
    this.height = height;
    if (width == 480 && height == 320) {
      cam = new OrthographicCamera(700, 466);
      this.width = 700;
      this.height = 466;
    } else if (width == 320 && height == 240) {
      cam = new OrthographicCamera(700, 525);
      this.width = 700;
      this.height = 525;
    } else if (width == 400 && height == 240) {
      cam = new OrthographicCamera(800, 480);
      this.width = 800;
      this.height = 480;
    } else if (width == 432 && height == 240) {
      cam = new OrthographicCamera(700, 389);
      this.width = 700;
      this.height = 389;
    } else if (width == 960 && height == 640) {
      cam = new OrthographicCamera(800, 533);
      this.width = 800;
      this.height = 533;
    } else if (width == 1366 && height == 768) {
      cam = new OrthographicCamera(1280, 720);
      this.width = 1280;
      this.height = 720;
    } else if (width == 1366 && height == 720) {
      cam = new OrthographicCamera(1280, 675);
      this.width = 1280;
      this.height = 675;
    } else if (width == 1536 && height == 1152) {
      cam = new OrthographicCamera(1366, 1024);
      this.width = 1366;
      this.height = 1024;
    } else if (width == 1920 && height == 1152) {
      cam = new OrthographicCamera(1366, 854);
      this.width = 1366;
      this.height = 854;
    } else if (width == 1920 && height == 1200) {
      cam = new OrthographicCamera(1366, 800);
      this.width = 1280;
      this.height = 800;
    } else if (width > 1280) {
      cam = new OrthographicCamera(1280, 768);
      this.width = 1280;
      this.height = 768;
    } else if (width < 800) {
      cam = new OrthographicCamera(800, 480);
      this.width = 800;
      this.height = 480;
    } else {
      cam = new OrthographicCamera(width, height);
    }
    cam.position.x = 400;
    cam.position.y = 240;
    cam.update();
    backgroundFX.resize(width, height);
    gameBatch.getProjectionMatrix().set(cam.combined);

    if (numPlayers == 1) {
      p1.setRotation(-90);

      stouchAreaP1.setRotation(-90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width),
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.x + 10, touchAreaP1.getCenter().y - 105);
    } else if (numPlayers == 2) {
      p1.setRotation(-90);
      p2.setRotation(90);

      stouchAreaP1.setRotation(-90);
      stouchAreaP2.setRotation(90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105);
      stouchAreaP2.setPosition(touchAreaP2.max.x - 170, touchAreaP2.getCenter().y - 40);
      p2.setPosition(touchAreaP2.max.x - 190, touchAreaP2.getCenter().y - 15);
    } else if (numPlayers == 3) {
      p1.setRotation(-90);
      p2.setRotation(-90);
      p3.setRotation(90);

      stouchAreaP1.setRotation(-90);
      stouchAreaP2.setRotation(-90);
      stouchAreaP3.setRotation(90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105);
      stouchAreaP2.setPosition(touchAreaP2.min.x, touchAreaP2.getCenter().y - 40);
      p2.setPosition(touchAreaP2.min.x + 10, touchAreaP2.getCenter().y - 105);
      stouchAreaP3.setPosition(touchAreaP3.max.x - 170, touchAreaP3.getCenter().y - 40);
      p3.setPosition(touchAreaP3.max.x - 190, touchAreaP3.getCenter().y - 15);
    } else if (numPlayers == 4) {
      p1.setRotation(-90);
      p2.setRotation(-90);
      p3.setRotation(90);
      p4.setRotation(90);

      stouchAreaP1.setRotation(-90);
      stouchAreaP2.setRotation(-90);
      stouchAreaP3.setRotation(90);
      stouchAreaP4.setRotation(90);

      touchAreaP1 =
          new BoundingBox(
              new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP2 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + this.height,
                  0));
      touchAreaP3 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + (this.height / 2),
                  0));
      touchAreaP4 =
          new BoundingBox(
              new Vector3(
                  -((this.width - 800) / 2) + (this.width / 2),
                  -((this.height - 480) / 2) + (this.height / 2),
                  0),
              new Vector3(
                  -((this.width - 800) / 2) + this.width,
                  -((this.height - 480) / 2) + this.height,
                  0));

      stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40);
      p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105);
      stouchAreaP2.setPosition(touchAreaP2.min.x, touchAreaP2.getCenter().y - 40);
      p2.setPosition(touchAreaP2.min.x + 10, touchAreaP2.getCenter().y - 105);
      stouchAreaP3.setPosition(touchAreaP3.max.x - 170, touchAreaP3.getCenter().y - 40);
      p3.setPosition(touchAreaP3.max.x - 190, touchAreaP3.getCenter().y - 15);
      stouchAreaP4.setPosition(touchAreaP4.max.x - 170, touchAreaP4.getCenter().y - 40);
      p4.setPosition(touchAreaP4.max.x - 190, touchAreaP4.getCenter().y - 15);
    }
  }