├── .gitignore
├── .vscode
├── settings.json
└── tasks.json
├── README.md
├── assets
└── .keep
├── project.flow
├── server.hxml
└── src
├── BuildInfo.hx
├── Main.hx
├── game
├── GameState.hx
├── Object.hx
└── World.hx
└── mp
├── Command.hx
├── Message.hx
└── Server.hx
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | /client.hxml
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "haxe.displayConfigurations": [
3 | ["client.hxml"],
4 | ["server.hxml"]
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "problemMatcher": "$haxe",
4 | "tasks": [
5 | {
6 | "taskName": "build web",
7 | "command": "haxelib",
8 | "args": ["run","flow","build","web"],
9 | "isBuildCommand": true
10 | },
11 | {
12 | "taskName": "build desktop",
13 | "command": "haxelib",
14 | "args": ["run","flow","build"],
15 | "isBuildCommand": true
16 | },
17 | {
18 | "taskName": "build server",
19 | "command": "haxe",
20 | "args": ["server.hxml"],
21 | "isBuildCommand": true
22 | },
23 | {
24 | "taskName": "generate client.hxml (web)",
25 | "isShellCommand": true,
26 | "command": "haxelib run flow info web --hxml > client.hxml"
27 | },
28 | {
29 | "taskName": "generate client.hxml (desktop)",
30 | "isShellCommand": true,
31 | "command": "haxelib run flow info --hxml > client.hxml"
32 | }
33 | ]
34 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HKOSCon2017 Haxe Game Workshop
2 |
3 | [](https://gitter.im/hkoscon2017-haxe-game/Lobby?utm_source=badge&utm_medium=badge&utm_content=badge)
4 |
5 | Workshop info: [Build a cross-platform game in Haxe](https://hkoscon.org/2017/topics/build-a-cross-platform-game-in-haxe/)
6 |
7 | This is an [agar.io](https://agar.io/) clone to demonstrate the capability of Haxe in building cross platform games,
8 | where codes are shared among multiple game platforms (web, mac, windows, android & ios),
9 | as well as between game client and game server for multiplayer games.
10 |
11 | Demo: https://kevinresol.github.io/hkoscon2017-haxe-game/ (single player mode)
12 |
13 | ## Preparation
14 |
15 | Participants should have programming experience with at least one programming language. Proficiency with JavaScript, Java, or C# is ideal, but experience with other languages such as C/C++, Python, or Ruby is also sufficient. Participants should have some familiarity using the command line. Participants should bring their own laptop computer, with either Windows, Mac, or Linux installed.
16 |
17 | Please follow the instruction listed below before the workshop, such that you can progress smoothly.
18 |
19 | ### Install Haxe
20 |
21 | Get Haxe from http://haxe.org/download/.
22 |
23 | ### Install Node.js
24 |
25 | Get Node.js from https://nodejs.org/, and optionally [yarn](https://yarnpkg.com/).
26 |
27 | ### Install Git (used by snowfall)
28 |
29 | Get [Git](https://git-scm.com/) and make it available in the command line. i.e. `git --version` should print something like `git version 2.7.4`.
30 |
31 | ### Install Haxe Libraries
32 |
33 | Note: if it is the first time you are using `haxelib`, you will have to run `haxelib setup` first.
34 |
35 |
36 | * [Luxe](https://luxeengine.com). According to the instruction at https://luxeengine.com/get/:
37 |
38 | ```bash
39 | haxelib install snowfall
40 | haxelib run snowfall update luxe
41 | ```
42 |
43 | * [haxe-ws](https://github.com/soywiz/haxe-ws)
44 |
45 | ```bash
46 | haxelib install haxe-ws
47 | ```
48 |
49 | * [hxnodejs](https://github.com/HaxeFoundation/hxnodejs)
50 |
51 | ```bash
52 | haxelib install hxnodejs
53 | ```
54 |
55 |
56 | ### Install Visual Studio Code
57 |
58 | Although in theory you can use any [IDE or text editor](https://haxe.org/documentation/introduction/editors-and-ides.html), we recommend using [Visual Studio Code](https://code.visualstudio.com/) with the [Haxe Extension Pack](https://marketplace.visualstudio.com/items?itemName=vshaxe.haxe-extension-pack), which offers the best Haxe support at the moment.
59 |
60 | ### Install C++ development tools
61 |
62 | (Optional, for building native targets, e.g. mac, windows, linux, ios, android)
63 | Depending on your OS, [Visual Studio](https://www.visualstudio.com/) (Windows), [XCode](https://developer.apple.com/xcode/) (Mac), or gcc (Linux).
64 |
65 | ## Notes
66 |
67 | We will introduce Haxe and go through creating a simple multi-player game during the workshop together. The instruction will be given during the workshop. Below are some notes for future reference.
68 |
69 | ### quick links
70 |
71 | * Haxe Manual: http://haxe.org/manual/introduction.html
72 | * Haxe API docs: https://devdocs.io/ (or http://api.haxe.org/)
73 | * Try Haxe: https://try.haxe.org/
74 | * Luxe engine beginners guide: https://luxeengine.com/guide/
75 | * Luxe engine API docs: https://luxeengine.com/docs/api/
76 | * `haxe-ws` library: http://lib.haxe.org/p/haxe-ws
77 | * `ws` npm package: https://www.npmjs.com/package/ws#usage-examples
78 |
79 | ### Server
80 |
81 | ```bash
82 | haxe server.hxml
83 | cd bin/server
84 | npm install ws # or `yarn add ws`
85 | node server.js
86 | ```
87 |
88 | ### Client
89 |
90 | ```bash
91 | haxelib run flow run web
92 | haxelib run flow run mac
93 | haxelib run flow run windows
94 | ```
95 |
96 | By default the game client is built for multiplayer mode (yes, multiplayer/singleplayer is determined at compile-time for simplicity).
97 | To build for single player mode, simply go to `project.flow` and comment out the `MULTIPLAYER` flag:
98 |
99 | ```
100 | // defines : ["MULTIPLAYER"],
101 | ```
102 |
103 |
104 | To give proper code completion, VS Code needs a hxml file, which can be generated by
105 | ```
106 | haxelib run flow info [web|windows|mac|linux] --hxml > client.hxml
107 | ```
108 | See https://github.com/vshaxe/vshaxe/wiki/Framework-Notes#snow.
109 |
110 | ### Shared Code
111 |
112 | The `World` class contains the core game logic.
113 | When the game is set to single-player mode, the `World` is run in the client.
114 | In other words, the same piece of Haxe code for the `World` class is compiled into different platforms
115 | (web, mac, windows, android & ios).
116 | When the game is in multi-player mode, the `World` is run on the server. Again, the same piece of
117 | Haxe code for the `World` class is compiled into the server language (nodejs for our choice here).
118 |
119 | The `Command` and `Message` enums represents the protocol between the client and server in multiplayer
120 | mode. The same piece of code is used in both client and server.
121 |
122 | ## Feedback / Questions
123 |
124 | Feel free to [open issues](https://github.com/kevinresol/hkoscon2017-haxe-game/issues) or contact us directly.
125 |
126 | ## License
127 |
128 |
129 |
131 |
132 |
133 |
134 | To the extent possible under law,
135 |
136 | Andy Li & Kevin Leung
137 | has waived all copyright and related or neighboring rights to
138 | "Build a cross-platform game in Haxe" workshop.
139 | This work is published from:
140 |
142 | Hong Kong.
143 |