Package general.datastructures

Examples of general.datastructures.Vector2f


    }
  }

  @Override
  public double getDistanceTo(IHitable target) {
    Vector2f t = target.getPosition();
    return this.position.getDistanceTo(t);
  }
View Full Code Here


          this.wc_movedir.normalize();
        }
        else
        {
          this.isMoving = false;
          wc_movedir = new Vector2f(0);
        }
      }
     
      Vector<Sprite> collidingSprites = this.collides(this.wc_position.add_cpy(wc_movedir.scale_cpy((float)speed*(((float)gametime)/10))));
     
 
View Full Code Here

  }
*/

  @Test
  public void testVector2f() {
    Vector2f vec1 = new Vector2f(5, 7);
    assertEquals(5,vec1.x(),0.0001);
    assertEquals(7,vec1.y(),0.0001);
   
    Vector2f vec2 = new Vector2f(5);
    assertTrue(vec1.isInRange(vec2, 2.0001f));
    assertFalse(vec1.isInRange(vec2, 1.9999f));
    assertEquals(Math.sqrt(50), vec2.length(), 0.0001);   
   
    Vector2f vec3 = new Vector2f(vec1);
    assertEquals(vec1, vec3);
   
    vec3.add(vec1);
    assertEquals(10, vec3.x(),0.0001);
    assertEquals(14, vec3.y(),0.0001);
   
    Vector2f vec4 = new Vector2f(4,0);
    vec4.normalize();
    assertEquals(1, vec4.length(), 0.0001);
    vec4.scale(3f);
    assertEquals(3, vec4.length(), 0.0001)
  }
View Full Code Here

 
  @Test
  public void testWaypoint()
  {
    Waypoint wp1, wp2, wp3, wp4, wp5;
    wp1 = new Waypoint(new Vector2f(3, 4), 0);
    assertNotNull(wp1);
    assertNull(wp1.getPredecessor());
    assertEquals(new Vector2f(3,4),wp1.getVector2f());
    assertEquals(0.0,wp1.getDistance(),1e-4);
   
    wp2 = new Waypoint(new Vector2f(3,8), 4, wp1);
    assertNotNull(wp2);
    assertEquals(wp1,wp2.getPredecessor());
   
    wp3 = new Waypoint(new Vector2f(1,8), 2, wp2);
   
    assertEquals(6, wp3.getDistance(),1e-4);
   
    Vector<Vector2f> points = new Vector<Vector2f>();
    Vector<Vector2f> actual_points = new Vector<Vector2f>();
    points = wp3.getRouteList(points);
    assertNotSame(actual_points,points);
   
    actual_points.add(wp3.getVector2f());
    actual_points.add(wp2.getVector2f());
    actual_points.add(wp1.getVector2f());
   
    assertEquals(actual_points, points);
   
    wp4 = new Waypoint(new Vector2f(3,4), 1, wp2);
    wp5 = new Waypoint(new Vector2f(2,4), 0);
   
    assertTrue(wp1.equals(wp1));
    assertTrue(wp1.equals(wp4));
    assertFalse(wp1.equals(wp2));
    assertFalse(wp1.equals(wp5));   
View Full Code Here

 
  @Test
  public void testPriorityNode()
  {
    Waypoint wp1,wp2,wp3,wp4;
    wp1 = new Waypoint(new Vector2f(1, 1), 1);
    wp2 = new Waypoint(new Vector2f(2, 2), 2);
    wp3 = new Waypoint(new Vector2f(3, 3), 3);
    wp4 = new Waypoint(new Vector2f(4, 4), 4);
   
    PriorityNode n1, n2, n3, n4;
    n1 = new PriorityNode(2, wp1);
     
    assertNotNull(n1);
View Full Code Here

  @Test
  public void testPriorityQueueInsert() throws EmptyListException
  {
    PriorityQueue pq = new PriorityQueue();
    Waypoint wp1, wp2, wp3, wp4, wp5;
    wp1 = new Waypoint(new Vector2f(1,1), 1);
    wp2 = new Waypoint(new Vector2f(2,2), 2);
    wp3 = new Waypoint(new Vector2f(3,3), 3);
    wp4 = new Waypoint(new Vector2f(4,4), 4);
    wp5 = new Waypoint(new Vector2f(5,5), 5);
   
    pq.insert(wp2, 2);
    assertFalse(pq.isEmpty());
    pq.insert(wp4, 4);
    assertFalse(pq.isEmpty());
View Full Code Here

  @Test
  public void testPriorityQueueDublicates() throws EmptyListException
  {
    PriorityQueue pq = new PriorityQueue();
    Waypoint wp1, wp2, wp3;
    wp1 = new Waypoint(new Vector2f(1,1), 1);
    wp2 = new Waypoint(new Vector2f(2,2), 2);
    wp3 = new Waypoint(new Vector2f(3,3), 3);
   
    pq.insert(wp1, 10);
    pq.insert(wp1, 9);
    pq.insert(wp2, 8);
    pq.insert(wp2, 7);
View Full Code Here


      if (playercount > 4 || playercount < 2) {
        throw new IllegalPlayerCountException("Ungueltige Spieleranzahl!", playercount);
      }
      mc_spawnpoints2.add(new Vector2f(10, 10));
      mc_spawnpoints2.add(new Vector2f(20,20));
      if (playercount >=3) {
        mc_spawnpoints2.add(new Vector2f(10,20));

        if (playercount == 4) {
          mc_spawnpoints2.add(new Vector2f(20,10));
        }
      }

      //map fuellen
      for (int i=0; i<10000; i++)
        for(int j=0; j<10000; j++)
        {
          if(i<5||i>=25||j<5||j>=25)
          {
            data2[i][j] = OldMap.TERRAIN_WATER;
          }
          else if (i>13&&i<18&&j>13&&j<18)
          {
            data2[i][j] = OldMap.TERRAIN_FORREST;
          }
          else
          {
            data2[i][j] = OldMap.TERRAIN_GRASS;
          }
        }

      return new OldMap(data2,30,30,mc_spawnpoints2);
     

    case TEMPLATE_ISLAND:
    default:
      byte[][] data = new byte[10000][10000];

      Vector<Vector2f> mc_spawnpoints = new Vector<Vector2f>();


      if (playercount > 4 || playercount < 2) {
        throw new IllegalPlayerCountException("Ungueltige Spieleranzahl!", playercount);
      }
      mc_spawnpoints.add(new Vector2f(10, 10));
      mc_spawnpoints.add(new Vector2f(20,20));
      if (playercount >=3) {
        mc_spawnpoints.add(new Vector2f(10,20));

        if (playercount == 4) {
          mc_spawnpoints.add(new Vector2f(20,10));
        }
      }

      //map fuellen
      for (int i=0; i<10000; i++)
View Full Code Here

    return (f * tilesize)-(tilesize/2);
  }

  public static Vector2f mapToWorld(Vector2f vec, int tilesize)
  {
    return vec.scale_cpy(tilesize).add_cpy(new Vector2f(-tilesize/2));
  }
View Full Code Here

  private static Random r = new Random();
 
  public static Vector2f getVector2f(float maxX, float maxY)
  {
    return new Vector2f(r.nextFloat()*maxX, r.nextFloat()*maxY);
  }
 
View Full Code Here

TOP

Related Classes of general.datastructures.Vector2f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.