Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Ghost Hunt [Multiplayer PacMan] [Networked Prototype, 2-4 Players]  (Read 2793 times)

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev

Ghost Hunt - Multiplayer Prototype
Download Link
Source Code (Git Repository)

Description
Written for university coursework, this is a multi-player game modeled after Pac-Man where the player and ghosts are all human players. The game is written in Scala using JSFML for graphics and audio, should be cross-platform (tested on Windows and Linux). To run, download, unzip and launch either the ghosthunt shell script (Linux or Mac) or the ghosthunt.bat batch file (windows) in the bin directory.

Controls
In-Game
- W = Move Up
- A = Move Left
- S = Move Right
- D = Move Down

In-Menu
- Mouse Click = Select a menu item (text boxes, buttons, etc.)
- Keyboard = Typing for Host and Port

Goals
The goals of the 'Hero' are to collect all the pellets and avoid the ghosts.
The goal of the ghosts are to hound and catch the player.

Known Issues
Gameplay
- It is possible for the ghosts to make victory impossible for the player by simply not moving, as this means they'll remain covering a pellet.
- It is difficult for the player to loose the ghosts when they are detected, as they have no means of repelling or escaping except for moving around the maze.
- Gameplay with only 2 players is boring.
- Players can't decide whether to be ghosts or the hero, the server automatically assigns those.
- Players can't start a game, the "Start Game" button is on the host window and must be clicked by whoever is running the host.

Technical
- If the hero disconnects, then two hero characters will be displayed on screen when the server returns to the lobby and in the next game.

Screenshots



Credits
FilenameTitleArtistLicenseSource
font.ttfSensationBernd MontagFreewarehttp://www.dafont.com/sansation.font
title.oggWingsHalcyonic Falcon Xhttp://creativecommons.org/publicdomain/zero/1.0/http://open.commonly.cc/
game.oggThose Of Us Who FightHalcyonic Falcon Xhttp://creativecommons.org/publicdomain/zero/1.0/http://open.commonly.cc/
endgame.oggThat Which We Have Lost And ForgottenHalcyonic Falcon Xhttp://creativecommons.org/publicdomain/zero/1.0/http://open.commonly.cc/
player_death.oggShot Gun Soundluminalacehttp://creativecommons.org/licenses/by/3.0/http://soundbible.com/1706-Shot-Gun.html
beep.oggbeepCHydranoshttp://creativecommons.org/publicdomain/zero/1.0/http://www.freesound.org/people/Hydranos/sounds/237706/




Hello, I figured I'd post this here. I made this in about a week fairly easily using Scala and JSFML, with the networking code going through Java sockets, for my coursework. Having now more-or-less graduated (still got to get the ceremony), I figured I'd share it around a little before it vanishes into the aether. I got an A for this, don't ask me how.

But I do like the core gameplay idea, so am toying with porting it over to something a bit more portable, making it less obvious a pacman clone, improving the assets (I made the graphics, the graphics suck), fixing the issues with the gameplay, implementing AI to allow for single-player or for game-play with 2 players to be enjoyable. I want to know if people think that's a good idea or not.
« Last Edit: June 26, 2014, 11:24:09 am by MorleyDev »
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Ghost Hunt [Multiplayer PacMan] [Networked Prototype, 2-4 Players]
« Reply #1 on: June 26, 2014, 01:15:11 pm »

Had a quick look through the source code. Seems like you're using MVC, is that right? Would you care to say a little bit more about the technical design aspects of it? :)

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: Ghost Hunt [Multiplayer PacMan] [Networked Prototype, 2-4 Players]
« Reply #2 on: June 26, 2014, 04:08:40 pm »

Had a quick look through the source code. Seems like you're using MVC, is that right? Would you care to say a little bit more about the technical design aspects of it? :)

Sure. Well, something very close to MVC. I find the basics of the pattern maps to most software nicely, with appropriate allowances and modifications of course (such allowances may turn it into MVP, or MVVM or...you get the idea).

I cheat the pattern in a few points in this, since it wasn't written to be maintained on a long-term basis so I could afford to cut corners (same reason that there is no unit tests). Some controllers do more than they should, and should of been split down to multiple controllers. Plus I've done things a bit less cleanly here, normally I find it better to encapsulate the business logic into a services layer instead of putting it straight in the controllers. In the way I've seen and had the best experience with MVC, "model" is just DTOs and the services are the business logic, with a data access layer acting as the glue between models and services.

Considering I wrote most of this whilst on pain killers and antibiotics as a result of infected wisdom tooth, it's kinda surprising to me there's actually any structure to the code at all xD

This is what I wrote about the responsibilities of each package in my uni write-up:

