Пример #1
0
  private void ColPush(Entity e1) {
    this.colVec.x = (e1.getPosX() - this.getPosX());
    this.colVec.y = (e1.getPosY() - this.getPosY());

    float overlap = (float) ((this.getRadius() + e1.getRadius()) - Math.abs(colVec.getLength()));

    this.lapVec.x = Math.abs(colVec.x * overlap * 0.5);
    this.lapVec.y = Math.abs(colVec.y * overlap * 0.5);
  }
Пример #2
0
 private static void generateScenery(
     String mapId, int x, int y, int nx, int ny, DatastoreService store) {
   if (x != nx && y != ny && x != y) { // Clear the diagonal line for escape
     Entity obstacle = new Entity(Transport.SCENERY);
     obstacle.setProperty("x", x);
     obstacle.setProperty("y", y);
     obstacle.setProperty("map", mapId);
     store.put(obstacle);
   }
 }
Пример #3
0
 void fixEntityCollision(Entity e) {
   while (checkEntityCollision(e)) {
     if (x < e.getX()) {
       x -= 2;
     } else if (x > e.getX()) {
       x += 2;
     } else if (y < e.getY()) {
       y -= 2;
     } else if (y > e.getY()) {
       y += 2;
     }
   }
 }
Пример #4
0
  private static Entity ensurePlayerExists(String username, DatastoreService store) {
    Query q =
        new Query(Transport.PLAYER)
            .setFilter(new Query.FilterPredicate("identity", Query.FilterOperator.EQUAL, username));
    Entity player = store.prepare(q).asSingleEntity();
    if (player == null) {
      Long x = 10l;
      Long y = 10l;
      player = new Entity(Transport.PLAYER);
      player.setProperty("identity", username);
      player.setProperty("speed", 4);
      PointSet points = new PointSet(20, 20);
      points.add(new Transport.Point(x, y));
      player.setProperty("path", new Gson().toJson(new Transport.Points(points)));
      store.put(player);

      QueueFactory.getDefaultQueue().add(withUrl("/tick").param("identity", username));
    }
    return player;
  }
Пример #5
0
 private static Entity ensureMapExists(Entity player, DatastoreService store) {
   Query mq = new Query(Transport.MAP);
   Entity map = store.prepare(mq).asSingleEntity();
   Random rand = new Random();
   if (map == null) {
     map = new Entity(Transport.MAP);
     String mapId = "sandbox";
     int width = 20;
     int height = 20;
     map.setProperty("width", width);
     map.setProperty("height", height);
     map.setProperty("identity", mapId);
     store.put(map);
     for (int j = 0; j < 8; j++) {
       int sx = width / 2;
       int sy = height / 2;
       for (int i = 0; i < 100; i++) {
         switch (rand.nextInt(4)) {
           case 0:
             sx++;
             break;
           case 1:
             sy++;
             break;
           case 2:
             sx--;
             break;
           case 3:
             sy--;
             break;
         }
         generateScenery(mapId, sx, sy, 10, 10, store);
       }
     }
     player.setProperty("map", mapId);
     store.put(player);
   }
   return map;
 }
Пример #6
0
 public void Collide(Entity e1) {
   if (e1.getType() == Entity.REDCELL) {
     ColPush(e1);
   } else if (e1.getType() == Entity.VIRUS) {
     ColPush(e1);
     this.infect(e1.getMouvementBehavior().getStartDir(), e1.getMouvementBehavior().getAngle());
   } else if (e1.getType() == Entity.OXYGEN) {
     this.setRemove(true);
     ColPush(e1);
   } else if (e1.getType() == Entity.FATCELL) this.setRemove(true);
 }
Пример #7
0
 boolean checkEntityCollision(Entity e) {
   Rectangle r1 = new Rectangle(getX(), getY(), WIDTH, HEIGHT);
   Rectangle r2 = new Rectangle(e.getX(), e.getY(), Entity.WIDTH, Entity.HEIGHT);
   return ((r1.intersects(r2)) || (r2.intersects(r1)));
 }