Beispiel #1
0
 public updateableObject(bool active, vector2 pos, char toDisplay)
 {
     this.toDisplay = toDisplay;
     this.pos       = pos;
     components     = new List <iComponent>();
     IsActive       = active;
 }
Beispiel #2
0
 public void deregisterBackground(vector2 pos, char c)
 {
     if (backGroundBuffer.ContainsKey(pos))
     {
         backGroundBuffer.Remove(pos);
     }
 }
Beispiel #3
0
 public void update()
 {
     if (followTargetStack.Count > 0)
     {
         CurrentCenter = followTargetStack.Last().pos;
     }
 }
Beispiel #4
0
        public static float[,] addCircleMap(float[,] map, float percentage, float lowerAmount)
        {
            float[,] reMapped = new float[map.GetLength(0), map.GetLength(1)];

            vector2 zero       = new vector2(map.GetLength(0) / 2, map.GetLength(1) / 2);
            vector2 currentPos = new vector2();
            vector2 max        = new vector2(map.GetLength(0), map.GetLength(1));

            float range = Remap(percentage, 0, 1, 0, max.dist(zero));

            for (int y = 0; y < map.GetLength(1); y++)
            {
                for (int x = 0; x < map.GetLength(0); x++)
                {
                    currentPos.x = x;
                    currentPos.y = y;

                    if (currentPos.dist(zero) > range)
                    {
                        reMapped[x, y] = 1;
                    }
                    else
                    {
                        reMapped[x, y] = map[x, y] - lowerAmount;

                        if (reMapped[x, y] < 0)
                        {
                            reMapped[x, y] = 0;
                        }
                    }
                }
            }

            return(reMapped);
        }
Beispiel #5
0
        public static vector2 getCenteredVector2(vector2 center, int dist)
        {
            int x = getCenteredInt(dist, center.x);
            int y = getCenteredInt(dist, center.y);

            return(new vector2(x, y));
        }
Beispiel #6
0
 public void register(vector2 pos, char c)
 {
     if (!renderBuffer.ContainsKey(pos))
     {
         renderBuffer.Add(pos, c);
     }
 }
Beispiel #7
0
 public void deregister(vector2 pos, char c)
 {
     if (renderBuffer.ContainsKey(pos))
     {
         renderBuffer.Remove(pos);
     }
 }
Beispiel #8
0
 public updateableObject(vector2 pos)
 {
     this.toDisplay = ' ';
     this.pos       = pos;
     components     = new List <iComponent>();
     IsActive       = true;
 }
Beispiel #9
0
 private Renderer()
 {
     worldPos         = new vector2(0, 0);
     windowHeight     = Console.WindowHeight - 1;
     windowWidth      = Console.WindowWidth - 1;
     renderBuffer     = new Dictionary <vector2, char>(new vector2HashCode());
     backGroundBuffer = new Dictionary <vector2, char>(new vector2HashCode());
 }
Beispiel #10
0
 public SaveData(string name)
 {
     this.name              = name;
     version                = Program.version;
     universe_data          = new universe.UniverseData();
     renderer_worldPos      = new vector2();
     e_playerController_pos = new vector2();
     updater_gameObjects    = new Dictionary <vector2, updateableObject>();
 }
Beispiel #11
0
        public static vector4 getSplit(vector2 pos, int chunkSize)
        {
            int chunkX = pos.x / chunkSize;
            int chunkY = pos.y / chunkSize;

            int tileX = pos.x % chunkSize;
            int tileY = pos.y % chunkSize;

            return(new vector4(chunkX, chunkY, tileX, tileY));
        }
Beispiel #12
0
 private char getBackgroundChar(vector2 pos)
 {
     if (Simplex.Noise.CalcPixel3D(pos.x, pos.y, Program.randomSeed, 0.5f) > 222)
     {
         return('.');
     }
     else
     {
         return(' ');
     }
 }