---
uk.co.morleydev.ghosthunt :- The root package contains the base classes for the running of the program itself, the Main entry point and the Game as well as the ControllerStore and ViewStore used for managing the alive controllers and views

controller :- Contains the controllers for the running of the client and server, and the logical processing and updating of the game world and entities, through events, network messages or frame ticks.

The controllers are where the primary difference between the client and server lie. The key difference is in which controllers are used. The client uses predominantly reactive controllers that receive information about how to act, but do very little logic themselves aside from when user input is involved. The server’s controllers send more data, as they are responsible for collision detection between actors and informing the game of many of the possible state changes such as when the hero wins or loses, and when pellets are collected.

However, there is also an overlap of controllers used by both server and client. The physics code is the key example here, with the physics being ran each frame both remotely and locally. This allows the server to only notify the the client about the changes to the direction of actors and the client to independently process their physics, reducing the amount of communication needed between client and server.

view :- Contains the views responsible for displaying the game world to the user, displaying the appropriate entities as well as the maze and pellets that are visible to the user.

data :- Contains all data access logic, including interfaces for accessing files such as loading spritesheets and sound effects, the event queue, the message-passing client and server communication layer, the maze store and the entity-component store.

model :- Contains objects used to transfer information between different subsystems, either as parameters, through accessing the data store, through the event system or through network events.

util :- Contains generic helper classes that did not fit neatly into any other package
--

I also did a diagram that shows the network messages that are passed between the various controllers for the server and clients.


The actors in the game world (so player and ghosts) are managed via a simplistic Entity-Component System I wrote. This Entity-Component system is also hijacked to provide the simplistic UI elements, such as the text 'box' used to enter a host and port. Using an ECS for those GUI elements actually worked pretty well, all-in-all.

*digs up descriptions of Components*

---
Ghost :- The ghost entity is tagged with a ghost component. This component has one piece of information, a number that represents which of the 3 ghost sprites represent this ghost.

Player :- The player entity is tagged with the player component. This component contains no useful data, it’s presence is used to tell that the entity is a player.

Actor :- Both player and ghost have the actor component. The actor component contains a position field that stores the x and y coordinates of the entity, and a direction field that stores the velocity of the entity.

Remote :- Entities that are not being controlled by the current client, so all entities on the server and all but one entity on each client, are given the remote component. The remote component also stores a UUID that identifies that user, for when the entitiy is referred to over networking traffic, such as for the handling of MoveRemoteActorOnServer and MoveRemoteActorOnClient messages.

Local :- The entity being controlled by the current client is tagged with the Local component. This component contains no fields, but it’s presence is used to determine that the entity can be controlled by local keyboard input. It is not used by the server as a result.

There are additional components used for the user interface, such as MenuOption, Text and TextBox. These are used for GUI entities, that typically have a one-to-one mapping between the entity and component (a menu option entity only has one component, MenuOption).

MenuOption :- A series of clickable lines of text. The position and size of the text is stored in the component as a field, alongside the actual text for each line and which line is currently active (or -1 for none). This allows for the MenuOptionController and MenuOptionView to manage the menus easily, updating active menus and displaying the menus respectively, and for any controllers that need menus to create one and inspect if any of the menus are active to determine if an option has been selected.

TextBox :- A text box which, when clicked on, will take what characters are typed into the keyboard. There can also be an optional filter to limit the characters (defaults to basic ASCII printable characters), as well as a position and size for the text box. This is used by the server and client connection controllers to allow users to specify hostname and port as needed.

Text :- The simplest of GUI components, text simply has a position, size of the text and a string to display. This text is then rendered in the TextView. This is used by, for example, the server lobby to display what players are connected.[/quote]
---

This is where the player-disconnect bug occurs, as the entity tagged with the player component isn't being properly cleaned up in that scenario.
« Last Edit: June 26, 2014, 05:18:59 pm by MorleyDev »
Logged

IndigoFenix

  • Bay Watcher
  • All things die, but nothing dies forever.
    • View Profile
    • Boundworlds: A Browser-Based Multiverse Creation and Exploration Game
Re: Ghost Hunt [Multiplayer PacMan] [Networked Prototype, 2-4 Players]
« Reply #3 on: July 01, 2014, 05:10:43 pm »

You can fix some of the gameplay issues by giving the ghosts the limitations of Pac-man ghosts.  They have to keep moving, and upon reaching a crossroad, must turn either left, right, or straight.  Also, power pills.

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Ghost Hunt [Multiplayer PacMan] [Networked Prototype, 2-4 Players]
« Reply #4 on: July 02, 2014, 10:04:54 am »

Oops, totally missed the response! Just finished reading through it! Thanks for writing it. All in all it seems really well organised, like it!