First commit

This commit is contained in:
2026-03-22 00:48:57 -03:00
commit b8713898e5
34 changed files with 2196 additions and 0 deletions

18
.editorconfig Normal file
View File

@@ -0,0 +1,18 @@
# https://editorconfig.org
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{java,scala,groovy,kt,kts}]
indent_size = 4
[*.gradle]
indent_size = 2
[*.md]
trim_trailing_whitespace = false

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
* text=auto eol=lf
*.bat text=auto eol=crlf

168
.gitignore vendored Normal file
View File

@@ -0,0 +1,168 @@
## Gradle:
.gradle/
gradle-app.setting
/build/
/android/build/
/core/build/
/lwjgl2/build/
/lwjgl3/build/
/html/build/
/teavm/build/
/ios/build/
/ios-moe/build/
/headless/build/
/server/build/
/shared/build/
## Java:
*.class
*.war
*.ear
hs_err_pid*
.attach_pid*
## Android:
/android/libs/armeabi-v7a/
/android/libs/arm64-v8a/
/android/libs/x86/
/android/libs/x86_64/
/android/gen/
/android/out/
local.properties
com_crashlytics_export_strings.xml
## Robovm:
/ios/robovm-build/
## iOS:
/ios/xcode/*.xcodeproj/*
!/ios/xcode/*.xcodeproj/xcshareddata
!/ios/xcode/*.xcodeproj/project.pbxproj
/ios/xcode/native/
/ios/IOSLauncher.app
/ios/IOSLauncher.app.dSYM
## GWT:
/html/war/
/html/gwt-unitCache/
.apt_generated/
/html/war/WEB-INF/deploy/
/html/war/WEB-INF/classes/
.gwt/
gwt-unitCache/
www-test/
.gwt-tmp/
## TeaVM:
# Not sure yet...
## IntelliJ, Android Studio:
.idea/
*.ipr
*.iws
*.iml
## Eclipse:
.classpath
.project
.metadata/
/android/bin/
/core/bin/
/lwjgl2/bin/
/lwjgl3/bin/
/html/bin/
/teavm/bin/
/ios/bin/
/ios-moe/bin/
/headless/bin/
/server/bin/
/shared/bin/
*.tmp
*.bak
*.swp
*~.nib
.settings/
.loadpath
.externalToolBuilders/
*.launch
## NetBeans:
/nbproject/private/
/android/nbproject/private/
/core/nbproject/private/
/lwjgl2/nbproject/private/
/lwjgl3/nbproject/private/
/html/nbproject/private/
/teavm/nbproject/private/
/ios/nbproject/private/
/ios-moe/nbproject/private/
/headless/nbproject/private/
/server/nbproject/private/
/shared/nbproject/private/
/nbbuild/
/android/nbbuild/
/core/nbbuild/
/lwjgl2/nbbuild/
/lwjgl3/nbbuild/
/html/nbbuild/
/teavm/nbbuild/
/ios/nbbuild/
/ios-moe/nbbuild/
/headless/nbbuild/
/server/nbbuild/
/shared/nbbuild/
/dist/
/android/dist/
/core/dist/
/lwjgl2/dist/
/lwjgl3/dist/
/html/dist/
/teavm/dist/
/ios/dist/
/ios-moe/dist/
/headless/dist/
/server/dist/
/shared/dist/
/nbdist/
/android/nbdist/
/core/nbdist/
/lwjgl2/nbdist/
/lwjgl3/nbdist/
/html/nbdist/
/teavm/nbdist/
/ios/nbdist/
/ios-moe/nbdist/
/headless/nbdist/
/server/nbdist/
/shared/nbdist/
nbactions.xml
nb-configuration.xml
## OS-Specific:
.DS_Store
Thumbs.db
## Miscellaneous:
*~
*.*#
*#*#
/.kotlin/
/assets/assets.txt
## Special cases:
## There is a resource-config.json file generated by nativeimage.gradle if you use Graal Native Image.
## Some usage may need extra resource configuration in a different file with the same name.
## You could also add that configuration to the text in nativeimage.gradle .
## You should delete or comment out the next line if you have configuration in a different resource-config.json .
**/resource-config.json
# Assets
/assets/sounds/*
/assets/sprites/*

33
README.md Normal file
View File

@@ -0,0 +1,33 @@
# fnafinjava
A [libGDX](https://libgdx.com/) project generated with [gdx-liftoff](https://github.com/libgdx/gdx-liftoff).
This project was generated with a template including simple application launchers and an `ApplicationAdapter` extension that draws libGDX logo.
## Platforms
- `core`: Main module with the application logic shared by all platforms.
- `lwjgl3`: Primary desktop platform using LWJGL3; was called 'desktop' in older docs.
## Gradle
This project uses [Gradle](https://gradle.org/) to manage dependencies.
The Gradle wrapper was included, so you can run Gradle tasks using `gradlew.bat` or `./gradlew` commands.
Useful Gradle tasks and flags:
- `--continue`: when using this flag, errors will not stop the tasks from running.
- `--daemon`: thanks to this flag, Gradle daemon will be used to run chosen tasks.
- `--offline`: when using this flag, cached dependency archives will be used.
- `--refresh-dependencies`: this flag forces validation of all dependencies. Useful for snapshot versions.
- `build`: builds sources and archives of every project.
- `cleanEclipse`: removes Eclipse project data.
- `cleanIdea`: removes IntelliJ project data.
- `clean`: removes `build` folders, which store compiled classes and built archives.
- `eclipse`: generates Eclipse project data.
- `idea`: generates IntelliJ project data.
- `lwjgl3:jar`: builds application's runnable jar, which can be found at `lwjgl3/build/libs`.
- `lwjgl3:run`: starts the application.
- `test`: runs unit tests (if any).
Note that most tasks that are not specific to a single project can be run with `name:` prefix, where the `name` should be replaced with the ID of a specific project.
For example, `core:clean` removes `build` folder only from the `core` project.

69
build.gradle Normal file
View File

@@ -0,0 +1,69 @@
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
google()
maven { url = 'https://central.sonatype.com/repository/maven-snapshots/' }
}
dependencies {
}
}
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
// This allows you to "Build and run using IntelliJ IDEA", an option in IDEA's Settings.
idea {
module {
outputDir = file('build/classes/java/main')
testOutputDir = file('build/classes/java/test')
}
}
}
configure(subprojects) {
apply plugin: 'java-library'
java.sourceCompatibility = 21
// From https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/
// The article can be helpful when using assets.txt in your project.
tasks.register('generateAssetList') {
inputs.dir("${project.rootDir}/assets/")
// projectFolder/assets
File assetsFolder = new File("${project.rootDir}/assets/")
// projectFolder/assets/assets.txt
File assetsFile = new File(assetsFolder, "assets.txt")
// delete that file in case we've already created it
assetsFile.delete()
// iterate through all files inside that folder
// convert it to a relative path
// and append it to the file assets.txt
fileTree(assetsFolder).collect { assetsFolder.relativePath(it) }.sort().each {
assetsFile.append(it + "\n")
}
}
processResources.dependsOn 'generateAssetList'
compileJava {
options.incremental = true
}
}
subprojects {
version = "$projectVersion"
ext.appName = 'fnafinjava'
repositories {
mavenCentral()
// You may want to remove the following line if you have errors downloading dependencies.
mavenLocal()
maven { url = 'https://central.sonatype.com/repository/maven-snapshots/' }
maven { url = 'https://jitpack.io' }
}
}
eclipse.project.name = 'fnafinjava' + '-parent'

14
core/build.gradle Normal file
View File

@@ -0,0 +1,14 @@
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
eclipse.project.name = appName + '-core'
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
if(enableGraalNative == 'true') {
implementation "io.github.berstanio:gdx-svmhelper-annotations:$graalHelperVersion"
}
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

View File

@@ -0,0 +1,63 @@
package io.github.eldek0;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import io.github.eldek0.asset.GameAssetManager;
import io.github.eldek0.screen.GameScene;
/** {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. */
public class App extends Game {
public static final GameAssetManager assets = new GameAssetManager();
public static final int SCREEN_WIDTH = 1024;
public static final int SCREEN_HEIGHT = 768;
private GameScene gameScene;
public static OrthographicCamera camera;
public static Viewport viewport;
@Override
public void create() {
camera = new OrthographicCamera();
viewport = new StretchViewport(SCREEN_WIDTH, SCREEN_HEIGHT, camera);
camera.position.set((float) SCREEN_WIDTH /2, (float) SCREEN_HEIGHT /2, 0);
camera.update();
assets.loadGameAssets();
//assets.loadMenuAssets();
assets.finishLoading();
System.out.println("Assets Loaded");
this.setScreen(new GameScene(this));
}
@Override
public void render() {
super.render();
}
@Override
public void dispose() {
if (gameScene != null) {
//gameScene.world.save();
}
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
public static Vector2 convertPosToWorldPos(Vector2 pos) {
Vector3 worldPos = new Vector3(pos.x, pos.y, 0);
camera.unproject(worldPos,
viewport.getScreenX(),
viewport.getScreenY(),
viewport.getScreenWidth(),
viewport.getScreenHeight()
);
return new Vector2(worldPos.x, worldPos.y);
}
}

View File

@@ -0,0 +1,593 @@
package io.github.eldek0.asset;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
public class GameAssetManager {
private final AssetManager manager = new AssetManager();
// =========================================================
// PATHS — Monitor
// =========================================================
// camera_sprites[0..10] → "sprites/monitor/1.png" .. "sprites/monitor/11.png"
// monitor_button → "sprites/monitor/button.png"
private static final String MONITOR_PATH = "sprites/monitor/";
public static final String MONITOR_BUTTON = MONITOR_PATH + "button.png";
// =========================================================
// PATHS — Office
// =========================================================
private static final String OFFICE_PATH = "sprites/office/";
private static final String OFFICE_INSIDE_PATH = OFFICE_PATH + "inside/";
private static final String OFFICE_HALLWAY_PATH = OFFICE_PATH + "hallway/";
private static final String OFFICE_RVENTS_PATH = OFFICE_PATH + "right_vents/";
private static final String OFFICE_LVENTS_PATH = OFFICE_PATH + "left_vents/";
private static final String OFFICE_UTILS_PATH = OFFICE_PATH + "utils/";
public static final String OFFICE_BG = OFFICE_PATH + "office.png";
// animatronic_offices[0..3] → inside/0.png .. inside/4.png
// flash_offices[0..10] → hallway/0.png .. hallway/10.png
// right_vent_offices[0..2] → right_vents/0.png .. right_vents/2.png
// left_vent_offices[0..2] → left_vents/0.png .. left_vents/2.png
// desk_animation[0..3] → utils/10.png .. utils/13.png
public static final String RIGHT_VENT_BUTTON_OFF = OFFICE_UTILS_PATH + "3.png";
public static final String RIGHT_VENT_BUTTON_ON = OFFICE_UTILS_PATH + "4.png";
public static final String LEFT_VENT_BUTTON_OFF = OFFICE_UTILS_PATH + "1.png";
public static final String LEFT_VENT_BUTTON_ON = OFFICE_UTILS_PATH + "2.png";
public static final String TELEPHONE_MUTE = OFFICE_UTILS_PATH + "20.png";
public static final String CTRL_ADV = OFFICE_UTILS_PATH + "40.png";
// warn_big[0..1] → utils/24.png .. utils/25.png
// warn_small[0..1] → utils/30.png .. utils/31.png
// Easter eggs
public static final String BALLOON_GIRL = OFFICE_INSIDE_PATH + "8.png";
public static final String DWARF = OFFICE_INSIDE_PATH + "DWARF.png";
public static final String PLASTIC = OFFICE_INSIDE_PATH + "10.png";
public static final String OFFICE_BUNNY = OFFICE_INSIDE_PATH + "3.png";
public static final String OFFICE_GOLDEN_FREDDY = OFFICE_INSIDE_PATH + "6.png";
public static final String OFFICE_MANGLE = OFFICE_INSIDE_PATH + "7.png";
public static final String OFFICE_BALLOON_BOY = OFFICE_INSIDE_PATH + "5.png";
// =========================================================
// PATHS — Mask
// =========================================================
private static final String MASK_PATH = "sprites/mask/";
// mask_sprites[0..9] → mask/1.png .. mask/10.png
public static final String MASK_BUTTON = MASK_PATH + "button.png";
// =========================================================
// PATHS — Cameras (utils)
// =========================================================
private static final String CAM_PATH = "sprites/cameras/";
private static final String CAM_UTILS_PATH = CAM_PATH + "utils/";
private static final String CAM_LABELS_PATH = CAM_PATH + "Labels/";
private static final String CAM_STATIC_PATH = CAM_PATH + "static/";
private static final String CAM_LOC_PATH = CAM_PATH + "locations/";
private static final String CAM_MANGLE_PATH = CAM_PATH + "mangle/";
public static final String CAMERA_MAP = CAM_UTILS_PATH + "Map.png";
public static final String CAMERA_BORDERLINE = CAM_UTILS_PATH + "Border.png";
public static final String CAMERA_RECORD_SPRITE = CAM_UTILS_PATH + "1.png";
public static final String CAMERA_SIGNAL_INTERRUPTED= CAM_UTILS_PATH + "2.png";
public static final String ROOM_BUTTON_UNSELECTED = CAM_LABELS_PATH + "13.png";
public static final String ROOM_BUTTON_SELECTED = CAM_LABELS_PATH + "14.png";
public static final String CLICKNHOLD = CAM_LABELS_PATH + "18.png";
public static final String MUSIC_BOX_BUTTON_OFF = CAM_LABELS_PATH + "16.png";
public static final String MUSIC_BOX_BUTTON_ON = CAM_LABELS_PATH + "17.png";
public static final String MUSIC_BOX_LABEL = CAM_LABELS_PATH + "15.png";
// room_buttons_labels[0..11] → Labels/1.png .. Labels/12.png
// mangle_cameras[0..3] → mangle/0.png .. mangle/3.png
// static_1[0..5] → static/1.png .. static/6.png
// static_2[0..3] → static/10.png .. static/13.png
// static_stripes[0..4] → static/s2/1.png .. static/s2/5.png
// music_box_timer_sprites[0..20] → cameras/music_box_timer/1.png .. 21.png
// Camera locations — each location has frames and a label
// party_room_1 [0..3] + label
// party_room_2 [0..4] + label
// party_room_3 [0..4] + label
// party_room_4 [0..6] + label
// prize_corner [0..5] + label
// right_air_vent [0..4] + label
// left_air_vent [0..5] + label
// game_area [0..5] + label
// kids_cove [0..2] + label
// parts_n_service[0..6] + label
// show_stage [0..6] + label
// main_hall [0..5] + label
// =========================================================
// PATHS — Battery
// =========================================================
private static final String BATTERY_PATH = "sprites/battery/";
// battery_stages[0..4] → battery/0.png .. battery/4.png
public static final String FLASHLIGHT_LABEL = BATTERY_PATH + "label.png";
// =========================================================
// PATHS — Menu
// =========================================================
private static final String MENU_PATH = "sprites/menu/";
public static final String MENU_MISC_PATH = MENU_PATH + "misc/";
private static final String MENU_LOGOS_PATH = MENU_PATH + "logos/";
private static final String MENU_NIGHTS_PATH = MENU_PATH + "nights/";
private static final String MENU_SPRINKLES_PATH= MENU_PATH + "sprinkles/";
private static final String MENU_PAYCHECKS_PATH= MENU_PATH + "paychecks/";
// background_menu[0..3] → misc/0.png .. misc/3.png
public static final String FNAF_TITLE = MENU_LOGOS_PATH + "2.png";
public static final String SCOTT_CREDITS = MENU_LOGOS_PATH + "1.png";
public static final String SEL_SCOTT_CREDITS = MENU_LOGOS_PATH + "10.png";
public static final String OPTION_SELECTED = MENU_LOGOS_PATH + "3.png";
public static final String NEW_GAME_OPTION = MENU_LOGOS_PATH + "5.png";
public static final String CONTINUE_OPTION = MENU_LOGOS_PATH + "6.png";
public static final String DELETE_DATA_LABEL = MENU_LOGOS_PATH + "7.png";
public static final String VERSION = MENU_LOGOS_PATH + "9.png";
public static final String NIGHT_LABEL_2 = MENU_LOGOS_PATH + "8.png";
public static final String ESC_TO_RETURN = MENU_LOGOS_PATH + "12.png";
public static final String EXTRAS_BUTTON = MENU_LOGOS_PATH + "13.png";
public static final String ANIMATRONICS_BUTTON = MENU_LOGOS_PATH + "14.png";
public static final String JUMPSCARES_BUTTON = MENU_LOGOS_PATH + "15.png";
public static final String MINIGAMES_BUTTON = MENU_LOGOS_PATH + "16.png";
public static final String SEL_SQUARE = MENU_LOGOS_PATH + "17.png";
public static final String REAL_TIME_BUTTON = MENU_LOGOS_PATH + "11.png";
public static final String LOADING_ICON = MENU_LOGOS_PATH + "0.png";
public static final String NIGHT_SIX_OPTION = MENU_NIGHTS_PATH + "11.png";
public static final String CUSTOM_NIGHT_OPTION = MENU_NIGHTS_PATH + "12.png";
public static final String LOST_SCREEN = MENU_NIGHTS_PATH + "9.png";
public static final String GAME_OVER = MENU_NIGHTS_PATH + "10.png";
public static final String REAL_TIME_NIGHT = MENU_NIGHTS_PATH + "8.png";
// nights_12am[0..6] → nights/1.png .. nights/7.png
public static final String STAR = MENU_MISC_PATH + "4.png";
public static final String BLUE_STAR = MENU_MISC_PATH + "5.png";
public static final String NEWSPAPER = MENU_PAYCHECKS_PATH + "1.png";
public static final String NIGHT_FIVE_PAYCHECK = MENU_PAYCHECKS_PATH + "2.png";
public static final String NIGHT_SIX_PAYCHECK = MENU_PAYCHECKS_PATH + "3.png";
public static final String NIGHT_SEVEN_PAYCHECK = MENU_PAYCHECKS_PATH + "4.png";
// Confetti: blue[0..4]→sprinkles/0..4, green[10..14], yellow[20..24], pink[30..34]
// =========================================================
// PATHS — Numbers & Clock
// =========================================================
private static final String NUMBERS_PATH = "sprites/numbers/";
private static final String CLOCK_PATH = "sprites/clock/";
// numbers[0..9] → numbers/1rst/medium/0.png .. 9.png
// numbers_small[0..9] → numbers/1rst/small/0.png .. 9.png
// numbers_big[0..9] → numbers/1rst/big/0.png .. 9.png
// numbers2[0..9] → numbers/2nd/medium/0.png .. 9.png
// numbers2_small[0..9] → numbers/2nd/small/0.png .. 9.png
public static final String DOTS = NUMBERS_PATH + "1rst/medium/dot.png";
public static final String NIGHT_LABEL = CLOCK_PATH + "20.png";
public static final String AM_LABEL = CLOCK_PATH + "2.png";
public static final String BIG_AM = CLOCK_PATH + "1.png";
// five_animation[0..4] → clock/3.png .. clock/7.png
// six_animation[0..5] → clock/8.png .. clock/13.png
// =========================================================
// PATHS — Custom Night
// =========================================================
private static final String CN_PATH = "sprites/custom_night/";
private static final String CN_ICONS_PATH = CN_PATH + "icons/";
private static final String CN_NAMES_PATH = CN_PATH + "names/";
private static final String CN_LABELS_PATH= CN_PATH + "labels/";
private static final String CN_MODES_PATH = CN_PATH + "modes/";
private static final String CN_REWARDS_PATH = CN_PATH + "rewards/";
// animatronic_icons[0..9] → icons/1.png .. icons/10.png
// animatronic_labels[0..9] → names/1.png .. names/10.png
// modes_labels[0..9] → modes/1.png .. modes/10.png
// custom_night_rewards[0..8]→ rewards/0.png .. rewards/8.png
public static final String CUSTOM_NIGHT_TITLE = CN_LABELS_PATH + "1.png";
public static final String ARROW_RIGHT = CN_LABELS_PATH + "2.png";
public static final String ARROW_LEFT = CN_LABELS_PATH + "3.png";
public static final String READY_BUTTON = CN_LABELS_PATH + "4.png";
public static final String ARROW_RIGHT2 = CN_LABELS_PATH + "5.png";
public static final String ARROW_LEFT2 = CN_LABELS_PATH + "6.png";
public static final String CUSTOM_NIGHT_LEVEL_INFO = CN_LABELS_PATH + "7.png";
// =========================================================
// PATHS — Jumpscares
// =========================================================
private static final String JS_PATH = "sprites/jumpscares/";
// puppet[0..14] → jumpscares/puppet/1.png .. 15.png
// toy_bunny[0..12] → jumpscares/toy_bonnie/1.png .. 13.png
// toy_chica[0..12] → jumpscares/toy_chica/1.png .. 13.png
// toy_freddy[0..11] → jumpscares/toy_freddy/1.png .. 12.png
// withered_freddy[0..15] → jumpscares/withered_freddy/1..13 + 7..9
// withered_bonnie[0..15] → jumpscares/withered_bonnie/1.png .. 16.png
// withered_chica[0..11] → jumpscares/withered_chica/1.png .. 12.png
// foxy[0..13] → jumpscares/withered_foxy/1.png .. 14.png
// mangle[0..15] → jumpscares/mangle/1.png .. 16.png
// golden_freddy[0..12] → jumpscares/withered_golden_freddy/1.png .. 13.png
// =========================================================
// PATHS — Cutscenes
// =========================================================
private static final String CS_PATH = "sprites/cutscenes/";
// cutscene_chica[0..2] → cutscenes/10.png .. cutscenes/12.png
// cutscene_bonnie[0..2] → cutscenes/20.png .. cutscenes/22.png
public static final String CUTSCENE_FREDDY = CS_PATH + "30.png";
public static final String CUTSCENE_PUPPET = CS_PATH + "40.png";
public static final String CUTSCENE_BACKGROUND = CS_PATH + "1.png";
public static final String CUTSCENE_BLACK = CS_PATH + "0.png";
public static final String CUTSCENE_MASK = CS_PATH + "2.png";
public static final String ERR_IMG = CS_PATH + "3.png";
public static final String ITS_ME = CS_PATH + "4.png";
// =========================================================
// PATHS — Minigames
// =========================================================
private static final String MG_PATH = "sprites/minigames/";
private static final String MG_GGGL_PATH = MG_PATH + "GG_GL/";
private static final String MG_SAVETHEM_PATH = MG_PATH + "SAVE THEM/";
private static final String MG_FOXY_PATH = MG_PATH + "Go! Go! Go!/";
private static final String MG_TCTTC_PATH = MG_PATH + "TCTTC/";
private static final String MG_SCREENS_PATH = MG_PATH + "screenshots/";
// Give Gifts Give Life
public static final String PUPPET_MINIGAME = MG_GGGL_PATH + "4.png";
public static final String SOUL = MG_GGGL_PATH + "7.png";
public static final String GIFT = MG_GGGL_PATH + "6.png";
public static final String GIVE_GIFTS = MG_GGGL_PATH + "10.png";
public static final String GIVE_LIFE = MG_GGGL_PATH + "11.png";
public static final String CHICA_MASK = MG_GGGL_PATH + "0.png";
public static final String FRED_MASK = MG_GGGL_PATH + "1.png";
public static final String BONNIE_MASK = MG_GGGL_PATH + "2.png";
public static final String FOXY_MASK = MG_GGGL_PATH + "3.png";
// Save Them
// freddy_walking[0..5] → SAVE THEM/0.png .. SAVE THEM/5.png
// endo_anim[0..1] → SAVE THEM/25.png .. SAVE THEM/26.png
public static final String TABLE = MG_SAVETHEM_PATH + "10.png";
public static final String DESK_MIN = MG_SAVETHEM_PATH + "11.png";
public static final String SCENEARY = MG_SAVETHEM_PATH + "12.png";
public static final String DUST = MG_SAVETHEM_PATH + "13.png";
public static final String FLOOR1 = MG_SAVETHEM_PATH + "14.png";
public static final String FLOOR2 = MG_SAVETHEM_PATH + "15.png";
public static final String WASD = MG_SAVETHEM_PATH + "16.png";
public static final String SUIT1 = MG_SAVETHEM_PATH + "20.png";
public static final String SUIT2 = MG_SAVETHEM_PATH + "21.png";
public static final String SUIT3 = MG_SAVETHEM_PATH + "22.png";
public static final String SUIT_GR_1 = MG_SAVETHEM_PATH + "23.png";
public static final String SUIT_GR_2 = MG_SAVETHEM_PATH + "24.png";
public static final String SAD_SOUL = MG_SAVETHEM_PATH + "27.png";
public static final String BLOOD = MG_SAVETHEM_PATH + "31.png";
public static final String BIG_GIFT = MG_SAVETHEM_PATH + "30.png";
// Foxy Go Go Go
// min_foxy_anim[0..1] → Go!/0.png .. Go!/1.png
// min_confetti[0..7] → Go!/10.png .. Go!/17.png
public static final String COURTAIN = MG_FOXY_PATH + "4.png";
public static final String SAD_CHILD = MG_FOXY_PATH + "20.png";
public static final String HAPPY_CHILD = MG_FOXY_PATH + "21.png";
public static final String ARROW_MIN = MG_FOXY_PATH + "22.png";
public static final String PURPLE_GUY = MG_FOXY_PATH + "23.png";
public static final String GET_READY_TXT = MG_FOXY_PATH + "31.png";
public static final String GO_TXT = MG_FOXY_PATH + "32.png";
public static final String HURRAY_TXT = MG_FOXY_PATH + "33.png";
// Take Cake to the Children
// cake_freddy_walking[0..1] → TCTTC/0.png .. TCTTC/1.png
// child_crying_states[0..6] → TCTTC/10.png .. TCTTC/16.png
// child_states[0..5] → TCTTC/20.png .. TCTTC/25.png
public static final String DEAD_CHILD = MG_TCTTC_PATH + "17.png";
public static final String CAR = MG_TCTTC_PATH + "30.png";
public static final String TAKE_CAKE_TO_THE_CHILDREN_LABEL = MG_TCTTC_PATH + "31.png";
// Screenshots
// min_screenshots[0..3] → screenshots/0.png .. screenshots/3.png
// Rare screens
private static final String RARE_PATH = "sprites/rare/";
// rare[0..2] → rare/1.png .. rare/3.png
// Animatronics extras
private static final String ANIMATRONICS_PATH = "sprites/animatronics/";
// anims_extra[0..8] → animatronics/0.png .. animatronics/8.png
// =========================================================
// LOADING
// =========================================================
public void loadMenuAssets() {
// Background menu
for (int i = 0; i < 4; i++) manager.load(MENU_MISC_PATH + i + ".png", Texture.class);
// Menu logos and labels
for (int i = 0; i <= 17; i++) manager.load(MENU_LOGOS_PATH + i + ".png", Texture.class);
// Night screens (12am) and overlays
for (int i = 1; i <= 12; i++) manager.load(MENU_NIGHTS_PATH + i + ".png", Texture.class);
manager.load(MENU_NIGHTS_PATH + "8.png", Texture.class);
manager.load(MENU_NIGHTS_PATH + "10.png", Texture.class);
manager.load(MENU_NIGHTS_PATH + "11.png", Texture.class);
// Paychecks
for (int i = 1; i <= 4; i++) manager.load(MENU_PAYCHECKS_PATH + i + ".png", Texture.class);
// Confetti
for (int i = 0; i < 5; i++) manager.load(MENU_SPRINKLES_PATH + i + ".png", Texture.class);
for (int i = 10; i < 15; i++) manager.load(MENU_SPRINKLES_PATH + i + ".png", Texture.class);
for (int i = 20; i < 25; i++) manager.load(MENU_SPRINKLES_PATH + i + ".png", Texture.class);
for (int i = 30; i < 35; i++) manager.load(MENU_SPRINKLES_PATH + i + ".png", Texture.class);
// Stars
manager.load(STAR, Texture.class);
manager.load(BLUE_STAR, Texture.class);
}
public void loadGameAssets() {
loadMonitorAssets();
loadOfficeAssets();
loadMaskAssets();
loadCameraAssets();
loadBatteryAssets();
loadNumbersAndClockAssets();
loadCustomNightAssets();
loadJumpscareAssets();
loadCutsceneAssets();
loadMinigameAssets();
loadMiscAssets();
}
private void loadMonitorAssets() {
for (int i = 1; i <= 11; i++) manager.load(MONITOR_PATH + i + ".png", Texture.class);
manager.load(MONITOR_BUTTON, Texture.class);
}
private void loadOfficeAssets() {
manager.load(OFFICE_BG, Texture.class);
// Animatronic offices (inside/0..4)
for (int i = 0; i < 4; i++) manager.load(OFFICE_INSIDE_PATH + i + ".png", Texture.class);
manager.load(OFFICE_INSIDE_PATH + "4.png", Texture.class);
// Flash hallway (hallway/0..10)
for (int i = 0; i < 11; i++) manager.load(OFFICE_HALLWAY_PATH + i + ".png", Texture.class);
// Vents
for (int i = 0; i < 3; i++) manager.load(OFFICE_RVENTS_PATH + i + ".png", Texture.class);
for (int i = 0; i < 3; i++) manager.load(OFFICE_LVENTS_PATH + i + ".png", Texture.class);
// Desk animation (utils/10..13)
for (int i = 10; i < 14; i++) manager.load(OFFICE_UTILS_PATH + i + ".png", Texture.class);
// Vent buttons
manager.load(RIGHT_VENT_BUTTON_OFF, Texture.class);
manager.load(RIGHT_VENT_BUTTON_ON, Texture.class);
manager.load(LEFT_VENT_BUTTON_OFF, Texture.class);
manager.load(LEFT_VENT_BUTTON_ON, Texture.class);
// Warn signs
for (int i = 24; i < 26; i++) manager.load(OFFICE_UTILS_PATH + i + ".png", Texture.class);
for (int i = 30; i < 32; i++) manager.load(OFFICE_UTILS_PATH + i + ".png", Texture.class);
// Specials
manager.load(TELEPHONE_MUTE, Texture.class);
manager.load(CTRL_ADV, Texture.class);
manager.load(OFFICE_BUNNY, Texture.class);
manager.load(OFFICE_GOLDEN_FREDDY, Texture.class);
manager.load(OFFICE_MANGLE, Texture.class);
manager.load(OFFICE_BALLOON_BOY, Texture.class);
manager.load(BALLOON_GIRL, Texture.class);
manager.load(DWARF, Texture.class);
manager.load(PLASTIC, Texture.class);
}
private void loadMaskAssets() {
for (int i = 1; i <= 10; i++) manager.load(MASK_PATH + i + ".png", Texture.class);
manager.load(MASK_BUTTON, Texture.class);
}
private void loadCameraAssets() {
manager.load(CAMERA_MAP, Texture.class);
manager.load(CAMERA_BORDERLINE, Texture.class);
manager.load(CAMERA_RECORD_SPRITE, Texture.class);
manager.load(CAMERA_SIGNAL_INTERRUPTED, Texture.class);
manager.load(ROOM_BUTTON_UNSELECTED, Texture.class);
manager.load(ROOM_BUTTON_SELECTED, Texture.class);
manager.load(CLICKNHOLD, Texture.class);
manager.load(MUSIC_BOX_BUTTON_OFF, Texture.class);
manager.load(MUSIC_BOX_BUTTON_ON, Texture.class);
manager.load(MUSIC_BOX_LABEL, Texture.class);
for (int i = 1; i <= 12; i++) manager.load(CAM_LABELS_PATH + i + ".png", Texture.class);
for (int i = 0; i < 4; i++) manager.load(CAM_MANGLE_PATH + i + ".png", Texture.class);
for (int i = 1; i <= 6; i++) manager.load(CAM_STATIC_PATH + i + ".png", Texture.class);
for (int i = 10; i < 14; i++) manager.load(CAM_STATIC_PATH + i + ".png", Texture.class);
for (int i = 1; i <= 5; i++) manager.load(CAM_STATIC_PATH + "s2/" + i + ".png", Texture.class);
for (int i = 1; i <= 21; i++) manager.load(CAM_PATH + "music_box_timer/" + i + ".png", Texture.class);
loadCameraLocation("PartyRoom1", 4);
loadCameraLocation("PartyRoom2", 5);
loadCameraLocation("PartyRoom3", 5);
loadCameraLocation("PartyRoom4", 7);
loadCameraLocation("PrizeCorner", 6);
loadCameraLocation("RightAirVent", 5);
loadCameraLocation("LeftAirVent", 6);
loadCameraLocation("GameArea", 6);
loadCameraLocation("KidsCove", 3);
loadCameraLocation("PartsnService", 7);
loadCameraLocation("ShowStage", 7);
loadCameraLocation("MainHall", 6);
}
/** Carga los frames (0..count-1) y el label de una ubicación de cámara. */
private void loadCameraLocation(String name, int frameCount) {
String base = CAM_LOC_PATH + name + "/";
for (int i = 0; i < frameCount; i++) manager.load(base + i + ".png", Texture.class);
manager.load(base + "label.png", Texture.class);
}
private void loadBatteryAssets() {
for (int i = 0; i < 5; i++) manager.load(BATTERY_PATH + i + ".png", Texture.class);
manager.load(FLASHLIGHT_LABEL, Texture.class);
}
private void loadNumbersAndClockAssets() {
for (int i = 0; i < 10; i++) {
manager.load(NUMBERS_PATH + "1rst/medium/" + i + ".png", Texture.class);
manager.load(NUMBERS_PATH + "1rst/small/" + i + ".png", Texture.class);
manager.load(NUMBERS_PATH + "1rst/big/" + i + ".png", Texture.class);
manager.load(NUMBERS_PATH + "2nd/medium/" + i + ".png", Texture.class);
manager.load(NUMBERS_PATH + "2nd/small/" + i + ".png", Texture.class);
}
manager.load(DOTS, Texture.class);
manager.load(NIGHT_LABEL, Texture.class);
manager.load(AM_LABEL, Texture.class);
manager.load(BIG_AM, Texture.class);
for (int i = 3; i < 8; i++) manager.load(CLOCK_PATH + i + ".png", Texture.class);
for (int i = 8; i < 14; i++) manager.load(CLOCK_PATH + i + ".png", Texture.class);
}
private void loadCustomNightAssets() {
for (int i = 1; i <= 10; i++) {
manager.load(CN_ICONS_PATH + i + ".png", Texture.class);
manager.load(CN_NAMES_PATH + i + ".png", Texture.class);
manager.load(CN_MODES_PATH + i + ".png", Texture.class);
}
for (int i = 0; i < 9; i++) manager.load(CN_REWARDS_PATH + i + ".png", Texture.class);
manager.load(CUSTOM_NIGHT_TITLE, Texture.class);
manager.load(ARROW_RIGHT, Texture.class);
manager.load(ARROW_LEFT, Texture.class);
manager.load(READY_BUTTON, Texture.class);
manager.load(ARROW_RIGHT2, Texture.class);
manager.load(ARROW_LEFT2, Texture.class);
manager.load(CUSTOM_NIGHT_LEVEL_INFO, Texture.class);
}
private void loadJumpscareAssets() {
loadFrames(JS_PATH + "puppet/", 1, 15);
loadFrames(JS_PATH + "toy_bonnie/", 1, 13);
loadFrames(JS_PATH + "toy_chica/", 1, 13);
loadFrames(JS_PATH + "toy_freddy/", 1, 12);
loadFrames(JS_PATH + "withered_freddy/", 1, 13);
loadFrames(JS_PATH + "withered_bonnie/", 1, 16);
loadFrames(JS_PATH + "withered_chica/", 1, 12);
loadFrames(JS_PATH + "withered_foxy/", 1, 14);
loadFrames(JS_PATH + "mangle/", 1, 16);
loadFrames(JS_PATH + "withered_golden_freddy/", 1, 13);
}
private void loadCutsceneAssets() {
for (int i = 10; i < 13; i++) manager.load(CS_PATH + i + ".png", Texture.class);
for (int i = 20; i < 23; i++) manager.load(CS_PATH + i + ".png", Texture.class);
manager.load(CUTSCENE_FREDDY, Texture.class);
manager.load(CUTSCENE_PUPPET, Texture.class);
manager.load(CUTSCENE_BACKGROUND, Texture.class);
manager.load(CUTSCENE_BLACK, Texture.class);
manager.load(CUTSCENE_MASK, Texture.class);
manager.load(ERR_IMG, Texture.class);
manager.load(ITS_ME, Texture.class);
}
private void loadMinigameAssets() {
// Give Gifts Give Life
manager.load(PUPPET_MINIGAME, Texture.class);
manager.load(SOUL, Texture.class);
manager.load(GIFT, Texture.class);
manager.load(GIVE_GIFTS, Texture.class);
manager.load(GIVE_LIFE, Texture.class);
manager.load(CHICA_MASK, Texture.class);
manager.load(FRED_MASK, Texture.class);
manager.load(BONNIE_MASK, Texture.class);
manager.load(FOXY_MASK, Texture.class);
// Save Them
for (int i = 0; i < 6; i++) manager.load(MG_SAVETHEM_PATH + i + ".png", Texture.class);
for (int i = 25; i < 27; i++) manager.load(MG_SAVETHEM_PATH + i + ".png", Texture.class);
manager.load(TABLE, Texture.class);
manager.load(DESK_MIN, Texture.class);
manager.load(SCENEARY, Texture.class);
manager.load(DUST, Texture.class);
manager.load(FLOOR1, Texture.class);
manager.load(FLOOR2, Texture.class);
manager.load(WASD, Texture.class);
manager.load(SUIT1, Texture.class);
manager.load(SUIT2, Texture.class);
manager.load(SUIT3, Texture.class);
manager.load(SUIT_GR_1,Texture.class);
manager.load(SUIT_GR_2,Texture.class);
manager.load(SAD_SOUL, Texture.class);
manager.load(BLOOD, Texture.class);
manager.load(BIG_GIFT, Texture.class);
// Foxy Go Go Go
for (int i = 0; i < 2; i++) manager.load(MG_FOXY_PATH + i + ".png", Texture.class);
for (int i = 10; i < 18; i++) manager.load(MG_FOXY_PATH + i + ".png", Texture.class);
manager.load(COURTAIN, Texture.class);
manager.load(SAD_CHILD, Texture.class);
manager.load(HAPPY_CHILD, Texture.class);
manager.load(ARROW_MIN, Texture.class);
manager.load(PURPLE_GUY, Texture.class);
manager.load(GET_READY_TXT, Texture.class);
manager.load(GO_TXT, Texture.class);
manager.load(HURRAY_TXT, Texture.class);
// Take Cake to the Children
for (int i = 0; i < 2; i++) manager.load(MG_TCTTC_PATH + i + ".png", Texture.class);
for (int i = 10; i < 17; i++) manager.load(MG_TCTTC_PATH + i + ".png", Texture.class);
for (int i = 20; i < 26; i++) manager.load(MG_TCTTC_PATH + i + ".png", Texture.class);
manager.load(DEAD_CHILD, Texture.class);
manager.load(CAR, Texture.class);
manager.load(TAKE_CAKE_TO_THE_CHILDREN_LABEL, Texture.class);
// Screenshots & Rare
for (int i = 0; i < 4; i++) manager.load(MG_SCREENS_PATH + i + ".png", Texture.class);
for (int i = 1; i <= 3; i++) manager.load(RARE_PATH + i + ".png", Texture.class);
// Animatronics extras
for (int i = 0; i < 9; i++) manager.load(ANIMATRONICS_PATH + i + ".png", Texture.class);
}
private void loadMiscAssets() {
manager.load(ESC_TO_RETURN, Texture.class);
manager.load(REAL_TIME_BUTTON, Texture.class);
manager.load(REAL_TIME_NIGHT, Texture.class);
manager.load(LOADING_ICON, Texture.class);
}
// =========================================================
// HELPERS
// =========================================================
/** Loads numbered frames: base + start.png .. base + end.png */
private void loadFrames(String basePath, int start, int end) {
for (int i = start; i <= end; i++) {
manager.load(basePath + i + ".png", Texture.class);
}
}
// =========================================================
// GENERIC GETTERS
// =========================================================
public Texture getTexture(String path) {
return manager.get(path, Texture.class);
}
/** Returns an array of consecutively numbered frames (start..end inclusive). */
public Texture[] getFrames(String basePath, int start, int end) {
Texture[] frames = new Texture[end - start + 1];
for (int i = start; i <= end; i++) {
frames[i - start] = manager.get(basePath + i + ".png", Texture.class);
}
return frames;
}
// =========================================================
// STATE & LIFECYCLE
// =========================================================
public boolean update() { return manager.update(); }
public void finishLoading() { manager.finishLoading(); }
public float getProgress() { return manager.getProgress(); }
public void dispose() { manager.dispose(); }
}

View File

@@ -0,0 +1,33 @@
package io.github.eldek0.camera;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
public class Camera extends CameraCls{
Table uiContainer;
public Stage stage;
public Camera(int width, int height) {
super(width, height);
viewport = new ExtendViewport(width, height, camera);
uiContainer = new Table();
uiContainer.setFillParent(true);
uiContainer.center();
stage = new Stage(viewport);
stage.addActor(uiContainer);
}
@Override
public void resize(int width, int height) {
viewport.update(width, height, true);
camera.update();
stage.getViewport().update(width, height, true);
}
public void render(float delta){
stage.act(delta);
stage.draw();
}
}

View File

@@ -0,0 +1,44 @@
package io.github.eldek0.camera;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.viewport.Viewport;
public abstract class CameraCls {
protected int width, height;
protected OrthographicCamera camera;
protected Viewport viewport;
public CameraCls(int width, int height) {
this.width = width;
this.height = height;
camera = new OrthographicCamera();
// Center the camera initially
camera.position.set(width / 2f, height / 2f, 0);
camera.update();
}
public Matrix4 combined() {return camera.combined;}
public abstract void resize(int width, int height);
public Vector2 getCameraPos() {
return new Vector2(camera.position.x, camera.position.y);
}
public void updateCam() {
camera.update();
}
public OrthographicCamera getCamera() {
return this.camera;
}
public float getCameraZoom() {
return camera.zoom;
}
}

View File

@@ -0,0 +1,77 @@
package io.github.eldek0.office;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import io.github.eldek0.App;
import io.github.eldek0.ui.HUD;
import static io.github.eldek0.App.assets;
import static io.github.eldek0.asset.GameAssetManager.*;
public class Office {
private static final float SPEED = 600;
public static final float MAX_POS_X = assets.getTexture(OFFICE_BG).getWidth() - App.SCREEN_WIDTH;
private final SpriteBatch batch;
private final HUD hud;
private ShapeRenderer shapeRenderer;
private int movement = 0; // 0, -1 (left), 1 (right)
private float positionX = 0;
public Office(HUD hud, SpriteBatch batch) {
this.hud = hud;
this.batch = batch;
this.shapeRenderer = new ShapeRenderer();
Gdx.input.setInputProcessor(new InputAdapter() {
@Override
public boolean mouseMoved(int screenX, int screenY) {
Vector2 worldPos = App.convertPosToWorldPos(new Vector2(screenX, screenY));
float threshold = (float) App.SCREEN_WIDTH / 2 * 0.5f;
if (worldPos.x < threshold) movement = 1;
else if (worldPos.x > App.SCREEN_WIDTH - threshold) movement = -1;
else movement = 0;
return true;
}
});
}
public void render(){
batch.begin();
batch.draw(assets.getTexture(OFFICE_BG),
positionX, 0);
Texture lightTextureRight = assets.getTexture(RIGHT_VENT_BUTTON_OFF);
Texture lightTextureLeft = assets.getTexture(LEFT_VENT_BUTTON_OFF);
float lightHeight = App.SCREEN_HEIGHT - 360 - lightTextureRight.getHeight();
batch.draw(lightTextureRight,
1440 + positionX, lightHeight);
batch.draw(lightTextureLeft,
100 + positionX, lightHeight);
batch.end();
}
public void update(float dt) {
positionX += (int) (SPEED * movement * dt);
if (-positionX < 0) {
positionX = 0;
} else if (-positionX > MAX_POS_X) {
positionX = -MAX_POS_X;
}
}
public void dispose() {
batch.dispose();
shapeRenderer.dispose();
}
}

View File

@@ -0,0 +1,62 @@
package io.github.eldek0.screen;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import io.github.eldek0.App;
import io.github.eldek0.office.Office;
import io.github.eldek0.ui.HUD;
public class GameScene implements Screen {
private final SpriteBatch batch;
private final Office office;
private final HUD hud;
public GameScene(App app) {
this.hud = new HUD(app);
this.batch = new SpriteBatch();
this.office = new Office(this.hud, batch);
}
@Override
public void show() {
}
@Override
public void render(float v) {
batch.setProjectionMatrix(App.camera.combined);
office.update(v);
hud.update(v);
office.render();
hud.render();
}
@Override
public void resize(int i, int i1) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}

View File

@@ -0,0 +1,63 @@
package io.github.eldek0.ui;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
public class Button {
private boolean inside = false;
private boolean beingPressed = false;
private boolean quitting = false;
private boolean entering = false;
private Texture buttonTexture;
private Rectangle bounds;
private float x, y, width, height;
public Button(Texture sprite, float x, float y, float width, float height) {
this.buttonTexture = sprite;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.bounds = new Rectangle(x, y, width, height);
}
public void update() {
boolean touched = Gdx.input.isTouched() || Gdx.input.isButtonPressed(0);
float touchX = Gdx.input.getX();
float touchY = Gdx.graphics.getHeight() - Gdx.input.getY();
if (touched && bounds.contains(touchX, touchY)) {
if (!beingPressed) {
beingPressed = true;
handleButton();
}
} else {
beingPressed = false;
}
}
public void render(SpriteBatch batch) {
batch.draw(buttonTexture, x, y, width, height);
}
private void handleButton() {
if (!inside) {
entering = true;
quitting = false;
inside = true;
} else {
quitting = true;
entering = false;
inside = false;
}
}
public boolean isInside() { return inside; }
public boolean isBeingPressed() { return beingPressed; }
public boolean isQuitting() { return quitting; }
public boolean isEntering() { return entering; }
}

View File

@@ -0,0 +1,15 @@
package io.github.eldek0.ui;
import com.badlogic.gdx.graphics.Texture;
import io.github.eldek0.App;
import io.github.eldek0.asset.GameAssetManager;
public class CameraButton extends Button {
public CameraButton(float x, float y) {
super(getButtonTexture(), x, y, getButtonTexture().getWidth(), getButtonTexture().getHeight());
}
private static Texture getButtonTexture() {
return App.assets.getTexture(GameAssetManager.MONITOR_BUTTON);
}
}

View File

@@ -0,0 +1,25 @@
package io.github.eldek0.ui;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import io.github.eldek0.App;
public class HUD {
private final SpriteBatch batch;
private final MaskButton maskButton;
private final CameraButton cameraButton;
public HUD(App app) {
this.batch = new SpriteBatch();
this.maskButton = new MaskButton(20, 20);
this.cameraButton = new CameraButton(510, 20);
}
public void render() {
batch.begin();
maskButton.render(batch);
cameraButton.render(batch);
batch.end();
}
public void update(float delta) {}
}

View File

@@ -0,0 +1,15 @@
package io.github.eldek0.ui;
import com.badlogic.gdx.graphics.Texture;
import io.github.eldek0.App;
import io.github.eldek0.asset.GameAssetManager;
public class MaskButton extends Button {
public MaskButton(float x, float y) {
super(getButtonTexture(), x, y, getButtonTexture().getWidth(), getButtonTexture().getHeight());
}
private static Texture getButtonTexture() {
return App.assets.getTexture(GameAssetManager.MASK_BUTTON);
}
}

19
gradle.properties Normal file
View File

@@ -0,0 +1,19 @@
# This doesn't need to be false, and some projects may be able to take advantage of setting daemon to true.
# We set it to false by default in order to avoid too many daemons from being created and persisting; each needs RAM.
org.gradle.daemon=false
# Sets starting memory usage to 512MB, maximum memory usage to 1GB, and tries to set as much to use Unicode as we can.
org.gradle.jvmargs=-Xms512M -Xmx1G -Dfile.encoding=UTF-8 -Dconsole.encoding=UTF-8
# "Configure on-demand" must be false because it breaks projects that have Android modules. The default is also false.
org.gradle.configureondemand=false
# The logging level determines which messages get shown about how Gradle itself is working, such as if build.gradle
# files are fully future-proof (which they never are, because Gradle constantly deprecates working APIs).
# You can change 'quiet' below to 'lifecycle' to use Gradle's default behavior, which shows some confusing messages.
# You could instead change 'quiet' below to 'info' to see info that's important mainly while debugging build files.
# Note that if you want to use Gradle Build Scans, you should set the below logging level to 'lifecycle', otherwise
# the link to the scan won't get shown at all.
# Documented at: https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_logging
org.gradle.logging.level=quiet
graalHelperVersion=2.0.1
enableGraalNative=false
gdxVersion=1.14.0
projectVersion=0.0.1

View File

@@ -0,0 +1,12 @@
#This file is generated by updateDaemonJvm
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/df211d3c3eefdc408b462041881bc575/redirect
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/93aeea858331bd6bb00ba94759830234/redirect
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/df211d3c3eefdc408b462041881bc575/redirect
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/b41931cf1e70bc8e08d7dd19c343ef00/redirect
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/3426ffcaa54c3f62406beb1f1ab8b179/redirect
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d6690dfd71c4c91e08577437b5b2beb0/redirect
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/df211d3c3eefdc408b462041881bc575/redirect
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/b41931cf1e70bc8e08d7dd19c343ef00/redirect
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1e91f45234d88a64dafb961c93ddc75a/redirect
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/552c7bffe0370c66410a51c55985b511/redirect
toolchainVersion=21

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

248
gradlew vendored Normal file
View File

@@ -0,0 +1,248 @@
#!/bin/sh
#
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

93
gradlew.bat vendored Normal file
View File

@@ -0,0 +1,93 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

186
lwjgl3/build.gradle Normal file
View File

@@ -0,0 +1,186 @@
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "io.github.fourlastor:construo:2.1.0"
if(enableGraalNative == 'true') {
classpath "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.9.28"
}
}
}
plugins {
id "application"
}
apply plugin: 'io.github.fourlastor.construo'
import io.github.fourlastor.construo.Target
sourceSets.main.resources.srcDirs += [ rootProject.file('assets').path ]
application.mainClass = 'io.github.eldek0.lwjgl3.Lwjgl3Launcher'
application.applicationName = appName
eclipse.project.name = appName + '-lwjgl3'
java.sourceCompatibility = 21
java.targetCompatibility = 21
if (JavaVersion.current().isJava9Compatible()) {
compileJava.options.release.set(21)
}
dependencies {
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
implementation project(':core')
if(enableGraalNative == 'true') {
implementation "io.github.berstanio:gdx-svmhelper-backend-lwjgl3:$graalHelperVersion"
}
}
def os = System.properties['os.name'].toLowerCase(Locale.ROOT)
run {
workingDir = rootProject.file('assets').path
// You can uncomment the next line if your IDE claims a build failure even when the app closed properly.
//setIgnoreExitValue(true)
if (os.contains('mac')) jvmArgs += "-XstartOnFirstThread"
}
jar {
// sets the name of the .jar file this produces to the name of the game or app, with the version after.
archiveFileName.set("${appName}-${projectVersion}.jar")
// the duplicatesStrategy matters starting in Gradle 7.0; this setting works.
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn configurations.runtimeClasspath
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
// these "exclude" lines remove some unnecessary duplicate files in the output JAR.
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
dependencies {
exclude('META-INF/INDEX.LIST', 'META-INF/maven/**')
}
// setting the manifest makes the JAR runnable.
// enabling native access helps avoid a warning when Java 24 or later runs the JAR.
// setting Multi-Release to true allows LWJGL3 to use different classes on recent Java versions.
manifest {
attributes 'Main-Class': application.mainClass, 'Enable-Native-Access': 'ALL-UNNAMED', 'Multi-Release': 'true'
}
// this last step may help on some OSes that need extra instruction to make runnable JARs.
doLast {
file(archiveFile).setExecutable(true, false)
}
}
// Builds a JAR that only includes the files needed to run on macOS, not Windows or Linux.
// The file size for a Mac-only JAR is about 7MB smaller than a cross-platform JAR.
tasks.register("jarMac") {
dependsOn("jar")
group("build")
jar.archiveFileName.set("${appName}-${projectVersion}-mac.jar")
jar.exclude("windows/x86/**", "windows/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**", "**/*.dll", "**/*.so",
'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
dependencies {
jar.exclude("windows/x86/**", "windows/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**",
'META-INF/INDEX.LIST', 'META-INF/maven/**')
}
}
// Builds a JAR that only includes the files needed to run on Linux, not Windows or macOS.
// The file size for a Linux-only JAR is about 5MB smaller than a cross-platform JAR.
tasks.register("jarLinux") {
dependsOn("jar")
group("build")
jar.archiveFileName.set("${appName}-${projectVersion}-linux.jar")
jar.exclude("windows/x86/**", "windows/x64/**", "macos/arm64/**", "macos/x64/**", "**/*.dll", "**/*.dylib",
'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
dependencies {
jar.exclude("windows/x86/**", "windows/x64/**", "macos/arm64/**", "macos/x64/**",
'META-INF/INDEX.LIST', 'META-INF/maven/**')
}
}
// Builds a JAR that only includes the files needed to run on Windows, not Linux or macOS.
// The file size for a Windows-only JAR is about 6MB smaller than a cross-platform JAR.
tasks.register("jarWin") {
dependsOn("jar")
group("build")
jar.archiveFileName.set("${appName}-${projectVersion}-win.jar")
jar.exclude("macos/arm64/**", "macos/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**", "**/*.dylib", "**/*.so",
'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
dependencies {
jar.exclude("macos/arm64/**", "macos/x64/**", "linux/arm32/**", "linux/arm64/**", "linux/x64/**",
'META-INF/INDEX.LIST', 'META-INF/maven/**')
}
}
construo {
// name of the executable
name.set(appName)
// human-readable name, used for example in the `.app` name for macOS
humanName.set(appName)
jlink {
guessModulesFromJar.set(false)
// You may need to add more modules, as needed.
modules.addAll("java.base", "java.management", "java.desktop", "jdk.unsupported")
}
targets.configure {
register("linuxX64", Target.Linux) {
architecture.set(Target.Architecture.X86_64)
jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_x64_linux_hotspot_21.0.10_7.tar.gz")
// Linux does not currently have a way to set the icon on the executable
}
register("macM1", Target.MacOs) {
architecture.set(Target.Architecture.AARCH64)
jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_aarch64_mac_hotspot_21.0.10_7.tar.gz")
// macOS needs an identifier
identifier.set("io.github.eldek0." + appName)
// Optional: icon for macOS, as an ICNS file
macIcon.set(project.file("icons/logo.icns"))
}
register("macX64", Target.MacOs) {
architecture.set(Target.Architecture.X86_64)
jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_x64_mac_hotspot_21.0.10_7.tar.gz")
// macOS needs an identifier
identifier.set("io.github.eldek0." + appName)
// Optional: icon for macOS, as an ICNS file
macIcon.set(project.file("icons/logo.icns"))
}
register("winX64", Target.Windows) {
architecture.set(Target.Architecture.X86_64)
// Optional: icon for Windows, as a PNG
icon.set(project.file("icons/logo.png"))
jdkUrl.set("https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.10%2B7/OpenJDK21U-jdk_x64_windows_hotspot_21.0.10_7.zip")
// Uncomment the next line to show a console when the game runs, to print messages.
//useConsole.set(true)
}
}
}
// Equivalent to the jar task; here for compatibility with gdx-setup.
tasks.register('dist') {
dependsOn 'jar'
}
distributions {
main {
contents {
into('libs') {
project.configurations.runtimeClasspath.files.findAll { file ->
file.getName() != project.tasks.jar.outputs.files.singleFile.name
}.each { file ->
exclude file.name
}
}
}
}
}
startScripts.dependsOn(':lwjgl3:jar')
startScripts.classpath = project.tasks.jar.outputs.files
if(enableGraalNative == 'true') {
apply from: file("nativeimage.gradle")
}

BIN
lwjgl3/icons/logo.icns Normal file

Binary file not shown.

BIN
lwjgl3/icons/logo.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
lwjgl3/icons/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

54
lwjgl3/nativeimage.gradle Normal file
View File

@@ -0,0 +1,54 @@
project(":lwjgl3") {
apply plugin: "org.graalvm.buildtools.native"
graalvmNative {
binaries {
main {
imageName = appName
mainClass = application.mainClass
requiredVersion = '23.0'
buildArgs.add("-march=compatibility")
jvmArgs.addAll("-Dfile.encoding=UTF8")
sharedLibrary = false
resources.autodetect()
}
}
}
run {
doNotTrackState("Running the app should not be affected by Graal.")
}
// Modified from https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/ ; thanks again, Lyze!
// This creates a resource-config.json file based on the contents of the assets folder (and the libGDX icons).
// This file is used by Graal Native to embed those specific files.
// This has to run before nativeCompile, so it runs at the start of an unrelated resource-handling command.
generateResourcesConfigFile.doFirst {
def assetsFolder = new File("${project.rootDir}/assets/")
def lwjgl3 = project(':lwjgl3')
def resFolder = new File("${lwjgl3.projectDir}/src/main/resources/META-INF/native-image/${lwjgl3.ext.appName}")
resFolder.mkdirs()
def resFile = new File(resFolder, "resource-config.json")
resFile.delete()
resFile.append(
"""{
"resources":{
"includes":[
{
"pattern": ".*(""")
// This adds every filename in the assets/ folder to a pattern that adds those files as resources.
fileTree(assetsFolder).each {
// The backslash-Q and backslash-E escape the start and end of a literal string, respectively.
resFile.append("\\\\Q${it.name}\\\\E|")
}
// We also match all of the window icon images this way and the font files that are part of libGDX.
resFile.append(
"""libgdx.+\\\\.png|lsans.+)"
}
]},
"bundles":[]
}"""
)
}
}

View File

@@ -0,0 +1,48 @@
package io.github.eldek0.lwjgl3;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import io.github.eldek0.App;
/** Launches the desktop (LWJGL3) application. */
public class Lwjgl3Launcher {
public static void main(String[] args) {
if (StartupHelper.startNewJvmIfRequired()) return; // This handles macOS support and helps on Windows.
createApplication();
}
private static Lwjgl3Application createApplication() {
return new Lwjgl3Application(new App(), getDefaultConfiguration());
}
private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() {
Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration();
configuration.setTitle("fnafinjava");
//// Vsync limits the frames per second to what your hardware can display, and helps eliminate
//// screen tearing. This setting doesn't always work on Linux, so the line after is a safeguard.
configuration.useVsync(true);
//// Limits FPS to the refresh rate of the currently active monitor, plus 1 to try to match fractional
//// refresh rates. The Vsync setting above should limit the actual FPS to match the monitor.
configuration.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate + 1);
//// If you remove the above line and set Vsync to false, you can get unlimited FPS, which can be
//// useful for testing performance, but can also be very stressful to some hardware.
//// You may also need to configure GPU drivers to fully disable Vsync; this can cause screen tearing.
configuration.setWindowedMode(App.SCREEN_WIDTH, App.SCREEN_HEIGHT);
//// You can change these files; they are in lwjgl3/src/main/resources/ .
//// They can also be loaded from the root of assets/ .
configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png");
//// This could improve compatibility with Windows machines with buggy OpenGL drivers, Macs
//// with Apple Silicon that have to emulate compatibility with OpenGL anyway, and more.
//// This uses the dependency `com.badlogicgames.gdx:gdx-lwjgl3-angle` to function.
//// You would need to add this line to lwjgl3/build.gradle , below the dependency on `gdx-backend-lwjgl3`:
//// implementation "com.badlogicgames.gdx:gdx-lwjgl3-angle:$gdxVersion"
//// You can choose to add the following line and the mentioned dependency if you want; they
//// are not intended for games that use GL30 (which is compatibility with OpenGL ES 3.0).
//// Know that it might not work well in some cases.
// configuration.setOpenGLEmulation(Lwjgl3ApplicationConfiguration.GLEmulation.ANGLE_GLES20, 0, 0);
return configuration;
}
}

View File

@@ -0,0 +1,227 @@
/*
* Copyright 2020 damios
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Note, the above license and copyright applies to this file only.
package io.github.eldek0.lwjgl3;
import com.badlogic.gdx.Version;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3NativesLoader;
import org.lwjgl.system.JNI;
import org.lwjgl.system.linux.UNISTD;
import org.lwjgl.system.macosx.LibC;
import org.lwjgl.system.macosx.ObjCRuntime;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* A helper object for game startup, featuring three utilities related to LWJGL3 on various operating systems.
* <p>
* The utilities are as follows:
* <ul>
* <li> Windows: Prevents a common crash related to LWJGL3's extraction of shared library files.</li>
* <li> macOS: Spawns a child JVM process with {@code -XstartOnFirstThread} in the JVM args (if it was not already).
* This is required for LWJGL3 to work on macOS.</li>
* <li> Linux (NVIDIA GPUs only): Spawns a child JVM process with the {@code __GL_THREADED_OPTIMIZATIONS}
* {@link System#getenv(String) Environment Variable} set to {@code 0} (if it was not already). This is required for
* LWJGL3 to work on Linux with NVIDIA GPUs.</li>
* </ul>
* <a href="https://jvm-gaming.org/t/starting-jvm-on-mac-with-xstartonfirstthread-programmatically/57547">Based on this java-gaming.org post by kappa</a>
* @author damios
*/
public class StartupHelper {
private StartupHelper() {}
private static final String JVM_RESTARTED_ARG = "jvmIsRestarted";
/**
* Must only be called on Linux. Check OS first (or use short-circuit evaluation)!
* @return whether NVIDIA drivers are present on Linux.
*/
public static boolean isLinuxNvidia() {
String[] drivers = new File("/proc/driver").list(
(dir, path) -> path.toUpperCase(Locale.ROOT).contains("NVIDIA")
);
if (drivers == null) return false;
return drivers.length > 0;
}
/**
* Applies the utilities as described by {@link StartupHelper}'s Javadoc.
* <p>
* All {@link System#getenv() Environment Variables} are copied to the child JVM process (if it is spawned), as
* specified by {@link ProcessBuilder#environment()}; the same applies for
* {@link System#getProperties() System Properties}.
* <p>
* <b>Usage:</b>
* <pre><code>
* public static void main(String[] args) {
* if (StartupHelper.startNewJvmIfRequired()) return;
* // ... The rest of main() goes here, as normal.
* }
* </code></pre>
* @return whether a child JVM process was spawned or not.
*/
public static boolean startNewJvmIfRequired() {
return startNewJvmIfRequired(true);
}
/**
* Applies the utilities as described by {@link StartupHelper}'s Javadoc.
* <p>
* All {@link System#getenv() Environment Variables} are copied to the child JVM process (if it is spawned), as
* specified by {@link ProcessBuilder#environment()}; the same applies for
* {@link System#getProperties() System Properties}.
* <p>
* <b>Usage:</b>
* <pre><code>
* public static void main(String[] args) {
* // The parameter on the next line could instead be false if you don't want to inherit IO.
* if (StartupHelper.startNewJvmIfRequired(true)) return;
* // ... The rest of main() goes here, as normal.
* }
* </code></pre>
* @param inheritIO whether I/O should be inherited in the child JVM process. Please note that enabling this will
* block the thread until the child JVM process stops executing.
* @return whether a child JVM process was spawned or not.
*/
public static boolean startNewJvmIfRequired(boolean inheritIO) {
String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT);
if (osName.contains("mac")) return startNewJvm0(/*isMac =*/ true, inheritIO);
if (osName.contains("windows")) {
// Here, we are trying to work around an issue with how LWJGL3 loads its extracted .dll files.
// By default, LWJGL3 extracts to the directory specified by "java.io.tmpdir": usually, the user's home.
// If the user's name has non-ASCII (or some non-alphanumeric) characters in it, that would fail.
// By extracting to the relevant "ProgramData" folder, which is usually "C:\ProgramData", we avoid this.
// We also temporarily change the "user.name" property to one without any chars that would be invalid.
// We revert our changes immediately after loading LWJGL3 natives.
String programData = System.getenv("ProgramData");
if (programData == null) programData = "C:\\Temp"; // if ProgramData isn't set, try some fallback.
String prevTmpDir = System.getProperty("java.io.tmpdir", programData);
String prevUser = System.getProperty("user.name", "libGDX_User");
System.setProperty("java.io.tmpdir", programData + "\\libGDX-temp");
System.setProperty(
"user.name",
("User_" + prevUser.hashCode() + "_GDX" + Version.VERSION).replace('.', '_')
);
Lwjgl3NativesLoader.load();
System.setProperty("java.io.tmpdir", prevTmpDir);
System.setProperty("user.name", prevUser);
return false;
}
return startNewJvm0(/*isMac =*/ false, inheritIO);
}
private static final String MAC_JRE_ERR_MSG = "A Java installation could not be found. If you are distributing this app with a bundled JRE, be sure to set the '-XstartOnFirstThread' argument manually!";
private static final String LINUX_JRE_ERR_MSG = "A Java installation could not be found. If you are distributing this app with a bundled JRE, be sure to set the environment variable '__GL_THREADED_OPTIMIZATIONS' to '0'!";
private static final String CHILD_LOOP_ERR_MSG = "The current JVM process is a spawned child JVM process, but StartupHelper has attempted to spawn another child JVM process! This is a broken state, and should not normally happen! Your game may crash or not function properly!";
/**
* Spawns a child JVM process if on macOS, or on Linux with NVIDIA drivers.
* <p>
* All {@link System#getenv() Environment Variables} are copied to the child JVM process (if it is spawned), as
* specified by {@link ProcessBuilder#environment()}; the same applies for
* {@link System#getProperties() System Properties}.
* @param isMac whether the current OS is macOS. If this is `false` then the current OS is assumed to be Linux (and
* an immediate check for NVIDIA drivers is performed).
* @param inheritIO whether I/O should be inherited in the child JVM process. Please note that enabling this will
* block the thread until the child JVM process stops executing.
* @return whether a child JVM process was spawned or not.
*/
public static boolean startNewJvm0(boolean isMac, boolean inheritIO) {
long processID = getProcessID(isMac);
if (!isMac) {
// No need to restart non-NVIDIA Linux
if (!isLinuxNvidia()) return false;
// check whether __GL_THREADED_OPTIMIZATIONS is already disabled
if ("0".equals(System.getenv("__GL_THREADED_OPTIMIZATIONS"))) return false;
} else {
// There is no need for -XstartOnFirstThread on Graal native image
if (!System.getProperty("org.graalvm.nativeimage.imagecode", "").isEmpty()) return false;
// Checks if we are already on the main thread, such as from running via Construo.
long objcMsgSend = ObjCRuntime.getLibrary().getFunctionAddress("objc_msgSend");
long nsThread = ObjCRuntime.objc_getClass("NSThread");
long currentThread = JNI.invokePPP(nsThread, ObjCRuntime.sel_getUid("currentThread"), objcMsgSend);
boolean isMainThread = JNI.invokePPZ(currentThread, ObjCRuntime.sel_getUid("isMainThread"), objcMsgSend);
if (isMainThread) return false;
if ("1".equals(System.getenv("JAVA_STARTED_ON_FIRST_THREAD_" + processID))) return false;
}
// Check whether this JVM process is a child JVM process already.
// This state shouldn't usually be reachable, but this stops us from endlessly spawning new child JVM processes.
if ("true".equals(System.getProperty(JVM_RESTARTED_ARG))) {
System.err.println(CHILD_LOOP_ERR_MSG);
return false;
}
// Spawn the child JVM process with updated environment variables or JVM args
List<String> jvmArgs = new ArrayList<>();
// The following line is used assuming you target Java 8, the minimum for LWJGL3.
String javaExecPath = System.getProperty("java.home") + "/bin/java";
// If targeting Java 9 or higher, you could use the following instead of the above line:
//String javaExecPath = ProcessHandle.current().info().command().orElseThrow()
if (!(new File(javaExecPath).exists())) {
System.err.println(getJreErrMsg(isMac));
return false;
}
jvmArgs.add(javaExecPath);
if (isMac) jvmArgs.add("-XstartOnFirstThread");
jvmArgs.add("-D" + JVM_RESTARTED_ARG + "=true");
jvmArgs.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
jvmArgs.add("-cp");
jvmArgs.add(System.getProperty("java.class.path"));
String mainClass = System.getenv("JAVA_MAIN_CLASS_" + processID);
if (mainClass == null) {
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
if (trace.length > 0) mainClass = trace[trace.length - 1].getClassName();
else {
System.err.println("The main class could not be determined.");
return false;
}
}
jvmArgs.add(mainClass);
try {
ProcessBuilder processBuilder = new ProcessBuilder(jvmArgs);
if (!isMac) processBuilder.environment().put("__GL_THREADED_OPTIMIZATIONS", "0");
if (!inheritIO) processBuilder.start();
else processBuilder.inheritIO().start().waitFor();
} catch (Exception e) {
System.err.println("There was a problem restarting the JVM.");
// noinspection CallToPrintStackTrace
e.printStackTrace();
}
return true;
}
private static String getJreErrMsg(boolean isMac) {
if (isMac) return MAC_JRE_ERR_MSG;
else return LINUX_JRE_ERR_MSG;
}
private static long getProcessID(boolean isMac) {
if (isMac) return LibC.getpid();
else return UNISTD.getpid();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

8
settings.gradle Normal file
View File

@@ -0,0 +1,8 @@
plugins {
// Applies the foojay-resolver plugin to allow automatic download of JDKs.
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
}
// A list of which subprojects to load as part of the same larger project.
// You can remove Strings from the list and reload the Gradle project
// if you want to temporarily disable a subproject.
include 'lwjgl3', 'core'