• Advertisement
Sign in to follow this  

C# How To Structure My Rogue-Like Game?

Recommended Posts

Hey,

 

So I'm currently working on my first serious project. It's basically a rogue-like combat game that focuses on melee. I want the combat to be a blend of Crawl and Hyper Light Drifter. Anyways, I've been thinking about how to structure the game and cannot organize my ideas. Earlier, I wanted to create a health system for my player. Instead of just adding one to my 'PlayerController' however, I made a generic one with variables and methods that would allow for generic data storage. You'd specify a max health, and then use a method to inflict damage whenever needed. There was also a method to check if the entity died.

 

 

I'm not sure if I can structure my whole project this way. So far my only other script is the one controlling player movement/attacks. I'm using Unity, so component-based design is a pretty big thing, Now I have to implement things like an XP system, a generic control for monster AI, and a template to define weapons. How should I approach all this code? How should I structure it? I took a look at this but still don't quite understand what it means.

 

 

The entire time I've been making games, I've just been doing my thing. I found out with my last decently sized project that just writing code is not a good idea. Can someone introduce me to some game design/structure principles?

 

Thanks.

Edited by Ovicior
Add Unity tag.

Share this post


Link to post
Share on other sites
Advertisement

So the problem you might have with the approach you took is being able to guarantee that a specific object has a specific module. So what would happen if a Crate Object was attacked but you hadn't given it a 'health' module? Sure you could go ahead and give it one but when you start entering things like: 0 health 100 damage reduction, into your modules just to avoid things crashing you are hacking your away around an issue.
Like wise, Unity provides functions for searching and checking for components being present:

SomeScript script = gameObject.GetComponent<SomeScript>();
if( script == null ) {
	// error out 
}

But that, while good coding practice to handle errors, is writing special exception cases for things you should be handling a little more consistently and smoothly. Also if the above code was to appear everywhere an entity tried to attack another entity, you would have a lot of redundant code that is prone to introducing errors.

So my suggestion would be to find some way of generalizing what actions can be taken in game. For example if you dictate something like "ALL objects that are physically present in the game are a subclass of class X" then you can place all your interactions that are possible in class X: hit, push, pickup etc. That way no matter what tries to 'hit' any object, for example, you know that it is an action that can be handled. Now of course you want to have every object act differently when interacted with. So that is where you could use the Strategy Pattern to 'attach' different behaviors to objects. Ask me directly later if you need help with the Strategy Pattern itself.

There are other ways to solve this problem of course, as is the way with programming, but this would be my specific recommendation. 

Share this post


Link to post
Share on other sites

