Esempio n. 1
0
  @Override
  public boolean touchDragged(int screenX, int screenY, int pointer) {

    if (currently_pressed_object != null) {
      //	System.out.println ("touch draggeding object!");

      Vector2 modified_values = (get_screen_to_stage_coordinates(screenX, screenY));

      ////
      // compensate for movie_display_group_offset

      modified_values.sub(view.MOVIE_DISPLAY_GROUP_OFFSET);

      ////
      // compensate for click position offset, otherwise the dragging will always occur with the
      // cursor at the lower left of the oject

      if (click_offset != null) modified_values.sub(click_offset);

      currently_pressed_object.set_position(modified_values);
      currently_pressed_object.update_properties();

      //				editor.get_properties_editor ().update_rows ();
      editor.get_properties_editor().update_rows_data();

      editor.get_display_info_panel().update_currently_pressed_object(currently_pressed_object);
    }
    return false;
  }
Esempio n. 2
0
  public void drawArrow(
      Vector2 a,
      Vector2 b,
      float width,
      float feather,
      float headDist,
      float headWidth,
      Color color) {
    // Firstly, draw the body of the arrow. B is the front.
    drawLine(a, b, width, feather, color);

    // Get the direction vector a->b
    dir.set(a);
    dir.sub(b);
    dir.scl(1 / dir.len());

    // Get the point down the line that the arrow head lines get to
    d.set(dir);
    d.scl(headDist);
    d.add(b);

    // Now, move d out to the sides
    amount.set(dir);
    amount.rotate(90);
    amount.scl(headWidth);

    right.set(d).add(amount);
    left.set(d).sub(amount);

    // Draw the arrow heads to not-quite-b to make it prettier
    c.set(b);
    c.sub(dir.scl(-width * 0.2f));
    drawLine(c, left, width, feather, color);
    drawLine(c, right, width, feather, color);
  }
 private int indexOfRightmostVertexOf(final Vector2 vector2) {
   final Vector2[] mVertices = this.mVertices;
   final int mVertexCount = this.mVertexCount;
   int n = 0;
   for (int i = 1; i < mVertexCount; ++i) {
     final Vector2 set = Vector2Pool.obtain().set(mVertices[i]);
     final Vector2 set2 = Vector2Pool.obtain().set(mVertices[n]);
     if (Vector2Util.isLess(set.sub(vector2), set2.sub(vector2))) {
       n = i;
     }
     Vector2Pool.recycle(set);
     Vector2Pool.recycle(set2);
   }
   return n;
 }
Esempio n. 4
0
  private void drawFeatheredFullLine(
      Vector2 a, Vector2 b, float width, float feather, Color color) {
    checkMaxVerts(3 * 6);

    // Calculate the normal that defines the center rectangle
    norm.set(b);
    norm.sub(a);
    norm.rotate(90);
    norm.setLength(width / 2); // Scale to line width

    // Calculate the normal that defines feathering
    feath.set(norm);
    feath.setLength(feather / 2);

    zeroAlpha.set(color);
    zeroAlpha.a = 0;

    // ORDER OF RENDERING

    // 1                    2
    // top feather
    // 3                    4

    // center

    // 5                    6
    // bottom feather
    // 7                    8

    // Top feather
    tL.set(a).add(norm).add(feath);
    tR.set(b).add(norm).add(feath);
    bL.set(a).add(norm);
    bR.set(b).add(norm);

    // Draw it
    // Top feather  (1-2-3)
    uncheckedTriangle(tL.x, tL.y, tR.x, tR.y, bL.x, bL.y, zeroAlpha, zeroAlpha, color);
    uncheckedTriangle(tR.x, tR.y, bL.x, bL.y, bR.x, bR.y, zeroAlpha, color, color);

    // Center line
    tL.set(a).add(norm);
    tR.set(b).add(norm);
    bL.set(a).sub(norm);
    bR.set(b).sub(norm);

    // Draw it
    uncheckedTriangle(tL.x, tL.y, tR.x, tR.y, bL.x, bL.y, color, color, color);
    uncheckedTriangle(tR.x, tR.y, bL.x, bL.y, bR.x, bR.y, color, color, color);

    // Bottom feather
    tL.set(a).sub(norm);
    tR.set(b).sub(norm);
    bL.set(a).sub(norm).sub(feath);
    bR.set(b).sub(norm).sub(feath);

    // Draw it
    uncheckedTriangle(tL.x, tL.y, tR.x, tR.y, bL.x, bL.y, color, color, zeroAlpha);
    uncheckedTriangle(tR.x, tR.y, bL.x, bL.y, bR.x, bR.y, color, zeroAlpha, zeroAlpha);
  }
