Jump to content

  • Log In with Google      Sign In   
  • Create Account

dworm

Member Since 05 Jan 2014
Offline Last Active Today, 12:49 AM

#5160437 a fitting framework (C#) for a 2D turnedbased RPG ?

Posted by dworm on 14 June 2014 - 12:17 AM

Nice!

 

Well XNA is an idea for me aswell...but am using VS 2012 Xpress and already read that things might don't work out with XNA anymore...

Is there a workaround to still use it there?

yes i never tried it but other ppl did:

 

https://msxna.codeplex.com/releases




#5155089 Crafting system, making economy that matters to player, discussion.

Posted by dworm on 21 May 2014 - 10:37 AM

play a bit of space ranger, the best "real world rpg" with economy ever created

 

second about efficiency... do you really need to SHOW all that happens in every single city?

because if not... you dont really need much efficiency, you just calculate what to do here and there, even every few seconds, nothing huge for processor...

 

and even if you want all the world to funcion real time you dont really need to do EVERYTHING at once

the efficiency is easy:

you split the assignment of actions  on each cycle (or even few cycles) for each city

this way even if you have 200 cities you only check their job once per cycle

you could even split the check between each citizen... since you dont need the merchant to work while the smith work, while the baker work, you can make them work one by one, or make working simple enough

 

anyway i dont think its that much work at all for a modern processor, in the end its pretty much  a few checks like:

baker has floor?

someone wants more bread?

baker is already working?

for stuff like prices you can adjourn them once in a while, at the end of the day, or week or similar




#5153834 Required to replenish resources/nature in 2d.

Posted by dworm on 15 May 2014 - 03:10 PM

 

This system could be done but the process consumption would be high.

really?

unless your map contains like 1 million trees i dont really think it can be that much consuming...




#5153810 naming my game

Posted by dworm on 15 May 2014 - 12:08 PM

"ehy, who s there?"




#5125910 pathfinding behaviour

Posted by dworm on 23 January 2014 - 11:11 AM

yes there surely is something wrong, here is the code

 

 

 
 public void Pathfind(int startX, int startY, int targetX, int targetY)
        {




            Point start = new Point (startX,startY);
            Point target = new Point (targetX,targetY);


            if (start.X == -1 || start.Y == -1)
            {
                return;
            }




            int actualX = start.X;
            int actualY = start.Y;
            squareMap[actualX, actualY].D = 0;
            squareMap[actualX, actualY].F = Math.Abs(actualX - target.X) + Math.Abs(actualY - target.Y);


            openListNumber = 1;
            Openlist[1] = new Point(actualX, actualY);
            bool found = false;
            int step = 0;
            while (!found)
            {


                int D;
                step++;
                D = squareMap[actualX, actualY].D;
                int S;


                foreach (Point dir in ValidMoves(actualX, actualY)) // find lowest  F score
                {
                    int k = D + 1 + Math.Abs(dir.X - target.X) + Math.Abs(dir.Y - target.Y);
                    S = squareMap[dir.X, dir.Y].F;
                    if (S > k)
                    {
                        squareMap[dir.X, dir.Y].F = k;
                        squareMap[dir.X, dir.Y].D = D + 1;
                        squareMap[dir.X, dir.Y].DirX = actualX - dir.X;
                        squareMap[dir.X, dir.Y].DirY = actualY - dir.Y;




                        if (S == 5000)
                        {
                            addToOpenList(dir.X, dir.Y);
                        }
                        else
                        {
                            correctOpenList(dir.X, dir.Y);
                        }
                    }


                }
                squareMap[actualX, actualY].Checked = true;


                if (target.X == actualX && target.Y == actualY)
                {
                    found = true;
                }


                //pick lowest open list
                actualX = Openlist[1].X;
                actualY = Openlist[1].Y;


                RemoveFromList();
                if (openListNumber < 0) { found = true; }


            }


            //backtrack path         
            int pointX = target.X;
            int pointY = target.Y;
            int dirX = 1;
            int dirY = 1;
            if (pointX == -1 && pointY == -1)
            {
                return;
            }


            while (pointX != start.X || pointY != start.Y)
            {
                dirX = squareMap[pointX, pointY].DirX;
                dirY = squareMap[pointX, pointY].DirY;
                pointX += dirX;
                pointY += dirY;
                squareMap[pointX, pointY].IsPath = true;
            }
            squareMap[pointX, pointY].IsPath = false;
        }

this to add to open list:

void addToOpenList(int x, int y)
        {
            openListNumber++;
            Openlist[openListNumber] = new Point(x, y);
            int nTemp = openListNumber;
            int nTemp2 = nTemp;
            int F = squareMap[x, y].F;
            Point temp;
            while (nTemp2 > 1)
            {
                nTemp2 = nTemp / 2;
                if (squareMap[Openlist[nTemp].X, Openlist[nTemp].Y].F > F)
                {
                    temp = Openlist[nTemp2];
                    Openlist[nTemp2] = Openlist[nTemp];
                    Openlist[nTemp] = temp;
                }
                nTemp = nTemp2;
            }


        }

this to remove

 void RemoveFromList()
        {
            Openlist[1] = Openlist[openListNumber];
            openListNumber--;
            int nTemp = 1;
            int nTemp2 = 1;
            bool jump = true;
            Point temp;
            while (jump)
            {
                nTemp2 = nTemp;
                if (nTemp2 * 2 < openListNumber)
                {
                    if (squareMap[Openlist[nTemp2].X, Openlist[nTemp2].Y].F > squareMap[Openlist[nTemp2 * 2].X, Openlist[nTemp2 * 2].Y].F)
                    {
                        nTemp = nTemp2 * 2;
                    }
                    if (squareMap[Openlist[nTemp].X, Openlist[nTemp].Y].F > squareMap[Openlist[nTemp2 * 2 + 1].X, Openlist[nTemp2 * 2 + 1].Y].F)
                    {
                        nTemp = nTemp2 * 2 + 1;
                    }
                }
                else if (nTemp2 * 2 <= openListNumber)
                {
                    if (squareMap[Openlist[nTemp2].X, Openlist[nTemp2].Y].F > squareMap[Openlist[nTemp2 * 2].X, Openlist[nTemp2 * 2].Y].F)
                    {
                        nTemp = nTemp2 * 2;
                    }
                }

                if (nTemp != nTemp2)
                {
                    temp = Openlist[nTemp2];
                    Openlist[nTemp2] = Openlist[nTemp];
                    Openlist[nTemp] = temp;
                }
                else
                {
                    jump = false;
                }
            }

this to correct when a tile is found better than the previous value

      void correctOpenList(int x, int y)
        {
            int nTemp = 1;
            while (Openlist[nTemp].X != x || Openlist[nTemp].Y != y)
            {
                nTemp += 1;
            }
            int nTemp2 = nTemp;
            int F = squareMap[x, y].F;
            Point temp;
            while (nTemp2 > 1)
            {
                nTemp2 = nTemp / 2;
                if (squareMap[Openlist[nTemp].X, Openlist[nTemp].Y].F > F)
                {
                    temp = Openlist[nTemp2];
                    Openlist[nTemp2] = Openlist[nTemp];
                    Openlist[nTemp] = temp;
                }
                nTemp = nTemp2;
            }

        }



#5125657 pathfinding behaviour

Posted by dworm on 22 January 2014 - 09:34 AM

Wanted to asked if this is normal or I did some mistake:

 

http://imgur.com/RJONEkq

 

http://imgur.com/eoDsyiC

 

ofc pink is path, black is obstacle, yellow is the open tiles evaluated

 

It seems there are too many yellow or at least I did expect them to be less, dunno really




PARTNERS