Android Open Source - BlastWords Tile






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//from w  w  w .  j a v  a2  s. c  o m
 * Tile.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.delay;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.studio332.blastwords.model.LetterInfo;
import com.studio332.blastwords.model.LetterInfo.Type;
import com.studio332.blastwords.util.Assets;
import com.studio332.blastwords.util.SoundManager;


public class Tile extends Image {
   private final int id;
   private Image lockOverlay;
   private LetterInfo info;
   private boolean selected = false;
   private boolean hold = false;
   private float velocity = 0.0f;
   private static int instaceCounter = 0;

   public Tile(LetterInfo info) {
      super();

      this.id = Tile.instaceCounter++;
      this.info = info;
      
      String imgName = info.getCharacter().toString().toLowerCase()+"-off";
      if ( info.getType().equals(Type.WILD)) {
         imgName = "wild-off";
      } else if ( info.getType().equals(Type.BLOCKER)) {
         imgName = "blocker-off";
      }
      
      Image i = new Image(Assets.instance().getDrawable(imgName));
      setDrawable(i.getDrawable() );
      setWidth(i.getWidth());
      setHeight(i.getHeight());

      if (this.isLocked()) {
         this.lockOverlay = new Image( Assets.instance().getDrawable("locked"));
      }
   }
   
   public boolean canFall() {
      return (this.selected == false && this.hold == false);
   }
   
   public void fadeThenDrop() {
      getColor().a = 0.0f;
      this.hold = true;
      Action a = sequence( fadeIn(0.4f), delay(0.4f), new Action() {
         @Override
         public boolean act(float delta) {
            hold = false;
            return false;
         } 
      });
      addAction(a);
   }

   public float getVelocity() {
      return this.velocity;
   }

   
   public void setVelocity( float v) {
      this.velocity = v;
   }

   public void stop() {
      this.velocity = 0.0f;
   }

   public boolean isSelected() {
      return this.selected;
   }
   
   public Type getType() {
      return this.info.getType();
   }

   public void setSelected(boolean sel) {
      this.selected = sel;
      this.hold = false;

      String imgName = this.info.getCharacter().toString().toLowerCase();
      if ( info.getType().equals(Type.WILD)) {
         imgName = "wild";
      } else if ( info.getType().equals(Type.BLOCKER)) {
         imgName = "blocker";
      }
      
      if (this.selected == false) {
         setDrawable(Assets.instance().getDrawable(imgName+"-off"));
      } else {
         SoundManager.instance().playSound(SoundManager.SELECT_TILE);
         setDrawable(Assets.instance().getDrawable(imgName+"-on"));
      }
   }
   
   public void hide() {
      setDrawable(Assets.instance().getDrawable("blank-off"));
   }
   
   public void show() {      
      String imgName = this.info.getCharacter().toString().toLowerCase();
      if ( info.getType().equals(Type.WILD)) {
         imgName = "wild";
      } else if ( info.getType().equals(Type.BLOCKER)) {
         imgName = "blocker";
      }
      setDrawable(Assets.instance().getDrawable(imgName+"-off"));
   }
   
   @Override
   public void setPosition(float x, float y) {
      super.setPosition(x, y);
      if (this.lockOverlay != null) {
         this.lockOverlay.setPosition(x, y);
      }
   }

   public Character getCharacter() {
      return this.info.getCharacter();
   }
   
   public boolean isBlocker() {
      return this.info.getType().equals(Type.BLOCKER);
   }
   
   public boolean isWild() {
      return this.info.getType().equals(Type.WILD);
   }

   public boolean isLocked() {
      return (isBlocker() || this.info.getType().equals(Type.LOCKED));
   }

   @Override
   public void draw(SpriteBatch batch, float parentAlpha) {
      super.draw(batch, parentAlpha);
      if (isLocked()) {
         this.lockOverlay.draw(batch, parentAlpha);
      }
   }

   public int getId() {
      return this.id;
   }

   @Override
   public String toString() {
      return "Tile " + this.info.getCharacter()+" pos: "+getX()+","+getY();
   }

   public boolean collidesWith(Tile other) {
      Rectangle r = new Rectangle(getX(), getY(), getWidth(), getHeight());
      Rectangle r2 = new Rectangle(other.getX(), other.getY(), other.getWidth(), other.getHeight());
      return r.overlaps(r2);
   }
}




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