Esempio n. 5
0
 public void drawLine(
     TextureRegion tex, Vector2 p1, Vector2 p2, Color col, float width, boolean precise) {
   Vector2 v = SolMath.getVec(p2);
   v.sub(p1);
   drawLine(tex, p1.x, p1.y, SolMath.angle(v, precise), v.len(), col, width);
   SolMath.free(v);
 }
Esempio n. 6
0
  public static float getAngle(Vector2 v1, Vector2 v2) {
    Vector2 temp = v2.cpy();

    temp.sub(v1);

    return (float) Math.atan2(temp.y, temp.x);
  }
Esempio n. 7
0
 public static Vector2 flee(Vector2 targetPos, Vehicle v) {
   Vector2 desiredVelocity = v.getCenter().cpy().sub(targetPos);
   Vector2 velocity = v.getVelocity();
   desiredVelocity.nor();
   desiredVelocity.mul(v.getMaxVelocity());
   desiredVelocity.sub(velocity).mul(CORRECTION);
   return desiredVelocity;
 }
Esempio n. 8
0
  private int indexOfRightmostVertexOf(final Vector2 pVector) {
    final Vector2[] vertices = this.mVertices;
    final int vertexCount = this.mVertexCount;

    int i = 0;
    for (int j = 1; j < vertexCount; j++) {

      final Vector2 vector2A = Vector2Pool.obtain().set(vertices[j]);
      final Vector2 vector2B = Vector2Pool.obtain().set(vertices[i]);
      if (Vector2Util.isLess(vector2A.sub(pVector), vector2B.sub(pVector))) {
        i = j;
      }
      Vector2Pool.recycle(vector2A);
      Vector2Pool.recycle(vector2B);
    }
    return i;
  }
Esempio n. 9
0
  public static boolean isTouchingCannon(Vector3 touchPos) {
    Cannon cannon = GameScreen.cannon;

    Vector2 origin = cannon.getPosition();
    origin.x = Utils.convertToWorld(origin.x);
    origin.y = Utils.convertToWorld(origin.y);
    origin.sub(new Vector2(cannon.wrapper.width / 2, cannon.wrapper.height / 2));
    Vector2 end = new Vector2(cannon.wrapper.width, cannon.wrapper.height);
    Rectangle rect = new Rectangle(origin.x, origin.y, end.x, end.y);
    return rect.contains(touchPos.x, touchPos.y);
  }
Esempio n. 10
0
  public static Vector2 arrive(Vector2 targetPos, Vehicle v) {
    Vector2 desiredVelocity = v.getCenter().cpy().sub(targetPos);
    Vector2 velocity = v.getVelocity();

    float len = desiredVelocity.len();
    if (len > 0.05f) {
      desiredVelocity.nor();
      float min = Math.min(len, v.getMaxVelocity());
      desiredVelocity.mul(min);
      desiredVelocity.sub(velocity).mul(-CORRECTION);
    }
    return desiredVelocity;
  }
