Giter Club home page Giter Club logo

phaserquest's Introduction

phaserquest

Phaser Quest is a reproduction of Mozilla's Browserquest using the following tools:

🔥 If you are interested in this project, you may also be interested in Westward, an open source Javascript MMORPG that I am working on! 🚀

Quick tour of the code

Client

The game canvas and the game states are created in js/client/main.js. The Home state is started first, and will display the home page of the game. The Game state is started upon calling startGame() from the Home state.

js/client/game.js contains the Game object, which corresponds to the Game state and contains the bulk of the client code. Game.init() is automatically called first by Phaser, to initialize a few variables. Game.preload() is then called, to load the assets that haven't been loaded in the Home state. When all assets are loaded, Phaser calls Game.create() where the basics of the game are set up. At the end of Game.create(), a call is made to Client.requestData() (from js/client/client.js) to request initialization data from the server. Upon reception of this data, Game.initWorld() is called, which finishes starting the game. The main update loop of the client is Game.update().

Server and updates

server.js is the Node.js server that supports the game. Most of the server-side game logic however is located in js/server/GameServer.js. Every 200ms, GameServer.updatePlayers() is called, and sends updates to all clients (if there are updates to send, as determined by the custom interest management system). Client-side, these updates are processed by Game.updateWorld() and Game.updateSelf().

The code used for the custom binary protocol for the exchange of update packets can be found in js/client/Decoder.js, js/server/Encoder.js and js/CODec.js.

Installing and running the game

For the client, everything is included in the code (phaser.js, easystar.min.js, ...). You will need npm to install the Node.js packages required for the server. To run the server, you'll need to have Node.js installed, as well as MongoDB.

Clone the repository. Inside the newly created directory, run npm install to install the Node.js packages listed in package.json. Make sure that you have MongoDB running, then run node server.js to start the game server. By default, it'll listen to connections on port 8081; you can change that behaviour by using the -p flag (e.g. node server.js -p 80). By default, it'll attempt to connect to MongoDB on port 27017; you can change that behaviour by using the --mongoPort flag (e.g. node server.js --mongoPort 25000).

Here you will find a step-by-step guide how to run and manage the application locally.

Using Docker

Alternatively, you can use the Dockerfile to create a container with all the necessary components already installed (thanks to Martin kramer for the corresponding pull request). You need to have Docker installed. Then, in the directory where you clones the project, run:

docker-compose build
docker-compose up -d

The default port when using the Docker way is 80, so you need to navigate to <IP_of_your_Docker_machine>:80 to be able to access the game (e.g. 192.168.99.100:80).

Modifying the map

In assets/maps/, you can find phaserquest_map.tmx, which is the Tiled file of the map of the game, to be edited with the Tiled Map Editor. One you have made modifications in the Tiled file, you need to export it as a JSON file. But that file will contain a lot of layers, a legacy from how the original Browserquest map was designed. A lot of layers will translate to a very poor performance with Phaser, which is a shame since most of these layers contain only a few tiles. The solution is to "flatten" them to cram as many tiles as possible in the same layers. You can do so by running formatMap() from js/server/format.js. It will look for a map.json file in assets/maps and output two new files, the flattened map files for the client and the server.

Note: It is recommended to use Tiled in version 1.1.6 or lower, which can be found here:

Map JSON format has changed in Tiled in higher versions. Cause of that provided tmx map won't be exported to JSON format supported by format.js script.

Further documentation

I have written and will keep writing articles about some development aspects of the game. The full list of existing articles is available here.

Here is the detail of the topics covered so far:

Donate

If you want to support me to make more open-source projects like Phaser Quest, consider having a look at my donation page. In particular, take a minute to have a look at my Patreon page, where you can find a listing of rewards for various levels of recurring contributions!

phaserquest's People

Contributors

brandonhanks avatar dependabot[bot] avatar frycz avatar jerenaux avatar kaundur avatar pastew avatar shockwavemk avatar sportanova 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  avatar  avatar  avatar  avatar  avatar

phaserquest's Issues

Game locks up on "Creating World..."

I have the server running OK, and the client seems to load. I type in a character and click "new game". But then the game basically locks up on the phrase "Creating World..."

Is there something I have to do to initialize the Mongo DB? I have Mongo DB installed on the default port and everything. I also made sure all the ports were open on the firewall, etc.

Is there any configuration that needs to be done, to get this to run on a particular server install?

Chat system not working

Hey,

Been having some issues with chat messages not being sent through by the server.
So this bit
rooms.forEach(function(room){
socket.broadcast.to(room).emit('chat', {id:playerID,txt:txt});
});
doesn't seem to work for me.

Any ideas?

How to fix

