diff options
Diffstat (limited to 'core')
9 files changed, 645 insertions, 0 deletions
diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 0000000..468d26e --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,9 @@ +sourceCompatibility = 1.7 +dependencies { + implementation 'org.jetbrains:annotations-java5:20.1.0' +} +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' + +sourceSets.main.java.srcDirs = [ "src/" ] + +eclipse.project.name = appName + "-core" diff --git a/core/src/com/ilotterytea/maxoning/MaxonConstants.java b/core/src/com/ilotterytea/maxoning/MaxonConstants.java new file mode 100644 index 0000000..ad771e4 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/MaxonConstants.java @@ -0,0 +1,7 @@ +package com.ilotterytea.maxoning; + +public class MaxonConstants { + public static final String GAME_NAME = "Maxon Petting Simulator"; + public static final String GAME_VERSION = "Alpha 1.0.0"; + public static final String GAME_PUBLISHER = "iLotterytea"; +} diff --git a/core/src/com/ilotterytea/maxoning/MaxonGame.java b/core/src/com/ilotterytea/maxoning/MaxonGame.java new file mode 100644 index 0000000..9a24256 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/MaxonGame.java @@ -0,0 +1,45 @@ +package com.ilotterytea.maxoning; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.ilotterytea.maxoning.screen.AssetLoadingScreen; +import com.ilotterytea.maxoning.screen.SplashScreen; + +public class MaxonGame extends Game { + public SpriteBatch batch; + public AssetManager assetManager; + + private static MaxonGame instance; + + public static MaxonGame getInstance() { + if (instance == null) { + instance = new MaxonGame(); + } + return instance; + } + + @Override + public void create () { + batch = new SpriteBatch(); + + assetManager = new AssetManager(); + this.setScreen(new AssetLoadingScreen(this)); + } + + @Override + public void render () { + super.render(); + } + + @Override + public void dispose () { + batch.dispose(); + for (String name : assetManager.getAssetNames()) { + assetManager.unload(name); + } + assetManager.dispose(); + instance.dispose(); + } +} diff --git a/core/src/com/ilotterytea/maxoning/anim/AnimatedImage.java b/core/src/com/ilotterytea/maxoning/anim/AnimatedImage.java new file mode 100644 index 0000000..8da1c19 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/anim/AnimatedImage.java @@ -0,0 +1,38 @@ +package com.ilotterytea.maxoning.anim; + +import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; + +public class AnimatedImage extends Image { + private float stateTime = 0; + private final TextureRegion[] regions; + private int index = 0; + + public AnimatedImage(TextureRegion[] regions) { + super(regions[0]); + this.regions = regions; + } + + @Override public void act(float delta) { + if (index > regions.length - 1) { + index = 0; + } + if (regions[index + 1] == null) { + index = 0; + } + super.setDrawable(new TextureRegionDrawable(regions[index])); + index++; + super.act(delta); + + } + + public void dispose() { + for (TextureRegion reg : regions) { + if (reg != null) { + reg.getTexture().dispose(); + } + } + } +} diff --git a/core/src/com/ilotterytea/maxoning/anim/SpriteUtils.java b/core/src/com/ilotterytea/maxoning/anim/SpriteUtils.java new file mode 100644 index 0000000..63c4f0b --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/anim/SpriteUtils.java @@ -0,0 +1,34 @@ +package com.ilotterytea.maxoning.anim; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; + +import java.util.Arrays; + +public class SpriteUtils { + public static TextureRegion[] splitToTextureRegions( + Texture texture, + int tileWidth, + int tileHeight, + int columns, + int rows + ) { + TextureRegion[][] tmp = TextureRegion.split(texture, tileWidth, tileHeight); + TextureRegion[] frames = new TextureRegion[(texture.getWidth() / columns) + (texture.getHeight() / rows)]; + + int index = 0; + + for (TextureRegion[] regArray : tmp) { + for (TextureRegion reg : regArray) { + if (reg != null) { + frames[index++] = reg; + } + } + } + + System.out.println(Arrays.deepToString(tmp)); + System.out.println(frames.length); + + return frames; + } +} diff --git a/core/src/com/ilotterytea/maxoning/screen/AssetLoadingScreen.java b/core/src/com/ilotterytea/maxoning/screen/AssetLoadingScreen.java new file mode 100644 index 0000000..0db18e6 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/screen/AssetLoadingScreen.java @@ -0,0 +1,107 @@ +package com.ilotterytea.maxoning.screen; + +import com.badlogic.gdx.*; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.utils.Timer; +import com.badlogic.gdx.utils.viewport.FillViewport; +import com.ilotterytea.maxoning.MaxonGame; +import com.ilotterytea.maxoning.anim.AnimatedImage; +import com.ilotterytea.maxoning.anim.SpriteUtils; + +import java.util.Arrays; + +public class AssetLoadingScreen implements Screen { + final MaxonGame game; + + final Stage stage; + final Skin skin; + final AnimatedImage animatedMaxon; + final Label loadingLabel; + + final Texture M4x0nnes; + + public AssetLoadingScreen(MaxonGame game) { + this.game = game; + + this.M4x0nnes = new Texture("sprites/sheet/loadingCircle.png"); + + this.skin = new Skin(Gdx.files.internal("main.skin")); + this.stage = new Stage(new FillViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); + + this.loadingLabel = new Label("Loading...", skin); + + TextureRegion[] txrr = SpriteUtils.splitToTextureRegions(M4x0nnes, 112, 112, 10, 5); + this.animatedMaxon = new AnimatedImage(txrr); + + animatedMaxon.setPosition(8, 8); + animatedMaxon.setScale(0.25f); + + loadingLabel.setPosition(animatedMaxon.getWidth() * 0.25f + loadingLabel.getX() + 16, 8); + + stage.addActor(animatedMaxon); + stage.addActor(loadingLabel); + + queueAssets(); + } + + @Override public void show() { render(Gdx.graphics.getDeltaTime()); } + + private void update(float delta) { + if (game.assetManager.update()) { + Timer.schedule(new Timer.Task() { + @Override + public void run() { + game.setScreen(new SplashScreen(game)); + dispose(); + } + }, 1f); + } + } + + @Override + public void render(float delta) { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + loadingLabel.setText(String.format("%s%% (Loaded %s assets)", MathUtils.floor(game.assetManager.getProgress() * 100), game.assetManager.getLoadedAssets())); + + stage.draw(); + stage.act(delta); + + update(delta); + } + + @Override + public void resize(int width, int height) { + stage.getViewport().update(width, height, true); + } + @Override public void pause() {} + @Override public void resume() {} + @Override public void hide() { dispose(); } + @Override public void dispose() {} + private void queueAssets() { + // Textures: + game.assetManager.load("icon.png", Texture.class); + game.assetManager.load("dev.png", Texture.class); + game.assetManager.load("sprites/sheet/loadingCircle.png", Texture.class); + game.assetManager.load("sprites/black.png", Texture.class); + game.assetManager.load("sprites/white.png", Texture.class); + game.assetManager.load("sprites/brand.png", Texture.class); + game.assetManager.load("sprites/ilotterytea.png", Texture.class); + game.assetManager.load("sprites/SplashWall.png", Texture.class); + + // Music: + game.assetManager.load("mus/menu/mus_menu_intro.ogg", Music.class); + game.assetManager.load("mus/menu/mus_menu_loop.ogg", Music.class); + // Sounds: + } +} diff --git a/core/src/com/ilotterytea/maxoning/screen/MenuScreen.java b/core/src/com/ilotterytea/maxoning/screen/MenuScreen.java new file mode 100644 index 0000000..b07f3c1 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/screen/MenuScreen.java @@ -0,0 +1,233 @@ +package com.ilotterytea.maxoning.screen; + +import com.badlogic.gdx.*; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.actions.Actions; +import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction; +import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.utils.viewport.FillViewport; +import com.ilotterytea.maxoning.MaxonConstants; +import com.ilotterytea.maxoning.MaxonGame; + +import java.util.ArrayList; + +public class MenuScreen implements Screen, InputProcessor { + + final MaxonGame game; + + final Stage stage; + final Skin skin; + + final Image brandLogo, maxonLogo; + final Label startLabel, infoLabel; + + final Texture wall, brandTxr, maxonTxr; + + final Music menuMusic; + + private ArrayList<ArrayList<Sprite>> wallTiles = new ArrayList<>(); + + private boolean anyKeyPressed = false; + + public MenuScreen(MaxonGame game) { + this.game = game; + + this.stage = new Stage(new FillViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); + this.skin = new Skin(Gdx.files.internal("main.skin")); + + this.brandTxr = new Texture(Gdx.files.internal("sprites/brand.png")); + this.maxonTxr = new Texture(Gdx.files.internal("icon.png")); + this.wall = new Texture(Gdx.files.internal("sprites/SplashWall.png")); + + this.menuMusic = game.assetManager.get("mus/menu/mus_menu_loop.ogg", Music.class); + + for (int i = 0; i < (Gdx.graphics.getHeight() / wall.getHeight()) + 1; i++) { + wallTiles.add(new ArrayList<Sprite>()); + for (int j = 0; j < (Gdx.graphics.getWidth() / wall.getWidth()); j++) { + Sprite spr = new Sprite(wall); + spr.setPosition(wall.getWidth() * j, wall.getHeight() * i); + + wallTiles.get(i).add(spr); + } + } + + this.maxonLogo = new Image(maxonTxr); + this.brandLogo = new Image(brandTxr); + + this.startLabel = new Label("PRESS ANY KEY TO START", skin, "press"); + this.infoLabel = new Label(String.format("%s %s", MaxonConstants.GAME_NAME, MaxonConstants.GAME_VERSION), skin, "credits"); + + brandLogo.setScale(0f); + + brandLogo.setPosition( + (Gdx.graphics.getWidth() / 2.0f) - (brandLogo.getWidth() / 2.0f), + (Gdx.graphics.getHeight() / 2.0f) - (brandLogo.getHeight() / 2.0f) + ); + + brandLogo.setOrigin( + brandLogo.getWidth() / 2.0f, + brandLogo.getHeight() / 2.0f + ); + + brandLogo.addAction( + Actions.sequence( + Actions.scaleTo(50f, 50f, 0f), + Actions.scaleTo(1f, 1f, 5f, Interpolation.circleIn), + Actions.repeat( + RepeatAction.FOREVER, + Actions.sequence( + Actions.parallel( + Actions.rotateTo(-10, 10f, Interpolation.sine), + Actions.scaleTo(0.85f, 0.85f, 10f, Interpolation.sine) + ), + Actions.parallel( + Actions.rotateTo(10, 10f, Interpolation.sine), + Actions.scaleTo(1.25f, 1.25f, 10f, Interpolation.sine) + ) + ) + )) + ); + + startLabel.setPosition( + (Gdx.graphics.getWidth() / 2.0f) - (startLabel.getWidth() / 2.0f), + 32 + ); + + startLabel.addAction( + Actions.repeat( + RepeatAction.FOREVER, + Actions.sequence( + Actions.alpha(0f), + Actions.fadeIn(1f), + Actions.delay(5f), + Actions.fadeOut(1f) + ) + ) + ); + + stage.addActor(infoLabel); + stage.addActor(brandLogo); + stage.addActor(startLabel); + + Gdx.input.setInputProcessor(new InputMultiplexer(this, stage)); + } + + @Override public void show() { + render(Gdx.graphics.getDeltaTime()); + menuMusic.setLooping(true); + menuMusic.play(); + } + + private final float wallVelocity = 1f; + + @Override + public void render(float delta) { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + // Draw the sprites: + /*for (ArrayList<Sprite> sprArray : wallTiles) { + for (Sprite tile : sprArray) { + tile.setPosition(tile.getX() + wallVelocity, tile.getY()); + tile.draw(game.batch); + } + }*/ + + /* + for (ArrayList<Sprite> sprArray : wallTiles) { + for (int i = 0; i < sprArray.size(); i++) { + Sprite spr = sprArray.get(i); + + if (spr.getX() + spr.getWidth() > Gdx.graphics.getWidth()) { + spr.setPosition(sprArray.get(0).getX() - spr.getWidth(), spr.getY()); + sprArray.remove(i); + sprArray.add(0, spr); + } + } + }*/ + + if (anyKeyPressed) { + startLabel.clearActions(); + startLabel.addAction( + Actions.sequence( + Actions.moveTo(startLabel.getX(), -192, 1f, Interpolation.smoother) + ) + ); + } + + stage.draw(); + stage.act(delta); + } + + @Override + public void resize(int width, int height) { + stage.getViewport().update(width, height, true); + } + + @Override public void pause() {} + @Override public void resume() {} + @Override public void hide() { dispose(); } + @Override + public void dispose() { + stage.dispose(); + skin.dispose(); + } + + @Override + public boolean keyDown(int keycode) { + if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { + Gdx.app.exit(); + } + + if (Gdx.input.isKeyPressed(Input.Keys.ANY_KEY)) { + anyKeyPressed = true; + } + + return false; + } + + @Override + public boolean keyUp(int keycode) { + return false; + } + + @Override + public boolean keyTyped(char character) { + return false; + } + + @Override + public boolean touchDown(int screenX, int screenY, int pointer, int button) { + if (Gdx.input.isTouched()) { + anyKeyPressed = true; + } + return false; + } + + @Override + public boolean touchUp(int screenX, int screenY, int pointer, int button) { + return false; + } + + @Override + public boolean touchDragged(int screenX, int screenY, int pointer) { + return false; + } + + @Override + public boolean mouseMoved(int screenX, int screenY) { + return false; + } + + @Override + public boolean scrolled(float amountX, float amountY) { + return false; + } +} diff --git a/core/src/com/ilotterytea/maxoning/screen/SplashScreen.java b/core/src/com/ilotterytea/maxoning/screen/SplashScreen.java new file mode 100644 index 0000000..82dc76a --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/screen/SplashScreen.java @@ -0,0 +1,158 @@ +package com.ilotterytea.maxoning.screen; + +import com.badlogic.gdx.*; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.actions.Actions; +import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.utils.Timer; +import com.badlogic.gdx.utils.viewport.FillViewport; +import com.ilotterytea.maxoning.MaxonConstants; +import com.ilotterytea.maxoning.MaxonGame; + +public class SplashScreen implements InputProcessor, Screen { + + final MaxonGame game; + + final Stage stage; + final Skin skin; + + final Image whiteSquare, dev; + final Label infoLabel; + + final Music introMusic; + + public SplashScreen(MaxonGame game) { + this.game = game; + + this.introMusic = game.assetManager.get("mus/menu/mus_menu_intro.ogg", Music.class); + + + this.stage = new Stage(new FillViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); + this.skin = game.assetManager.get("main.skin", Skin.class); + + this.infoLabel = new Label( + String.format("%s %s", MaxonConstants.GAME_NAME, MaxonConstants.GAME_VERSION), + skin, "credits" + ); + + this.dev = new Image(game.assetManager.get("dev.png", Texture.class)); + this.whiteSquare = new Image(game.assetManager.get("sprites/white.png", Texture.class)); + + infoLabel.setPosition( + 8, + (Gdx.graphics.getHeight() - infoLabel.getHeight()) - 8 + ); + + dev.setScale(5f); + + dev.setPosition( + (Gdx.graphics.getWidth() / 2.0f) - (dev.getWidth() * 5f / 2.0f), + (Gdx.graphics.getHeight() / 2.0f) - (dev.getHeight() * 5f / 2.0f) + ); + + whiteSquare.setPosition(0, 0); + whiteSquare.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + + dev.addAction(Actions.sequence( + Actions.alpha(0), + Actions.fadeIn(1f), + Actions.delay(5f), + Actions.fadeOut(0.25f) + )); + + whiteSquare.addAction(Actions.sequence( + Actions.alpha(0), + Actions.fadeIn(0.5f), + Actions.delay(25f), + Actions.fadeOut(0.5f) + )); + + stage.addActor(whiteSquare); + stage.addActor(infoLabel); + stage.addActor(dev); + + Gdx.input.setInputProcessor(new InputMultiplexer(this, stage)); + } + + @Override public void show() { + introMusic.play(); + render(Gdx.graphics.getDeltaTime()); + } + + private final float wallVelocity = 1f; + + @Override + public void render(float delta) { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + stage.draw(); + stage.act(delta); + + if (!introMusic.isPlaying()) { + game.setScreen(new MenuScreen(game)); + } + } + + @Override + public void resize(int width, int height) { + stage.getViewport().update(width, height, true); + } + + @Override public void pause() {} + @Override public void resume() {} + @Override public void hide() { dispose(); } + @Override public void dispose() {} + + @Override + public boolean keyDown(int keycode) { + if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { + Gdx.app.exit(); + } + if (Gdx.input.isKeyPressed(Input.Keys.ANY_KEY)) { + game.setScreen(new MenuScreen(game)); + dispose(); + } + return false; + } + + @Override + public boolean keyUp(int keycode) { + return false; + } + + @Override + public boolean keyTyped(char character) { + return false; + } + + @Override + public boolean touchDown(int screenX, int screenY, int pointer, int button) { + return false; + } + + @Override + public boolean touchUp(int screenX, int screenY, int pointer, int button) { + return false; + } + + @Override + public boolean touchDragged(int screenX, int screenY, int pointer) { + return false; + } + + @Override + public boolean mouseMoved(int screenX, int screenY) { + return false; + } + + @Override + public boolean scrolled(float amountX, float amountY) { + return false; + } +} diff --git a/core/src/com/ilotterytea/maxoning/utils/colors/HexToARGB.java b/core/src/com/ilotterytea/maxoning/utils/colors/HexToARGB.java new file mode 100644 index 0000000..5db8f1d --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/utils/colors/HexToARGB.java @@ -0,0 +1,14 @@ +package com.ilotterytea.maxoning.utils.colors; + +import com.badlogic.gdx.graphics.Color; + +public final class HexToARGB { + public static Color convert(String hex) { + hex = hex.charAt(0) == '#' ? hex.substring(1) : hex; + int r = Integer.valueOf(hex.substring(0, 2), 16); + int g = Integer.valueOf(hex.substring(2, 4), 16); + int b = Integer.valueOf(hex.substring(4, 6), 16); + int a = hex.length() != 8 ? 255 : Integer.valueOf(hex.substring(6, 8), 16); + return new Color(r / 255f, g / 255f, b / 255f, a / 255f); + } +} |
