// Path: core/src/com/ychstudio/components/TextureComponent.java
// public class TextureComponent implements Component {
//     
//     public TextureRegion region;
// 
//     public TextureComponent(TextureRegion textureRegion) {
//         region = new TextureRegion(textureRegion);
//     }
// }
// 
// Path: core/src/com/ychstudio/components/TransformComponent.java
// public class TransformComponent implements Component {
//    
//     public Vector2 pos = new Vector2();
//     public Vector2 scale = new Vector2(1, 1);
//     
//     public int zIndex;
//     
//     public float rotation = 0;
//     
//     public TransformComponent(float x, float y) {
//         this(x, y, 0);
//     }
//     
//     public TransformComponent(float x, float y, int zIndex) {
//         this(x, y, zIndex, 1.0f, 1.0f, 0);
//     }
// 
//     public TransformComponent(float x, float y, int zIndex, float sclX, float sclY, float rotation) {
//         pos.set(x, y);
//         this.zIndex = zIndex;
//         scale.set(sclX, sclY);
//         this.rotation = rotation;
//     }
//     
//     public TransformComponent(Vector2 pos, Vector2 scl, float rotation) {
//         this.pos.set(pos);
//         this.scale.set(scl);
//         this.rotation = rotation;
//     }
// }
// 
// Path: core/src/com/ychstudio/gamesys/GameManager.java
// public class GameManager implements Disposable {
// 
//     public static final GameManager instance = new GameManager();
// 
//     public static final float PPM = 16f;
// 
//     public static final short NOTHING_BIT = 0;
//     public static final short WALL_BIT = 1;
//     public static final short PLAYER_BIT = 1 << 1;
//     public static final short PILL_BIT = 1 << 2;
//     public static final short GHOST_BIT = 1 << 3;
//     public static final short GATE_BIT = 1 << 4;
//     public static final short LIGHT_BIT = 1 << 5;
// 
//     public AssetManager assetManager;
// 
//     public Vector2 playerSpawnPos;
//     public Vector2 ghostSpawnPos;
// 
//     public int totalPills = 0;
// 
//     public int highScore = 0;
//     public int score = 0;
// 
//     public int displayScore = 0;
//     public int displayHighScore = 0;
// 
//     public int playerLives = 4;
//     public boolean playerIsInvincible = true;
// 
//     public boolean bigPillEaten = false;
//     public boolean playerIsAlive = true;
//     private boolean gameOver = false;
// 
//     public AStartPathFinding pathfinder;
// 
//     public Location<Vector2> playerLocation;
// 
//     private GameManager() {
//         assetManager = new AssetManager();
//         assetManager.load("images/actors.pack", TextureAtlas.class);
//         assetManager.load("sounds/pill.ogg", Sound.class);
//         assetManager.load("sounds/big_pill.ogg", Sound.class);
//         assetManager.load("sounds/ghost_die.ogg", Sound.class);
//         assetManager.load("sounds/pacman_die.ogg", Sound.class);
//         assetManager.load("sounds/clear.ogg", Sound.class);
// 
//         assetManager.finishLoading();
// 
//         playerSpawnPos = new Vector2();
//         ghostSpawnPos = new Vector2();
//     }
// 
//     public void decreasePlayerLives() {
//         playerLives--;
//     }
// 
//     public void resetPlayerLives() {
//         playerLives = 3;
//     }
// 
//     public void makeGameOver() {
//         gameOver = true;
//     }
// 
//     public boolean isGameOver() {
//         return gameOver;
//     }
// 
//     public void resetGame(boolean restart) {
//         if (restart) {
//             score = 0;
//             displayScore = 0;
//             resetPlayerLives();
//         }
//         totalPills = 0;
//         playerIsAlive = true;
//         bigPillEaten = false;
//         gameOver = false;
//     }
// 
//     public void addScore(int score) {
//         this.score += score;
//         if (this.score > highScore) {
//             highScore = this.score;
//         }
//     }
// 
//     @Override
//     public void dispose() {
//         assetManager.dispose();
//     }
// }


import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.ychstudio.components.TextureComponent;
import com.ychstudio.components.TransformComponent;
import com.ychstudio.gamesys.GameManager;
import java.util.Comparator;
package com.ychstudio.systems;


public class RenderSystem extends IteratingSystem {

    private final Array<Entity> renderArray;

    private final SpriteBatch batch;

    private final ComponentMapper<TransformComponent> transformM = ComponentMapper.getFor(TransformComponent.class);
    private final ComponentMapper<TextureComponent> rendererM = ComponentMapper.getFor(TextureComponent.class);

    public RenderSystem(SpriteBatch batch) {
        super(Family.all(TransformComponent.class, TextureComponent.class).get());

        this.batch = batch;

        renderArray = new Array<>();
    }

