Move.java :  » Game » foogamelib » kku » cs » fgl » transition » Java Open Source

Java Open Source » Game » foogamelib 
foogamelib » kku » cs » fgl » transition » Move.java
package kku.cs.fgl.transition;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

public class Move extends TransitionBase {
  public static final int MOVE_IN = 0;
  public static final int MOVE_OUT = 1;
  protected float target_x,target_y; 
  protected float src_x,src_y; 
  protected int mode; 

  public Move() {
    
  }
  public Move(float tx,float ty,int mode) {
    this(1000,tx,ty,mode);
  }

  public Move(int duration,float tx,float ty,int mode) {
    super(duration);
    this.mode = mode;
    this.target_x=tx;
    this.target_y=ty;    
    this.src_x = target_x;
    this.src_y = target_y;
  }
  

  public void update(StateBasedGame game, GameContainer container, int delta) throws SlickException {
    super.update(game, container, delta);
    float t=(float)getTime()/getDuration();
    updateScene(t);
  }
  public void updateScene(float dtime){
    float tx=src_x+(target_x-src_x)*dtime;
    float ty=src_y+(target_y-src_y)*dtime;
    scene1.setCenter(tx,ty);    
  }
  void init(StateBasedGame game, GameContainer container) {
    if(mode==MOVE_IN){
      this.target_x = container.getWidth()/2;
      this.target_y = container.getHeight()/2;
    }else{
      this.src_x = container.getWidth()/2;
      this.src_y = container.getHeight()/2;      
    }
    time=0;
    updateScene(0);
    //System.out.println("move from "+src_x+","+src_y+" to "+target_x+","+target_y);
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.