Esempio n. 11
0
  /**
   * Ray-cast the world in constant steps specified in {@link #setRay(Vector2, Vector2, float)}
   *
   * @see World#rayCast(RayCastCallback, Vector2, Vector2)
   *     <p>Note: this implementation asumes that the raycast will hit.
   */
  public void process() {
    Vector2 step = new Vector2(endPoint);
    step.sub(beginPoint);
    step.nor();
    step.scl(stepLength);

    Vector2 endPoint = new Vector2(beginPoint);
    endPoint.add(step);

    while (!hit) {
      world.rayCast(this, beginPoint, endPoint);
      endPoint.add(step);
    }
  }
  public static void moveTo(Entity entity, Vector2 destination) {
    Physics physicsComponent = EntityUtil.getComponent(entity, Physics.class);
    Body body = physicsComponent.getBody();
    float mass = body.getMass();
    Vector2 currentVelocity = body.getLinearVelocity();
    Vector2 position = body.getPosition();

    Vector2 desiredVelocity =
        destination.cpy().sub(position).nor().scl(physicsComponent.getMaxSpeed());

    Vector2 impulse = desiredVelocity.sub(currentVelocity).scl(mass);

    PhysicsUtil.applyImpulse(entity, impulse);
  }
Esempio n. 13
0
  /** Shoots a {@link Bullet} at the specified position */
  public void shoot(Vector2 position) {

    Vector2 direction = new Vector2(position);
    direction.sub(this.getPosition());
    direction.nor();
    this.setAngle(direction.angleRad());

    this.setTransform(body.getPosition(), direction.angleRad());

    Vector2 velocity = new Vector2(direction.x * BULLET_SPEED, direction.y * BULLET_SPEED);

    Bullet bullet = new Bullet(level, this.getPosition(), velocity);
    bullet.setAngle(direction.angleRad());
    level.add(bullet);
  }
Esempio n. 14
0
  /** Adjusts the position and size of the given group to its children */
  public static void adjustGroup(Actor root) {
    if (!(root instanceof Group)) {
      return;
    }

    Group group = (Group) root;
    if (group.getChildren().size == 0) {
      return;
    }

    Vector2 origin = Pools.obtain(Vector2.class);
    Vector2 size = Pools.obtain(Vector2.class);
    Vector2 tmp3 = Pools.obtain(Vector2.class);
    Vector2 tmp4 = Pools.obtain(Vector2.class);

    calculateBounds(group.getChildren(), origin, size);

    /*
     * minX and minY are the new origin (new 0, 0), so everything inside the
     * group must be translated that much.
     */
    for (Actor actor : group.getChildren()) {
      actor.setPosition(actor.getX() - origin.x, actor.getY() - origin.y);
    }

    /*
     * Now, we calculate the current origin (0, 0) and the new origin (minX,
     * minY), and group is translated by that difference.
     */
    group.localToParentCoordinates(tmp3.set(0, 0));
    group.localToParentCoordinates(tmp4.set(origin.x, origin.y));
    tmp4.sub(tmp3);
    group.setBounds(group.getX() + tmp4.x, group.getY() + tmp4.y, size.x, size.y);
    group.setOrigin(size.x / 2.0f, size.y / 2.0f);

    Pools.free(origin);
    Pools.free(size);
    Pools.free(tmp3);
    Pools.free(tmp4);
  }
Esempio n. 15
0
  public void drawLine(Vector2 a, Vector2 b, float width, Color color) {
    setType(GL20.GL_TRIANGLES);

    // Calculate the normal that defines the center rectangle
    norm.set(b);
    norm.sub(a);
    norm.rotate(90);
    norm.setLength(width / 2); // Scale to line width

    // 1                    2
    // top feather
    // 3                    4

    // Top feather
    tL.set(a).add(norm);
    tR.set(b).add(norm);
    bL.set(a).sub(norm);
    bR.set(b).sub(norm);

    uncheckedTriangle(tL.x, tL.y, tR.x, tR.y, bL.x, bL.y, color, color, color);
    uncheckedTriangle(tR.x, tR.y, bL.x, bL.y, bR.x, bR.y, color, color, color);
  }
