示例#1
0
  public GameScreen(final Drop gam) {
    this.game = gam;

    // load the images for the droplet and the bucket, 64x64 pixels each
    dropImage = new Texture(Gdx.files.internal("droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("bucket.png"));

    // load the drop sound effect and the rain background "music"
    dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));
    rainMusic.setLooping(true);

    // create the camera and the SpriteBatch
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);

    // create a Rectangle to logically represent the bucket
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 64 / 2; // center the bucket horizontally
    bucket.y = 20; // bottom left corner of the bucket is 20 pixels above
    // the bottom screen edge
    bucket.width = 64;
    bucket.height = 64;

    // create the raindrops array and spawn the first raindrop
    raindrops = new Array<Rectangle>();
    spawnRaindrop();
  }
  @Override
  public void create() {
    // load the images for the droplet and the bucket, 64x64 pixels each
    dropImage = new Texture(Gdx.files.internal("bottle.png"));
    bucketImage = new Texture(Gdx.files.internal("bucket_black.png"));
    brokenBucketImage = new Texture(Gdx.files.internal("bottle_broken.png"));

    // load the drop sound effect and the rain background "music"
    //        dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav"));
    //        rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));

    // start the playback of the background music immediately
    //        rainMusic.setLooping(true);
    //        rainMusic.play();

    // create the camera and the SpriteBatch
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);
    batch = new SpriteBatch();

    // create a Rectangle to logically represent the bucket
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 64 / 2; // center the bucket horizontally
    bucket.y = 20; // bottom left corner of the bucket is 20 pixels above the bottom screen edge
    bucket.width = 64;
    bucket.height = 80;

    // create the raindrops array and spawn the first raindrop
    raindrops = new Array<Rectangle>();
    brokenBottles = new Array<Rectangle>();
    spawnRaindrop();
  }
示例#3
0
文件: Player.java 项目: marshauf/uni
 @Override
 public void read(Json json, JsonValue jsonData) {
   Iterator<JsonValue> iter = jsonData.iterator();
   JsonValue value;
   while (iter.hasNext()) {
     value = iter.next();
     switch (value.name()) {
       case "name":
         name = value.asString();
         break;
       case "dir":
         dir.x = value.get("x").asFloat();
         dir.y = value.get("x").asFloat();
         break;
       case "speed":
         speed = value.asFloat();
         break;
       case "bounds":
         bounds.width = value.getFloat("width");
         bounds.height = value.getFloat("height");
         setPosition(
             new Vector2(
                 value.getFloat("x") + bounds.width / 2, value.getFloat("y") + bounds.height / 2));
         break;
       case "score":
         score.read(json, value);
         break;
     }
   }
 }
 private void spawnRaindrop() {
   Rectangle raindrop = new Rectangle();
   raindrop.x = MathUtils.random(0, 800 - 64);
   raindrop.y = 480;
   raindrop.width = 32;
   raindrop.height = 128;
   raindrops.add(raindrop);
   lastDropTime = TimeUtils.nanoTime();
 }
示例#5
0
文件: Car.java 项目: javakaian/Oyun
  public void update(float delta) {

    collisionRect.x = position.x;
    collisionRect.y = position.y;
    collisionRect.width = size.x;
    collisionRect.height = size.y;

    position.add(speed.cpy().scl(delta));
  }
  public ShopTable(float x, float y, float velX, float velY, int width, int height) {
    super(x, y, velX, velY, width, height);

    rect.x = x;
    rect.y = y;
    rect.width = width;
    rect.height = height;

    item1 = new ShopPickup(x + 20, y + 32, 0, 0, 32, 32);
    item2 = new ShopPickup(x + 52, y + 32, 0, 0, 32, 32);
    item3 = new ShopPickup(x + 84, y + 32, 0, 0, 32, 32);
  }
