Android Open Source - snappyfrog Salary






From Project

Back to project page snappyfrog.

License

The source code is released under:

Apache License

If you think the Android project snappyfrog 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.masseranolabs.snappyfrog;
/*from  w  w w .  j a v a2  s.  c  o m*/
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.utils.Pool.Poolable;
import com.badlogic.gdx.utils.SnapshotArray;

public class Salary extends Actor implements Poolable {
  private float SPEED = ResHelper.LinearWidthValue(100.0f);
  private Sprite salary;
  private boolean hit;
  private boolean leftToRight;
  LevelScreen parent;
  private Explosion explosion;
  
  public Salary(LevelScreen parent){
    super();
    this.parent = parent;
    
    explosion = new Explosion();
    explosion.setScale(ResHelper.LinearHeightValue(1.0f));
    
    salary = Game.getTextureAtlas().createSprite("gamescene/salary");
    salary.setScale(ResHelper.LinearHeightValue(1.0f));
    
    reset();
  }
  
  @Override
  public void reset() {
    hit = false;
    leftToRight = Game.getRandomGenerator().nextBoolean();
    explosion.reset();
  }
  
  public void setStartLocation(float topLineHeight){
    setPosition(leftToRight ? -getWidth() : Game.getWidth(), 
        topLineHeight - Game.getRandomGenerator().nextInt((int)ResHelper.LinearHeightValue(40.0f)));
  }
  
  @Override
  public float getWidth() {
    return salary.getWidth();
  }
  
  @Override
  public float getHeight() {
    return salary.getHeight();
  }  
  
  @Override
  public void act(float delta) {
    super.act(delta);
    
    // Move
    if (leftToRight) moveBy(SPEED * delta, 0);
    else moveBy(-SPEED * delta, 0);
    
    // Check for out of bounds
    if (getX() + getWidth() < -1 || getX() > Game.getWidth() + 1){
      parent.removeSalary(this);
    }else if (!hit){
      SnapshotArray<Actor> lasers = parent.lasersGroup.getChildren();
      Actor laser;
      for (int i = 0; i < lasers.size; i++){
        laser = lasers.get(i);
        if (laser.getX() > getX() && laser.getX() < getX() + getWidth() &&
          laser.getY() < getY() + getHeight() && laser.getY() > getY()
          ){
          hit = true;
          
          Game.getCrashSound().play();
          explosion.setPosition(getX(), getY());
          explosion.explode();      
          
          // Bounce down
          addAction(Actions.moveBy(0, ResHelper.LinearHeightValue(-100.0f), 1.0f, Interpolation.circleOut));
          
          // remove laser
          parent.removeLaserBeam((LaserBeam)laser);
          
          parent.increaseSalaryHitCount();
          break;
        }
      }
    }else{
      explosion.act(delta);
    }
  }
  
  @Override
  public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    
    batch.draw(salary, getX(), getY(), getOriginX(), getOriginY(),
                  getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
    
    explosion.draw(batch, parentAlpha);
  }
}




Java Source Code List

com.masseranolabs.bridge.SLComposeViewController.java
com.masseranolabs.snappyfrog.AndroidServices.java
com.masseranolabs.snappyfrog.ButtonFactory.java
com.masseranolabs.snappyfrog.DesktopServices.java
com.masseranolabs.snappyfrog.Explosion.java
com.masseranolabs.snappyfrog.Frog.java
com.masseranolabs.snappyfrog.Game.java
com.masseranolabs.snappyfrog.LaserBeam.java
com.masseranolabs.snappyfrog.LevelScreen.java
com.masseranolabs.snappyfrog.MainActivity.java
com.masseranolabs.snappyfrog.MainActivity.java
com.masseranolabs.snappyfrog.Main.java
com.masseranolabs.snappyfrog.Obstacle.java
com.masseranolabs.snappyfrog.OuyaServices.java
com.masseranolabs.snappyfrog.PlatformServices.java
com.masseranolabs.snappyfrog.PowerBar.java
com.masseranolabs.snappyfrog.ResHelper.java
com.masseranolabs.snappyfrog.RobovmLauncher.java
com.masseranolabs.snappyfrog.Salary.java
com.masseranolabs.snappyfrog.ScreenshotFactory.java
com.masseranolabs.snappyfrog.StagedScreen.java
com.masseranolabs.snappyfrog.client.GwtLauncher.java
com.masseranolabs.snappyfrog.client.HtmlServices.java
com.masseranolabs.snappyfrog.iOSServices.java
org.robovm.bindings.admob.GADAdMobExtras.java
org.robovm.bindings.admob.GADAdNetworkExtras.java
org.robovm.bindings.admob.GADAdSizeManager.java
org.robovm.bindings.admob.GADAdSize.java
org.robovm.bindings.admob.GADBannerViewDelegateAdapter.java
org.robovm.bindings.admob.GADBannerViewDelegate.java
org.robovm.bindings.admob.GADBannerView.java
org.robovm.bindings.admob.GADErrorCode.java
org.robovm.bindings.admob.GADGender.java
org.robovm.bindings.admob.GADInterstitialDelegateAdapter.java
org.robovm.bindings.admob.GADInterstitialDelegate.java
org.robovm.bindings.admob.GADInterstitial.java
org.robovm.bindings.admob.GADRequestErrorConstants.java
org.robovm.bindings.admob.GADRequestError.java
org.robovm.bindings.admob.GADRequest.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitialAdapter.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitialDelegateAdapter.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitialDelegate.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitial.java
org.robovm.bindings.admob.mediation.GADCustomEventRequest.java
org.robovm.bindings.admob.sample.Sample.java