Merge branch 'main' into gdx-video-background

This commit is contained in:
Nguyễn Thế Hưng
2025-10-01 02:18:55 +07:00
committed by GitHub
11 changed files with 98 additions and 6 deletions

View File

@ -26,6 +26,7 @@ public class Game extends ApplicationAdapter {
Scene currentScene;
Scene introScene;
public Scene mainMenuScene;
public Scene settingsScene;
public ArrayList<Scene> gameScenes;
@Override
@ -44,7 +45,7 @@ public class Game extends ApplicationAdapter {
gameScenes = new ArrayList<>();
currentScene = introScene = new Intro(this);
gameScenes.add(introScene);
// By the end of the intro, the main menu scene will be created and assigned to Game.mainMenuScene
// By the end of the intro, other secenes will be created and assigned to Game.mainMenuScene
}
@Override
@ -65,6 +66,9 @@ public class Game extends ApplicationAdapter {
case MAIN_MENU:
currentScene = mainMenuScene;
break;
case SETTINGS:
currentScene = settingsScene;
break;
case IN_GAME:
// Render in-game scene
break;

View File

@ -3,5 +3,6 @@ package org.vibecoders.moongazer;
public enum State {
INTRO,
MAIN_MENU,
SETTINGS,
IN_GAME
}

View File

@ -89,6 +89,10 @@ public class Assets {
assetManager.load("textures/main_menu/background.png", Texture.class);
assetManager.load("textures/main_menu/title.png", Texture.class);
assetManager.load("textures/ui/text_button.png", Texture.class);
assetManager.load("textures/ui/IconExitGame.png", Texture.class);
assetManager.load("textures/ui/UI_Icon_Setting.png", Texture.class);
assetManager.load("textures/ui/ImgReShaSoundOn.png", Texture.class);
assetManager.load("textures/ui/UI_Gcg_Icon_Close.png", Texture.class);
}
public static boolean isLoadedAll() {

View File

@ -29,8 +29,11 @@ public class Intro extends Scene {
startTime = System.currentTimeMillis() + 500;
log.info("Starting to load all remaining assets...");
Assets.loadAll();
// Create scenes
game.mainMenuScene = new MainMenu(game);
game.settingsScene = new Settings(game);
game.gameScenes.add(game.mainMenuScene);
game.gameScenes.add(game.settingsScene);
}
/**

View File

@ -5,6 +5,7 @@ import static org.vibecoders.moongazer.Constants.*;
import org.vibecoders.moongazer.Game;
import org.vibecoders.moongazer.State;
import org.vibecoders.moongazer.managers.Assets;
import org.vibecoders.moongazer.ui.UIImageButton;
import org.vibecoders.moongazer.ui.UITextButton;
import com.badlogic.gdx.Gdx;
@ -68,8 +69,15 @@ public class MainMenu extends Scene {
UITextButton loadButton = new UITextButton("Load", font);
UITextButton settingsButton = new UITextButton("Settings", font);
UITextButton exitButton = new UITextButton("Exit", font);
int buttonWidth = 300;
int buttonHeight = 80;
int buttonWidth = 300, buttonHeight = 80;
playButton.setSize(buttonWidth, buttonHeight);
loadButton.setSize(buttonWidth, buttonHeight);
settingsButton.setSize(buttonWidth, buttonHeight);
exitButton.setSize(buttonWidth, buttonHeight);
int centerX = WINDOW_WIDTH / 2 - buttonWidth / 2;
int startY = WINDOW_HEIGHT / 2 - buttonHeight / 2;
int spacing = 65;
@ -78,13 +86,25 @@ public class MainMenu extends Scene {
loadButton.setSize(buttonWidth, buttonHeight); loadButton.setPosition(centerX, startY - spacing);
settingsButton.setSize(buttonWidth, buttonHeight); settingsButton.setPosition(centerX, startY - spacing * 2);
exitButton.setSize(buttonWidth, buttonHeight); exitButton.setPosition(centerX, startY - spacing * 3);
exitButton.onClick(() -> log.info("Exit clicked"));
playButton.onClick(() -> log.debug("Play clicked"));
loadButton.onClick(() -> log.debug("Load clicked"));
settingsButton.onClick(() -> {
log.debug("Settings clicked");
if (game.transition == null) {
game.transition = new Transition(game, this, game.settingsScene, State.SETTINGS, 350);
}
});
exitButton.onClick(() -> {
log.debug("Exit clicked");
Gdx.app.exit();
});
root.addActor(playButton.getActor());
root.addActor(loadButton.getActor());
root.addActor(settingsButton.getActor());
root.addActor(exitButton.getActor());
game.stage.addActor(root);
}

View File

@ -0,0 +1,50 @@
package org.vibecoders.moongazer.scenes;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import static org.vibecoders.moongazer.Constants.*;
import org.vibecoders.moongazer.Game;
import org.vibecoders.moongazer.State;
import org.vibecoders.moongazer.managers.Assets;
import org.vibecoders.moongazer.ui.UIImageButton;
public class Settings extends Scene {
public Settings(Game game) {
super(game);
// WIP
UIImageButton settingButton = new UIImageButton("textures/ui/UI_Icon_Setting.png");
UIImageButton exitImgButton = new UIImageButton("textures/ui/IconExitGame.png");
UIImageButton soundButton = new UIImageButton("textures/ui/ImgReShaSoundOn.png");
UIImageButton closeButton = new UIImageButton("textures/ui/UI_Gcg_Icon_Close.png");
settingButton.setSize(50, 50);
exitImgButton.setSize(50, 50);
soundButton.setSize(50, 50);
closeButton.setSize(50, 50);
settingButton.setPosition(20, WINDOW_HEIGHT - 70);
exitImgButton.setPosition(WINDOW_WIDTH - 70, WINDOW_HEIGHT - 70);
soundButton.setPosition(20, 20);
closeButton.setPosition(WINDOW_WIDTH - 70, 20);
root.addActor(settingButton.getActor());
root.addActor(exitImgButton.getActor());
root.addActor(soundButton.getActor());
root.addActor(closeButton.getActor());
settingButton.onClick(() -> log.debug("Settings clicked"));
exitImgButton.onClick(() -> {
log.debug("Exit clicked");
if (game.transition == null) {
game.transition = new Transition(game, this, game.mainMenuScene, State.MAIN_MENU, 350);
}
});
soundButton.onClick(() -> log.debug("Sound clicked"));
closeButton.onClick(() -> log.debug("Close clicked"));
game.stage.addActor(root);
}
@Override
public void render(SpriteBatch batch) {
batch.draw(Assets.getWhiteTexture(), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
}
}

View File

@ -1,10 +1,20 @@
package org.vibecoders.moongazer.ui;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import org.vibecoders.moongazer.managers.Assets;
public class UIImageButton extends UIButton {
public UIImageButton() {
this.button = new ImageButton(new ImageButton.ImageButtonStyle());
public UIImageButton(String texturePath) {
Texture texture = Assets.getAsset(texturePath, Texture.class);
TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture));
ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
style.imageUp = drawable;
style.imageDown = drawable;
style.imageOver = drawable;
this.button = new ImageButton(style);
this.actor = button;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 869 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB