Move asset loading to central Assets object. Add joystix font
@ -45,7 +45,7 @@ project(":desktop") {
|
||||
implementation project(":core")
|
||||
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
|
||||
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||
|
||||
api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +55,6 @@ project(":core") {
|
||||
|
||||
dependencies {
|
||||
api "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
|
||||
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
|
||||
}
|
||||
}
|
||||
|
BIN
core/assets/fonts/joystix.ttf
Normal file
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
BIN
core/assets/sprites/level.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 788 B |
Before Width: | Height: | Size: 895 B |
81
core/src/com/me/pacman/Assets.java
Normal file
@ -0,0 +1,81 @@
|
||||
package com.me.pacman;
|
||||
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
||||
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
|
||||
|
||||
public class Assets {
|
||||
|
||||
private AssetManager manager;
|
||||
|
||||
public TextureRegion[][] level;
|
||||
public TextureRegion[][] chase;
|
||||
public TextureRegion[][] death;
|
||||
public TextureRegion[][] ghosts;
|
||||
public TextureRegion[][] pacman;
|
||||
public TextureRegion[][] points;
|
||||
public TextureRegion[][] volume;
|
||||
|
||||
public Assets() {
|
||||
this.manager = new AssetManager();
|
||||
}
|
||||
|
||||
public void loadAssets() {
|
||||
manager.load("level_background.png", Texture.class);
|
||||
manager.load("logo.png", Texture.class);
|
||||
|
||||
|
||||
manager.load("sprites/level.png", Texture.class);
|
||||
manager.load("sprites/chase.png", Texture.class);
|
||||
manager.load("sprites/death.png", Texture.class);
|
||||
manager.load("sprites/ghosts.png", Texture.class);
|
||||
manager.load("sprites/pacman.png", Texture.class);
|
||||
manager.load("sprites/points.png", Texture.class);
|
||||
manager.load("sprites/volume.png", Texture.class);
|
||||
|
||||
// Yayyy! all of this to load a font
|
||||
FileHandleResolver resolver = new InternalFileHandleResolver();
|
||||
manager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
|
||||
manager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
|
||||
FreetypeFontLoader.FreeTypeFontLoaderParameter font = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
|
||||
font.fontFileName = "fonts/joystix.ttf";
|
||||
font.fontParameters.size = 10;
|
||||
font.fontParameters.mono = true;
|
||||
manager.load("fonts/joystix.ttf", BitmapFont.class, font);
|
||||
|
||||
// finish loading assets from disk
|
||||
manager.finishLoading();
|
||||
|
||||
// cache our texture regions
|
||||
level = TextureRegion.split(manager.get("sprites/level.png", Texture.class), 8, 8);
|
||||
chase = TextureRegion.split(manager.get("sprites/chase.png", Texture.class), 16, 16);
|
||||
death = TextureRegion.split(manager.get("sprites/death.png", Texture.class), 16, 16);
|
||||
ghosts = TextureRegion.split(manager.get("sprites/ghosts.png", Texture.class), 16, 16);
|
||||
pacman = TextureRegion.split(manager.get("sprites/pacman.png", Texture.class), 16, 16);
|
||||
points = TextureRegion.split(manager.get("sprites/points.png", Texture.class), 16, 16);
|
||||
volume = TextureRegion.split(manager.get("sprites/volume.png", Texture.class), 16, 16);
|
||||
}
|
||||
|
||||
public Texture getLevelBackground() {
|
||||
return manager.get("level_background.png", Texture.class);
|
||||
}
|
||||
|
||||
public Texture getLogo() {
|
||||
return manager.get("logo.png", Texture.class);
|
||||
}
|
||||
|
||||
public BitmapFont getFont() {
|
||||
return manager.get("fonts/joystix.ttf", BitmapFont.class);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
manager.dispose();
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,6 @@ package com.me.pacman;
|
||||
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
@ -19,7 +18,7 @@ public class PacDude extends Game {
|
||||
public static final int LEVEL_WIDTH = 224;
|
||||
public static final int LEVEL_HEIGHT = 288;
|
||||
|
||||
public AssetManager assets;
|
||||
public Assets assets;
|
||||
public SpriteBatch batch;
|
||||
public ShapeRenderer sr;
|
||||
|
||||
@ -32,7 +31,9 @@ public class PacDude extends Game {
|
||||
viewport = new FitViewport(LEVEL_WIDTH, LEVEL_HEIGHT, cam);
|
||||
viewport.apply(true);
|
||||
|
||||
assets = new AssetManager();
|
||||
assets = new Assets();
|
||||
assets.loadAssets();
|
||||
|
||||
batch = new SpriteBatch();
|
||||
sr = new ShapeRenderer();
|
||||
|
||||
|
@ -6,19 +6,26 @@ import com.me.pacman.PacDude;
|
||||
|
||||
public class Level {
|
||||
|
||||
private PacDude game;
|
||||
|
||||
private TextureRegion pellet;
|
||||
private TextureRegion powerPellet;
|
||||
|
||||
// Grid of components, [rows][columns]
|
||||
public LevelComponent[][] components;
|
||||
|
||||
public Level(String level) {
|
||||
|
||||
public Level(PacDude game, String level) {
|
||||
this.game = game;
|
||||
|
||||
pellet = game.assets.level[0][7];
|
||||
powerPellet = game.assets.level[0][6];
|
||||
|
||||
LevelLoader loader = new LevelLoader(level);
|
||||
components = loader.loadLevel();
|
||||
}
|
||||
|
||||
public void render(PacDude game, int offsetX, int offsetY) {
|
||||
Texture sprites = game.assets.get("sprites/sprites_1.png");
|
||||
TextureRegion powerPellet = new TextureRegion(sprites, 16, 16, 8, 8);
|
||||
TextureRegion pellet = new TextureRegion(sprites, 24, 16, 8, 8);
|
||||
|
||||
public void render(int offsetX, int offsetY) {
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
LevelComponent[] row = components[i];
|
||||
for (int j = 0; j < row.length; j++) {
|
||||
|
@ -1,6 +1,13 @@
|
||||
package com.me.pacman.state;
|
||||
|
||||
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
||||
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
|
||||
import com.me.pacman.PacDude;
|
||||
import com.me.pacman.level.Level;
|
||||
|
||||
@ -8,6 +15,7 @@ public class MenuState extends State {
|
||||
|
||||
private Texture levelBackground;
|
||||
private Texture logo;
|
||||
private BitmapFont font;
|
||||
|
||||
private Level level;
|
||||
|
||||
@ -17,22 +25,18 @@ public class MenuState extends State {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
game.assets.load("level.png", Texture.class);
|
||||
game.assets.load("logo.png", Texture.class);
|
||||
game.assets.load("sprites/sprites_1.png", Texture.class);
|
||||
game.assets.finishLoading();
|
||||
|
||||
levelBackground = game.assets.get("level.png", Texture.class);
|
||||
logo = game.assets.get("logo.png", Texture.class);
|
||||
levelBackground = game.assets.getLevelBackground();
|
||||
logo = game.assets.getLogo();
|
||||
logo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
||||
font = game.assets.getFont();
|
||||
|
||||
level = new Level("level");
|
||||
level = new Level(game,"level");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
game.batch.draw(levelBackground, 0, 16);
|
||||
level.render(game, 0, 16);
|
||||
level.render(0, 16);
|
||||
game.batch.draw(logo, 0, 124, 224, 120);
|
||||
}
|
||||
|
||||
|
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,6 @@
|
||||
#Tue Dec 24 14:05:31 GET 2019
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|