All Projects → matiasbeckerle → Doom Lgs

matiasbeckerle / Doom Lgs

A multiplayer Node.js light gun shooter inspired on Doom

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Doom Lgs

Tosios
The Open-Source IO Shooter is an open-source multiplayer game in the browser
Stars: ✭ 157 (+336.11%)
Mutual labels:  game, multiplayer, pixijs
Dodgem
A Simple Multiplayer Game, built with Mage Game Engine.
Stars: ✭ 12 (-66.67%)
Mutual labels:  game, multiplayer, socket-io
Open Builder
Open "Minecraft-like" game with multiplayer support and Lua scripting support for the both client and server
Stars: ✭ 569 (+1480.56%)
Mutual labels:  game, multiplayer
Gameproject3
游戏服务器框架,网络层分别用SocketAPI、Boost Asio、Libuv三种方式实现, 框架内使用共享内存,无锁队列,对象池,内存池来提高服务器性能。还包含一个不断完善的Unity 3D客户端,客户端含大量完整资源,坐骑,宠物,伙伴,装备, 这些均己实现上阵和穿戴, 并可进入副本战斗,多人玩法也己实现, 持续开发中。
Stars: ✭ 655 (+1719.44%)
Mutual labels:  game, multiplayer
Ancientbeast
Turn Based Strategy Game. Master your beasts! 🐺
Stars: ✭ 907 (+2419.44%)
Mutual labels:  game, multiplayer
Multiplayer Fps
🎮 A multiplayer first person shooter game based on Unity Game Engine
Stars: ✭ 404 (+1022.22%)
Mutual labels:  game, multiplayer
Lasercrabs
Launch your LASERCRAB at walls, ceilings, and enemy heads in this indie multiplayer shooter where "move" and "attack" are synonymous.
Stars: ✭ 465 (+1191.67%)
Mutual labels:  game, multiplayer
Veloren
[Mirror] An open world, open source voxel RPG inspired by Dwarf Fortress and Cube World
Stars: ✭ 868 (+2311.11%)
Mutual labels:  game, multiplayer
Stuntrally
The main repository containing Stunt Rally sources and game data. A 3D racing game based on VDrift and OGRE with track editor.
Stars: ✭ 314 (+772.22%)
Mutual labels:  game, multiplayer
Frag.exe
Multiplayer First-Person Shooter written in C++ using my own engine, Qor
Stars: ✭ 8 (-77.78%)
Mutual labels:  game, multiplayer
Librg
🚀 Making multi-player gamedev simpler since 2017
Stars: ✭ 813 (+2158.33%)
Mutual labels:  game, multiplayer
Retrotanks
RetroTanks: Atari Combat Reimagined, built in Meteor.js. Great isomorphic JavaScript example.
Stars: ✭ 9 (-75%)
Mutual labels:  game, multiplayer
Duckhunt Js
DuckHunt ported to JS and HTML5
Stars: ✭ 390 (+983.33%)
Mutual labels:  game, pixijs
Darkest Dungeon Unity
Darkest Dungeon port in Unity. Almost completely identical to the original. Platforms: PC/Android.
Stars: ✭ 378 (+950%)
Mutual labels:  game, multiplayer
Freeorion
Source code repository of the FreeOrion project.
Stars: ✭ 507 (+1308.33%)
Mutual labels:  game, multiplayer
Emptyepsilon
Open source bridge simulator. Build with the SeriousProton engine.
Stars: ✭ 341 (+847.22%)
Mutual labels:  game, multiplayer
Openspades
Compatible client of Ace of Spades 0.75
Stars: ✭ 769 (+2036.11%)
Mutual labels:  game, multiplayer
Gdk For Unity
SpatialOS GDK for Unity
Stars: ✭ 296 (+722.22%)
Mutual labels:  game, multiplayer
Phaserquest
Reproduction of Mozilla's BrowserQuest using Phaser, socket.io and Node.js
Stars: ✭ 313 (+769.44%)
Mutual labels:  game, socket-io
Khan
khan will drive all your enemies to the sea (and also take care of your game's clans)!
Stars: ✭ 22 (-38.89%)
Mutual labels:  game, multiplayer

DoomLGS

A multiplayer Node.js light gun shooter inspired on Doom. This is a proof of concept for a server/client game.

Play

Currently available for play in heroku.

Server

Runs on a Node.js server and uses socket.io library for communication. Sends snapshots of the game state to all the connected players several times per second, using a small structure to identify uniquely each instance of the game objects.

Insights

Server scripts are placed in /server folder and the main or bootstraper server.js file is located at root. All dependencies are defined at package.json and managed by NPM.

Game session is managed by the gameManager wich starts a cycle when the game is deployed to the server.

From server.js script:

gameManager.start();

From gameManager.js script:

/**
 * Starts a game iteration keeping two different ticks:
 *  - Snapshot will notify our players about the current game state.
 *  - Game will keep alive our game creating enemies, etc.
 */
var start = function () {
    snapshot = {
        dirty: false,
        players: 0,
        enemies: {}
    };
    tickSnapshot = setInterval(updateSnapshot, 100);
    tickGame = setInterval(updateGame, 3000);
};

With that code in mind the players will receive updates each 100ms and after 3s an enemy could be spawned too. Simple, right? Perhaps you are wondering how you send that snapshot to the players. The answer is listening for a game update.

From server.js script:

gameManager.onUpdate = function (snapshot) {
    socketManager.sendUpdate(snapshot);
};

What about socketManager? Is necessary too! That class stablishes a communication with players and sometimes it also emits a message (our snapshot).

From socketManager.js script:

/**
 * Sends an update to connected clients.
 * @param {Snapshot} snapshot The current game status.
 */
var sendUpdate = function (snapshot) {
    io.emit("update", snapshot);
};

But wait... what about listening? If someone enters our game the server is ready to listen for connections, disconnections and also player events like hitting an enemy!

From socketManager.js script:

/**
 * Starts socket communication.
 * @param {Http} http The recently created server.
 */
var listen = function (http) {
    io = socketio.listen(http);

    io.sockets.on("connection", function (socket) {
        // Add a new client
        addClient(socket);

        // Someone kills an enemy
        socket.on("enemyHit", function (enemyId) {
            SocketManager.onEnemyHit(enemyId);
        });

        // Someone goes offline
        socket.on("disconnect", function () {
            removeClient(socket);
        });
    });
};

Client

Uses Pixi.js as a game engine and socket.io library for communication. Consumes the snapshots provided by the server and handles all the game objects (populated with the game engine information) in the scene.

Insights

All client source files are placed inside /public. The dependencies are defined at bower.json file and managed by Bower.

  • /assets contains images and sound.
  • /build is used for building only, no files should be modified inside this folder.
  • /css contains the styles (not much to see here).
  • /lib contains the 3rd party libraries.
  • /scripts contains our game scripts.
  • index.html the only HTML required file.

I chose RequireJS for handling module loading because I'm familiar with. The boostrap file is main.js that defines some dependencies and starts the game.

From main.js script:

requirejs(["game"], function (Game) {
    Game.start();
});

Starting the game involves several things to consider. First of all there is the assets loading.

From game.js script:

// Where the game begins!
var start = function () {
    PIXI.loader
        .add("background", "/assets/e2m2.png")
        .add("soldier", "/assets/enemy.png")
        .load(onAssetsLoaded);

    ...
};

When the assets are loaded I proceed with mounting the scene and binding with networking in order to receive updates.

From game.js script:

function onAssetsLoaded(loader, resources) {
    // Add scene background
    scene.addChild(new PIXI.Sprite(resources.background.texture));

    // Append the view
    document.getElementById("game").appendChild(renderer.view);

    // Everything ready, force the first update
    Networking.forceAnUpdate();

    // Listen for updates
    Networking.update = function (updatedServerSnapshot) {
        update(updatedServerSnapshot);
    };

    UI.showGame();

    // Start animating
    animate();
}

There is the Pixi.js cycle too, similar to other game engines.

From game.js script:

/**
 * Pixi.js cycle.
 */
function animate() {
    requestAnimationFrame(animate);

    // Render the container
    renderer.render(scene);
}

Perhaps you are wondering what Networking does. That's right. Manages the communication with the server. An example is when the server sends a snapshot to the players.

From networking.js script:

// The server send us an update of the current game state
socket.on("update", function (updatedServerSnapshot) {
    // Check for changes
    if (updatedServerSnapshot.dirty || forceUpdate) {
        Networking.update(updatedServerSnapshot);
        forceUpdate = false;
    }
});

Another responsability of the Networking class is to notify about certain events. Suppose that a player hits an enemy, that needs to be reported to the server to validate because we are based on the authoritative server concept.

From networking.js script:

/**
 * Communicate to the server that an enemy has been hit.
 */
function enemyHit(enemyId) {
    socket.emit("enemyHit", enemyId);
}

Networking

Shared data between server and clients needs to be minimal. In order to achieve that goal I've created a networking EnemyN class to provide basic information about each enemy instance. Clients takes that basic EnemyN information and creates their own instances with more complex stuff like the sprite information. In this game minimal data consists only in: position and id.

Build

To build and run this game you will need to install Node.js and Gulp. Once the two are finished you only have to run the following command:

$ gulp

Task runner

Automating was done through Gulp because I wanted to learn about it. Yes, this projects has a lot of wanted-to-learn technologies and tools. Tasks are defined in gulpfile.js at root.

Testing

You don't want to take this as an example. The project started without testing in mind so it isn't so strong in that regarding. Anyways, there are some tests inside /test folder and runs thanks to Mocha, Chai and Sinon.

Disclaimer

Assets being used on this proof of concept are property of their owners: id Software. The only purpose is to learn about networking, I'm not trying to sell anything. Thanks for all the inspiration, id Software: John Romero, John Carmack, Adrian Carmack, Kevin Cloud, Tom Hall, Sandy Petersen, Shawn Green, Robert Prince.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].