    @Override
    public void update(float deltaTime) {
        super.update(deltaTime);

        renderArray.sort(new Comparator<Entity>() {
            @Override
            public int compare(Entity o1, Entity o2) {
                TransformComponent transform1 = transformM.get(o1);
                TransformComponent transform2 = transformM.get(o2);
                return transform2.zIndex - transform1.zIndex;
            }

        });

        batch.begin();
        for (Entity entity : renderArray) {
            TransformComponent transform = transformM.get(entity);
            TextureComponent tex = rendererM.get(entity);
// Path: core/src/com/ychstudio/components/TextureComponent.java
// public class TextureComponent implements Component {
//     
//     public TextureRegion region;
// 
//     public TextureComponent(TextureRegion textureRegion) {
//         region = new TextureRegion(textureRegion);
//     }
// }
// 
// Path: core/src/com/ychstudio/components/TransformComponent.java
// public class TransformComponent implements Component {
//    
//     public Vector2 pos = new Vector2();
//     public Vector2 scale = new Vector2(1, 1);
//     
//     public int zIndex;
//     
//     public float rotation = 0;
//     
//     public TransformComponent(float x, float y) {
//         this(x, y, 0);
//     }
//     
//     public TransformComponent(float x, float y, int zIndex) {
//         this(x, y, zIndex, 1.0f, 1.0f, 0);
//     }
// 
//     public TransformComponent(float x, float y, int zIndex, float sclX, float sclY, float rotation) {
//         pos.set(x, y);
//         this.zIndex = zIndex;
//         scale.set(sclX, sclY);
//         this.rotation = rotation;
//     }
//     
//     public TransformComponent(Vector2 pos, Vector2 scl, float rotation) {
//         this.pos.set(pos);
//         this.scale.set(scl);
//         this.rotation = rotation;
//     }
// }
// 
// Path: core/src/com/ychstudio/gamesys/GameManager.java
// public class GameManager implements Disposable {
// 
//     public static final GameManager instance = new GameManager();
// 
//     public static final float PPM = 16f;
// 
//     public static final short NOTHING_BIT = 0;
//     public static final short WALL_BIT = 1;
//     public static final short PLAYER_BIT = 1 << 1;
//     public static final short PILL_BIT = 1 << 2;
//     public static final short GHOST_BIT = 1 << 3;
//     public static final short GATE_BIT = 1 << 4;
//     public static final short LIGHT_BIT = 1 << 5;
// 
//     public AssetManager assetManager;
// 
//     public Vector2 playerSpawnPos;
//     public Vector2 ghostSpawnPos;
// 
//     public int totalPills = 0;
// 
//     public int highScore = 0;
//     public int score = 0;
// 
//     public int displayScore = 0;
//     public int displayHighScore = 0;
// 
//     public int playerLives = 4;
//     public boolean playerIsInvincible = true;
// 
//     public boolean bigPillEaten = false;
//     public boolean playerIsAlive = true;
//     private boolean gameOver = false;
// 
//     public AStartPathFinding pathfinder;
// 
//     public Location<Vector2> playerLocation;
// 
//     private GameManager() {
//         assetManager = new AssetManager();
//         assetManager.load("images/actors.pack", TextureAtlas.class);
//         assetManager.load("sounds/pill.ogg", Sound.class);
//         assetManager.load("sounds/big_pill.ogg", Sound.class);
//         assetManager.load("sounds/ghost_die.ogg", Sound.class);
//         assetManager.load("sounds/pacman_die.ogg", Sound.class);
//         assetManager.load("sounds/clear.ogg", Sound.class);
// 
//         assetManager.finishLoading();
// 
//         playerSpawnPos = new Vector2();
//         ghostSpawnPos = new Vector2();
//     }
// 
//     public void decreasePlayerLives() {
//         playerLives--;
//     }
// 
//     public void resetPlayerLives() {
//         playerLives = 3;
//     }
// 
//     public void makeGameOver() {
//         gameOver = true;
//     }
// 
//     public boolean isGameOver() {
//         return gameOver;
//     }
// 
//     public void resetGame(boolean restart) {
//         if (restart) {
//             score = 0;
//             displayScore = 0;
//             resetPlayerLives();
//         }
//         totalPills = 0;
//         playerIsAlive = true;
//         bigPillEaten = false;
//         gameOver = false;
//     }
// 
//     public void addScore(int score) {
//         this.score += score;
//         if (this.score > highScore) {
//             highScore = this.score;
//         }
//     }
// 
//     @Override
//     public void dispose() {
//         assetManager.dispose();
//     }
// }


// Path: core/src/com/ychstudio/systems/RenderSystem.java
import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.ychstudio.components.TextureComponent;
import com.ychstudio.components.TransformComponent;
import com.ychstudio.gamesys.GameManager;
import java.util.Comparator;

package com.ychstudio.systems;


public class RenderSystem extends IteratingSystem {

    private final Array<Entity> renderArray;

    private final SpriteBatch batch;

    private final ComponentMapper<TransformComponent> transformM = ComponentMapper.getFor(TransformComponent.class);
    private final ComponentMapper<TextureComponent> rendererM = ComponentMapper.getFor(TextureComponent.class);

    public RenderSystem(SpriteBatch batch) {
        super(Family.all(TransformComponent.class, TextureComponent.class).get());

        this.batch = batch;

        renderArray = new Array<>();
    }

    @Override
    public void update(float deltaTime) {
        super.update(deltaTime);

        renderArray.sort(new Comparator<Entity>() {
            @Override
            public int compare(Entity o1, Entity o2) {
                TransformComponent transform1 = transformM.get(o1);
                TransformComponent transform2 = transformM.get(o2);
                return transform2.zIndex - transform1.zIndex;
            }

        });

        batch.begin();
        for (Entity entity : renderArray) {
            TransformComponent transform = transformM.get(entity);
            TextureComponent tex = rendererM.get(entity);
            float width = tex.region.getRegionWidth() / GameManager.PPM;