Android Open Source - X3n0break Powerup






From Project

Back to project page X3n0break.

License

The source code is released under:

GNU General Public License

If you think the Android project X3n0break 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 org.x3n0m0rph59.breakout;
/*  w  w  w.  jav a  2  s  .  co m*/
import java.util.EnumMap;
import java.util.Map;

import org.x3n0m0rph59.breakout.Effect.Type;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Powerup extends GameObject {
  /**
   * 
   */
  private static final long serialVersionUID = 7418474324088350613L;

  public enum State {FLOATING, STUCK_TO_GRAPPLING_HOOK}
  private State state = State.FLOATING;
  
  private Effect.Type type;
  
  private final Map<Effect.Type, SpriteObject> sprites = new EnumMap<Type, SpriteObject>(Effect.Type.class);
  
  private final ParticleSystem trail = new ParticleSystem(new SpriteTuple[]{
                     new SpriteTuple(ResourceMapper.getPath("star1.png", ResourceType.SPRITE), 255.0f, 255.0f, 255, 255), 
                     new SpriteTuple(ResourceMapper.getPath("star2.png", ResourceType.SPRITE), 345.0f, 342.0f, 345, 342), 
                     new SpriteTuple(ResourceMapper.getPath("star3.png", ResourceType.SPRITE), 270.0f, 261.0f, 270, 261), 
                     new SpriteTuple(ResourceMapper.getPath("star4.png", ResourceType.SPRITE), 264.0f, 285.0f, 264, 285)}, 
                     position, -1.0f, 1.75f, 0.0f, 360.0f, 10.0f,  95.0f, 150.0f, 3.5f);
  
  public Powerup(Point position, Effect.Type type) {
    super(null, position, Config.POWERUP_WIDTH, Config.POWERUP_HEIGHT, 0.0f, 0.0f, 0.0f, Config.POWERUP_SPEED);
    
    this.type = type;
    
    
    sprites.put(Effect.Type.BOTTOM_WALL, new SpriteObject(
        ResourceMapper.getPath("powerup_bottom_wall.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));
    
    sprites.put(Effect.Type.PADDLE_GUN, new SpriteObject(
        ResourceMapper.getPath("powerup_paddle_gun.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));

    sprites.put(Effect.Type.SHRINK_PADDLE, new SpriteObject(
        ResourceMapper.getPath("powerup_shrink.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));
    
    sprites.put(Effect.Type.EXPAND_PADDLE, new SpriteObject(
        ResourceMapper.getPath("powerup_expand.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));

    sprites.put(Effect.Type.FIREBALL, new SpriteObject(
        ResourceMapper.getPath("powerup_fireball.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));
    
    sprites.put(Effect.Type.MULTIBALL, new SpriteObject(
        ResourceMapper.getPath("powerup_multiball.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));

    sprites.put(Effect.Type.SLOW_DOWN, new SpriteObject(
        ResourceMapper.getPath("powerup_slow_down.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));
    
    sprites.put(Effect.Type.SPEED_UP, new SpriteObject(
        ResourceMapper.getPath("powerup_speed_up.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));

    sprites.put(Effect.Type.STICKY_BALL, new SpriteObject(
        ResourceMapper.getPath("powerup_sticky_ball.png", ResourceType.SPRITE), Config.POWERUP_WIDTH,
        Config.POWERUP_HEIGHT, 100, 100));
  }
  
  @Override
  public void render(SpriteBatch batch) {
    trail.render(batch);
    
    final SpriteObject sprite = sprites.get(type);
    if (sprite != null) {
      setSprite(sprite);      
    }
    
    super.render(batch);
  }

  @Override
  public void step(float delta) {    
    trail.setPositionAndAngle(new Point(getBoundingBox().getX(), getBoundingBox().getY()), 180.0f);
    trail.step(delta);
    
    for (final SpriteObject s : sprites.values())
      s.step(delta);
    
    if (state != State.STUCK_TO_GRAPPLING_HOOK)
      super.step(delta);    
    
    if (getY() >= Config.getInstance().getScreenHeight())
        setDestroyed(true);
  }
  
  public Effect.Type getType() {
    return type;
  }

  @Override
  public void setPosition(Point position) {
    super.setPosition(position);
    
    trail.setPositionAndAngle(new Point(getBoundingBox().getX(), 
                    getBoundingBox().getY()), 
                        (float) Math.toRadians(180.0f));
  }
  
  @Override
  public boolean isExcemptFromSpeedFactorChange() {
    return true;
  }

  public State getState() {
    return state;
  }

  public void setState(State state) {
    this.state = state;
  }
  
}




Java Source Code List

org.x3n0m0rph59.breakout.App.java
org.x3n0m0rph59.breakout.BackgroundFactory.java
org.x3n0m0rph59.breakout.Background.java
org.x3n0m0rph59.breakout.Ball.java
org.x3n0m0rph59.breakout.BottomWall.java
org.x3n0m0rph59.breakout.Brick.java
org.x3n0m0rph59.breakout.Config.java
org.x3n0m0rph59.breakout.Destroyable.java
org.x3n0m0rph59.breakout.EffectManager.java
org.x3n0m0rph59.breakout.Effect.java
org.x3n0m0rph59.breakout.FontLoader.java
org.x3n0m0rph59.breakout.FontTuple.java
org.x3n0m0rph59.breakout.ForceFeedback.java
org.x3n0m0rph59.breakout.GameInputProcessor.java
org.x3n0m0rph59.breakout.GameObject.java
org.x3n0m0rph59.breakout.GameScreen.java
org.x3n0m0rph59.breakout.GameState.java
org.x3n0m0rph59.breakout.GrapplingHookSegment.java
org.x3n0m0rph59.breakout.GrapplingHook.java
org.x3n0m0rph59.breakout.HelpInputProcessor.java
org.x3n0m0rph59.breakout.HelpScreen.java
org.x3n0m0rph59.breakout.HighScoreManager.java
org.x3n0m0rph59.breakout.HighScoreScreen.java
org.x3n0m0rph59.breakout.HighScore.java
org.x3n0m0rph59.breakout.HighscoreInputProcessor.java
org.x3n0m0rph59.breakout.IOSLauncher.java
org.x3n0m0rph59.breakout.LevelLoader.java
org.x3n0m0rph59.breakout.LevelSetSelectorInputProcessor.java
org.x3n0m0rph59.breakout.LevelSetSelectorScreen.java
org.x3n0m0rph59.breakout.Logger.java
org.x3n0m0rph59.breakout.MenuInputProcessor.java
org.x3n0m0rph59.breakout.MenuScreen.java
org.x3n0m0rph59.breakout.MusicLoader.java
org.x3n0m0rph59.breakout.MusicStream.java
org.x3n0m0rph59.breakout.ObjectPool.java
org.x3n0m0rph59.breakout.Paddle.java
org.x3n0m0rph59.breakout.ParticleSystem.java
org.x3n0m0rph59.breakout.Particle.java
org.x3n0m0rph59.breakout.Point.java
org.x3n0m0rph59.breakout.Poolable.java
org.x3n0m0rph59.breakout.Powerup.java
org.x3n0m0rph59.breakout.Projectile.java
org.x3n0m0rph59.breakout.Renderable.java
org.x3n0m0rph59.breakout.ResourceMapperDecisionCache.java
org.x3n0m0rph59.breakout.ResourceMapper.java
org.x3n0m0rph59.breakout.ScoreBoard.java
org.x3n0m0rph59.breakout.ScreenManager.java
org.x3n0m0rph59.breakout.ScreenType.java
org.x3n0m0rph59.breakout.SettingsInputProcessor.java
org.x3n0m0rph59.breakout.SettingsScreen.java
org.x3n0m0rph59.breakout.SoundLayer.java
org.x3n0m0rph59.breakout.SoundLoader.java
org.x3n0m0rph59.breakout.SoundSprite.java
org.x3n0m0rph59.breakout.SpaceBomb.java
org.x3n0m0rph59.breakout.SpriteLoader.java
org.x3n0m0rph59.breakout.SpriteObject.java
org.x3n0m0rph59.breakout.SpriteTuple.java
org.x3n0m0rph59.breakout.Star.java
org.x3n0m0rph59.breakout.Stepable.java
org.x3n0m0rph59.breakout.TextAnimationManager.java
org.x3n0m0rph59.breakout.TextAnimation.java
org.x3n0m0rph59.breakout.Util.java
org.x3n0m0rph59.breakout.Vector.java
org.x3n0m0rph59.breakout.android.AndroidLauncher.java
org.x3n0m0rph59.breakout.client.HtmlLauncher.java
org.x3n0m0rph59.breakout.desktop.DesktopLauncher.java