Android Open Source - Froggy Lilypad






From Project

Back to project page Froggy.

License

The source code is released under:

GNU General Public License

If you think the Android project Froggy listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mopgames.GameObjects;
/*from w w  w .  j a va2  s. co  m*/
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import java.util.Random;

public class Lilypad extends Scrollable {
  private Random r;

  private Rectangle hitBox;

  public static final int VERTICAL_GAP = 45;
  public static final int SKULL_WIDTH = 40;
  public static final int SKULL_HEIGHT = 11;
  public static final int LILYPAD_GAP = 49;
  private static final int minHeight = 8;
  private static final int minWidth = 40;

  private float groundY;
  private boolean isScored = false;

  // When Pipe's constructor is invoked, invoke the super (Scrollable)
  // constructor
  public Lilypad(float x, float y, float scrollSpeed, float groundY) {
    super(x, y - minHeight, minWidth, minHeight, scrollSpeed);
    // Initialize a Random object for Random number generation
    r = new Random();
    hitBox = new Rectangle();
    this.groundY = groundY;
    // reset(x);
  }

  @Override
  public void update(float delta) {
    // Call the update method in the superclass (Scrollable)
    super.update(delta);
    hitBox.set(position.x, position.y + height / 3, width, height / 3);
  }

  @Override
  public void reset(float newX) {
    newX += (0.5 + r.nextDouble() * 0.7) * LILYPAD_GAP;
    // Call the reset method in the superclass (Scrollable)
    super.reset(newX);
    // Change the height to a random number
    double seed = r.nextDouble() * 0.3;
    height = (int) (minHeight * (1 + seed));
    width = (int) (minWidth * (1 + seed));
    position.y = groundY - height;
    isScored = false;
  }

  public void onRestart(float x, float scrollSpeed) {
    velocity.x = scrollSpeed;
    reset(x);
  }

  public boolean collidesLand(Frog frog) {
    // if (position.x < frog.getX() + frog.getWidth()) {
    if (position.x < frog.getBoundingCircle().x
    // Bad corner collision (following)
        && !(position.y < frog.getBoundingCircle().y && position.x + 5 > frog
            .getBoundingCircle().x))
      return (Intersector.overlaps(frog.getBoundingCircle(), hitBox));
    // }
    return false;
  }

  public boolean isScored() {
    return isScored;
  }

  public void setScored(boolean b) {
    isScored = b;
  }

  public Rectangle getHitBox() {
    return hitBox;
  }
}




Java Source Code List

android.UnusedStub.java
com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelper.java
com.mopgames.ActionResolverDesktop.java
com.mopgames.MainActivity.java
com.mopgames.Main.java
com.mopgames.RobovmLauncher.java
com.mopgames.Froggy.FroggyGame.java
com.mopgames.GameObjects.Background.java
com.mopgames.GameObjects.Frog.java
com.mopgames.GameObjects.Lilypad.java
com.mopgames.GameObjects.MenuItem.java
com.mopgames.GameObjects.ScrollHandler.java
com.mopgames.GameObjects.Scrollable.java
com.mopgames.GameWorld.GameRenderer.java
com.mopgames.GameWorld.GameWorld.java
com.mopgames.Helpers.ActionResolver.java
com.mopgames.Helpers.AssetLoader.java
com.mopgames.Helpers.InputHandler.java
com.mopgames.Screens.GameScreen.java
com.mopgames.Screens.SplashScreen.java
com.mopgames.TweenAccessors.SpriteAccessor.java
com.mopgames.TweenAccessors.ValueAccessor.java
com.mopgames.TweenAccessors.Value.java
com.mopgames.client.ActionResolverDesktop.java
com.mopgames.client.GwtLauncher.java
com.mopgames.ui.SimpleButton.java