help with DungeonGame

Started by
13 comments, last by PeterVercauteren 12 years, 6 months ago
Hi,

So I recently started writing code in XNA C#.
I managed to pull off some gametests and movement (minigolf & pong).

Now after a few tutorials and articles I created a multilayered TileEngine (most code comes from XNAresources.com)
A start for my simple dungeon runner (d&d, descent boardgame like).

But what I'm curious for is, how to manage my code.

I suppose you guys are familiar with the gameboard Descent or d&d like games.

a Tile can be made from just dirt, ice, lava, mud, .... these have certain caracteristics (like slowing movement, damage players)
or a trap can be set onto that tile by the dungeon master.

Now is it best for me to write a set of properties like

single slow = 1;
single damage = 5;
...



or use something like

tile type = ice;

'or

tile type = lava;



Also any suggestion on how to proceed any further? Networking will be used somewhere next year.

my idea is to introduce a card system, which will propably be a list of cards in an xml file.
There will be several types of cards (items, player improvments, DM improvments like traps, spawns, ...)

What would be a good way to implement the use of these cards? as some can be used whenever a player wants (in the DMs turn for example)
I suppose a better question would be, how to implement the turn function? (movement, attack, ..., next player, DMs turn)


Regards
Peter
Advertisement
The most simple way i'd say is to make just one tile class and put all the properties in it like damage, movement cost, texture, etc.

You can also make a base tile that holds the position, texture etc and make derived classes for the different types. This can save a lot of space for saving maps since not all tiles will have a slow or damage attribute so with this method it doesn't need to write that to file.

Obvious there are many ways to handle this, you can also make just a string in the class that plainly says what type of tile it is and do the calculations afterwards but this can be anoying if you want to change stuff in the future.

I haven't actually made a game like that before but I'd go for using the tile type technique. Unless you can think of an instance where you'd need say a bunch of mud tiles to slow the player down by varied amounts. But it's more likely that you'll want the tiles to be consistent in what they do no matter where you put them so that you can better predict what will happen in a particular area.

For your card system you may want to try looking into some sort of a queue system. Card effects would be executed in the order in which they make it into the queue rather than waiting for one specific turn. Or you can make sure there's a particular phase during the DMs turn in which a player can play his card and if the player misses that opportunity, then too bad. There will be pros and cons with whatever system you decide to go with. But one of the nice things about the style of game that you seem to be making is that you can probably test it out with pen and paper first to determine which technique works best.
Well I'll be trying to do a combination of the 2.
So just set a type of the tile and save the coordinates for calculation purposes between 2 tiles.

One thing that bothers me thought is corners and line of sight. I was thinking of using a tiletype like for example "Block(texture)"
with this I can set for example wall, statues, columns, ...

But then the line of sight is from center of tile1 to center tile2. How do I check if in between there are blocks?

And about these turn events? any thoughts? :)
You should use enums to denote the "type" of tile as they can be easily changed later and provide an easy way to change a tiles data in its constructor:

Pseudo

enum TileType {empty, mud, lava, rock}

locationX
locationY // On the grid
TileType type // What type we are

// Add any special data here (but do not initialise)
burnAmount; // Lava
slowAmount // Mud
canBuild // All

// Constructor
public Tile (locationX, locationY, TileType type) {
locationX = locationX
locationY = locationY
type = type

// now switch for different types
switch(type) {
case Lava:
burnAmount = 100;
canBuild = false;
case Mud:
slowAmount = 100;
canBuild = false;
case Rock:
canBuild = true;
}
}



This is also extendible:


public TileOfDoom extends Tile(TileType type, SecondaryTileType type2) {
super(type)

switch(type2) {.... etc
}


For the turn system, add different stages to your game loop with some kind of identifier (probably enums again):


enum TurnType {playerMovement, playerAttack, dungeonMaster, any};

TurnType currentTurn = playerMovement;

while(gameIsRunning) {
update()
buffer()
render()
}

update() {
switch(currentTurn) {
case playerMovement:
playerMovement(); // Run player movement
currentTurn = TurnType.DungeonMaster // Switch to new turn type
}
}

// For checks against whether a player can place a card (they will probably come from your input watcher / handler)
if(game.currentTurn = playerMovement) // Can only play card during the players movement phase

if(game.currentTurn = any) // Can play whenever


For "straight" lines of sight something very basic is:



function checkTile(Tile tile, Tile tile2) // Check if tile2 is visible from tile1

// Run this and modify for each direction... I'll just show you NORTH
playerVision = 10; // Block vision of the player
checkDistance = Math.max(playerVision, (player.getY - map.Height) // Find the bigger value, the amount the player can move North or the players vision length

boolean obstructed = false;
for(int i = 0; i < checkDistance; i++) { // For each block to check vision for
if( tile.getTile( (player.getX, player.getY - i) . type == blockerType) // Check if any of the blocks are not see through and break if we find one
obstructcted = true; // Blocked!
break; // Don't check further
}




One thing that bothers me thought is corners and line of sight. I was thinking of using a tiletype like for example "Block(texture)"
with this I can set for example wall, statues, columns, ...

But then the line of sight is from center of tile1 to center tile2. How do I check if in between there are blocks?


Coming up with a general line-of-sight (or "field-of-view") procedure for grid based maps can be complicated. I'd recommend reading about the different algorithms here, and there is a comparison of various algorithms here
@[color="#1c2837"]Viscis: Thanks alot, these codes are quite usefull :)
[color="#1c2837"]I'll continue writing the game on thursday, I'll let you know how it goes!
[color="#1c2837"]

[color="#1c2837"]@laztrezort: Really usefull links thanks!
[color="#1c2837"]

[color="#1c2837"]I'll look further into the algorithms of the FOV.
[color="#1c2837"]Alhtough I propably wont be using a maximum vision distance, but instead just room by room. Line of sights stay important though.
As I'm bored at work, I'm writing up some ideas, codes, links for resources and so on.


I was thinking of a highlight system for the movement, attack range.
Now I was thinking of starting of from the players position... So let's say player is at 0,0
then we check -1,-1 / 0,-1 / 1,-1 / 1,0 / 1,1 / 0,1 / -1,1 / -1,0 then the tiles next to these.
when in range I set a highlighttexture on it (transparency).

But when should i stop? as the range has no direct link to the coordinates of where the player stands.
Also using this feature you can walk through walls....

I did found however an algorithm for short pathfindings, which might be usefull for walking around walls :)

http://en.wikipedia.org/wiki/Dijkstras_algorithm

But how combining them? Is there any existing article on this?

This topic is closed to new replies.

Advertisement