Beispiel #13
0
 public bool Equals(vector2 X, vector2 Y)
 {
     if (X.x == Y.x && X.y == Y.y)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #14
0
 private static char getBackgroundChar(vector2 pos)
 {
     //init new Random so that the stars are stable position wise
     if (new Random(pos.GetHashCode() + Program.randomSeed).NextDouble() > 0.9)
     {
         return('.');
     }
     else
     {
         return(' ');
     }
 }
Beispiel #15
0
 public void registerBackground(vector2 pos, char c)
 {
     if (!backGroundBuffer.ContainsKey(pos))
     {
         backGroundBuffer.Add(pos, c);
     }
     else
     {
         backGroundBuffer.Remove(pos);
         registerBackground(pos, c);
     }
 }
Beispiel #16
0
 public virtual bool move(vector2 newPos)
 {
     if (game.renderer.isPosEmpty(newPos))
     {
         game.renderer.deregister(pos, toDisplay);
         pos = newPos;
         game.renderer.register(pos, toDisplay);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #17
0
        public static void randomSeedResettingTest(int testsToAverage)
        {
            Console.WriteLine("Testing Random Seed Times");

            int    startSeed = 5;
            Random r         = new Random(startSeed);

            var watch = System.Diagnostics.Stopwatch.StartNew();


            int counter = 0;

            for (int i = 0; i < testsToAverage; i++)
            {
                if (r.NextDouble() > 0.6)
                {
                    counter++;
                }
            }

            watch.Stop();

            double noSeedResetTime = watch.ElapsedMilliseconds / (double)testsToAverage;

            Console.WriteLine("No Reset Time : " + noSeedResetTime + " ms with " + counter + " above 0.6");

            watch.Restart();

            vector2HashCode hasher = new vector2HashCode();

            counter = 0;
            for (int i = 0; i < testsToAverage; i++)
            {
                vector2 seed = new vector2(i + startSeed, i);
                r = new Random(hasher.GetHashCode(seed));
                if (r.NextDouble() > 0.6)
                {
                    counter++;
                }
            }

            watch.Stop();

            double SeedResetTime = watch.ElapsedMilliseconds / (double)testsToAverage;

            Console.WriteLine("Reset Time : " + SeedResetTime + " ms with " + counter + " above 0.6");
        }
Beispiel #18
0
 public bool isPosEmptyBackground(vector2 pos)
 {
     return(!backGroundBuffer.ContainsKey(pos));
 }
Beispiel #19
0
        public static void testListDictLoopTimes(int listSize, int testsToAverage)
        {
            Console.WriteLine("Testing List Loop Times");

            List <testComponent> componentsList = new List <testComponent>();
            Dictionary <vector2, testComponent> componentsDict = new Dictionary <vector2, testComponent>();

            Console.WriteLine("Fill Test 0 - For Loop and List");

            var watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                watch.Stop();
                componentsList.Clear();
                watch.Start();
                for (int j = 0; j < listSize; j++)
                {
                    componentsList.Add(new testComponent(new vector2(j, j)));
                }
            }

            watch.Stop();
            double elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Fill: Test 0 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Fill: Test 1 - For Loop and Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                watch.Stop();
                componentsDict.Clear();
                watch.Start();
                for (int j = 0; j < listSize; j++)
                {
                    vector2 pos = new vector2(j, j);
                    componentsDict.Add(pos, new testComponent(pos));
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Fill: Test 1 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 2 - For Loop and List");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsList.Count; j++)
                {
                    componentsList[j].update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 2 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 3 - For Loop and Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsDict.Count; j++)
                {
                    componentsDict[new vector2(j, j)].update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 3 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 4 - Foreach Loop and List");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                foreach (iComponent v in componentsList)
                {
                    v.update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 4 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Iteration: Test 5 - Foreach Loop and Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                foreach (KeyValuePair <vector2, testComponent> kvp in componentsDict)
                {
                    kvp.Value.update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Iteration: Test 5 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Find: Test 6 - List");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsList.Count; j++)
                {
                    iComponent working = componentsList.Single(s => (s.pos.x == j));
                    working.update(null);
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Find: Test 6 - Took " + (elapsedMs / testsToAverage) + " ms");

            Console.WriteLine("Find: Test 7 - Dict");

            watch = System.Diagnostics.Stopwatch.StartNew();

            for (int i = 0; i < testsToAverage; i++)
            {
                for (int j = 0; j < componentsDict.Count; j++)
                {
                    testComponent working;

                    if (componentsDict.TryGetValue(new vector2(j, j), out working))
                    {
                        working.update(null);
                    }
                }
            }

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Find: Test 7 - Took " + (elapsedMs / (testsToAverage) + " ms"));
            Console.ReadLine();
        }
Beispiel #20
0
 public void load()
 {
     worldPos = game.save.renderer_worldPos;
 }
Beispiel #21
0
 public bool isPosEmpty(vector2 pos)
 {
     return(!renderBuffer.ContainsKey(pos));
 }
Beispiel #22
0
 public vector4()
 {
     i = new vector2();
     j = new vector2();
 }
Beispiel #23
0
 public float dist(vector2 other)
 {
     return((float)Math.Sqrt(Math.Pow(x - other.x, 2) + Math.Pow(y - other.y, 2)));
 }
Beispiel #24
0
        public void renderFrame(bool fastMode)
        {
            if (fastMode)
            {
                vector2 currentLocation = new vector2();

                Console.SetCursorPosition(0, 0);

                for (int y = 0; y < windowHeight; y++)
                {
                    currentLocation.y = y + worldPos.y;
                    char[] toPrint = new char[windowWidth];

                    for (int x = 0; x < windowWidth; x++)
                    {
                        currentLocation.x = x + worldPos.x;
                        if (renderBuffer.ContainsKey(currentLocation))
                        {
                            toPrint[x] = renderBuffer[currentLocation];
                        }
                        else
                        {
                            if (backGroundBuffer.ContainsKey(currentLocation))
                            {
                                toPrint[x] = backGroundBuffer[currentLocation];
                            }
                            else
                            {
                                toPrint[x] = getBackgroundChar(currentLocation);
                            }
                        }
                    }

                    Console.WriteLine(toPrint);
                }
            }
            else
            {
                vector2 currentLocation = new vector2();

                Console.SetCursorPosition(0, 0);

                for (int y = 0; y < windowHeight; y++)
                {
                    List <Char> toPrint = new List <char>();
                    currentLocation.y = y + worldPos.y;
                    for (int x = 0; x < windowWidth; x++)
                    {
                        currentLocation.x = x + worldPos.x;
                        if (renderBuffer.ContainsKey(currentLocation))
                        {
                            if (lastConsoleColor != ConsoleColor.Green)
                            {
                                Console.Write(toPrint.ToArray());
                                toPrint.Clear();
                                setConsoleColor(ConsoleColor.Green);
                                toPrint.Add(renderBuffer[currentLocation]);
                            }
                            else
                            {
                                toPrint.Add(renderBuffer[currentLocation]);
                            }
                        }
                        else
                        {
                            if (lastConsoleColor != ConsoleColor.DarkGray)
                            {
                                Console.Write(toPrint.ToArray());
                                toPrint.Clear();
                                setConsoleColor(ConsoleColor.DarkGray);

                                if (backGroundBuffer.ContainsKey(currentLocation))
                                {
                                    toPrint.Add(backGroundBuffer[currentLocation]);
                                }
                                else
                                {
                                    toPrint.Add(getBackgroundChar(currentLocation));
                                }
                            }
                            else
                            {
                                if (backGroundBuffer.ContainsKey(currentLocation))
                                {
                                    toPrint.Add(backGroundBuffer[currentLocation]);
                                }
                                else
                                {
                                    toPrint.Add(getBackgroundChar(currentLocation));
                                }
                            }
                        }
                    }
                    Console.WriteLine(toPrint.ToArray());
                }
            }
        }
Beispiel #25
0
 public vector2(vector2 toCopy)
 {
     x = toCopy.x;
     y = toCopy.y;
 }
Beispiel #26
0
 public static vector2 add(vector2 a, vector2 b)
 {
     return(new vector2(a.x + b.x, a.y + b.y));
 }
Beispiel #27
0
 public vector4(int i, int j, int x, int y)
 {
     this.i = new vector2(i, j);
     this.j = new vector2(x, y);
 }
Beispiel #28
0
 public static vector2 sub(vector2 a, vector2 b)
 {
     return(new vector2(a.x - b.x, a.y - b.y));
 }
Beispiel #29
0
 public static vector2 negate(vector2 a)
 {
     return(new vector2(-a.x, -a.y));
 }
Beispiel #30
0
 public vector4(vector2 i, vector2 j)
 {
     this.i = i;
     this.j = j;
 }