Esempio n. 16
0
  @Override
  public void update() {
    if (!isActive()) return;

    posCpy.set(GameModel.getPlayer().position);
    diffToPlayer.set(posCpy.sub(position));

    float wantedAngle = MathUtils.atan2(diffToPlayer.y, diffToPlayer.x);
    /*
                      ^
            3,14 <--- |----> 0
    */
    if (direction == AbstractMap.N && (wantedAngle > MathUtils.PI || wantedAngle < 0)) return;
    else if (direction == AbstractMap.S && wantedAngle > 0) return;
    else if (direction == AbstractMap.W
        && (!(wantedAngle < MathUtils.PI / 2f && wantedAngle > -MathUtils.PI / 2f))) return;
    else if (direction == AbstractMap.E
        && (!(wantedAngle > MathUtils.PI / 2f || wantedAngle < -MathUtils.PI / 2f))) return;

    body.setTransform(position.x, position.y, wantedAngle);

    if (diffToPlayer.len() < Config.getDimensions().WORLD_WIDTH / 2f)
      if (MathUtils.random()
          < (type == CANNON_TYPE.SINGLE ? Config.BULLET_RATE_LOW : Config.BULLET_RATE_MEDIUM)) {
        float angle = body.getAngle() * MathUtils.radiansToDegrees;

        origin.set(position).add(diffToPlayer.scl(.1f));
        posCpy.set(GameModel.getPlayer().position);

        if (type == CANNON_TYPE.SINGLE) {
          weapon.fire1(origin, posCpy.rotate(MathUtils.random(-1, 1)));
          createGunSmoke(angle);
        } else if (type == CANNON_TYPE.DOUBLE) {
          weapon.fire1(origin, posCpy.rotate(MathUtils.random(-1, 1)));
          weapon.fire2(origin, posCpy.rotate(MathUtils.random(-1, 1)));
        }
      }
  }
Esempio n. 17
0
 @Override
 public boolean update(SolGame game, SolShip owner, boolean tryToUse) {
   myShouldTeleport = false;
   if (!tryToUse) return false;
   Vector2 pos = owner.getPos();
   Fraction frac = owner.getPilot().getFraction();
   SolShip ne = game.getFractionMan().getNearestEnemy(game, MAX_RADIUS, frac, pos);
   if (ne == null) return false;
   Vector2 nePos = ne.getPos();
   Planet np = game.getPlanetMan().getNearestPlanet();
   if (np.isNearGround(nePos)) return false;
   for (int i = 0; i < 5; i++) {
     myNewPos.set(pos);
     myNewPos.sub(nePos);
     myAngle = myConfig.angle * SolMath.rnd(.5f, 1) * SolMath.toInt(SolMath.test(.5f));
     SolMath.rotate(myNewPos, myAngle);
     myNewPos.add(nePos);
     if (game.isPlaceEmpty(myNewPos, false)) {
       myShouldTeleport = true;
       return true;
     }
   }
   return false;
 }
