diff --git a/build.gradle b/build.gradle index 3cb16e6..e14d98a 100644 --- a/build.gradle +++ b/build.gradle @@ -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" } } diff --git a/core/assets/fonts/joystix.ttf b/core/assets/fonts/joystix.ttf new file mode 100644 index 0000000..a0b3405 Binary files /dev/null and b/core/assets/fonts/joystix.ttf differ diff --git a/core/assets/level.png b/core/assets/level_background.png similarity index 100% rename from core/assets/level.png rename to core/assets/level_background.png diff --git a/core/assets/sprites/level.png b/core/assets/sprites/level.png new file mode 100644 index 0000000..0cb7054 Binary files /dev/null and b/core/assets/sprites/level.png differ diff --git a/core/assets/sprites/sprites_2.png b/core/assets/sprites/points.png similarity index 100% rename from core/assets/sprites/sprites_2.png rename to core/assets/sprites/points.png diff --git a/core/assets/sprites/sprites_1.png b/core/assets/sprites/sprites_1.png deleted file mode 100644 index d5033fa..0000000 Binary files a/core/assets/sprites/sprites_1.png and /dev/null differ diff --git a/core/assets/sprites/text_1.png b/core/assets/sprites/text_1.png deleted file mode 100644 index 30dbba0..0000000 Binary files a/core/assets/sprites/text_1.png and /dev/null differ diff --git a/core/src/com/me/pacman/Assets.java b/core/src/com/me/pacman/Assets.java new file mode 100644 index 0000000..cd1dc4c --- /dev/null +++ b/core/src/com/me/pacman/Assets.java @@ -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(); + } + +} diff --git a/core/src/com/me/pacman/PacDude.java b/core/src/com/me/pacman/PacDude.java index 898986b..628cb6c 100644 --- a/core/src/com/me/pacman/PacDude.java +++ b/core/src/com/me/pacman/PacDude.java @@ -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(); diff --git a/core/src/com/me/pacman/level/Level.java b/core/src/com/me/pacman/level/Level.java index cead758..4b272c9 100644 --- a/core/src/com/me/pacman/level/Level.java +++ b/core/src/com/me/pacman/level/Level.java @@ -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++) { diff --git a/core/src/com/me/pacman/state/MenuState.java b/core/src/com/me/pacman/state/MenuState.java index 277723a..4b9c556 100644 --- a/core/src/com/me/pacman/state/MenuState.java +++ b/core/src/com/me/pacman/state/MenuState.java @@ -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); } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f4d7b2b..38f14c1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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