Android Open Source - Ready-Set-Rogue Tile 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 a va  2  s.  c  om
import com.badlogic.ashley.core.*;
import com.badlogic.ashley.utils.ImmutableArray;
import com.warsheep.scamp.components.ECSMapper;
import com.warsheep.scamp.components.TileComponent;
import com.warsheep.scamp.components.TransformComponent;

import java.util.ArrayList;

public class TileProcessor extends EntitySystem implements EntityListener, MovementProcessor.MovementListener {

    private ImmutableArray<Entity> tileEntities;
    private TransformComponent trans;
    private TileComponent tile;
    private static final int TILE_SIZE = 24;
    private final int MAP_WIDTH;
    private final int MAP_HEIGHT;
    private ArrayList<Entity>[][] map;

    public TileProcessor(int mapWidth, int mapHeight) {
        MAP_WIDTH = mapWidth;
        MAP_HEIGHT = mapHeight;
        map = new ArrayList[MAP_WIDTH][MAP_HEIGHT];
    }

    public ArrayList<Entity> queryByPosition(int x, int y) {
        return map[x][y];
    }

    @Override
    public void addedToEngine(Engine engine) {
        Family family = Family.all(TileComponent.class).get();
        engine.addEntityListener(family, this);

        tileEntities = engine.getEntitiesFor(Family.all(TileComponent.class).get());
    }

    @Override
    public void entityAdded(Entity entity) {
        trans = ECSMapper.transform.get(entity);
        tile = ECSMapper.tile.get(entity);

        trans.position.x = tile.x * TILE_SIZE;
        trans.position.y = tile.y * TILE_SIZE;
        trans.position.z = tile.z;

        if (map[tile.x][tile.y] == null) {
            map[tile.x][tile.y] = new ArrayList<>();
        }

        map[tile.x][tile.y].add(entity);
    }

    @Override
    public void entityRemoved(Entity entity) {
        tile = ECSMapper.tile.get(entity);
        map[tile.x][tile.y].remove(entity);
    }

    @Override
    public void tileMove(Entity entity, int oldX, int oldY) {
        tile = ECSMapper.tile.get(entity);
        if(tile != null) {
            this.map[oldX][oldY].remove(entity);
            this.map[tile.x][tile.y].add(entity);
        }
    }
}




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