Example #1
0
        ////////////////////////////////////
        // Derp-LineSegment Circle Casting - for field tile collisions
        // Returns: true if collision, false otherwise
        // out double t: this will be the parameter t, how far we can move along our vector before we get within Derp's radius of the line segment
        ////////////////////////////////////
        public static bool DerpLineSegmentCast(Derp d, myVector v, myLineSegment wall, out double t)
        {
            myLineSegment derpMoveLine = new myLineSegment(d.x, d.y, v);

            t = derpMoveLine.SegmentIntersectionWithRadius(wall, d.stats.radius);

            return(t < 1.0 - 1e-6);
        }
Example #2
0
        static public double DerpCircleCast(Derp d1, Derp d2, myVector v)
        {
            double distX = d2.x - d1.x;
            double distY = d2.y - d1.y;

            // make sure we are close before we do any of the computational checking
            if (distX * distX + distY * distY > distSquaredThreshholdX)
            {
                return(1.0);
            }

            // Intersect distance
            double radius = d1.stats.radius + d2.stats.radius;

            // solve the quadratic to find the intersection of two circles
            double A = v.x * v.x + v.y * v.y;
            double B = 2 * (d1.x * v.x - d2.x * v.x + d1.y * v.y - d2.y * v.y);
            double C = (d1.x * d1.x) + (d2.x * d2.x) - 2 * d2.x * d1.x + (d1.y * d1.y) + (d2.y * d2.y) - 2 * d2.y * d1.y - (radius * radius);

            // unreal answers or a t that is greater than 1.0 means no collision
            double discr = (B * B) - 4 * A * C;

            if (discr < 0.0)
            {
                return(1.0); //imaginary answer
            }
            double t = (-B - Math.Sqrt(discr)) / (2 * A);

            if (t > 1.0)
            {
                return(1.0); // no collision with this step size
            }
            // this is detecting a collision behind us
            // NOTICE: there may be issues here in the future... if someone moves into us? (wait... they can't though. we guarentee that no one will move somewhere they can't... I think...)
            if (t < 0.0)
            {
                return(1.0);
            }

            // BUFFER
            // if we let them get right up next to each other, sometimes the floating point error is enough to let them slip through (I think)
            // add a buffer if there is a collision
            if (t < 1.0 - 1e-6)
            {
                t -= bufferDistance / Math.Sqrt(v.x * v.x + v.y * v.y);
                t  = Math.Max(t, 0.0);
            }

            return(t);
        }
Example #3
0
    void spawnDerp()
    {
        Derp   derpPrefab = pickRandomDerp();
        Sprite s          = derpPrefab.gameObject.GetComponent <SpriteRenderer>().sprite;

        float startX = getRightPos() + s.border.y / 2;
        float endX   = getLeftPos() - s.border.y / 2;
        float startY = getRandY();
        float endY   = getRandY();

        Vector3 start = new Vector3(startX, startY, 0);
        Vector3 end   = new Vector3(endX, endY, 0);
        Derp    e     = (Derp)Instantiate(derpPrefab, start, Quaternion.identity);

        e.gameObject.transform.SetParent(this.gameObject.transform, true);
        e.setPath(start, end);
    }
Example #4
0
        public void TestObjectLiteralCastAttr()
        {
            object o = "string";

            Assert.False(o is Derp);

            o = Script.ToPlainObject(new { });
            Assert.False(o is Derp);

            o = new Derp();
            Assert.False(o is Derp); // no Foo

            o = Script.ToPlainObject(new { Foo = 1 });
            Assert.True(o is Derp);

            o = new Derp {
                Foo = 2
            };
            Assert.True(o is Derp);
        }
        // Save from Add page
        public IActionResult Save(string Title, IFormFile Image, int Rating)
        {
            Derp newderp = new Derp();

            newderp.Title  = Title;
            newderp.Image  = Image.FileName;
            newderp.Rating = Rating;

            db.Derps.Add(newderp);
            db.SaveChanges(); // saves all of the database stuff

            // save image on harddrive too
            // open up a new file
            FileStream fs = new FileStream("wwwroot/images/" + Image.FileName, FileMode.OpenOrCreate);

            // dump in all of the image data
            Image.CopyTo(fs);
            // close/save file
            fs.Dispose();


            return(Redirect("/"));
        }
Example #6
0
        public override void LoadContent()
        {
            ContentManager Content = Game.game.Content;

            ///////////////////////////////////////////////////////////////////////////////////////////
            // Load Block Images and Set Offsets for necessary ones
            // srcOffset is if the image is actually a strip, it tells us which src to get it from
            // positionOffset tell how high off the ground this block is (for overlapping field blocks)
            ///////////////////////////////////////////////////////////////////////////////////////////
            Dictionary <char, Texture2D> blocks         = new Dictionary <char, Texture2D>();
            Dictionary <char, Rectangle> srcOffset      = new Dictionary <char, Rectangle>();
            Dictionary <char, int>       positionOffset = new Dictionary <char, int>();

            // 0 Grass
            blocks['0']         = Content.Load <Texture2D>(@"FieldBlocks\Block_Grass");
            srcOffset['0']      = new Rectangle(0, 0, Field.BLOCK_WIDTH, blocks['0'].Height);
            positionOffset['0'] = 0;
            // + Road
            blocks['+']         = Content.Load <Texture2D>(@"FieldBlocks\Block_Road");
            srcOffset['+']      = new Rectangle(0, 0, Field.BLOCK_WIDTH, blocks['+'].Height);
            positionOffset['+'] = 0;
            // - Growing Zone
            blocks['-']         = Content.Load <Texture2D>(@"FieldBlocks\Block_Road");
            srcOffset['-']      = new Rectangle(0, 0, Field.BLOCK_WIDTH, blocks['-'].Height);
            positionOffset['-'] = 0;
            // * Hub Starting Point
            blocks['A']         = Content.Load <Texture2D>(@"FieldBlocks\SpawnerInactive");
            srcOffset['A']      = new Rectangle(0, 0, Field.BLOCK_WIDTH, blocks['A'].Height);
            positionOffset['A'] = 0;

            // Diagonal Blocks
            // 1 bottom-right path
            blocks['1']         = Content.Load <Texture2D>(@"FieldBlocks\Block_GrassCorner");
            srcOffset['1']      = new Rectangle(0, 0, Field.BLOCK_WIDTH, Field.BLOCK_HEIGHT);
            positionOffset['1'] = 0;
            // 1 bottom-right path
            blocks['2']         = Content.Load <Texture2D>(@"FieldBlocks\Block_GrassCorner");
            srcOffset['2']      = new Rectangle(Field.BLOCK_WIDTH, 0, Field.BLOCK_WIDTH, Field.BLOCK_HEIGHT);
            positionOffset['2'] = 0;
            // 1 bottom-right path
            blocks['3']         = Content.Load <Texture2D>(@"FieldBlocks\Block_GrassCorner");
            srcOffset['3']      = new Rectangle(Field.BLOCK_WIDTH * 2, 0, Field.BLOCK_WIDTH, Field.BLOCK_HEIGHT);
            positionOffset['3'] = 0;
            // 1 bottom-right path
            blocks['4']         = Content.Load <Texture2D>(@"FieldBlocks\Block_GrassCorner");
            srcOffset['4']      = new Rectangle(Field.BLOCK_WIDTH * 3, 0, Field.BLOCK_WIDTH, Field.BLOCK_HEIGHT);
            positionOffset['4'] = 0;

            // Load other images
            Texture2D[] selector = new Texture2D[2];
            // 0 - SelectedBlock
            selector[0] = Content.Load <Texture2D>(@"FieldBlocks\Selector");
            selector[1] = Content.Load <Texture2D>(@"FieldBlocks\Deleter");

            field.InitializeBlocks(blocks, srcOffset, positionOffset, selector);

            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // Load the DNA Content
            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            Texture2D[] SpawnerBase    = new Texture2D[2];
            Texture2D[] SpawnerBaseEnd = new Texture2D[4];
            Texture2D[] DNATexture     = new Texture2D[9];

            SpawnerBase[0] = Content.Load <Texture2D>(@"FieldBlocks\SpawnerInactive");
            SpawnerBase[1] = Content.Load <Texture2D>(@"FieldBlocks\SpawnerActive");

            SpawnerBaseEnd[0] = Content.Load <Texture2D>(@"FieldBlocks\SpawnerInactiveLeft");
            SpawnerBaseEnd[1] = Content.Load <Texture2D>(@"FieldBlocks\SpawnerActiveLeft");
            SpawnerBaseEnd[2] = Content.Load <Texture2D>(@"FieldBlocks\SpawnerInactiveRight");
            SpawnerBaseEnd[3] = Content.Load <Texture2D>(@"FieldBlocks\SpawnerActiveRight");

            DNATexture[0] = Content.Load <Texture2D>(@"FieldBlocks\RedDNA");
            DNATexture[1] = Content.Load <Texture2D>(@"FieldBlocks\BlueDNA");
            DNATexture[2] = Content.Load <Texture2D>(@"FieldBlocks\SolarDNA");

            Spawner.InitializeTextures(SpawnerBase, SpawnerBaseEnd, DNATexture, 0);

            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // Load the Derp Spawn
            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            DerpSpawn.InitializeTexture(Content.Load <Texture2D>(@"Derps\DerpSpawn"));

            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // Load the Derp Content
            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            Dictionary <String, Texture2D>  baseTextures = new Dictionary <String, Texture2D>();
            Dictionary <String, SpriteInfo> baseOffsets  = new Dictionary <String, SpriteInfo>();

            Dictionary <String, Texture2D>  accessoryTextures = new Dictionary <String, Texture2D>();
            Dictionary <String, SpriteInfo> accessoryOffsets  = new Dictionary <String, SpriteInfo>();

            // Epoch 0

            // Medium Sized
            baseTextures.Add("e0s1", Content.Load <Texture2D>(@"Derps\derp_e0_s1"));
            baseOffsets.Add("e0s1", new SpriteInfo(24, 24, 12, 17, 1));

            // Give the media to the Derp class. It will handle which ones to use.
            Derp.InitializeTextures(baseTextures, baseOffsets, accessoryTextures, accessoryOffsets);

            // Load the Attack Sprites
            Dictionary <String, Texture2D>  attackTextures = new Dictionary <String, Texture2D>();
            Dictionary <String, SpriteInfo> attackInfo     = new Dictionary <String, SpriteInfo>();

            // Small Close-Ranged Attacks
            attackTextures.Add("small-close", Content.Load <Texture2D>(@"Derps\derp_attack_small"));
            attackInfo.Add("small-close", new SpriteInfo(16, 16, 8, 8, 5));

            // Give the media to the DerpAttack class.
            DerpAttack.InitializeTextures(attackTextures, attackInfo);

            // Load the GUI components
            gui.LoadContent();
        }
Example #7
0
 public Derp ReturnEnum(Derp num)
 {
     num = Derp.herp;
     return num;
 }
Example #8
0
        // Check for a Derp's Circle-Cast across the field
        // This will work like a BFS, starting from the initial position
        // then check all 4 corners around the position to build on the bfs
        public bool CheckFieldCollision(Derp d, myVector v, out double t, out myLineSegment col)
        {
            // initial optimistic setup that there will not be a collision
            bool ret = false;

            t   = 1.0;
            col = null;

            // calculate starting point
            int startX = (int)(d.x / BLOCK_WIDTH);
            int startY = (int)(d.y / BLOCK_HEIGHT);

            // Unit Vector in desired direction
            myVector vUnit = new myVector(v.x, v.y);

            vUnit.toUnit();

            // set up the bfs
            Queue <SimpleNode> q = new Queue <SimpleNode>();

            bool[,] vis = new bool[height + 1, width + 1];

            q.Enqueue(new SimpleNode(startX, startY, 0));
            vis[startY, startX] = true;

            // Create the 4 line segments so we don't have to do quiiite as much object creation in this loop
            myLineSegment[] segs = new myLineSegment[4];
            for (int i = 0; i < 4; ++i)
            {
                segs[i] = new myLineSegment(null, null);
            }

            // BFS
            int[] dx       = { 0, 1, 0, -1 };
            int[] dy       = { -1, 0, 1, 0 };
            int   cur_step = 0;

            while (q.Count > 0)
            {
                SimpleNode cur = q.Dequeue();

                // end early if we had a hit already in a previous step
                if (ret && cur_step != cur.step)
                {
                    break;
                }

                // checking 4 nodes around us
                myPoint p1 = new myPoint(cur.x * BLOCK_WIDTH, cur.y * BLOCK_HEIGHT);
                myPoint p2 = new myPoint((cur.x + 1) * BLOCK_WIDTH, cur.y * BLOCK_HEIGHT);
                myPoint p3 = new myPoint((cur.x + 1) * BLOCK_WIDTH, (cur.y + 1) * BLOCK_HEIGHT);
                myPoint p4 = new myPoint(cur.x * BLOCK_WIDTH, (cur.y + 1) * BLOCK_HEIGHT);
                segs[0].Update(p1, p2);
                segs[1].Update(p2, p3);
                segs[2].Update(p4, p3);
                segs[3].Update(p1, p4);

                for (int i = 0; i < 4; ++i)
                {
                    int nx = cur.x + dx[i];
                    int ny = cur.y + dy[i];

                    if (nx < 0 || nx > width || ny < 0 || ny >= height || vis[ny, nx])
                    {
                        continue;
                    }

                    double possible_t;
                    if (Geometry.DerpLineSegmentCast(d, v, segs[i], out possible_t))
                    {
                        // We have a hit! If the next zone is safe to move in, then continue the bfs
                        if (gameGrid[ny, nx] != '0')
                        {
                            q.Enqueue(new SimpleNode(nx, ny, cur.step + 1));
                            vis[ny, nx] = true;
                        }
                        // We hit an unnavigable space. Stop the BFS, this is as far as we go
                        else
                        {
                            ret = true;

                            if (Math.Abs(possible_t - t) < 1e-5 && col != null)
                            {
                                // break ties by taking the furthest behind the direction we wish to go
                                // Calculate the center point on the wall, and get the dot product of the vector to that point.
                                // The most negative value is the furthest behind
                                myPoint  segMidPoint1 = new myPoint((segs[i].p1.x + segs[i].p2.x) / 2.0, (segs[i].p1.y + segs[i].p2.y) / 2.0);
                                myVector toMidPoint1  = new myVector(segMidPoint1.x - d.x, segMidPoint1.y - d.y);

                                myPoint  segMidPoint2 = new myPoint((col.p1.x + col.p2.x) / 2.0, (col.p1.y + col.p2.y) / 2.0);
                                myVector toMidPoint2  = new myVector(segMidPoint2.x - d.x, segMidPoint2.y - d.y);

                                if (vUnit.dot(toMidPoint1) < vUnit.dot(toMidPoint2))
                                {
                                    t   = possible_t;
                                    col = new myLineSegment(segs[i].p1.x, segs[i].p1.y, segs[i].p2.x, segs[i].p2.y); // careful... memory bugs
                                }
                            }
                            else if (possible_t < t)
                            {
                                t   = possible_t;
                                col = new myLineSegment(segs[i].p1.x, segs[i].p1.y, segs[i].p2.x, segs[i].p2.y); // careful... memory bugs
                            }
                        }
                    }
                }

                // if we are a special diagonal case, then check the cross hit as well
                myLineSegment diag = null;

                char c = gameGrid[cur.y, cur.x];
                if (c == '1' || c == '3')
                {
                    diag = new myLineSegment(p2, p4);
                }

                if (c == '2' || c == '4')
                {
                    diag = new myLineSegment(p1, p3);
                }

                if (diag != null)
                {
                    double possible_t;
                    if (Geometry.DerpLineSegmentCast(d, v, diag, out possible_t))
                    {
                        ret = true;

                        if (Math.Abs(possible_t - t) < 1e-5 && col != null)
                        {
                            // break ties by taking the furthest behind the direction we wish to go
                            // Calculate the center point on the wall, and get the dot product of the vector to that point.
                            // The most negative value is the furthest behind
                            myPoint  segMidPoint1 = new myPoint((diag.p1.x + diag.p2.x) / 2.0, (diag.p1.y + diag.p2.y) / 2.0);
                            myVector toMidPoint1  = new myVector(segMidPoint1.x - d.x, segMidPoint1.y - d.y);

                            myPoint  segMidPoint2 = new myPoint((col.p1.x + col.p2.x) / 2.0, (col.p1.y + col.p2.y) / 2.0);
                            myVector toMidPoint2  = new myVector(segMidPoint2.x - d.x, segMidPoint2.y - d.y);

                            if (vUnit.dot(toMidPoint1) < vUnit.dot(toMidPoint2))
                            {
                                t   = possible_t;
                                col = new myLineSegment(diag.p1.x, diag.p1.y, diag.p2.x, diag.p2.y); // careful... memory bugs
                            }
                        }
                        else if (possible_t < t)
                        {
                            t   = possible_t;
                            col = new myLineSegment(diag.p1.x, diag.p1.y, diag.p2.x, diag.p2.y); // careful... memory bugs
                        }
                    }
                }

                cur_step = cur.step;
            }

            return(ret);
        }