feat(scene): intro scene

It should work but that's all we have for now 💀
This commit is contained in:
2025-09-29 22:35:35 +07:00
parent 01ff15119c
commit b82e3db733
7 changed files with 120 additions and 9 deletions

View File

@ -0,0 +1,26 @@
package org.vibecoders.moongazer;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
public class Assets {
private static final AssetManager assetManager = new AssetManager();
public static <T> T getAsset(String fileName, Class<T> type) {
return assetManager.get(fileName, type);
}
public static void loadAll() {
// We load all assets here for simplicity :)
assetManager.load("icons/logo.png", Texture.class);
assetManager.finishLoading();
}
public static AssetManager getAssetManager() {
return assetManager;
}
public static void dispose() {
assetManager.dispose();
}
}

View File

@ -1,29 +1,54 @@
package org.vibecoders.moongazer;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.vibecoders.moongazer.Constants.*;
import org.vibecoders.moongazer.scene.*;
public class Game extends ApplicationAdapter {
private static final Logger log = LoggerFactory.getLogger(Game.class);
public static State state = State.INTRO;
SpriteBatch batch;
Texture logo;
Scene currentScene;
Scene introScene;
@Override
public void create() {
log.debug("create stub");
log.info("Loading assets...");
Assets.loadAll();
log.info("Assets loaded successfully.");
batch = new SpriteBatch();
currentScene = introScene = new Intro();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
switch (Game.state) {
case INTRO:
currentScene = introScene;
break;
case MAIN_MENU:
// Render main menu scene
break;
case IN_GAME:
// Render in-game scene
break;
default:
log.warn("Unknown state: {}", state);
}
batch.begin();
currentScene.render(batch);
batch.end();
}
@Override
public void dispose() {
log.debug("stub");
introScene.dispose();
Assets.dispose();
log.debug("Resources disposed");
}
}

View File

@ -17,7 +17,7 @@ public class Main {
cfg.useVsync(true);
cfg.setIdleFPS(10);
cfg.setWindowIcon("icons/logo.png");
log.info("Starting game client");
log.info("Starting game client...");
new Lwjgl3Application(new Game(), cfg);
}
}

View File

@ -0,0 +1,7 @@
package org.vibecoders.moongazer;
public enum State {
INTRO,
MAIN_MENU,
IN_GAME
}

View File

@ -0,0 +1,45 @@
package org.vibecoders.moongazer.scene;
import static org.vibecoders.moongazer.Constants.WINDOW_HEIGHT;
import static org.vibecoders.moongazer.Constants.WINDOW_WIDTH;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vibecoders.moongazer.Assets;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.ScreenUtils;
public class Intro extends Scene {
private Texture logo;
private long startTime;
private long endTime = 0;
private static final Logger log = LoggerFactory.getLogger(Intro.class);
public Intro() {
logo = Assets.getAsset("icons/logo.png", Texture.class);
startTime = System.currentTimeMillis() + 500;
}
public void render(SpriteBatch batch) {
ScreenUtils.clear(Color.BLACK);
log.debug("Rendering logo at position: ({}, {})", WINDOW_WIDTH / 2 - logo.getWidth() / 4,
WINDOW_HEIGHT / 2 - logo.getHeight() / 4);
var currentOpacity = (float) (System.currentTimeMillis() - startTime) / 1000;
if (currentOpacity > 1) {
if (endTime == 0) {
endTime = System.currentTimeMillis() + 3000;
}
currentOpacity = 1 - ((float) (System.currentTimeMillis() - endTime) / 1000);
}
batch.setColor(1, 1, 1, currentOpacity);
batch.draw(logo, WINDOW_WIDTH / 2 - logo.getWidth() / 4, WINDOW_HEIGHT / 2 - logo.getHeight() / 4,
logo.getWidth() / 2, logo.getHeight() / 2);
}
public void dispose() {
log.debug("sybau");
}
}

View File

@ -0,0 +1,8 @@
package org.vibecoders.moongazer.scene;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public abstract class Scene {
public abstract void render(SpriteBatch batch);
public abstract void dispose();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 112 KiB