Giter Site home page Giter Site logo

spacefx's Introduction

SpaceFX


A simple tiny space game written in JavaFX.

The "dev" branch contains new developments that might come to the game later on. The "simpleversion" branch is like the name says more simple and should also run on embedded devices etc. The "master" branch now contains some more fun things like enemies attacking in waves, a level boss that needs more hits to kill, enemies that drop bombs and an enemy boss that also fires rockets.

If you want to see/play it in a browser you can check it out at the jpro demo page

Donations are welcome at Paypal

Desktop and Mobile

Desktop

iOS

Android

Web

Youtube video

I've recorded a little video that shows the game in action.

Requirements for building a native package

If you would like to build a native package you should have at least JDK 13 installed on your machine. Make sure you run on Java13 and do a gradle clean build jar on the command line and execute the build app script e.g. bash build_app.sh. If everything worked ok you will find the native app in the folder /build/installer. To build a native package you will need the early access release of the jpackage tool. Please find more info here.

master branch

This branch is using gradle for the build and it needs JDK 17 with OpenJFX 17.0.0.1. On my machines I use Zulu for the JDK 17 installation and OpenJFX for the JavaFX installation. You should be able to fork the branch and open the build.gradle file in your favourite IDE as a project to run it from the code. To compile it you need to make sure you are on JDK13 and OpenJFX is installed, then execute the following on the command line.

OS X:

cd /PATH/TO/SpaceFX

./gradlew clean build

bash ./build_app.sh

Windows:

cd \PATH\TO\SpaceFX

.\gradlew.bat clean build

.\build_app.bat

Linux:

cd /PATH/TO/SpaceFX

./gradlew clean build

bash ./build_app_linux.sh

After that you will find the runnable jar file in

/PATH/TO/SpaceFX/build/libs

and the bundle created by the jpackage tool from JDK17 in

/PATH/TO/SpaceFX/build/installer

mobile branch

This branch uses maven for the build and it needs at least JDK 11. In principle you simply have to follow the instructions over at github from Gluon to make it run on iOS and Android. If you have the setup your system as mentioned on the github page with the Gluon examples you can build/deploy SpaceFX to your device as follows. To build/run it on iOS you need to run it on a Mac and to build/run it on Android you need to run it on Linux. First of all make sure you are on JDK11 and that you have installed all things described on github.

iOS: Make sure your iPhone is registered as a developer device at apple and is plugged into your Mac.

export JAVA_HOME=$GRAALVM_HOME

cd /PATH/TO/SpaceFX

mvn clean -Pios client:build

mvn -Pios client:run

The iOS spacefx.app file can be found at

/PATH/TO/SpaceFX/target/client/arm64-ios/

OSX:

export JAVA_HOME=$GRAALVM_HOME

cd /PATH/TO/SpaceFX

mvn clean client:build

The OSX spacefx binary can be found at

/PATH/TO/SpaceFX/target/client/x86_64-darwin

Android: Make sure your Android phone is a developer phone and is plugged into your Linux machine.

export JAVA_HOME=$GRAALVM_HOME

cd /PATH/TO/SpaceFX

mvn clean -Pandroid client:build

mvn -Pandroid client:run

The Android spacefx.apk file can be found at

/PATH/TO/SpaceFX/target/client/aarch64-android/gvm/apk/bin

Linux:

export JAVA_HOME=$GRAALVM_HOME

cd /PATH/TO/SpaceFX

mvn clean client:build

The Linux binary can be found at

/PATH/TO/SpaceFX/target/x86_64-linux

Keep in mind that at the moment there is no support for sound when using the GraalVM/Substrate combo.

###Attention: Because we use different build tools for the master and mobile branch at the moment it can lead to problems in your favourite IDE when switching branches. To avoid those problems just keep the following steps in mind:

When switching from the master to the mobile branch you should follow these simple steps:

  • remove the project from your IDE
  • close your IDE
  • switch branch from master to mobile
  • remove files/folders like .gradle, .idea, /build and /logs
  • start your IDE
  • open the pom.xml file as a project

When switching from mobile to the master branch you should follow these simple steps:

  • remove the project from your IDE
  • close your IDE
  • switch branch from mobile to master
  • start your IDE
  • open the build.gradle file as a project

Run SpaceFX in the browser using jpro

To run SpaceFX in the browser you will need to set the used JDK to 11 in the build.gradle file. In the future you will also be able to use JDK 13 etc. More info on how to run a JavaFX application in the browser can be found here jpro.

To make SpaceFX run in your browser you need to be on the master branch and execute the following steps: Open the build.gradle file in an editor and comment out the line:

//mainClassName = "$moduleName/eu.hansolo.spacefx.SpaceFX"

Now enable the line:

mainClassName = "eu.hansolo.spacefx.SpaceFX"

On the command line execute:

cd /PATH/TO/SpaceFX

./gradlew jproRun

Open a browser and go to localhost:8080

spacefx's People

Contributors

floriankirmaier avatar hansolo avatar miho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spacefx's Issues

Screen moving

Launched game in MS Windows has a big screen. So cannot see top and bottom borders

When trying to look where borders of game window ends usually used Alt+mouseLeft button and then moving.
But this option does not work for this window

UPD: other windows in MSWin seems also do not moving. So in would be great to change in-game window resolution.

Cannot run java 17

