Android Open Source - LucyTheMoocher Grid






From Project

Back to project page LucyTheMoocher.

License

The source code is released under:

MIT License

If you think the Android project LucyTheMoocher 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.lucythemoocher.graphics;
/*from  w w  w.  j  a  v  a 2  s . c  om*/
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;

public class Grid {
  private Image fullImage_;
  private Image grid_[];
  private int nbImg_;
  private float height_;
  private float width_;
  
  /**
   * Constructor<br/>
   * Create an array of images with one image<br/>
   * Warning, all the images in the full image must be
   * delimited by one pixel width of pink 0xFF00FF. Be sure that the 0xFF00FF
   * is only used for delimit the box.
   * @param imgId
   */
  public Grid(int imgId) {
    fullImage_ = new Image(imgId);
    
    //Search the first occurrence of pink
    for ( int i=1; i<fullImage_.getBitmap().getBitmap().getWidth(); i++ ) {
      if ( fullImage_.getBitmap().getBitmap().getPixel(i,1) == -65281 ) {
        width_ = i-1;
        break;
      }
    }
    for ( int j=1; j<fullImage_.getBitmap().getBitmap().getHeight(); j++ ) {
      if ( fullImage_.getBitmap().getBitmap().getPixel(1,j) == -65281 ) {
        height_ = j-1;
        break;
      }
    }
    int ver = (int) ((int)fullImage_.h()/(height_+2)) ;
    int hor = (int) ((int)fullImage_.w()/(width_+2));
    
    nbImg_ = ver*hor;
    grid_ = new Image[nbImg_];
    for (int i=0; i<ver; i++) {
      for (int j=0; j<hor; j++) {
        BitmapDrawable currBitmap = new BitmapDrawable(
            Bitmap.createBitmap(fullImage_.getBitmap().getBitmap(),
                (int)(1+j*(width_+2)), (int)(1+i*(height_+2)), (int)width_, (int)height_, null, true));
        grid_[i*hor+j] = new Image(currBitmap);
      }
    }
  }
  
  /**
   * Get the image at position id
   * @param id
   * @return image at id
   */
  public Image getImage(int id) {
    return grid_[id%nbImg_];
  }
  
  public float boxH() {
    return height_;
  }
  
  public float boxW() {
    return width_;
  }
  
  public Image getFullImage() {
    return fullImage_;
  }
  
  public int getSize() {
    return nbImg_;
  }
}




Java Source Code List

com.lucythemoocher.LucyTheMoocherActivity.java
com.lucythemoocher.FX.FXManager.java
com.lucythemoocher.FX.FX.java
com.lucythemoocher.Globals.Globals.java
com.lucythemoocher.actors.Actor.java
com.lucythemoocher.actors.ActorsManager.java
com.lucythemoocher.actors.Monster.java
com.lucythemoocher.actors.MonstersManager.java
com.lucythemoocher.actors.PlayerCharacter.java
com.lucythemoocher.actors.Projectile.java
com.lucythemoocher.actors.ProjectilesManager.java
com.lucythemoocher.actors.Tank.java
com.lucythemoocher.actors.TargetCharacter.java
com.lucythemoocher.actors.maincharacter.state.StateAttack.java
com.lucythemoocher.actors.maincharacter.state.StateFalling.java
com.lucythemoocher.actors.maincharacter.state.StateJumping.java
com.lucythemoocher.actors.maincharacter.state.StateNone.java
com.lucythemoocher.actors.maincharacter.state.StateRunning.java
com.lucythemoocher.actors.maincharacter.state.StateWallSliding.java
com.lucythemoocher.actors.maincharacter.state.StateWallWalking.java
com.lucythemoocher.actors.maincharacter.state.State.java
com.lucythemoocher.controls.AIController.java
com.lucythemoocher.controls.ActionController.java
com.lucythemoocher.controls.ButtonListener.java
com.lucythemoocher.controls.Controllable.java
com.lucythemoocher.controls.Controller.java
com.lucythemoocher.controls.GlobalController.java
com.lucythemoocher.controls.KeysListener.java
com.lucythemoocher.controls.TouchListener.java
com.lucythemoocher.events.EventNormal.java
com.lucythemoocher.events.EventSlow.java
com.lucythemoocher.events.Event.java
com.lucythemoocher.game.GameThread.java
com.lucythemoocher.game.Game.java
com.lucythemoocher.game.LevelLoader.java
com.lucythemoocher.graphics.ActorDrawer.java
com.lucythemoocher.graphics.Animation.java
com.lucythemoocher.graphics.Background.java
com.lucythemoocher.graphics.Camera.java
com.lucythemoocher.graphics.Drawable.java
com.lucythemoocher.graphics.Grid.java
com.lucythemoocher.graphics.HUD.java
com.lucythemoocher.graphics.Image.java
com.lucythemoocher.graphics.PersistentEffect.java
com.lucythemoocher.graphics.PersistentPic.java
com.lucythemoocher.graphics.PictureContainer.java
com.lucythemoocher.gui.MenuButtonListener.java
com.lucythemoocher.gui.MenuButtonTouchListener.java
com.lucythemoocher.gui.MenuButton.java
com.lucythemoocher.loops.CreditsLoop.java
com.lucythemoocher.loops.GameOverLoop.java
com.lucythemoocher.loops.InitMenuLoop.java
com.lucythemoocher.loops.LivesMenuLoop.java
com.lucythemoocher.loops.LoopGame.java
com.lucythemoocher.loops.LoopPause.java
com.lucythemoocher.loops.Loop.java
com.lucythemoocher.loops.MasterLoop.java
com.lucythemoocher.physics.Box.java
com.lucythemoocher.physics.Cinematic.java
com.lucythemoocher.physics.Map.java
com.lucythemoocher.sounds.SoundManager.java
com.lucythemoocher.sounds.SoundsState.java
com.lucythemoocher.sounds.StateLevel1.java
com.lucythemoocher.sounds.StateLevel2.java
com.lucythemoocher.sounds.StateLevel3.java
com.lucythemoocher.sounds.StateNormal.java
com.lucythemoocher.util.Direction.java
com.lucythemoocher.util.MathUtil.java
com.lucythemoocher.util.Resources.java
com.lucythemoocher.util.Timer.java