コード例 #1
0
ファイル: PlayNImage.java プロジェクト: emarchiori/eadventure
  @Override
  public boolean loadAsset() {
    logger.info("Loading image " + descriptor.getUri());
    loaded = false;
    if (image == null) {
      try {
        String path = assetHandler.getAbsolutePath(descriptor.getUri().getPath());
        image = PlayN.assets().getImage(path);
        if (image != null) {
          logger.info(
              "Image loaded OK: {} from {} width {}",
              new Object[] {descriptor.getUri(), path, image.width()});
          return image.isReady();
        } else {
          logger.error("Image NOT loaded: {}", descriptor.getUri());
          return true;
        }
      } catch (Exception e) {
        logger.error("Error loading image: {}", descriptor.getUri(), e);
        return false;
      }
    }
    image.addCallback(
        new ResourceCallback<Image>() {

          @Override
          public void done(Image resource) {
            loaded = true;
          }

          @Override
          public void error(Throwable err) {}
        });
    return loaded;
  }
コード例 #2
0
ファイル: Glyph.java プロジェクト: Zroxer/tripleplay
 /**
  * Ensures that the canvas image is at least the specified dimensions and cleared to all
  * transparent pixels. Also creates and adds the image layer to the parent layer if needed.
  */
 public void prepare(float width, float height) {
   // recreate our canvas if we need more room than we have (TODO: should we ever shrink it?)
   if (_image == null || _image.width() < width || _image.height() < height) {
     _image = PlayN.graphics().createImage(width, height);
     if (_layer != null) _layer.setImage(_image);
   } else {
     _image.canvas().clear();
   }
   if (_layer == null) {
     _layer = PlayN.graphics().createImageLayer(_image);
     if (_depth != null) _layer.setDepth(_depth);
     _parent.add(_layer);
   }
   _preparedWidth = width;
   _preparedHeight = height;
 }
コード例 #3
0
 @Override
 public void main() {
   platform().graphics().registerFont("text/Museo.otf", "Museo-300", Font.Style.PLAIN);
   platform().graphics().registerFont("text/Museo.otf", "Museo-300", Font.Style.BOLD);
   platform().graphics().registerFont("text/Museo.otf", "Museo-300", Font.Style.ITALIC);
   platform().graphics().registerFont("text/Museo.otf", "Museo-300", Font.Style.BOLD_ITALIC);
   PlayN.run(_game);
 }
コード例 #4
0
 /**
  * Creates a new background using the given image. The image is assumed to be divided into a 3x1
  * grid of 3 equal pieces.
  *
  * <p>NOTE: the image must be preloaded since we need to determine the stretching factor. If this
  * cannot be arranged using the application resource strategy, callers may consider setting the
  * background style from the images callback.
  */
 public Scale3Background(Image image) {
   if (!image.isReady()) {
     // complain about this, we don't support asynch images
     PlayN.log().warn("Scale3 image not preloaded: " + image);
   }
   _image = image;
   _s3 = new Scale3(image.width(), image.height());
 }
コード例 #5
0
ファイル: Player.java プロジェクト: kotucz/ld26
 @Override
 public void update(float delta) {
   super.update(delta);
   if (getBody().getPosition().y > 16) {
     PlayN.log().debug("Fallen!");
     SOUND_OUCH.play();
     dead = true;
   }
 }
コード例 #6
0
  @Override
  public void start() {
    InAppPayments payments = new HtmlInAppPayments();
    InAppPaymentsFactory.buildInAppPayments(payments);

    HtmlPlatform platform = HtmlPlatform.register();
    platform.assets().setPathPrefix("paymentsdemo/");
    PlayN.run(new PaymentsDemo());
  }
コード例 #7
0
  @Override
  public void init() {
    _screens.push(new DemoMenuScreen(_screens));

    // propagate events so that things like buttons inside a scroller work
    if (!Arrays.asList(mainArgs).contains("--no-propagate")) {
      PlayN.setPropagateEvents(true);
    }
  }
コード例 #8
0
ファイル: Player.java プロジェクト: kotucz/ld26
 @Override
 public void contact(PhysicsEntity other) {
   if (other instanceof Spike) {
     PlayN.log().debug("Ouch!");
     SOUND_OUCH.play();
     dead = true;
   } else if (other instanceof Block) {
     Block block = (Block) other;
     if (!block.isCollidable()) {
       exitReached = true;
     }
   }
 }
コード例 #9
0
 private Result rollHit(int attackerToHit, int defenderArmorClass) {
   int roll = (int) (PlayN.random() * 20) + 1;
   if (roll == 1) {
     return Result.CRITICAL_HIT;
   }
   if (roll == 20) {
     return Result.CRITICAL_MISS;
   }
   if (roll > attackerToHit) {
     return Result.MISSED;
   }
   int target = attackerToHit - defenderArmorClass;
   if (roll > target) {
     return Result.DEFLECTED;
   }
   return Result.HIT;
 }
コード例 #10
0
ファイル: SliderPage.java プロジェクト: hatboyzero/tripleplay
  public Group createInterface() {
    Font fixedFont = PlayN.graphics().createFont("Fixed", Font.Style.PLAIN, 16);

    Slider slider;
    Label sliderValue;
    Group iface =
        new Group(AxisLayout.vertical().gap(15))
            .add(
                new Shim(15, 15),
                new Label("Click and drag the slider to change the value:"),
                slider = new Slider(0, -100, 100),
                sliderValue =
                    new Label("0")
                        .setConstraint(Constraints.minSize("-000"))
                        .setStyles(Style.HALIGN.right, Style.FONT.is(fixedFont)));
    slider.value.map(FORMATTER).connect(sliderValue.text.slot());
    return iface;
  }
