Android Open Source - Ready-Set-Rogue Movement Processor






From Project

Back to project page Ready-Set-Rogue.

License

The source code is released under:

GNU General Public License

If you think the Android project Ready-Set-Rogue 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.warsheep.scamp.processors;
// w  ww.  j  av  a2 s.  c  o  m
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.gdx.math.Vector3;
import com.warsheep.scamp.components.*;
import com.warsheep.scamp.processors.StateProcessor.StateListener;

import java.util.ArrayList;
import java.util.Queue;

public class MovementProcessor extends IteratingSystem implements StateListener {
    private boolean pause = false;
    private ArrayList<MovementListener> listeners;

    public static interface MovementListener {

        default public void tileMove(Entity mover, int oldX, int oldY) {
            // Do nothing
        }

        default public void transformMove(Entity mover) {
            // Do nothing
        }
    }

    public MovementProcessor(ArrayList<MovementListener> listeners) {
        super(Family.all(MovementComponent.class).get());
        this.listeners = listeners;
    }

    @Override
    public void processEntity(Entity entity, float deltaTime) {
        TransformComponent trans = ECSMapper.transform.get(entity);
        MovementComponent mov = ECSMapper.movement.get(entity);
        StateComponent state = ECSMapper.state.get(entity);
//        TilePositionComponent tilePos = ECSMapper.tilePosition.get(entity);

/*        // Don't do anything if we're already at our target
        System.out.println(trans.position.y - mov.target.y);
        if ((Math.abs(trans.position.x - mov.target.x) < 5 &&
                Math.abs(trans.position.y - mov.target.y) < 5)
                || (Math.abs(trans.position.x - mov.target.x) > 24 ||
                Math.abs(trans.position.y - mov.target.y) > 24 )) {
            System.out.println("time to stop");
            entity.remove(MovementComponent.class);
            state.inProgress = false;
            state.previousState = state.state;
            state.state = StateComponent.State.IDLE;
        } else {
            mov.timeSinceMove += deltaTime; // Update how long we've been moving ...
            mov.alpha += MOVE_SPEED / mov.timeSinceMove; // ... And how far we've come

            if (mov.alpha > .80) {
                //    mov.alpha = 1.0f;
            }
            trans.position.interpolate(mov.target, mov.alpha, mov.interpolation);

        }
        */
        for (Vector3 pos : mov.target) {
            trans.position.x = pos.x + trans.xOffset;
            trans.position.y = pos.y + trans.yOffset;
        }
        entity.remove(MovementComponent.class);
        state.state = StateComponent.State.IDLE;
        state.inProgress = false;
    }


    @Override
    public boolean checkProcessing() {
        return !pause;
    }

    public void pause(boolean pause) {
        this.pause = pause;
    }

    public void moving(Entity entity, Queue<StateComponent.Directionality> direction) {
        MovementComponent mov = new MovementComponent();
        if (ECSMapper.movement.get(entity) != null) {
            mov = ECSMapper.movement.get(entity);
        }

        for (StateComponent.Directionality dir : direction) {
            TileComponent tilePos = ECSMapper.tile.get(entity);
            System.out.print(dir);
            int oldX = tilePos.x;
            int oldY = tilePos.y;
            int x = tilePos.x;
            int y = tilePos.y;
            switch (dir) {
                case UP:
                    y++;
                    break;
                case DOWN:
                    y--;
                    break;
                case LEFT:
                    x--;
                    break;
                case RIGHT:
                    x++;
                    break;
                default:
                    break;
            }
            mov.target.add(new Vector3(x * 24.0f, y * 24.0f, 10.0f));
            ECSMapper.tile.get(entity).x = x;
            ECSMapper.tile.get(entity).y = y;

            for (MovementListener listener : listeners) {
                listener.tileMove(entity, oldX, oldY);
            }
        }
        entity.add(mov);
    }

    public void listen(MovementListener listener) {
        this.listeners.add(listener);
    }
}




Java Source Code List

com.warsheep.scamp.AssetDepot.java
com.warsheep.scamp.IOSLauncher.java
com.warsheep.scamp.MapImporter.java
com.warsheep.scamp.PrefabFactory.java
com.warsheep.scamp.Scamp.java
com.warsheep.scamp.adt.BSPRectangle.java
com.warsheep.scamp.adt.Container.java
com.warsheep.scamp.adt.Pair.java
com.warsheep.scamp.adt.Room.java
com.warsheep.scamp.algorithms.BSPMapGenerator.java
com.warsheep.scamp.algorithms.Compositor.java
com.warsheep.scamp.android.AndroidLauncher.java
com.warsheep.scamp.client.HtmlLauncher.java
com.warsheep.scamp.components.AIControllableComponent.java
com.warsheep.scamp.components.AttackerComponent.java
com.warsheep.scamp.components.CameraComponent.java
com.warsheep.scamp.components.CollidableComponent.java
com.warsheep.scamp.components.ControllableComponent.java
com.warsheep.scamp.components.DamageableComponent.java
com.warsheep.scamp.components.DropComponent.java
com.warsheep.scamp.components.ECSMapper.java
com.warsheep.scamp.components.FactionComponent.java
com.warsheep.scamp.components.InventoryComponent.java
com.warsheep.scamp.components.LevelComponent.java
com.warsheep.scamp.components.MovementComponent.java
com.warsheep.scamp.components.StateComponent.java
com.warsheep.scamp.components.TileComponent.java
com.warsheep.scamp.components.TransformComponent.java
com.warsheep.scamp.components.VisibleComponent.java
com.warsheep.scamp.desktop.AssetPacker.java
com.warsheep.scamp.desktop.DesktopLauncher.java
com.warsheep.scamp.processors.AIProcessor.java
com.warsheep.scamp.processors.CameraProcessor.java
com.warsheep.scamp.processors.CollisionProcessor.java
com.warsheep.scamp.processors.CombatProcessor.java
com.warsheep.scamp.processors.ControlProcessor.java
com.warsheep.scamp.processors.DeathProcessor.java
com.warsheep.scamp.processors.LevelingProcessor.java
com.warsheep.scamp.processors.MovementProcessor.java
com.warsheep.scamp.processors.StateProcessor.java
com.warsheep.scamp.processors.TileProcessor.java
com.warsheep.scamp.processors.VisibilityProcessor.java
com.warsheep.scamp.screens.MainGameScreen.java
com.warsheep.scamp.screens.MainMenuScreen.java