示例#7
0
  public static long spawnRaindrop(Array<Rectangle> raindrops) {

    // create a raindrop and randomly place it at the top of the screen
    Rectangle raindrop = new Rectangle();
    raindrop.x = MathUtils.random(0, 800 - 64);
    raindrop.y = 480;
    raindrop.width = 64;
    raindrop.height = 64;
    raindrops.add(raindrop);

    return TimeUtils.nanoTime();
  }
示例#8
0
 @Override
 public void create() {
   dropImage = new Texture(Gdx.files.internal("data/generic_water.png"));
   bucketImage = new Texture(Gdx.files.internal("data/bucket.png"));
   camera = new OrthographicCamera();
   camera.setToOrtho(false, 800, 480);
   batch = new SpriteBatch();
   bucket = new Rectangle();
   bucket.x = 800 / 2 - 48 / 2; // center the bucket horizontally
   bucket.y = 20; // bottom left corner of the bucket is 20 pixels above
   // the bottom screen edge
   bucket.width = 48;
   bucket.height = 48;
   raindrops = new Array<Rectangle>();
   spawnRaindrop();
   System.out.println(dropImage.getWidth() + "  " + dropImage.getHeight());
 }
示例#9
0
  /*
   *  The create() method initializes our all of our resources and loads them into memory before the rest of the game is run
   *  This method is the first called after the entry point(based on platform) and is only called once.
   *  This is also a convenient place to put boiler plate code for the rest of the game that we only want ran once on startup.
   *
   *  NOTE: Gdx.files.internal() defaults to the assets put into the Android project folder and takes String "filename.filetype" as a parameter.
   */
  @Override
  public void create() {
    dropImage = new Texture(Gdx.files.internal("droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("bucket.png"));

    dropSound = Gdx.audio.newSound(Gdx.files.internal("droplet.mp3"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));

    rainMusic.setLooping(true); // set rainMusic (rain.mp3) to play over and over again
    rainMusic.play(); // starts the rainMusic audio

    camera = new OrthographicCamera(); // initialize camera, part of opengl/opengl-es.

    /*
     * sets the camera to 2 dimensional plane. Seems redundant since we are using OrthographicCamera() object.
     * Note: investigate camera settings
     */
    camera.setToOrtho(false, 800, 400);

    batch = new SpriteBatch(); // new sprite batch used in render() ie.Draws images.

    /*
     * set bucket properties. Use Rectangle object to represent bucket, track position and set size
     * used for collision detection with raindrop objects
     *
     */
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 64 / 2;
    bucket.y = 20;
    bucket.width = 64;
    bucket.height = 64;

    /*
     * initializes Libgdx Array.
     * Note: Investigate how  Libgdx Array is different than regular Java Array.
     */
    raindrops = new Array<Rectangle>();

    /*
     * creates new raindrops to be drawn for our game. This method is called here to
     * start the first raindrop.
     */
    spawnRaindrop();
  }
  // This gets called once (Constructor)
  public GameScreen(Skyfall gameRef) {
    Gdx.app.log("MY TAG", "in gamescreen constructor");

    this.game = gameRef;

    // These variables will adjust as gameTime passes
    dropSpeed = 200;
    pastGameTime = 0;
    respawnTime = 1000000000;

    // create a Rectangle to represent the paddle
    paddle = new Rectangle();
    paddle.x = GameUtilities.CENTER_X - 70; // center the paddle horizontally
    paddle.y = 50; // bottom left corner of the paddle is 20px above the bottom of the screen edge
    paddle.width = 140;
    paddle.height = 160;

    // create the circles array and spawn the first circle
    circles = new ArrayList<Circle>();
    spawnCircle();
  }
  /**
   * Obtains the actor at (x,y) with TOLERANCE.
   *
   * <p>Creates a square with size = TOLERANCE and checks:
   *
   * <p>1. if some vertex from the TOLERANCE square is inside an actor bbox 2. if some actor bbox
   * vertex is inside the TOLERANCE square
   */
  public InteractiveActor getInteractiveActorAtWithTolerance(float x, float y, float tolerance) {

    List<SceneLayer> layers = getLayers();

    tmpToleranceRect.x = x - tolerance / 2;
    tmpToleranceRect.y = y - tolerance / 2;
    tmpToleranceRect.width = tolerance;
    tmpToleranceRect.height = tolerance;

    for (SceneLayer layer : layers) {

      if (!layer.isVisible()) continue;

      // Obtain actors in reverse (close to camera)
      for (int l = layer.getActors().size() - 1; l >= 0; l--) {
        BaseActor a = layer.getActors().get(l);

        if (a instanceof InteractiveActor && ((InteractiveActor) a).hasInteraction()) {

          if (a.hit(x, y)
              || a.hit(tmpToleranceRect.x, tmpToleranceRect.y)
              || a.hit(tmpToleranceRect.x + tmpToleranceRect.width, tmpToleranceRect.y)
              || a.hit(tmpToleranceRect.x, tmpToleranceRect.y + tmpToleranceRect.height)
              || a.hit(
                  tmpToleranceRect.x + tmpToleranceRect.width,
                  tmpToleranceRect.y + tmpToleranceRect.height)) return (InteractiveActor) a;

          float[] verts = a.getBBox().getTransformedVertices();
          for (int i = 0; i < verts.length; i += 2) {
            float vx = verts[i];
            float vy = verts[i + 1];

            if (tmpToleranceRect.contains(vx, vy)) return (InteractiveActor) a;
          }
        }
      }
    }

    return null;
  }
示例#12
0
  @Override
  public void draw(SpriteBatch batch, float parentAlpha) {
    if (widget == null) return;

    validate();

    // Setup transform for this group.
    applyTransform(batch, computeTransform());

    if (scrollX)
      hKnobBounds.x =
          hScrollBounds.x + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
    if (scrollY)
      vKnobBounds.y =
          vScrollBounds.y
              + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));

    // Calculate the widget's position depending on the scroll state and available widget area.
    float y = widgetAreaBounds.y;
    if (!scrollY) y -= (int) maxY;
    else y -= (int) (maxY - visualAmountY);

    if (!fadeScrollBars && scrollbarsOnTop && scrollX) {
      float scrollbarHeight = 0;
      if (style.hScrollKnob != null) scrollbarHeight = style.hScrollKnob.getMinHeight();
      if (style.hScroll != null)
        scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
      y += scrollbarHeight;
    }

    float x = widgetAreaBounds.x;
    if (scrollX) x -= (int) visualAmountX;
    widget.setPosition(x, y);

    if (widget instanceof Cullable) {
      widgetCullingArea.x = -widget.getX() + widgetAreaBounds.x;
      widgetCullingArea.y = -widget.getY() + widgetAreaBounds.y;
      widgetCullingArea.width = widgetAreaBounds.width;
      widgetCullingArea.height = widgetAreaBounds.height;
      ((Cullable) widget).setCullingArea(widgetCullingArea);
    }

    // Caculate the scissor bounds based on the batch transform, the available widget area and the
    // camera transform. We need to
    // project those to screen coordinates for OpenGL ES to consume.
    getStage().calculateScissors(widgetAreaBounds, scissorBounds);

    // Draw the background ninepatch.
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    if (style.background != null) style.background.draw(batch, 0, 0, getWidth(), getHeight());
    batch.flush();

    // Enable scissors for widget area and draw the widget.
    if (ScissorStack.pushScissors(scissorBounds)) {
      drawChildren(batch, parentAlpha);
      ScissorStack.popScissors();
    }

    // Render scrollbars and knobs on top.
    batch.setColor(
        color.r,
        color.g,
        color.b,
        color.a * parentAlpha * Interpolation.fade.apply(fadeAlpha / fadeAlphaSeconds));
    if (scrollX && scrollY) {
      if (style.corner != null) {
        style.corner.draw(
            batch,
            hScrollBounds.x + hScrollBounds.width,
            hScrollBounds.y,
            vScrollBounds.width,
            vScrollBounds.y);
      }
    }
    if (scrollX) {
      if (style.hScroll != null)
        style.hScroll.draw(
            batch, hScrollBounds.x, hScrollBounds.y, hScrollBounds.width, hScrollBounds.height);
      if (style.hScrollKnob != null)
        style.hScrollKnob.draw(
            batch, hKnobBounds.x, hKnobBounds.y, hKnobBounds.width, hKnobBounds.height);
    }
    if (scrollY) {
      if (style.vScroll != null)
        style.vScroll.draw(
            batch, vScrollBounds.x, vScrollBounds.y, vScrollBounds.width, vScrollBounds.height);
      if (style.vScrollKnob != null)
        style.vScrollKnob.draw(
            batch, vKnobBounds.x, vKnobBounds.y, vKnobBounds.width, vKnobBounds.height);
    }

    resetTransform(batch);
  }
