Android Open Source - BlastWords Blaster






From Project

Back to project page BlastWords.

License

The source code is released under:

Apache License

If you think the Android project BlastWords 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

/**
 * BlastWords/* w  w  w. j  ava  2s. c o  m*/
 * Blaster.java
 * 
 * Created by Lou Foster
 * Copyright Studio332 2013. All rights reserved.
 */
package com.studio332.blastwords.objects;

import static com.badlogic.gdx.scenes.scene2d.actions.Actions.moveTo;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.studio332.blastwords.util.Assets;

public class Blaster extends Actor {
   private Image plunger;
   private Image body;
   private final float plungerYOffset = 135.0f;
   private boolean grabbed = false;
   private float grabbedAtY;
   private Listener listener;
   
   public Blaster() {
      super();
      
      this.body = new Image(Assets.instance().getDrawable("blaster-body"));
      this.plunger = new Image(Assets.instance().getDrawable("blaster-plunger"));
   }
   
   public void setListener( Listener l ) {
      this.listener = l;
   }
   
   public boolean grab (float x, float y) {
      float l = this.plunger.getX();
      float t = this.plunger.getY();
      float w = this.plunger.getWidth();
      float h = this.plunger.getHeight();
      if (x >= l && x <= l+w && y>=t && y<=t+h) {
         this.grabbed = true;
         this.grabbedAtY = y;
      }
      return false;
   }
   
   public boolean isGrabbed() {
      return this.grabbed;
   }
   
   public void letGo() {
      this.grabbed = false;
      float x = this.plunger.getX();
      float y =  this.body.getY()+this.plungerYOffset;
      this.plunger.addAction( moveTo(x,y,0.2f));
   }
   
   public void dragPlunger( float x, float y ) {
      
      float delY = y - this.grabbedAtY;
      float newY = this.body.getY()+this.plungerYOffset+delY;
      if ( newY > this.body.getY()+this.plungerYOffset ) {
         this.plunger.setPosition( this.plunger.getX(), this.body.getY()+this.plungerYOffset);
         return;
      }

      float blastY = this.body.getY()+this.plungerYOffset-110.0f;
      if ( newY <= blastY) {
          if ( this.listener != null ) {
             this.listener.blastHandler();
          }
          letGo();
          return;
      }
      this.plunger.setPosition(this.plunger.getX(), this.body.getY()+this.plungerYOffset+delY);
   }
   
   @Override
   public void setPosition(float x, float y) {
      super.setPosition(x, y);
      this.body.setPosition(x, y);
      this.plunger.setPosition(x, y+this.plungerYOffset);
   }
   
   @Override
   public void act(float delta) {
      this.plunger.act(delta);
      super.act(delta);
   }
   
   @Override
   public void draw(SpriteBatch batch, float parentAlpha) {
      this.plunger.draw(batch, parentAlpha);
      this.body.draw(batch, parentAlpha);
   }
   
   /*
    * Listener for blast events
    */
   public interface Listener {
      void blastHandler();
   }
}




Java Source Code List

com.studio332.blastwords.BlastWords.java
com.studio332.blastwords.MainActivity.java
com.studio332.blastwords.Main.java
com.studio332.blastwords.model.BlastWordsGame.java
com.studio332.blastwords.model.LetterInfo.java
com.studio332.blastwords.model.Settings.java
com.studio332.blastwords.objects.Blaster.java
com.studio332.blastwords.objects.Bomb.java
com.studio332.blastwords.objects.Digit.java
com.studio332.blastwords.objects.GameTimer.java
com.studio332.blastwords.objects.ScoreBoard.java
com.studio332.blastwords.objects.Tile.java
com.studio332.blastwords.screens.AbstractScreen.java
com.studio332.blastwords.screens.GameOver.java
com.studio332.blastwords.screens.GameScreen.java
com.studio332.blastwords.screens.GameStateListener.java
com.studio332.blastwords.screens.MainMenuScreen.java
com.studio332.blastwords.screens.Popup.java
com.studio332.blastwords.screens.SplashScreen.java
com.studio332.blastwords.util.Assets.java
com.studio332.blastwords.util.BlastWordsActions.java
com.studio332.blastwords.util.Overlay.java
com.studio332.blastwords.util.ParticleEffectActor.java
com.studio332.blastwords.util.SoundManager.java