Thought problem - how would you approach this?

Hi all,

Long time/first timer. I’m considering a new game as in class I’ve made two smaller ones, but want to up my game and make something bigger. I’m thinking of a quasi turn-based RPG. What I want to do is make your character and your enemy(s) have combat in a grid-space. Imagine a 10x10 grid - your character is on one side, the enemy on the other. Your character has a certain range to attack, can move a certain number of grids, etc. The grids themselves may have objects on them to block ranged attacks, could have spells on them to effect your offense/defense stats, etc. I’ve been thinking it over and have a decent handle on all the variables the character/enemy would have, but dont’ know how to approach the grid.

How would you approach it? Each individual grid square has to hold it’s condition (ie if it has an item on it, character, spell effect) as well as geographic position. Part of me thinks I can put these all in fixed positions, ie maybe the first grid is at centered at position 0,0 (x,z coordinates) and the next one is at 1,0 (assume each grid is .5 meter). Then characters just raycast through invisible colliders. I also thought of doing an array, one for each row/column.

Those are the ideas have, but am hoping someone can approach this problem from a whole other angle. Thanks for reading and I appreciate any feedback!

Greg

Sounds like a smaller version of a tactical rpg… something like Shining Force:

Note the gameplay, you’re on a grid, you move around, and the tile you’re on effects your player. If you’re in the woods you move slower, but if you attack from the woods to say a road, you have a higher chance of performing a critical.

There’s tons of other games like it as well. Final Fantasy Tactics and Ogre Tactics are two critically acclaimed games in the style. I myself, being an old school Sega nerd tend towards my Shining Force.

Anyhow, as for your problem.

I’d have a class representing a tile in the grid. This class would contain properties defining all the modifiers of that tile.

I’d have another class that represented the grid. In which I stored all the tiles… internally I’d probably just store them tiles in an array or list… they work well for grids.

On this class I’d have methods for getting the tiles, querying the neighbor tiles, etc. This could be useful to implement along side some A* system so I can pathfind over it as well using the modifiers of each tile as weights in the A* system.

Then when in battle, you just pull the tile you’re on, apply the modifers to the players attack, and do attack like usual.

Thanks for the feedback. It’s almost like I want to make a checkerboard, where each tile has it’s own properties and I can create functions to determine the distance between the tile the player is on and the tile the enemy is on.

I can see how this would work - you have each tile have a fixed position, graphical representation, and other properties. Then put in some functions to query the distance between that and another tile. This would be one huge script - what object in Unity would you put it on? A blank gameobject, where you stack the individual tiles into? I’m trying to think how it’d work out in Unity…

I would like to point out that you can write classes that don’t necessarily have to be MonoBehaviours that you attach to GameObjects. They can just be a class of any generic sort.

Also I personally would separate the ‘graphical’ aspect of a tile from the ‘visual’ aspect.

Why does a tile have to have a visual aspect to it? Why can’t it just be I have a terrain drawn however I pleased using models and the sort… and then an invisible grid (maybe add a method to draw the grid as gizmos for testing purposes?) that is represented in memory that overlays whatever the terrain is.

This class wouldn’t really be that big.

Well… it’d probably be 2 classes:

class Tile

  • Id : string
  • Weight : float
  • SomeAttribute : *
  • SomeOtherAttribute : *

class TileGrid

  • GetTiles() IEnumerable
  • SetTile(t:Tile, row:int, col:int ) : void
  • GetTile(row:int, col:int) : Tile
  • GetNeighbors(t:Tile) : IEnumerable
    … etc

Then say you wanted a path finder to find shortest paths from one tile to another…

class TileGridAStar

  • FindShortestPath(grid:TileGrid, start:Tile, end:Tile) : Path

class Path

  • GetPathFromStartToFinish() : IEnumerable

And of course all these classes could be decorated with more methods as helpers. Like treat the Path as an Enumerator to traverse easily.

That makes a lot of sense, having the different classes like you’ve laid out there. There doesn’t necessarily have to be a graphical element. Imagine you were in a cave. I wouldn’t mind you seeing the cave floor - but maybe a shiny white ‘grid’ overlays it. That way when it’s the player’s turn, the player can select ‘move’ and then move the cursor over the grid to select where he’s moving to. I’m going to play around with making these classes and see if I can get it to work, just selecting shortest path, making a raidus of certain grid tiles, etc. Thanks for your feedback!