示例#13
0
  public void layout() {
    final Drawable bg = style.background;
    final Drawable hScrollKnob = style.hScrollKnob;
    final Drawable vScrollKnob = style.vScrollKnob;

    float bgLeftWidth = 0, bgRightWidth = 0, bgTopHeight = 0, bgBottomHeight = 0;
    if (bg != null) {
      bgLeftWidth = bg.getLeftWidth();
      bgRightWidth = bg.getRightWidth();
      bgTopHeight = bg.getTopHeight();
      bgBottomHeight = bg.getBottomHeight();
    }

    float width = getWidth();
    float height = getHeight();

    float scrollbarHeight = 0;
    if (hScrollKnob != null) scrollbarHeight = hScrollKnob.getMinHeight();
    if (style.hScroll != null)
      scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
    float scrollbarWidth = 0;
    if (vScrollKnob != null) scrollbarWidth = vScrollKnob.getMinWidth();
    if (style.vScroll != null)
      scrollbarWidth = Math.max(scrollbarWidth, style.vScroll.getMinWidth());

    // Get available space size by subtracting background's padded area.
    areaWidth = width - bgLeftWidth - bgRightWidth;
    areaHeight = height - bgTopHeight - bgBottomHeight;

    if (widget == null) return;

    // Get widget's desired width.
    float widgetWidth, widgetHeight;
    if (widget instanceof Layout) {
      Layout layout = (Layout) widget;
      widgetWidth = layout.getPrefWidth();
      widgetHeight = layout.getPrefHeight();
    } else {
      widgetWidth = widget.getWidth();
      widgetHeight = widget.getHeight();
    }

    // Determine if horizontal/vertical scrollbars are needed.
    scrollX = forceScrollX || (widgetWidth > areaWidth && !disableX);
    scrollY = forceScrollY || (widgetHeight > areaHeight && !disableY);

    boolean fade = fadeScrollBars;
    if (!fade) {
      // Check again, now taking into account the area that's taken up by any enabled scrollbars.
      if (scrollY) {
        areaWidth -= scrollbarWidth;
        if (!scrollX && widgetWidth > areaWidth && !disableX) {
          scrollX = true;
        }
      }
      if (scrollX) {
        areaHeight -= scrollbarHeight;
        if (!scrollY && widgetHeight > areaHeight && !disableY) {
          scrollY = true;
          areaWidth -= scrollbarWidth;
        }
      }
    }

    // Set the widget area bounds.
    widgetAreaBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, areaHeight);

    if (fade) {
      // Make sure widget is drawn under fading scrollbars.
      if (scrollX) areaHeight -= scrollbarHeight;
      if (scrollY) areaWidth -= scrollbarWidth;
    } else {
      if (scrollbarsOnTop) {
        // Make sure widget is drawn under non-fading scrollbars.
        if (scrollX) widgetAreaBounds.height += scrollbarHeight;
        if (scrollY) widgetAreaBounds.width += scrollbarWidth;
      } else {
        // Offset widget area y for horizontal scrollbar.
        if (scrollX) {
          if (hScrollOnBottom) {
            widgetAreaBounds.y += scrollbarHeight;
          } else {
            widgetAreaBounds.y = 0;
          }
        }
        // Offset widget area x for vertical scrollbar.
        if (scrollY) {
          if (vScrollOnRight) {
            widgetAreaBounds.x = 0;
          } else {
            widgetAreaBounds.x += scrollbarWidth;
          }
        }
      }
    }

    // If the widget is smaller than the available space, make it take up the available space.
    widgetWidth = disableX ? width : Math.max(areaWidth, widgetWidth);
    widgetHeight = disableY ? height : Math.max(areaHeight, widgetHeight);

    maxX = widgetWidth - areaWidth;
    maxY = widgetHeight - areaHeight;
    if (fade) {
      // Make sure widget is drawn under fading scrollbars.
      if (scrollX) maxY -= scrollbarHeight;
      if (scrollY) maxX -= scrollbarWidth;
    }
    scrollX(MathUtils.clamp(amountX, 0, maxX));
    scrollY(MathUtils.clamp(amountY, 0, maxY));

    // Set the bounds and scroll knob sizes if scrollbars are needed.
    if (scrollX) {
      if (hScrollKnob != null) {
        float hScrollHeight =
            style.hScroll != null ? style.hScroll.getMinHeight() : hScrollKnob.getMinHeight();
        // the small gap where the two scroll bars intersect might have to flip from right to left
        float boundsX, boundsY;
        if (vScrollOnRight) {
          boundsX = bgLeftWidth;
        } else {
          boundsX = bgLeftWidth + scrollbarWidth;
        }
        // bar on the top or bottom
        if (hScrollOnBottom) {
          boundsY = bgBottomHeight;
        } else {
          boundsY = height - bgTopHeight - hScrollHeight;
        }
        hScrollBounds.set(boundsX, boundsY, areaWidth, hScrollHeight);
        hKnobBounds.width =
            Math.max(
                hScrollKnob.getMinWidth(), (int) (hScrollBounds.width * areaWidth / widgetWidth));
        hKnobBounds.height = hScrollKnob.getMinHeight();
        hKnobBounds.x =
            hScrollBounds.x
                + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
        hKnobBounds.y = hScrollBounds.y;
      } else {
        hScrollBounds.set(0, 0, 0, 0);
        hKnobBounds.set(0, 0, 0, 0);
      }
    }
    if (scrollY) {
      if (vScrollKnob != null) {
        float vScrollWidth =
            style.vScroll != null ? style.vScroll.getMinWidth() : vScrollKnob.getMinWidth();
        // the small gap where the two scroll bars intersect might have to flip from bottom to top
        float boundsX, boundsY;
        if (hScrollOnBottom) {
          boundsY = height - bgTopHeight - areaHeight;
        } else {
          boundsY = bgBottomHeight;
        }
        // bar on the left or right
        if (vScrollOnRight) {
          boundsX = width - bgRightWidth - vScrollWidth;
        } else {
          boundsX = bgLeftWidth;
        }
        vScrollBounds.set(boundsX, boundsY, vScrollWidth, areaHeight);
        vKnobBounds.width = vScrollKnob.getMinWidth();
        vKnobBounds.height =
            Math.max(
                vScrollKnob.getMinHeight(),
                (int) (vScrollBounds.height * areaHeight / widgetHeight));
        if (vScrollOnRight) {
          vKnobBounds.x = width - bgRightWidth - vScrollKnob.getMinWidth();
        } else {
          vKnobBounds.x = bgLeftWidth;
        }
        vKnobBounds.y =
            vScrollBounds.y
                + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));
      } else {
        vScrollBounds.set(0, 0, 0, 0);
        vKnobBounds.set(0, 0, 0, 0);
      }
    }

    widget.setSize(widgetWidth, widgetHeight);
    if (widget instanceof Layout) ((Layout) widget).validate();
  }
