Ejemplo n.º 1
0
        public void generateBitmap(int flag)
        {
            int s = Math.Max(40, flag);

            bitmap = new Bitmap(s * 2, s * 2);
            for (int x = 0; x < s * 2; x += 4)
            {
                for (int y = 0; y < s + 20; y += 4)
                {
                    Random random = new Random(Guid.NewGuid().GetHashCode());
                    int    seed   = random.Next(0, s);
                    bool   draw   = MathExt.Distance(new Point(x, y),
                                                     new Point(s, s)) < seed;
                    if (draw)
                    {
                        Random col   = new Random(Guid.NewGuid().GetHashCode());
                        int    a     = col.Next(50, 100);
                        int    slide = col.Next(-50, 50);
                        int    r     = MathExt.Bounded(0, color.R + slide, 255);
                        slide = col.Next(-50, 50);
                        int g = MathExt.Bounded(0, color.G + slide, 255);
                        slide = col.Next(-50, 50);
                        int b = MathExt.Bounded(0, color.B + slide, 255);

                        Graphics.FromImage(bitmap).FillRectangle(
                            new SolidBrush(Color.FromArgb(a, r, g, b)),
                            x, y, 4, 4);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void keyBehaviour()
        {
            switch (selectionMode)
            {
            case SelectionMode.STARTING_PLATFORM:
            case SelectionMode.REG_PLATFORM:
                Platform p = (Platform)selected;
                if (is4Down && p.getWidth() < 500)
                {
                    p.changeWidth(5);
                }
                if (is5Down && p.getWidth() > 25)
                {
                    p.changeWidth(-5);
                }

                if (selectionMode == SelectionMode.REG_PLATFORM)
                {
                    // Extras for regular platforms
                    if (MathExt.Distance(
                            players.ElementAt(0).getLocation(),
                            p.getLocation()) < 20000)
                    {
                        if (arrowDown[UP])
                        {
                            p.moveY(-5);
                        }
                        if (arrowDown[DOWN])
                        {
                            p.moveY(5);
                        }
                        if (arrowDown[LEFT])
                        {
                            p.moveX(-5);
                        }
                        if (arrowDown[RIGHT])
                        {
                            p.moveX(5);
                        }

                        foreach (Sentry s in sentries)
                        {
                            s.editorAdjust();
                        }
                    }
                }
                break;
            }
            updateSelectionStats();
        }
Ejemplo n.º 3
0
        public bool update(Cause cause, MouseEventArgs m, KeyEventArgs k)
        {
            // null m XOR k if the cause isn't relevant
            switch (cause)
            {
            case Cause.MOUSE_MOVE:
                for (int i = 0; i < objects.Length; i++)
                {
                    int  x   = (int)(m.X * (1280 / (float)main.getSize().Width));
                    int  y   = (int)(m.Y * (720 / (float)main.getSize().Height));
                    bool val = objects[i].isHovering(new Point(x, y));

                    selVector[i] = val;
                    objects[i].setSelect(val);
                }
                break;

            case Cause.KEY_PRESS:
                // SET CONTROLS
                Keys[] controls = main.getSettings().getControls();
                Keys[] up       = new Keys[] { controls[0], Keys.Up };
                Keys[] down     = new Keys[] { controls[1], Keys.Down };
                Keys[] left     = new Keys[] { controls[2], Keys.Left };
                Keys[] right    = new Keys[] { controls[3], Keys.Right };

                // FIND SELECTED
                int selected = -1;
                for (int i = 0; i < objects.Length; i++)
                {
                    if (selVector[i])
                    {
                        selected = i;
                        break;
                    }
                }

                if (selected == -1)
                {
                    bool assignedSel = false;

                    for (int i = 0; i < objects.Length; i++)
                    {
                        if (objects[i].canBeSelected() && !assignedSel)
                        {
                            selVector[i]     = true;
                            lastSelVector[i] = true;
                            objects[i].setSelect(true);
                            assignedSel = true;
                        }
                        else
                        {
                            selVector[i]     = false;
                            lastSelVector[i] = false;
                            objects[i].setSelect(false);
                        }
                    }
                    return(true);
                }

                int    candIndex       = selected;
                double closestDistance = Double.MaxValue;

                for (int i = 0; i < objects.Length; i++)
                {
                    if (i != selected && objects[i].canBeSelected())
                    {
                        Point old       = objects[selected].getLocation();
                        Point cand      = objects[i].getLocation();
                        bool  direction = false;
                        // Principal direction
                        if (k.KeyCode == up[0] || k.KeyCode == up[1])
                        {
                            // UP
                            direction = cand.Y < old.Y;
                            //direction = cand.Y < old.Y &&
                            //    Math.Abs(cand.Y - old.Y) >
                            //    Math.Abs(cand.X - old.X);
                        }
                        else if (k.KeyCode == down[0] ||
                                 k.KeyCode == down[1])
                        {
                            // DOWN
                            direction = cand.Y > old.Y;
                            //direction = cand.Y > old.Y &&
                            //    Math.Abs(cand.Y - old.Y) >
                            //    Math.Abs(cand.X - old.X);
                        }
                        else if (k.KeyCode == left[0] ||
                                 k.KeyCode == left[1])
                        {
                            // LEFT
                            direction = cand.X < old.X;
                            //direction = cand.X < old.X &&
                            //    Math.Abs(cand.Y - old.Y) <
                            //    Math.Abs(cand.X - old.X);
                        }
                        else if (k.KeyCode == right[0] ||
                                 k.KeyCode == right[1])
                        {
                            // RIGHT
                            direction = cand.X > old.X;
                            //direction = cand.X > old.X &&
                            //    Math.Abs(cand.Y - old.Y) <
                            //    Math.Abs(cand.X - old.X);
                        }

                        if (direction &&
                            MathExt.Distance(old, cand) < closestDistance)
                        {
                            candIndex       = i;
                            closestDistance = MathExt.Distance(old, cand);
                        }
                    }
                }

                if (candIndex != selected)
                {
                    for (int i = 0; i < selVector.Length; i++)
                    {
                        selVector[i] = (i == candIndex);
                        objects[i].setSelect(i == candIndex);
                    }
                }

                break;
            }

            bool different = false;

            for (int i = 0; i < selVector.Length; i++)
            {
                different |= (selVector[i] != lastSelVector[i]);
                // Safe as index has already been compared
                lastSelVector[i] = selVector[i];
            }

            return(different);
        }