Esempio n. 18
0
  @Override
  public boolean touchDown(int arg0, int arg1, int arg2, int arg3) {
    ////
    // for checking proper clicks, and potentially drags

    currently_pressed_object =
        get_object_at(
            arg0,
            arg1); // view.get_top_object_at_coordinate (arg0, arg1); //
                   // p_y_pos)trigger_on_mouse_click_on_object_at (arg0, arg1);

    if (currently_pressed_object != null) {
      ////
      // sets the click_offset vector, to be used when dragging objects

      Vector2 modified_values = get_screen_to_stage_coordinates(arg0, arg1);

      modified_values.sub(view.MOVIE_DISPLAY_GROUP_OFFSET);

      click_offset = new Vector2(modified_values.sub(currently_pressed_object.get_position()));

      //			System.out.println (click_offset);

      ////
      // updates the Display_info_panel s Currently_touched (or something) label witht the object in
      // question
      // as well as the properties_list's currently selected row

      editor
          .get_properties_editor()
          .set_currently_selected_object((Main_object) currently_pressed_object);
      editor.get_properties_editor().set_row_selection();

      editor.get_display_info_panel().update_currently_pressed_object(currently_pressed_object);

      ////
      // in case of a hotspot, trigger hotspot's Script

      if (currently_pressed_object instanceof Hotspot) {
        System.out.println(
            "controller - Hotspot has been pressed, issuing Script! " + currently_pressed_object);
        //				System.out.println ("post stuff");

        Hotspot c_hotspot = (Hotspot) currently_pressed_object;

        System.out.println("the next event! " + c_hotspot.get_script().get_next_event());

        handle_new_script(c_hotspot.get_script());

        //    			KEvent <Hotspot> k_event = new KEvent <Hotspot> (KEvent.Type.SAY, (Hotspot)
        // currently_pressed_object);
        //    			dispatch_KEvent (k_event);
        //
        //    			view.display_text
        //				(
        //					"blorg!",
        //					currently_pressed_object.get_position ().add (view.get_movie_display_group_offset
        // ()).x,
        //					currently_pressed_object.get_position ().add (view.get_movie_display_group_offset
        // ()).y + 200
        //				);

      }
    }

    return false;
  }
  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);
  }
Esempio n. 20
0
  // TODO Comment
  private void updateVertexDefault(int index, boolean inside) {

    BoundingBox box = boundingBoxes.items[index / verticesPerBox];
    box.needsCullingUpdate = true;

    int k = index % vertices.size;
    StripVertex stripVertex = vertexDataArray.items[k];
    AuxVertexFinder auxVertexFinder = this.auxVertexFinder;

    Array<Float> vertexData = inside ? stripVertex.insideVertexData : stripVertex.outsideVertexData;
    vertexData.clear();

    auxVertexFinder.setInsideStrip(inside);

    Vector2 currentVertex = vertices.items[k];
    Vector2 defaultAux = auxVertexFinder.getAux(vertices, k);

    boolean roundCorner = false;

    { // within these brackets i figure out if i should round the corner.
      // i hope to rewrite this code to something i can understand one day after writing it
      Vector2 previous = tmp.set(vertices.items[(k - 1 + vertices.size) % vertices.size]);
      Vector2 copyOfDefaultAux = tmp1.set(defaultAux);

      previous.sub(currentVertex);
      copyOfDefaultAux.sub(currentVertex);

      float angle = previous.angleRad() - copyOfDefaultAux.angleRad();
      angle = ((angle + MathUtils.PI2) % MathUtils.PI) * 2f;
      boolean angleMoreThanPI;
      if (inside) {
        angleMoreThanPI = angle > MathUtils.PI * 1.1f;
      } else {
        angleMoreThanPI = angle < MathUtils.PI * 0.9f;
      }

      if (auxVertexFinder.clockWisePolygon) angleMoreThanPI = !angleMoreThanPI;

      if (angleMoreThanPI) {
        boolean sharpCorner = Math.abs(MathUtils.PI - angle) > Math.PI * 0.4f;
        roundCorner = roundSharpCorners && sharpCorner;
      }
    }

    if (roundCorner) {
      Vector2 beginningAux = auxVertexFinder.getAuxEnding(vertices, k, 0);
      Vector2 endingAux = auxVertexFinder.getAuxBeginning(vertices, k, 0);
      Vector2 middleAux =
          tmp.set(defaultAux).sub(currentVertex).nor().scl(halfWidth).add(currentVertex);

      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(beginningAux, VERTEX_TYPE_AUX, vertexData);

      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(middleAux, VERTEX_TYPE_AUX, vertexData);

      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(endingAux, VERTEX_TYPE_AUX, vertexData);
    } else {
      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(defaultAux, VERTEX_TYPE_AUX, vertexData);
    }
  }