示例#14
0
  public BuggySprite(
      TextureAtlas myTextures,
      TiledMapTileLayer pTiles,
      TiledMapTileLayer lTiles,
      ArrayList<PlatformSprite> platforms,
      GameInputManager inputManager,
      int lives,
      World world,
      MainGameLayer gameLayer) {

    super(myTextures.findRegion("buggy_F1"), pTiles, lTiles);
    standRegion = myTextures.findRegion("buggy_F1");
    m_walkAnimation =
        new AnimateSpriteFrame(myTextures, new String[] {"buggy_F1", "buggy_F2"}, 0.3f, -1);
    m_standAnimation = new AnimateSpriteFrame(myTextures, new String[] {"buggy_F1"}, 1.0f, -1);

    m_attackAnimation = new AnimateSpriteFrame(myTextures, new String[] {"man_stand_F1"}, 0.3f, 1);

    m_hitAnimation = null;
    m_tutorialAnimation = new AnimateSpriteFrame(myTextures, new String[] {"buggy_F1"}, 0.5f, -1);
    m_idleAnimation = new AnimateSpriteFrame(myTextures, new String[] {"buggy_F1"}, 0.5f, -1);

    m_throughDoorAnimation = new AnimateFadeOut(0.5f);
    m_floatAnimation =
        new AnimateSpriteFrame(myTextures, new String[] {"man_jump_F3", "man_jump_F3"}, 0.65f, -1);

    m_teleportIn = new AnimateFadeIn(0.35f);
    m_teleportOut = new AnimateFadeOut(0.35f);

    AnimateTranslateVertical f1 = new AnimateTranslateVertical(1.0f, 0f, -3f, 1);
    AnimateTranslateVertical f2 = new AnimateTranslateVertical(3.0f, 1.0f, -1f, 1);
    GameAnimateable[] af = {f1, f2};

    m_floatAnimation2 = new GameAnimationSequence(af, -1);

    AnimateFade fo = new AnimateFade(0.2f, 0.9f, 0.2f);
    AnimateDelay delay = new AnimateDelay(0.25f);
    AnimateFade fi = new AnimateFade(0.2f, 0.2f, 0.9f);
    AnimateFade ff = new AnimateFade(0.25f, 0.2f, 1.0f);
    GameAnimateable[] a = {fo, fi, delay, fo, fi, delay, fo, ff};

    m_invincibleAnimation = new GameAnimationSequence(a, 1);
    m_invincibleAnimation.setIgnoreStop(true);

    m_inputManager = inputManager;
    m_platforms = platforms;

    m_activeWeapon = null;

    maxSpeedX = 6.0f;
    defaultMaxSpeedX = 6.0f;
    maxSpeedY = 4.0f;
    maxFallVelocity = 20.0f;
    m_horizontalDragFactor = 1.0f;
    m_climbingDragFactor = 0.25f;
    m_gravity = 0.8f;

    m_jumping = false;
    m_climbing = false;
    m_currDir = 1;

    m_lives = lives;
    m_boundingBox.width = this.getBoundingRectangle().width / 4;
    m_boundOffX = this.getBoundingRectangle().width / 2;
    m_boundingBox.height = this.getBoundingRectangle().height / 5;

    m_gameLayer = gameLayer;

    this.runAnimation(m_standAnimation);

    if (gameLayer.m_stage > 1)
      pLight = gameLayer.createConeLight(new Color(0.8f, 0.8f, 0.5f, 0.75f), 1100, 0, 0, 0, 25);
    else pLight = gameLayer.createConeLight(new Color(0.8f, 0.8f, 0.5f, 0.35f), 700, 0, 0, 0, 25);

    pLight.setXray(true);
    pLight.setActive(false);
    m_lightX = this.getWidth() - 20;
  }
  private void androidInput() {

    left.width = 75;
    right.width = 75;
    shoot.width = 75;
    jump.width = 75;
    start.width = 75;

    leftSt.width = Game.res.getWidth("small", "Left", 0, Align.bottomLeft, false);
    rightSt.width = Game.res.getWidth("small", "Right", 0, Align.bottomLeft, false);
    shootSt.width = Game.res.getWidth("small", "Shoot", 0, Align.bottomLeft, false);
    ;
    jumpSt.width = Game.res.getWidth("small", "Jump", 0, Align.bottomLeft, false);
    startSt.width = Game.res.getWidth("small", "Start", 0, Align.bottomLeft, false);

    leftSt.height = Game.res.getHeight("small", "Up", 0, Align.bottomLeft, false);
    rightSt.height = Game.res.getHeight("small", "Down", 0, Align.bottomLeft, false);
    shootSt.height = Game.res.getHeight("small", "Shoot", 0, Align.bottomLeft, false);
    jumpSt.height = Game.res.getHeight("small", "Jump", 0, Align.bottomLeft, false);
    startSt.height = Game.res.getHeight("small", "Start", 0, Align.bottomLeft, false);

    left.height = 75;
    right.height = 75;
    shoot.height = 75;
    jump.height = 75;
    start.height = 50;

    start.x = 10;
    start.y = MyConstants.WORLD_HEIGHT - start.height - 10;

    startSt.x = (start.x + (start.width * .5f)) - (startSt.width * .5f);
    startSt.y = (start.y + (start.height * .5f)) + (startSt.height * .5f);

    jump.x = (MyConstants.WOLRD_WIDTH) - (jump.width * .5f) - 10;
    jump.y = (jump.height * .5f) + 10;

    jumpSt.x = jump.x - (jumpSt.width * .5f);
    jumpSt.y = jump.y + (jumpSt.height * .5f);

    shoot.x = (jump.x) - jump.width - 15;
    shoot.y = (shoot.height * .5f) + 10;

    shootSt.x = shoot.x - (shootSt.width * .5f);
    shootSt.y = shoot.y + (shootSt.height * .5f);

    left.x = 10;
    left.y = 10;

    rightSt.x = (right.x + (right.width * .5f)) - (rightSt.width * .5f);
    rightSt.y = (right.y + (right.height * .5f)) + (rightSt.height * .5f);

    right.x = 10 + left.width + 10;
    right.y = 10;

    leftSt.x = (left.x + (left.width * .5f)) - (leftSt.width * .5f);
    leftSt.y = (left.y + (left.height * .5f)) + (leftSt.height * .5f);

    for (int i = 0; i < MyConstants.NUM_TOUCHES; i++) {
      if (Gdx.input.isTouched(i)) {
        if (left.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          lefts[i] = true;
        } else {
          lefts[i] = false;
        }
        if (right.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          rights[i] = true;
        } else {
          rights[i] = false;
        }
        if (shoot.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          shoots[i] = true;
        } else {
          shoots[i] = false;
        }
        if (jump.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          jumps[i] = true;
        } else {
          jumps[i] = false;
        }
        if (start.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          starts[i] = true;
        } else {
          starts[i] = false;
        }
      } else {
        lefts[i] = false;
        rights[i] = false;
        shoots[i] = false;
        jumps[i] = false;
        starts[i] = false;
      }
    }

    MyInput.setKey(MyConstants.booleanArrayContains(true, lefts), MyInput.LEFT);
    MyInput.setKey(MyConstants.booleanArrayContains(true, rights), MyInput.RIGHT);
    MyInput.setKey(MyConstants.booleanArrayContains(true, shoots), MyInput.SHOOT);
    MyInput.setKey(MyConstants.booleanArrayContains(true, jumps), MyInput.JUMP);
    MyInput.setKey(MyConstants.booleanArrayContains(true, starts), MyInput.START);
  }
示例#16
0
 public void setHeight(float height) {
   bounds.height = height;
 }
示例#17
0
文件: Player.java 项目: marshauf/uni
 public Player(Vector2 startPosition) {
   bounds.width = 4;
   bounds.height = 4;
   setPosition(startPosition);
 }
示例#18
0
 public void updateBounds() {
   recBounds.x = fX - fWidth / 2;
   recBounds.y = fY - fHeight / 2;
   recBounds.width = fWidth;
   recBounds.height = fHeight;
 }