Android Open Source - ZombieBird Scroll Handler






From Project

Back to project page ZombieBird.

License

The source code is released under:

Apache License

If you think the Android project ZombieBird 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.kilobolt.GameObjects;
/* w w  w . j  av  a 2s .c  o m*/
public class ScrollHandler {
  
  // ScrollHandler will create all five objects that are needed
  private Grass frontGrass, backGrass;
  private Pipe pipe1, pipe2, pipe3;
  
  // ScrollHandler will use these constants to determine how fast we need to scroll and
  // also determine the size of the gap between each pair of pipes
  public static final int SCROLL_SPEED = -59;
  public static final int PIPE_GAP = 49;
  
  // Constructor receives a float that determines where to create the Grass and Pipe objects
  public ScrollHandler(float yPos) {
    frontGrass = new Grass(0, yPos, 143, 11, SCROLL_SPEED);
    backGrass = new Grass(frontGrass.getTailX(), yPos, 143, 11, SCROLL_SPEED);
    
    pipe1 = new Pipe(210, 0, 22, 60, SCROLL_SPEED, yPos);
    pipe2 = new Pipe(pipe1.getTailX() + PIPE_GAP, 0, 22, 70, SCROLL_SPEED, yPos);
    pipe3 = new Pipe(pipe2.getTailX() + PIPE_GAP, 0, 22, 60, SCROLL_SPEED, yPos);
  }
  
  public void update(float delta) {
    // Update objects
    frontGrass.update(delta);
    backGrass.update(delta);
    pipe1.update(delta);
    pipe2.update(delta);
    pipe3.update(delta);
    
    // Check to see if any pipes are scrolled left and reset if needed.
    if(pipe1.isScrolledLeft()) {
      pipe1.reset(pipe3.getTailX() + PIPE_GAP);
    } else if (pipe2.isScrolledLeft()) {
      pipe2.reset(pipe1.getTailX() + PIPE_GAP);
    } else if (pipe3.isScrolledLeft()) {
      pipe3.reset(pipe2.getTailX() + PIPE_GAP);
    }
    
    // Check pipes too
    if(frontGrass.isScrolledLeft()) {
      frontGrass.reset(backGrass.getTailX());
    } else if (backGrass.isScrolledLeft()) {
      backGrass.reset(frontGrass.getTailX());
    }
  }
  
  public Grass getFrontGrass() {
    return frontGrass;
  }
  
  public Grass getBackGrass() {
    return backGrass;
  }
  
  public Pipe getPipe1() {
    return pipe1;
  }
  
  public Pipe getPipe2() {
    return pipe2;
  }
  
  public Pipe getPipe3() {
    return pipe3;
  }
}




Java Source Code List

com.kilobolt.GameObjects.Bird.java
com.kilobolt.GameObjects.Grass.java
com.kilobolt.GameObjects.Pipe.java
com.kilobolt.GameObjects.ScrollHandler.java
com.kilobolt.GameObjects.Scrollable.java
com.kilobolt.GameWorld.GameRenderer.java
com.kilobolt.GameWorld.GameWorld.java
com.kilobolt.Screens.GameScreen.java
com.kilobolt.ZBHelpers.AssetLoader.java
com.kilobolt.ZBHelpers.InputHandler.java
com.kilobolt.ZombieBird.MainActivity.java
com.kilobolt.ZombieBird.Main.java
com.kilobolt.ZombieBird.RobovmLauncher.java
com.kilobolt.ZombieBird.ZBGame.java
com.kilobolt.ZombieBird.client.GwtLauncher.java