コード例 #11
0
 @Override
 protected void handleError(RuntimeException error) {
   PlayN.log().warn("Screen failure", error);
 }
コード例 #12
0
ファイル: SpringHtml.java プロジェクト: nsn/spring
 @Override
 public void start() {
   HtmlPlatform platform = HtmlPlatform.register();
   platform.assets().setPathPrefix("spring/");
   PlayN.run(new Spring());
 }
コード例 #13
0
 private int rollDamage(int attackerDamageDieSize) {
   int roll = (int) (PlayN.random() * attackerDamageDieSize) + 1;
   return roll;
 }
コード例 #14
0
ファイル: SpringJava.java プロジェクト: nsn/spring
 public static void main(String[] args) {
   JavaPlatform platform = JavaPlatform.register();
   platform.assets().setPathPrefix("com/nightspawn/spring/resources");
   PlayN.run(new Spring());
 }
コード例 #15
0
 @Override
 public void main() {
   platform().assetManager().setPathPrefix("pong/resources");
   Game game = (new PongGameFactory()).get();
   PlayN.run(game);
 }
コード例 #16
0
ファイル: TetrisFlash.java プロジェクト: slspeek/playn-novice
 @Override
 public void start() {
   FlashPlatform platform = FlashPlatform.register();
   platform.assetManager().setPathPrefix("tetrisflash/");
   PlayN.run(new Tetris());
 }
コード例 #17
0
ファイル: Player.java プロジェクト: kotucz/ld26
public class Player extends DynamicPhysicsEntity implements PhysicsEntity.HasContactListener {

  public static final float JUMP_SPEED = -20f;
  public static final float MOVE_SPEED = 10f;
  public static final float MOVE_ACC = 5f;

  public static final Sound SOUND_OUCH = PlayN.assets().getSound("sounds/ouch");
  public static final Sound SOUND_JUMP = PlayN.assets().getSound("sounds/jump");

  public static final float RADIUS = 0.49f;
  public static String TYPE = "Player";

  boolean dead = false;
  boolean exitReached = false;

  public Player(PeaWorld peaWorld, World world, float x, float y, float angle) {
    super(peaWorld, world, x, y, 2 * RADIUS, 2 * RADIUS, angle);
  }

  @Override
  Body initPhysicsBody(World world, float x, float y, float width, float height, float angle) {
    FixtureDef fixtureDef = new FixtureDef();
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position = new Vec2(0, 0);
    Body body = world.createBody(bodyDef);

    CircleShape circleShape = new CircleShape();
    circleShape.m_radius = RADIUS;
    fixtureDef.shape = circleShape;
    fixtureDef.density = 0.4f;
    fixtureDef.friction = 1f;
    fixtureDef.restitution = 0.0f;
    circleShape.m_p.set(0, 0);
    body.createFixture(fixtureDef);
    //        body.setLinearDamping(0.2f);
    body.setTransform(new Vec2(x, y), angle);
    return body;
  }

  @Override
  public void update(float delta) {
    super.update(delta);
    if (getBody().getPosition().y > 16) {
      PlayN.log().debug("Fallen!");
      SOUND_OUCH.play();
      dead = true;
    }
  }

  @Override
  public void contact(PhysicsEntity other) {
    if (other instanceof Spike) {
      PlayN.log().debug("Ouch!");
      SOUND_OUCH.play();
      dead = true;
    } else if (other instanceof Block) {
      Block block = (Block) other;
      if (!block.isCollidable()) {
        exitReached = true;
      }
    }
  }

  void playerControl(LudumDare26Game.ControlsState controlsState) {
    boolean doStop = !(controlsState.leftPressed || controlsState.rightPressed);

    final Body body = getBody();
    float linearDamping = 0;
    if (doStop) {
      body.setAngularVelocity(0);
      //                linearDamping = 10f;
      Vec2 linearVelocity = body.getLinearVelocity();
      linearVelocity.x *= 0.9;
      //                body.applyForce(new Vec2(v, 0), body.getPosition());
      body.setLinearVelocity(linearVelocity);
    } else {
      Vec2 linearVelocity = body.getLinearVelocity();
      final int dir = (controlsState.leftPressed ? -1 : 0) + (controlsState.rightPressed ? 1 : 0);
      float v = linearVelocity.x;
      v += dir * MOVE_ACC;
      v = Math.max(-MOVE_SPEED, Math.min(v, MOVE_SPEED));
      linearVelocity.x = v;
      //                body.applyForce(new Vec2(v, 0), body.getPosition());
      body.setLinearVelocity(linearVelocity);
      //                linearDamping = 1f;
    }
    body.setLinearDamping(linearDamping);
  }

  public void jump() {
    Vec2 linearVelocity = getBody().getLinearVelocity();
    linearVelocity.y = JUMP_SPEED;
    getBody().setLinearVelocity(linearVelocity);

    SOUND_JUMP.play();
  }

  @Override
  public Image getImage() {
    return image;
    // return chrome;
  }

  private static Image image = loadImage("player.png");
}
コード例 #18
0
ファイル: TextFont.java プロジェクト: toxic88/hybrid
 /**
  * Default constructor. <br>
  *
  * @param id
  * @param style
  * @param size
  */
 TextFont(String id, Style style, float size) {
   this.playNFont = PlayN.graphics().createFont(id, style, size);
 }
コード例 #19
0
ファイル: PlayNGoActivity.java プロジェクト: Igosuki/playn-go
 @Override
 public void main() {
   platform().assets().setPathPrefix("com/gepsens/playn/resources");
   PlayN.run(new PlayNGo());
 }
コード例 #20
0
 @Override
 public void main() {
   platform().assets().setPathPrefix("com/test2/resources");
   testClass = new TestClass();
   PlayN.run(testClass);
 }