Initial Commit

This commit is contained in:
2022-04-28 23:49:36 +02:00
commit 2fe4a6afaf
17 changed files with 822 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project.name = appName + "-core"
@@ -0,0 +1,70 @@
package uberelectron.gameSystems;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.tiled.TiledMapTileSet;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import java.util.HashMap;
/***
* Clase encargada de cargar las texturas y los assets y gestionarlos.
*/
public class TileSetManager
{
public TileSetManager()
{
tileSetsMap = new HashMap<>();
//testSet = new TiledMapTileSet();
}
public boolean loadTileSet(String path, String tileSetName,
//int numTilesX, int numTilesY,
int tileWidth, int tileHeight)
{
System.out.println("Cargando el tileSet de: " + path);
//Cargamos la textura indicada.
Texture txLoader = new Texture(Gdx.files.internal(path));
//Dividimos la textura en cada uno de sus tiles.
TextureRegion[][] splitedTiles = TextureRegion.split(txLoader, tileWidth, tileHeight);
TiledMapTileSet tileSet = new TiledMapTileSet();
//Añadimos al tileSet todas las tiles que hemos partido.
int idCounter = 0;
for(int y = 0; y < splitedTiles.length; y++)
{
for(int x = 0; x < splitedTiles[y].length; x++)
{
StaticTiledMapTile tile = new StaticTiledMapTile(splitedTiles[y][x]);
tileSet.putTile(idCounter, tile);
idCounter++;
}
}
System.out.println("Se han cargado " + idCounter + " tiles en " + tileSetName);
tileSetsMap.put(tileSetName, tileSet);
return true;
}
public TiledMapTileSet GetTileSet(String tileSetName)
{
TiledMapTileSet set = tileSetsMap.get(tileSetName);
if(set == null)
{
System.err.println("No se ha encontrado el tileSet: " + tileSetName);
}
return set;
}
//TiledMapTileSet testSet;
HashMap<String, TiledMapTileSet> tileSetsMap;
}
@@ -0,0 +1,113 @@
package uberelectron.testgame;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.maps.MapLayers;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TiledMapTileSet;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.utils.ScreenUtils;
public class TileMapTest implements Screen
{
final testGame game;
OrthographicCamera camera;
TiledMap map;
//TiledMapRenderer mapRenderer;
OrthogonalTiledMapRenderer mapRenderer;
TiledMapTileSet tileSet;
final int[][] oldMapData =
{
{16, 17, 18, 18, 18, 19, 20, 21, 22, 23, 2, 2, 2, 2, 2, 16},
{3 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 4},
{65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65}
};
final int[][] mapData =
{
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2},
};
public TileMapTest(final testGame game)
{
this.game = game;
this.map = new TiledMap();
tileSet = game.tileSetManager.GetTileSet("testTiles");
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
float unitScale = 4f;
mapRenderer = new OrthogonalTiledMapRenderer(map, unitScale);
MapLayers layers = map.getLayers();
TiledMapTileLayer bgLayer = new TiledMapTileLayer(16,3,8,8);
bgLayer.setName("bgLayer");
for(int y = 0; y < bgLayer.getHeight(); y++)
{
for(int x = 0; x < bgLayer.getWidth(); x++)
{
TiledMapTileLayer.Cell ce = new TiledMapTileLayer.Cell();
ce.setTile(tileSet.getTile(mapData[y][x]));
bgLayer.setCell(x, y, ce);
}
}
layers.add(bgLayer);
}
@Override
public void show() {}
@Override
public void render(float delta)
{
ScreenUtils.clear(0, 0, 0.2f, 1);
camera.update();
mapRenderer.setView(camera);
game.batch.setProjectionMatrix(camera.combined);
game.batch.begin();
game.font.draw(game.batch, "Texto de prueba", 100, 150);
game.font.draw(game.batch, "Y otro mas", 100, 100);
mapRenderer.render();
game.batch.end();
}
@Override
public void resize(int width, int height) {}
@Override
public void pause() {}
@Override
public void resume() {}
@Override
public void hide() {}
@Override
public void dispose()
{
//Dispose this class assets.
}
}
@@ -0,0 +1,57 @@
package uberelectron.testgame;
//import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import uberelectron.gameSystems.TileSetManager;
public class testGame extends Game
{
public SpriteBatch batch;
public BitmapFont font;
//Texture img;
public TileSetManager tileSetManager;
@Override
public void create()
{
batch = new SpriteBatch();
font = new BitmapFont();
tileSetManager = new TileSetManager();
LoadTileSets();
this.setScreen(new TileMapTest(this));
//img = new Texture("badlogic.jpg");
}
@Override
public void render()
{
/*ScreenUtils.clear(1, 0, 0, 1);
batch.begin();
batch.draw(img, 0, 0);
batch.end();*/
super.render();
}
@Override
public void dispose()
{
batch.dispose();
font.dispose();
//img.dispose();
}
void LoadTileSets()
{
tileSetManager.loadTileSet("testTiles.png",
"testTiles",
8, 8);
}
}