Exemple #1
0
        public override AABB GetBounds()
        {
            vf min = (float.MaxValue, float.MaxValue);
            vf max = (float.MinValue, float.MinValue);

            foreach (Polygon shape in shapes.Values)
            {
                AABB bounds = shape.GetBounds();
                if (bounds.topLeft.x < min.x)
                {
                    min.x = bounds.topLeft.x;
                }
                if (bounds.topLeft.y < min.y)
                {
                    min.y = bounds.topLeft.y;
                }
                if (bounds.bottomRight.x > max.x)
                {
                    max.x = bounds.bottomRight.x;
                }
                if (bounds.bottomRight.y > max.y)
                {
                    max.y = bounds.bottomRight.y;
                }
            }

            return(new AABB(min, max));
        }
Exemple #2
0
            public override void Draw(Game target, World world)
            {
                //int radius_s = (int)world.ScreenLength(1);
                vf position_s = world.ScreenPoint(position_w);

                //target.FillCircle(position_s, radius_s, Pixel.Presets.White);
                target.Draw(position_s, Pixel.Presets.White);
            }
Exemple #3
0
        public override void Draw(Game target, World cam)
        {
            IEnumerable <vf> vertices_w = GetTransformedVertices();
            vf last_s = cam.ScreenPoint(vertices_w.Last());

            foreach (vf v in vertices_w)
            {
                vf current_s = cam.ScreenPoint(v);
                target.DrawLine(last_s, current_s, colourOutline);
                last_s = current_s;
            }
        }
Exemple #4
0
        public override void Draw(Game target, World cam)
        {
            foreach (Polygon shape in shapes.Values)
            {
                shape.rotation   -= lastRotation - rotation;
                shape.scale      -= lastScale - scale;
                shape.position_w -= lastPosition_w - position_w;
                shape.Draw(target, cam);
            }

            lastPosition_w = position_w;
            lastRotation   = rotation;
            lastScale      = scale;
        }
Exemple #5
0
        public override void Draw(SpaceGame target)
        {
            target.PixelMode = Pixel.Mode.Alpha;

            // motion information
            // box
            vf boxTopLeft     = bounds.bottomRight - 60;
            vf boxBottomRight = boxTopLeft + 50;
            vf boxMiddle      = boxTopLeft + 25;

            target.FillRect(boxTopLeft, boxBottomRight, new Pixel(200, 100, 100, 100));

            vf dirOfVel  = player.vel.Normalized() * Math.Min(player.vel.Length * 10, 23);
            vf dirOfShip = vf.Along(default, 10, -player.rotation + (float)Math.PI / 2);
Exemple #6
0
        public IEnumerable <vf> GetRotatedVertices()
        {
            foreach (vf p in vertices)
            {
                vf result = (0, 0);

                float rot = rotation - (float)Math.PI / 2;

                float cos = (float)Math.Cos(rot);
                float sin = (float)Math.Sin(rot);

                result.x = scale * (p.x * cos - p.y * sin);
                result.y = scale * (p.x * sin + p.y * cos);

                yield return(result);
            }
        }
Exemple #7
0
        public virtual void Update(SpaceGame target, float elapsed)
        {
            graphics.position_w = position_w;

            // a = F / m
            vel   += forces / mass * elapsed;
            forces = (0, 0);

            position_w += vel;

            // rotation hack
            rotationVel   += rotationForces / mass * elapsed;
            rotationForces = 0;

            if (rotationVel >= rotationVelCap || rotationVel <= -rotationVelCap)
            {
                rotationVel = rotationVelCap * System.Math.Sign(rotationVel);
            }
            rotation   += rotationVel;
            rotationVel = rotationVel.TowardsButNotPass(0, rotationalDecayAmount * elapsed);
        }
Exemple #8
0
        static void Process(string d, ref ProcessingState state)
        {
            if (state.vertices == null)
            {
                state.vertices = new List <vf>();
            }
            if (state.scale == 0)
            {
                state.scale = 1;
            }

            Regex  regex = new Regex(@".*?\(");
            string key   = regex.Match(d).Value;

            key = key.Substring(0, key.Length - 1);

            regex = new Regex(@"\((.*?)\)");
            string value = regex.Match(d).Value;

            value = value.Substring(1, value.Length - 2);

            switch (key)
            {
            case "scale": {
                if (float.TryParse(value, out float sScaleFloat))
                {
                    state.scale = sScaleFloat;
                }
            }
            break;

            case "v": {
                string[] vData = value.Split(',');

                vf   result = default;
                bool onX    = true;
                foreach (string vElement in vData)
                {
                    if (float.TryParse(vElement, out float vElementFloat))
                    {
                        if (onX)
                        {
                            result.x = vElementFloat;
                            onX      = false;
                        }
                        else
                        {
                            result.y = vElementFloat;
                        }
                    }
                }

                state.vertices.Add(result);
            }
            break;

            case "name": {
                state.name = value;
            }
            break;

            case "colour": {
                string[] cData      = value.Split(',');
                byte[]   cDataBytes = new byte[4];

                int i = 0;
                foreach (string cElement in cData)
                {
                    if (byte.TryParse(cElement, out byte cElementByte))
                    {
                        cDataBytes[i] = cElementByte;
                    }
                    i++;
                }
                if (i == 2)
                {
                    cDataBytes[3] = 255;                                         // didn't get alpha value, default to fully opaque
                }
                state.colour = new Pixel(cDataBytes[0], cDataBytes[1], cDataBytes[2], cDataBytes[3]);
            }
            break;
            }
        }
Exemple #9
0
        public Entity(vf position_w)
        {
            this.position_w = position_w;

            graphics = IO.AssetManager.GetShape("default");
        }
Exemple #10
0
 public void ApplyForce(vf force) => forces += force;
Exemple #11
0
 public ChunkLocalStar(vf position_w) : base()
 {
     this.position_w    = position_w;
     this.shouldBeSaved = false;
 }
Exemple #12
0
 public static vi ChunkFromWorldPosition_c(vf position_w) => (System.Math.Floor(position_w.x / chunkSize), System.Math.Floor(position_w.y / chunkSize));