JAVA open source game framework FXGL

This article is for populations with basic Java knowledge, follow this article to learn and can run Javathe game.

Author: HelloGitHub- Qin

HelloGitHub launched "to explain open source projects" series, today to give us an open-source Java games Framework Program - FXGLGames

Project Source address: https: //github.com/AlmasB/FXGLGames

I. Project Description

Say that Javalanguage is not nowhere, you can do a desktop program that can do background development, mobile application can do, you can do game development. The focus of this article, we will talk about a Javagame framework FXGL, it requires no installation or set up, out of the box, only local installation jdk8+can be. Games can be easily packaged as executable *.jarfiles, command line to run.

Second, run the project

2.1 precondition

  • Installation Jdk8 or later, full name of the Java Development Kit, which is a Java library functions is to compile and run Java programs toolkit.
  • Installation Maven3 environment, building project management and project dependencies.
  • Installation of development tools, such as: Idea, Eclipse, Spring Tool Suite and so on.
  • Git installation tool, use GitBash tools to download, submit code and other operations.

2.2 Download Project

Run the following code to download the project locally.

cd D:\devEnv
git clone https://github.com/AlmasB/FXGLGames.git

2.3 Running the Project

2.3.1 Run the executable file

Project binariesdirectory is already built a good game.

Local execute the following command, you can run the project.

java -jar xxx.jar

2.3.2 source code to build the project

Construction of the project by source, these projects are mavenprojects, execute the following code can build and run the project.

cd project_name
mvn clean package -DskipTests
cd target
java -jar xxx.java

2.3.3 game show operating results

  1. GeometryWars
    这个游戏已有构建好的可执行文件,在 binaries 目录,运行效果如下图:

  2. Mario(马里奥)
    这个游戏需要源码打包,参考上面步骤即可。注:此项目需要将 jdk 版本升级到 11,才可以构建和运行项目。运行效果如下图:

  3. Pacman
    这个游戏已有构建好的可执行文件,在 binaries 目录,运行效果如下图:

  4. BattleTanks
    这个游戏需要源码打包,参考上面步骤即可。运行效果如下图:

  5. SpaceInvaders
    这个游戏已有构建好的可执行文件,在 binaries 目录,运行效果如下图:

三、项目入门

接下来通过构建一个简单的例子,我们来看看进行游戏开发需要怎么开始。

3.1 本地创建 maven 项目

pom.xml 文件添加依赖:

<dependency>
    <groupId>com.github.almasb</groupId> <artifactId>fxgl</artifactId> <version>11.7</version> </dependency>

3.2 添加入口类

创建 BasicGameApp.java,文件内容如下:

package demo;

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.settings.GameSettings;

public class BasicGameApp extends GameApplication { @Override protected void initSettings(GameSettings settings) { settings.setWidth(600); settings.setHeight(400); settings.setTitle("Hello World"); } public static void main(String[] args) { launch(args); } }

3.3 运行效果

在开发工具直接右键 运行 入口类 BasicGameApp.java 即可,运行效果如下图:

四、最后

Java 无所不能是真的!本篇将的项目你 get 到了吗? Java 开发小游戏还是相当炫酷的!学习英语可以听英文歌曲、看英文视频等等方式。学习编程我想也可以通过开发一款游戏的方式来增加学习兴趣,感受编码的魅力。有了直观的视觉冲击可能更加能激发你的学习和动手能力! 通过我内容分享,能让更多的朋友们感受到开源项目的魅力,由而对编程产生兴趣,是我最大的乐趣!

教程至此,你应该也能快速运行游戏项目了。编程是不是也特别有意思呢?快邀请你的小伙伴一起加入到 Java 游戏开发乐趣中吧~

Guess you like

Origin www.cnblogs.com/lykbk/p/tyuytuu34343434.html