WeChat Official Account | WeChat Official Account |
---|---|
- coding live room: https://live.bilibili.com/11883038
- WeChat official account: DealiAxy
- Email: [email protected]
- Zhihu community: https://www.zhihu.com/people/dealiaxy
- CNBlog:https://www.cnblogs.com/deali/
For details of the project, please click
- The game engine XEngine is designed based on JavaFX.
- Use the self-developed game engine XEngine to realize the complete game function.
- Game Resource Management: Font, Picture, Audio Management
- Overworld Administration, Multi-Map Switching
- MVVM hierarchical design, code decoupling, module high cohesion
- Model system design, modular design
- Message System and Event Processing Implemented by Subscriber Mode
First, download the latest version and double-click the jar package to run, or
java -jar crazyalpha.jar
the code was built on openjdk8, notice that there is no javafx support in jdk11, so if you want to run or build the code, please use jdk8!
Game.Engine
:Self-implemented game engine packageAnnotation
:engine annotation package with engine-defined annotationsGameEventHandler
:Event Processor AnnotationsGameManager
:Annotations on various managers in the gameGameModel
:Model annotationsGameObject
: Game Object AnnotationsGameView
:View annotations for implementing MVVM layered design
Base
:Basic class package, contains various abstract base classes defined by the engineBaseModel
:Basic modelImageModel
:Basic graphic modelShapeModel
:Basic shape modelTextModel
:Basic text model
Enum
:definition of various enumerations (omitted)Utils
:Other tools (omitted)GameObject
:Game object base class, all objects are derived from this classGameView
:Other interfaces besides the main game interface are derived from the view base class
Game.EventHandler
:Contains all event handlersGame.Manager
:Contains various managers, maps, resources, data, models, events, etc.Game.Object
:contains definitions of all game objectsModel
:contains definitions of all game modelsGameMap
:Game Map ObjectGenerator
:Game Event Generator
Game.View
:view package, which contains definitions for all viewsGame
:Global game object, created using singleton modeMain
:Game main classRender
:Core renderer, responsible for rendering the game
In order to develop this game, I first developed a game engine based on JavaFX. The engine implements a series of functions from game resource management, model definition, to screen rendering, and is designed according to the design ideas of existing commercial game engines on the market. "The sparrow is small and complete," although it can't match other mature game engines, it is fully functional and can meet the development needs of most 2D games.
The top left is the logo of the game, the bottom left corner shows the highest score, and the following is the author information and version. In the lower right corner are two buttons, one to launch the game button and the other to exit the button.
The top left corner is the player's avatar, the current score, and the health value; directly above is the current level; the center of the picture is the big windmill, the big windmill emits letters following the music rhythm, the player needs to press the corresponding letter before the letters fly out of the screen to score.
The bottom left shows the game scores and whether to break the highest score. The return to the main interface button is displayed in the lower right corner.
This is my first time using Java to do game development. Previously, the understanding of Java language was limited to JavaEE. I recently learned about JavaFX. After using it for a while, I found out that JavaFX is so easy to use. GUI design framework, just use less people, I encountered a lot of problems in the development process, basically can not find domestic information, but also have a versatile StackOverFlow, in addition, Oracle official website documentation is quite detailed, thanks ~
For people like me who write a dynamic language like Python, the feeling of writing a lot of Java code is very cumbersome, but it is very worry-free, no need to brainstorm, no need to entangle the type of this parameter, you do not need to force Type checking, everything is clearly arranged by the IDE and JVM, I don't need to worry about the type of problem, and because the Java syntax is relatively rigid, there is not so much flexible writing, which is both a disadvantage and an advantage. The disadvantage is that for me. For those who like to show off their skills, writing Java code doesn't have much pleasure, but the advantage is the same function. The code that is implemented is basically the same. Different people will not have much difference in implementation. This ensures the code. Maintenance, you may now write a big project in Python, the code is all elegant, eclectic, very cool when writing, but when you refactor after the completion, you can't read the previous code, even though there are comments, but not every line of code has a comment, flexible writing increases the difficulty of understanding, so Java is absolutely dominant in large projects. The position is not a hole in the wind.
This game development has also deepened my understanding of the Java language, such as reflections, such as events. When I started doing event processing, I was a bit confused. Java is neither trusted nor really The concept of "event", everything is implemented with interfaces and classes. The implementation of interface functions is generally passed to the anonymous class that implements an event interface (of course, lambda expressions can be used in Java8), but this is not what it is. Big problems, these problems have other methods to solve, but it is more complicated to write. Maybe I used to write to C# before, so when I write Java code, I can't help but compare it, but in fact, the contrast between these two languages is not high, because the age of birth is different, C# is indeed better than language design. Java is much more sophisticated. In recent years, new versions of Java have been or are not mimicking the features of C# many years ago, such as Java8 lambda expressions, Java11 var definition variables, and so on.
In addition, this development of the small game makes me realize that the syntax is very simple, not as complicated and complicated as C# and C++, so it is especially friendly for beginners, because one will match the best IDE. : IDEA, it is easy to write a variety of projects, there is a saying that because the Java language itself has too few functions, so there are various design patterns to complement the Java language.