It helps me a lot to think about everything in the game as an object, and then understand the concepts beyond gameobject hierchys and Interfaces(like the C# term not the User inteface one)

Everything in your game will likely be a gameobject, so you should create a gameobject prefab.

Anytime you update your GameObject prefab, those changes will happen globally to any prefabs using the GameObject prefab.

Then think about the people in your game world, because in my world ALL players/npcs interact with physics. So I built a character prefab.

The character prefab handles ALL environment related interactions.  If I build it right, I can build it once and never look at it again in a best case scenario.

Expand character into 2 new prefabs.

Player and Enemy

Player -> attach Controllers  to move character

Enemy -> Attach AI to move character.

 

Sorry if my explanation is weird, but the overall idea is think really really hard about your objects and try to make them as versatile as possible and slowly expand.  If you run into a physics problem 8 months into the development process, you don't want to have to look through 152 different objects with physics attached to them, you just want to try to fix 1.

Don't be afraid to write, and if you study UML that is not a bad place to start either.

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By RoKabium Games
      Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama
    • By Dave Haylett
      I'm using WriteableBitmaps in my project, and the tiffbitmapencoder and tiffbitmapdecoder classes to save off and restore a certain large graphic file from a WriteableBitmap to hard disc (the image is too big for the PNGbitmapencoder/decoder).
      This is working ok, but I'd like to encode to and decode from memory if possible, instead of having to save to disc. This is because, as part of the user experience this massive image can get wiped/cut down, and it takes a few precious seconds to reconstruct it again from scratch (which is also part of the user experience), but I can't afford the memory to just clone the whole image into another bitmap and clone it back again when needed, instead of rebuilding.
      Compressing it to TIF and holding in memory until it's needed again seems a viable option, but currently I can only compress/decompress to/from a file on disc.
      I've tried using MemoryStream instead of FileStream, and even though the encoder seems to like it, the decoder doesn't.
      Is it possible for me to achieve this?
    • By Dave Haylett
      Hi everyone. I need some help with my project. It's a 2D-graphics-heavy WPF front-end app written in C#, which talks to two Access 2000 databases (yes I know, it's all I've got). It will be distributed freely on the internet, and so will be being used by Windows users of various installations/versions of Windows, Office, etc.
      One of the two databases (let's call it A), is intended to be read-only, and will be distributed with the app. It has half a dozen relational tables which I as the developer have populated, and is connected to in the app via OleDB Jet 4 with SQL querying the data now and then as the user uses the front-end. The database will be replaced whenever I release an update to the app.
      Database B is read/write, and contains end-user preferences, for example when they favourite something in my front-end, a Favourites table in here gets appended to. This database is not distributed with my app, and should not be overwritten, as it will lose user prefs, etc. and annoy my users.
      Whenever my app is run by a user, during initialisation database A will suck in the user data from database B (using simple SQL SELECT * INTO...), so that all the tables can be joined together by the SQL in database A (to include user prefs/favourites in SQL queries), and whenever the user favourites something, a record is created both in A (for the short-term session) and B (permanently). Database B isn't just about holding favourites, there is other user data in here as well, so there are 3 or 4 tables in B.
      So far, this is all working fine and I'm happy...
      Unfortunately my app is currently 32-bit, and it now needs to break the 32-bit memory barrier what with the size and volume of the graphics I'm pulling in (using the HDD is not really an option, as different graphics are needed kind of instantly and the hard disc would be being hosed and the app dog-slow otherwise, I suspect even off an SSD).
      I'm using VS2015, and switching to 64-bit will probably fix the memory problem, but it breaks Jet 4.0. I'm sure this is old news to most of you.
      To try to keep with 32-bit (and Jet4) but get the memory I need I've tried the -largeaddressaware toggle, and I've tried the editbin suggestion, but I just can't get these solutions to work in VS2015 no matter how hard I try. Are these definitely 100% solutions to 2gb memory limit in 32-bit applications? Should they always work? Am I dumb in being unable to get this to work?
      So otherwise I'm resigned to migrating to 64-bit, and having to get around the database issue, not the memory issue.
      My users will be using a variety of Windows versions (probably 7 and 10), and I'm sure various versions of Office, and so my solution for querying my two Access databases needs to be pretty open if possible.
      Googling has suggested I switch from JET4 to ACE12, but this is apparently requiring me to uninstall Office 2000 and install a 64-bit version (which I don't have), so I can't use it, and I suspect any users who also have an old version of Office installed won't be able to use it either?
      Googling has also suggested I use MS SQL Server. This sounds fine if there's such a thing as a "lite" local version which can manage database access, but I still need to somehow get the data from the databases (A.mdb and B.mdb) into the SQL Server each time the users fire up my app.
      The only solution I can think of at the minute, is to export all the tables from database A into CSVs every time I update the data in there, and have the app import them in a lame way, and also convert database B into some crappy text file which gets written to whenever the user changes a preference. I'd much rather use SQL to do all this if possible, as when the user browses around the app, queries involving joining several tables in A are regularly created and executed to adjust the user's experience/return search results/etc.
      So to summarise my misery, is there either an easy reliable way for me to keep with 32-bit/Jet4 and be able to address >2gb. Or is there instead an easy reliable way for me to switch to 64-bit and successfully query two Access databases without requiring all my users to have 64-bit Office installed?
      Thanks for reading and I hope someone can help.
    • By eldwin11929
      We're looking for programmers for our project.
      Our project is being made in Unity
      Requirements:
      -Skills in Unity
      -C#
      -Javascript
      -Node.js
      We're looking for programmers who can perform a variety of functions on our project.
      Project is a top-down hack-and-slash pvp dungeon-crawler like game. Game is entirely multiplayer based, using randomized dungeons, and a unique combat system with emphasis on gameplay.
      We have a GDD to work off of, and a Lead Programmer you would work under.
      Assignments may include:
      -Creating new scripts of varying degrees specific to the project (mostly server-side, but sometimes client-side)
      -Assembling already created monsters/characters with existing or non-existing code.
      -Creating VFX
      -Assembling already created environment models
      If interested, please contact: eldwin11929@yahoo.com
      This project is unpaid, but with royalties.
       
      ---
      Additional Project Info:
      Summary:
      Bassetune Reapers is a Player-verus-Player, competitive dungeon crawler. This basically takes on aspects of dungeon crawling, but with a more aggressive setting. Players will have the option to play as the "dungeon-crawlers" (called the 'Knights', or "Knight Class", in-game) or as the "dungeon" itself (literally called the 'Bosses', or "Boss Class", in-game). What this means is that players can choose to play as the people invading the dungeon, or as the dungeon-holders themselves.
      Key Features:
      -Intense, fast-paced combat
      -Multiple skills, weapons, and ways to play the game
      -Tons of different Bosses, Minibosses, creatures and traps to utilize throughout the dungeon
      -Multiple unique environments
      -Interesting, detailed lore behind both the game and world
      -Intricate RPG system
      -Ladder and ranking system
      -Lots of customization for both classes s of customization for both classes
  • Advertisement