Listening on 8081
/root/phaserquest/js/server/GameServer.js:686
GameServer.dirtyAOIs.forEach(function(aoi){
^

TypeError: Cannot read property 'forEach' of undefined
at Object.GameServer.clearAOIs (/root/phaserquest/js/server/GameServer.js:686:26)
at Timeout.GameServer.updatePlayers [as _onTimeout] (/root/phaserquest/js/server/GameServer.js:679:16)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)

How to fix that?

How to edit the sprites

Is there a specific tool that we can use to easily edit the sprites JSON and PNG, or are there some kind of atlas format files missing ?

Format script does not work with Tiled versions higher than 1.1.6

Context

Map JSON format has changed in Tiled in versions higher than 1.1.6. Cause of that provided tmx map in phaserquest won't be exported to JSON format supported by format script.

Issue

format script throws an error when formatting JSON map exported from Tiled in versions higher than 1.1.6:

➜  server git:(master) node -e 'require("./format").format()'
Formatting ...
/Users/adamsawicki/Kodowanie/phaserquest/js/server/format.js:62
                    var tileProperties = map.tilesets[0].tileproperties[layer.data[j]-1];
                                                                       ^

TypeError: Cannot read property '-1' of undefined
    at /Users/adamsawicki/Kodowanie/phaserquest/js/server/format.js:62:72
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:61:3)

This, in turn, makes running edited map impossible.

Possible solution

Provide information to developers that using Tiled version 1.1.6 or lower is a workaround for the issue.

Alternative solution

Modify format script to the new JSON format.

Additional information

More details can be found in this thread: https://discourse.mapeditor.org/t/are-old-versions-of-tiled-available/3721/4

TypeError: GameServer.server.db.collection is not a function

What have I done?
I followed the instructions and ran node server.js.

What happened?

Listening on 8081
(node:934736) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Map read
Connection to db established
connection with ID M1nFdvQFOeBD6vjvAAAA
0 already connected
/home/marek/phaserquest/js/server/GameServer.js:268
    GameServer.server.db.collection('players').insertOne(document,function(err){
                         ^

TypeError: GameServer.server.db.collection is not a function
    at Object.GameServer.addNewPlayer (/home/marek/phaserquest/js/server/GameServer.js:268:26)
    at Socket.<anonymous> (/home/marek/phaserquest/server.js:117:16)
    at Socket.emit (events.js:314:20)
    at /home/marek/phaserquest/node_modules/socket.io/lib/socket.js:503:12
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

Nginx Reverse Proxy

Thank you so much for this! I've been tinkering with BrowserQuest for a while with limited success. I am going the Docker route. I have PhaserQuest working locally using a docker with an alternative port. When I forward the container, the main page loads but displays a black screen. After investigating, the folder 'assets' and 'socket.io' are trying to be loaded from the main access point, in this case 'pq'. I can access the folders if I put 'pq' in front of the URL but I cannot seem to forward those two folders properly. Do you have any ideas?

Starting server (server.js) error

Thanks for your great job. I am very interesting PQ, wanna run ASAP.
BTW, I faced error when I start server.

[root@localhost]# node server.js
Listening on 8081

/home/neoguru/html/pq_test/js/server/GameServer.js:84
Object.assign(GameServer.db.entities,GameServer.db.client_entities); // me
^
TypeError: Object function Object() { [native code] } has no method 'assign'
at Object.GameServer.readMap (/home/neoguru/html/pq_test/js/server/GameServer.js:84:12)
at Server.io.on.socket.pings (/home/neoguru/html/pq_test/server.js:85:8)
at Server.g (events.js:180:16)
at Server.emit (events.js:92:17)
at net.js:1056:10
at process._tickCallback (node.js:458:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:945:3

I am not fix mongoDB yet. Do I have to set it first?

Grid size different to original BrowserQuest map

Inspecting the original tmx file its map file width is 16px.

However the new tmx file in phaserquest is different, being 32px.

When my 16px grid map is run under phasequest, things are displayed 1/4 the size:

canvas

Changing the grid size didn't enlarge things. Is there something I need to do?

Hey man, Do you have the files for editing maps

Hello,

As you may well know I'm the author of the RPG Mod Branch.
I was wondering do you have the file exports for map editing? I was hoping to polish it a bit and eventually import some of my own maps into the game.
Kind regards,
Josh L.

Very Interesting

I've been working with BrowserQuest for a couple years now, and this is something new indeed. I am loving it thus far, though it seems a bit choppy around the edges. Anyway, what is the compatibility with mobile devices? Does this take away from that of the original BQ?

Regardless, I am re-writing BQ from absolute scratch (still maintaining some aspects) and still using the canvas system, and thus far I have improved the rendering tremendously. I encourage you to take a look at my repository :)

https://github.com/Tach-Yon/Kaetram

How to modify the configuration,help

Hello, I need your help, I want to modify

assets\json\db.json;

assets\json\entities_ client.json;

assets\json\entities_ server.json;

assets\sprites\atlas1.json;

But I don't know how to generate this file. Is there any tool or manual modification?

Creating an offline version of Phaserquest

Hi there, I would first like to apologize since this is not exactly an issue. But I really want to create an offline version of Phaserquest with some scope update to make the game smaller as I would just like an RPG game that takes around 1-2 hours to finish to teach my brother some concepts through gamification. I was just wondering how feasible would it be to do this? I would like to add some new npcs with the sprites from BQ and also a quest system as well. Thank you!

Deleting grass layer cause character to display above "v" tiles instead of behind

It seems when grass layer is deleted, character would be displayed on above tiles which it shouldn't (e.g. house roofs, top of trees).

(However I can only reproduce it from my own tmx file)

** Update **

I think this has something to do withnbGroundLayers being 4. I changed it to 1 (to suit my need) and things works now. Not sure how to properly fix this though. I don't see a similar 4 in browserQuest source code. Why is it necessary here?

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.