示例#1
0
文件: Projectile.cs 项目: voidel/mobo
        public Projectile(Texture2D texture, Vector2 position, Vector2 velocity, float rotation, int index, Player playerOwner, StationNode stationNodeOwner)
        {
            bounds.X     = 10000;
            bounds.Y     = 10000;
            this.texture = texture;
            if (playerOwner != null)
            {
                // A player fired projectile
                origin = new Vector2(texture.Width / 2, 3);
                bounds = new Rectangle((int)position.X - bounds.Width / 2, (int)position.Y - bounds.Height / 2, 3, 3);
            }
            else
            {
                // A StationNode fired projectile
                origin = new Vector2(texture.Width / 2f, texture.Height / 2f);
                bounds = new Rectangle((int)position.X - bounds.Width / 2, (int)position.Y - bounds.Height / 2, 12, 12);
            }

            this.position = position;
            this.velocity = velocity;
            this.rotation = rotation;

            // Give the projectile a unique index if one not already supplied
            if (index == -1)
            {
                this.index = rand.Next();
            }
            else
            {
                this.index = index;
            }

            // Assign to owner
            if (playerOwner != null)
            {
                this.playerOwner = playerOwner;
            }
            else
            {
                this.stationNodeOwner = stationNodeOwner;
            }

            // Set up a timer to remove projectile when the lifetime is up
            lifeTime           = new Timer(2000);
            lifeTime.Elapsed  += OnLifeTimeOver;
            lifeTime.AutoReset = false;
            lifeTime.Enabled   = true;

            // Set up a timer for the death animation
            deathAnim           = new Timer(100);
            deathAnim.Elapsed  += OnDeathOver;
            deathAnim.AutoReset = false;

            // Play sound
            float f = (float)rand.NextDouble();

            ContentStore.laser.Play(0.25f, f / 2, 0);
        }
示例#2
0
        private void AssignNodeTextures()
        {
            foreach (Node node in flat_list.Values)
            {
                StationNode snode = node.data;

                if (snode.nodeType == StationNodeType.Pipe)
                {
                    string k = "nswe";

                    Vector2 diff = node.parent.position - node.position;

                    if (diff.X == 1)
                    {
                        k = k.Replace('s', 'S');
                    }
                    if (diff.X == -1)
                    {
                        k = k.Replace('n', 'N');
                    }
                    if (diff.Y == 1)
                    {
                        k = k.Replace('e', 'E');
                    }
                    if (diff.Y == -1)
                    {
                        k = k.Replace('w', 'W');
                    }

                    foreach (Node child in node.children)
                    {
                        Vector2 childiff = child.position - node.position;

                        if (childiff.X == 1)
                        {
                            k = k.Replace('s', 'S');
                        }
                        if (childiff.X == -1)
                        {
                            k = k.Replace('n', 'N');
                        }
                        if (childiff.Y == 1)
                        {
                            k = k.Replace('e', 'E');
                        }
                        if (childiff.Y == -1)
                        {
                            k = k.Replace('w', 'W');
                        }
                    }

                    switch (k)
                    {
                    case "NSwe": snode.texture = ContentStore.pipe_h; break;

                    case "nsWE": snode.texture = ContentStore.pipe_v; break;

                    case "NsWe": snode.texture = ContentStore.pipe_se; break;

                    case "NswE": snode.texture = ContentStore.pipe_ne; break;

                    case "nSWe": snode.texture = ContentStore.pipe_sw; break;

                    case "nSwE": snode.texture = ContentStore.pipe_nw; break;

                    case "NsWE": snode.texture = ContentStore.pipe_e; break;

                    case "nSWE": snode.texture = ContentStore.pipe_w; break;

                    case "NSWe": snode.texture = ContentStore.pipe_s; break;

                    case "NSwE": snode.texture = ContentStore.pipe_n; break;

                    case "NSWE": snode.texture = ContentStore.pipe_c; break;
                    }
                }

                else if (snode.nodeType == StationNodeType.Turret)
                {
                    snode.texture = ContentStore.orb_blue;
                }

                snode.origin = new Vector2(snode.texture.Width / 2, snode.texture.Height / 2);
            }
        }