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.actors.maincharacter.state;
/*www.java2s.com*/import com.lucythemoocher.Globals.Globals;
import com.lucythemoocher.actors.PlayerCharacter;
import com.lucythemoocher.graphics.Animation;
import com.lucythemoocher.physics.Cinematic;
import com.lucythemoocher.util.Direction;
publicclass StateWallWalking extends State {
privatefloat begin_;
public StateWallWalking(PlayerCharacter pc, Cinematic pos, Animation anim, int dir) {
super(pc, pos, anim, dir);
if ( dir_ == Direction.LEFT ) {
int tab[] = {16,17,18,19};
anim_.setAnimation(tab, ANIMATION_SPEED);
} else {
int tab[] = {12,13,14,15};
anim_.setAnimation(tab, ANIMATION_SPEED);
}
begin_ = Globals.getInstance().getGame().getTime();
}
@Override
publicvoid update() {
super.update();
if ( Globals.getInstance().getGame().getTime()-begin_ < WALL_WALKING_TIME ) {
pos_.moveUp();
} else { // If the wall walk is over
pc_.changeState(new StateWallSliding(pc_, pos_, anim_, dir_));
}
// If there is no more collisions
if ( dir_ == Direction.LEFT ) {
if ( !pos_.hasLeftCollision() ) {
pc_.changeState(new StateFalling(pc_, pos_, anim_, dir_));
}
} else {
if ( !pos_.hasRightCollision() ) {
pc_.changeState(new StateFalling(pc_, pos_, anim_, dir_));
}
}
}
@Override
publicvoid moveUp() {
if ( dir_ == Direction.LEFT ) {
if ( pos_.hasLeftCollision() ) {
pc_.changeState(new StateJumping(pc_, pos_, anim_, Direction.RIGHT));
}
} else {
if ( pos_.hasRightCollision() ) {
pc_.changeState(new StateJumping(pc_, pos_, anim_, Direction.LEFT));
}
}
}
@Override
publicvoid moveLeft() {
if ( dir_ == Direction.RIGHT ) {
if ( pos_.hasRightCollision() ) {
pc_.changeState(new StateJumping(pc_, pos_, anim_, Direction.LEFT));
}
}
}
@Override
publicvoid moveRight() {
if ( dir_ == Direction.LEFT ) {
if ( pos_.hasLeftCollision() ) {
pc_.changeState(new StateJumping(pc_, pos_, anim_, Direction.RIGHT));
}
}
}
}