Android Open Source - snappyfrog Laser Beam






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;
/*ww  w.  j a  v a 2  s.c  o  m*/
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool.Poolable;

public class LaserBeam extends Actor implements Poolable {
  private Sprite laser;
  private Vector2 velocity;
  private Vector2 startLocation;
  private boolean visible;
  LevelScreen parent;
  
  public LaserBeam(LevelScreen parent){
    super();
    this.parent = parent;
    
    laser = Game.getTextureAtlas().createSprite("gamescene/laser");
    laser.setScale(ResHelper.LinearHeightValue(1.0f));
    startLocation = new Vector2();
    
    reset();
  }
  
  @Override
  public void reset() {
    visible = false;
  }
  
  public void setStartLocation(float x, float y){
    startLocation.x = x;
    startLocation.y = y;
    setPosition(x, y);
  }
  
  public void shoot(Vector2 target){
    visible = true;
    
    velocity = target.cpy().sub(startLocation);
    velocity.nor();
    velocity.scl(ResHelper.LinearHeightValue(500.0f));

    setRotation(velocity.angle());
  }

  
  @Override
  public float getWidth() {
    return laser.getWidth();
  }
  
  @Override
  public float getHeight() {
    return laser.getHeight();
  }  
  
  @Override
  public void act(float delta) {
    super.act(delta);
    
    // Move
    moveBy(velocity.x * delta, velocity.y * delta);
    
    // Check for out of bounds
    if (getX() + getWidth() < 0 || getX() > Game.getWidth() ||
      getY() + getHeight() < 0 || getY() > Game.getHeight()){
      parent.removeLaserBeam(this);
    }
  }
  
  @Override
  public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    
    if (visible){
      batch.draw(laser, getX(), getY(), getOriginX(), getOriginY(),
                  getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
    }
  }
}




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