Ejemplo n.º 1
0
  /** Constructor: Sets up this panel and loads the images. */
  public Engine() {
    addKeyListener(new Controller());

    setBackground(Color.black);
    setPreferredSize(new Dimension(WIDTH, HEIGHT));
    setFocusable(true);

    // init world
    final int defWidth = 150;
    final int defHeight = 15;
    final Random gen = new Random();
    // 50% random, 25% hills, 25% platform
    if (gen.nextBoolean()) {
      world = RandomLevel.genWorldRandom(defWidth, defHeight, tp);
    } else {
      if (gen.nextBoolean()) {
        world = RandomLevel.genWorldHills(defWidth, defHeight, tp);
      } else {
        world = RandomLevel.genWorldPlatform(defWidth, defHeight, tp);
      }
    }
    //        world = new Level("house.txt", tp);

    // init hero
    hero = new Hero();
    hero.setImage(tp.get(Texture.hero));
    hero.setPos(world.getStart());
    renderer.addDynProp(hero);
    renderer.setWorld(world);

    // init test light
    Point[] bgLights = world.getAll(Texture.bgLightDead);
    Light tempLight;
    final int cso = 15; // Cell size offset.
    final int rRange = 100;
    final int rMin = 75;

    for (Point light : bgLights) {
      tempLight = new Light(light.x + cso, light.y + cso, world);
      tempLight.setRadius((short) (Math.random() * rRange + rMin));
      renderer.addStaticProp(tempLight);
      triggers.add(tempLight);
    }

    // Don't start this loop until setup is complete!
    if (thread == null) {
      running = true;
      thread = new Thread(this);
      thread.start();
    }
  }