java -jar SpaceFX-windows-17.0.0.jar
Error: LinkageError occurred while loading main class eu.hansolo.spacefx.Launcher
java.lang.UnsupportedClassVersionError: eu/hansolo/spacefx/Launcher (class file version 60.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 61.65535

$java -version
openjdk version "17.0.4" 2022-07-19 LTS
OpenJDK Runtime Environment Zulu17.36+13-CA (build 17.0.4+8-LTS)
OpenJDK 64-Bit Server VM Zulu17.36+13-CA (build 17.0.4+8-LTS, mixed mode, sharing)

Strange behaviour of in-game controls

Before press left or right need to release all previous button like you drive with one finger.

Use case

  1. You moving left
  2. then moving right(finger from left button not removed, or removed later while moving right)
  3. trying to move left but spaceship just stopped even you still press left and Game waiting for when you release all buttons.

Starting SpaceFX with `./gradlew run` fails on OSX 10.14.6 with OpenJDK 12

Playing around with SpaceFX I found, that SpaceFX won't start from command using ./gradlew run.

Following error message was given:

> Task :run
No module was provided for main class, assuming the current module. Prefer providing 'mainClassName' in the following format: '$moduleName/a.b.Main'
Exception in Application init method
java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application init method
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:895)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
        at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: java.lang.ExceptionInInitializerError
        at spacefx/eu.hansolo.spacefx.SpaceFX.init(SpaceFX.java:271)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:824)
        ... 2 more
Caused by: java.lang.NullPointerException
        at spacefx/eu.hansolo.spacefx.PropertyManager.storeProperties(PropertyManager.java:71)
        at spacefx/eu.hansolo.spacefx.PropertyManager.createProperties(PropertyManager.java:105)
        at spacefx/eu.hansolo.spacefx.PropertyManager.readProperties(PropertyManager.java:94)
        at spacefx/eu.hansolo.spacefx.PropertyManager.<init>(PropertyManager.java:38)
        at spacefx/eu.hansolo.spacefx.PropertyManager.<clinit>(PropertyManager.java:31)
        ... 4 more
Exception running application eu.hansolo.spacefx.SpaceFX

Looks like something in the spacefx/eu.hansolo.spacefx.PropertyManager.

Could not create player to play mp3 file

when i try to run it , i got this:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class eu.hansolo.spacefx.SpaceFX
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:518)
at javafx.scene.media.MediaPlayer.(MediaPlayer.java:421)
at eu.hansolo.spacefx.SpaceFX.(SpaceFX.java:158)
... 13 more
Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:295)
at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118)
at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:474)
... 15 more

How do I build this on mac?

I tried to use the build-app.sh but got some errors. One is:
build_app.sh: line 69: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/jlink: No such file or directory

I got the directory but it does not contain jlink. Does this not work on java 8?
Can I build/run the game without creating a native package? I am more interested in the javafx aspects.

Automatic module jpro.webapi requires "badass" magic for jlink

Automatic module jpro.webapi requires "badass" magic for jlink to work.

The badass-jlink plugin takes a more pragmatic approach by combining all non-modular dependencies into a single jar. This way, only the resulting merged module needs a module descriptor.

The following error message is emitted by a plain jlink call:

Error: automatic module cannot be used with jlink: jpro.webapi from file:///.../sormuras/bach-hansolos-spacefx/lib/jpro.webapi.jar

It'd be cool, if SpaceFX (at least the master branch) either:

  • doesn't make use of code loaded from automatic modules at all, or...
  • ...jpro.webapi was provided a Java module with a compiled module-info.class.

Windows: Executable jar file very large

After building the project on Windows 10, the resulting executable jar file has a size of around 98 MB which seems a little bit too much to me. Most of this is caused by the png and sound files.

Some observations on import into Eclipse

This is not a real bug report, but summarizes what I found when importing this project into Eclipse (Version: 2023-03 (4.27.0)). Some of these may be just Eclipse-specific issues.

  1. After cloning the Git repository and importing the existing Grade projects into my Eclipse workspace, I get compile errors because the JavaFX classes are not visible to the compiler. I could fix that by moving the "Project and External Dependencies" from the classpath to the module path (in the Eclipse project 's Java Build Path)
  2. The Java compiler shows lots of warnings like "The type Color from module javafx.graphics may not be accessible to clients due to missing 'requires transitive'". I could fix these by adding "transitive" to the "requires javafx.controls" statement in "module-info.java".
  3. There are warnings about enum case labels which can easily be suppressed by adding a default case or an annotation.
  4. There are a handful of warnings left about unused imports, fields and methods.
  5. Executing the Gradle task "build" from within Eclipse succeeds.
  6. Executing the Gradle task "application > run" from within Eclipse leads to the error message shown below.

As said, I am unsure which of these issues are just Eclipse-specific.

In any case, thanks for your great work!

Working Directory: C:\Users\armin\git\SpaceFX
Gradle user home: C:\Users\armin.gradle
Gradle Distribution: Local installation at C:\gradle\gradle-7.6
Gradle Version: 7.6
Java Home: C:\Program Files\Java\jdk-18.0.1.1
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: run

Configure project :
Project : => 'spacefx' Java module

Task :compileJava
Task :processResources
Task :classes
Task :mergeClasses SKIPPED

Task :run FAILED
WARNING: module-info.class ignored in patch: C:\Users\armin\git\SpaceFX\build\classes\java\main
Error occurred during initialization of boot layer
java.lang.module.FindException: Module eu.hansolo.spacefx.Launcher not found

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':run'.

Process 'command 'C:\Program Files\Java\jdk-18.0.1.1\bin\java.exe'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.6/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 8s
3 actionable tasks: 3 executed

Big background image causes crash on iPad

SpaceFX works fine on iPhone, however, when deploying to an iPad (Mini 4), it crashes due to a very big background image:

new Image(getClass().getResourceAsStream("backgroundL1.jpg"), 700 * BKG_SCALING_FACTOR, 3379 * BKG_SCALING_FACTOR

iPad visual bounds: 768x1004, image size: 781x3769. It is not that big, but it seems there is no enough memory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.