Пример #1
0
    public void Update(Vector3 position, Camera.Facing facing)
    {
        if (Settings.MouseClick(false))
        {
            this.avalible = false;
            if (facing == Camera.Facing.North || facing == Camera.Facing.South)
            {
                if (Settings.mouseRec.X >= Settings.gManager.PreferredBackBufferWidth / 2)
                {
                    this.bullets.Add(new Bullet(position, true));
                }
                else
                {
                    this.bullets.Add(new Bullet(position, false));
                }
            }
            else if (facing == Camera.Facing.West || facing == Camera.Facing.East)
            {
                if (Settings.mouseRec.X >= Settings.gManager.PreferredBackBufferWidth / 2)
                {
                    this.bullets.Add(new Bullet(position, false));
                }
                else
                {
                    this.bullets.Add(new Bullet(position, true));
                }
            }
        }
        else if (Settings.KeyPress(Keys.LeftControl))
        {
            if (this.bullets.Count == 0)
            {
                this.bullets.Add(new Bullet(position, true));
            }
            else
            {
                this.bullets.Add(new Bullet(position, this.bullets[this.bullets.Count - 1].right));
            }
        }

        foreach (Bullet b in this.bullets)
        {
            b.acceleration += 0.6f;
            b.acceleration  = MathHelper.Clamp(b.acceleration, 0f, 4f);
            MoveForward(b, facing);
            b.matrix = Matrix.CreateTranslation(b.position);
            b.timer++;
            if (b.timer > 100)
            {
                b.kill = true;
            }
        }
        for (int i = 0; i < this.bullets.Count - 1; i++)
        {
            if (this.bullets[i].kill)
            {
                this.bullets.Remove(this.bullets[i]);
            }
        }
    }
Пример #2
0
    private void MoveForward(Bullet b, Camera.Facing facing)
    {
        //b.position -= b.acceleration;

        if (facing == Camera.Facing.North)
        {
            if (b.right)
            {
                b.position.X += b.acceleration;
            }
            else
            {
                b.position.X -= b.acceleration;
            }
        }
        else if (facing == Camera.Facing.East)
        {
            if (b.right)
            {
                b.position.Z -= b.acceleration;
            }
            else
            {
                b.position.Z += b.acceleration;
            }
        }
        else if (facing == Camera.Facing.West)
        {
            if (b.right)
            {
                b.position.Z += b.acceleration;
            }
            else
            {
                b.position.Z -= b.acceleration;
            }
        }
        else if (facing == Camera.Facing.South)
        {
            if (b.right)
            {
                b.position.X -= b.acceleration;
            }
            else
            {
                b.position.X += b.acceleration;
            }
        }
    }