Exemplo n.º 1
0
        public override bool OnUpdate(float inDeltaSeconds)
        {
            base.OnUpdate(inDeltaSeconds);

            Actor actor = Spatial.Parent.GameObject as Actor;

            // Attack
            if (AttackCooldown > 0.0f)
            {
                AttackCooldown -= inDeltaSeconds;
            }

            if (FireRequested && actor.Blackboard.Target != null && AttackCooldown <= 0.0f)
            {
                Firing = true;
                (actor.Blackboard.Target as Actor).Damage(1);
                AttackCooldown = SRandom.Float(0.6f, 1.0f);
                FireRequested  = false;
            }
            else
            {
                Firing = false;
            }

            return(true);
        }
Exemplo n.º 2
0
 public void Awake()
 {
     rand            = new SRandom((uint)System.DateTime.Now.Millisecond);
     currentWalkTime = 0;
     nextWalkTime    = rand.RandomFloatInRange(minMaxWalkTime.x, minMaxWalkTime.y);
     currentWalkDir  = rand.RandomDirection2D();
 }
Exemplo n.º 3
0
        /*
         * WaveTypes:
         *      RandomSideWave: Spaces enemies evenly on a randomly selected side.
         *      RandomDiagonalWave: Spaces enemies evenly across the DiagonalWaveSize, corner is randomly selected.
         *      RandomLocation: Spawns an enemy on a random location.
         *
         */

        private Vector2[] RandomSideWave()
        {
            Vector2[] vs = new Vector2[spawnSize];

            int   side       = SRandom.Next(1, 5);
            float sideLength = 0;

            if (side < 3)
            {
                sideLength = WindowSize.Width;
            }
            else
            {
                sideLength = WindowSize.Height;
            }

            float gapLength = (sideLength / (float)spawnSize);
            float sum       = gapLength / 2;

            for (int i = 0; i < spawnSize; i++)
            {
                vs[i] = SidePoint(side, sum, 0, 0);
                sum  += gapLength;
            }
            return(vs);
        }
Exemplo n.º 4
0
Arquivo: Room.cs Projeto: radtek/SCM2
        // 销毁房间内所有对象
        public virtual void Clear()
        {
            if (Map != null)
            {
                foreach (var u in AllUnits)
                {
                    smm.Del(u.UID);
                    u.Room = null;
                }

                Map.Clear();
            }

            if (BuffRunner != null)
            {
                BuffRunner.Clear();
            }

            if (TBRunner != null)
            {
                TBRunner.Clear();
            }

            UsrsID     = null;
            Players    = null;
            frameSeqNo = 0;
            rand       = null;
            idSeq      = 0;
        }
Exemplo n.º 5
0
        private Vector2[] RandomLocation()
        {
            Vector2[] vs = new Vector2[spawnSize];

            for (int i = 0; i < spawnSize; i++)
            {
                int     side = SRandom.Next(1, 5);
                Vector2 v    = Vector2.Zero;
                float   x    = 0;
                float   y    = 0;

                if (side < 3)
                {
                    x = WindowSize.Width * SRandom.NextFloat();
                }
                else
                {
                    y = WindowSize.Height * SRandom.NextFloat();
                }

                v     = SidePoint(side, 0, x, y);
                vs[i] = v;
            }
            return(vs);
        }
Exemplo n.º 6
0
        private void MoveObject(Collidable c1, Collidable c2) // c1 should be moved
        {
            Vector2 collidedPos = c1.Position;
            Vector2 backVect;

            backVect = c1.PrevPos - c2.Position;
            while (backVect.Length() == 0)
            {
                backVect = new Vector2(2 * SRandom.NextFloat() - 1, 2 * SRandom.NextFloat() - 1); //! LOL
            }
            backVect.Normalize();
            backVect *= 0.2f;
            float   dotProd = Vector2.Dot(backVect, c1.Velocity);
            Vector2 result  = dotProd / backVect.LengthSquared() * backVect;

            while (c1.BoundBox.Intersects(c2.BoundBox))
            {
                c1.Position += backVect;
            }
            c1.Velocity -= result;

            //if (c1.BoundBox.Bottom == c2.BoundBox.Top || c1.BoundBox.Top == c2.BoundBox.Bottom)
            //    c1.Position = new Vector2(collidedPos.X, c1.Position.Y);
            //else
            //    c1.Position = new Vector2(c1.Position.X, collidedPos.Y);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        public AbstractForceController()
            : base(ControllerType.AbstractForceController)
        {
            Enabled = true;

            Strength      = 1.0f;
            Position      = new Vector2(0, 0);
            MaximumSpeed  = 100.0f;
            TimingMode    = TimingModes.Switched;
            ImpulseTime   = 0.0f;
            ImpulseLength = 1.0f;
            Triggered     = false;
            StrengthCurve = new Curve();
            Variation     = 0.0f;
            Randomize     = new SRandom(1234);
            DecayMode     = DecayModes.None;
            DecayCurve    = new Curve();
            DecayStart    = 0.0f;
            DecayEnd      = 0.0f;

            StrengthCurve.Keys.Add(new CurveKey(0, 5));
            StrengthCurve.Keys.Add(new CurveKey(0.1f, 5));
            StrengthCurve.Keys.Add(new CurveKey(0.2f, -4));
            StrengthCurve.Keys.Add(new CurveKey(1f, 0));
        }
Exemplo n.º 8
0
        public override void Draw(Graphics g)
        {
            Weapon weapon = GameObject as Weapon;

            Spatial spatial = GameObject.GetComponent <Spatial>();

            if (spatial != null)
            {
                Actor actor = spatial.Parent.GameObject as Actor;

                Vector2 center = actor.Spatial.WorldPosition;

                g.DrawLine(weaponPen, Conversion.ToPoint(center + spatial.WorldForward * 8.0f), Conversion.ToPoint(center + spatial.WorldForward * 16.0f));

                if (weapon.Firing && actor.Blackboard.Target != null)
                {
                    Vector2 a = center + spatial.WorldForward * 8.0f;
                    Vector2 b = actor.Blackboard.Target.Spatial.WorldPosition;

                    Vector2 direction = (b - a).Normalize();
                    float   distance  = (float)(b - a).Length();
                    float   aFrac     = SRandom.Float(0.0f, 0.4f);
                    float   bFrac     = SRandom.Float(0.6f, 1.0f);

                    g.DrawLine(firePen, Conversion.ToPoint(a + direction * aFrac * distance), Conversion.ToPoint(a + direction * bFrac * distance));
                }
            }
        }
Exemplo n.º 9
0
 public LevelInfo(uint randomSeed, string levelName)
 {
     GUID       = GetGUID();
     RandomSeed = randomSeed;
     SRandom    = new SRandom(randomSeed);
     LevelName  = levelName;
 }
Exemplo n.º 10
0
        private static void SpeedTest()
        {
            int countPerThread = 10000;
            int threadCount    = 10;

            Thread[] threads = new Thread[threadCount];

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() => {
                    for (int j = 0; j < countPerThread; j++)
                    {
                        SRandom.Next();
                    }
                });
            }

            foreach (Thread thread in threads)
            {
                thread.Start();
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }

            stopwatch.Stop();

            Console.WriteLine("Generated " + threadCount * countPerThread + " ulongs accross " + threadCount + " threads :" + stopwatch.ElapsedMilliseconds + "ms");
        }
Exemplo n.º 11
0
 protected override void SpecificActivation(Vector2 source, Vector2 target)
 {
     base.SpecificActivation(source, target);
     base.CalculateAngle();
     spriteRotSpeed = 0.05f * SRandom.NextFloat();
     Angle         += randomAngleOffsetMultiplier * SRandom.NextFloat();
     friction       = 0f;
     AddSpeed(5, Angle);
 }
Exemplo n.º 12
0
Arquivo: Room.cs Projeto: radtek/SCM2
        // 战斗开始
        public virtual void BattleBegin(int randomSeed)
        {
            rand       = new SRandom(randomSeed);
            Winner     = null;
            Finished   = false;
            frameSeqNo = 0;

            InitBattle();
        }
Exemplo n.º 13
0
 // 随机打乱出生顺序
 public void GetRandomRespawnPlace(List <MapData> RespawnList, SRandom rand)
 {
     FC.For(RespawnList.Count, (i) =>
     {
         int RandomNum          = rand.Next(RespawnList.Count);
         var temp               = RespawnList[RandomNum];
         RespawnList[RandomNum] = RespawnList[i];
         RespawnList[i]         = temp;
     });
 }
Exemplo n.º 14
0
        private void Respawn(float inRespawnDelay)
        {
            Spatial.SetPosition(Vector2.Random(1024, 512));
            Spatial.SetFacing(SRandom.Float(360.0f));

            Blackboard = new Blackboard();

            Blackboard.SetFloat("RespawnDelay", inRespawnDelay);

            Health = 10;
        }
Exemplo n.º 15
0
        private List <Texture2D> GetSplitTexture()
        {
            int largestSplit = 3;

            if (largestSplit > Texture.Width)
            {
                largestSplit = Texture.Width / 2;
            }
            int pixelSize = 2;

            if (pixelSize > Texture.Width)
            {
                pixelSize = Texture.Width / 2 - 1;
            }

            int width  = Texture.Width / Subimages;
            int height = Texture.Height;
            List <Texture2D> texList = new List <Texture2D>();
            Texture2D        tex1    = new Texture2D(Texture.GraphicsDevice, width, height);
            Texture2D        tex2    = new Texture2D(Texture.GraphicsDevice, width, height);

            Color[] colors     = new Color[Texture.Width * Texture.Height];
            Color[] colorsTex1 = new Color[width * height];
            Color[] colorsTex2 = new Color[width * height];
            int     breakPoint = SRandom.Next(width / 2 - largestSplit, width / 2 + largestSplit);

            Texture.GetData(colors);
            for (int y = 0; y < height; y++)
            {
                if (y % pixelSize == 0)
                {
                    breakPoint = SRandom.Next(width / 2 - largestSplit, width / 2 + largestSplit);
                }
                for (int x = 0; x < width; x++)
                {
                    if (x < breakPoint)
                    {
                        colorsTex1[x + y * width] = colors[x + y * Texture.Width];
                        colorsTex2[x + y * width] = Color.Transparent;
                    }
                    else
                    {
                        colorsTex1[x + y * width] = Color.Transparent;
                        colorsTex2[x + y * width] = colors[x + y * Texture.Width];
                    }
                }
            }
            tex1.SetData(colorsTex1);
            tex2.SetData(colorsTex2);
            texList.Add(tex1);
            texList.Add(tex2);
            splitTextures = texList;
            return(texList);
        }
Exemplo n.º 16
0
    public Game(int seed)
    {
        this.seed = seed;
        random    = new SRandom(seed);

        for (int x = 0; x < Size; ++x)
        {
            squares[x, 0]        = squares[x, 1] = 2;
            squares[x, Size - 2] = squares[x, Size - 1] = 1;
        }
        pieces[1] = pieces[2] = 2 * Size;
    }
Exemplo n.º 17
0
 // Use this for initialization
 void Start()
 {
     inGame                     = false;
     hasShownScreen             = true;
     hasGenerated               = true;
     currentLevelTransitionTime = delayToGenerate + 1;
     depth               = 0;
     rand                = new SRandom((uint)System.DateTime.Now.Millisecond);
     inDeathScene        = false;
     shouldRespawnPlayer = false;
     inGameMenu          = false;
 }
Exemplo n.º 18
0
        //public void Spawn()
        //{
        //    SpawnAt(new Vector2((float)SRandom.NextDouble() * width + 50, (float)SRandom.NextDouble() * height + 50));
        //}

        //public void SpawnAt(Vector2 source)
        //{
        //    if (spawnTimer.IsFinished)
        //    {
        //        if (ActivateEntities(source, source, SRandom.Next((int)IDs.HEALTHDROP,(int)IDs.ENERGYDROP + 1)))
        //            spawnTimer.Reset();
        //    }
        //}

        public void SpawnAt(Vector2[] source)
        {
            foreach (Vector2 v in source)
            {
                int dropType = SRandom.Next((int)IDs.HEALTHDROP, (int)IDs.ENERGYDROP + 1);
                if (dropType == (int)IDs.HEALTHDROP_TIER2 && SRandom.NextFloat() > healthSpawnChance_tier2)
                {
                    dropType = (int)IDs.HEALTHDROP;
                }
                ActivateEntities(v, v, dropType);
            }
        }
Exemplo n.º 19
0
        private Vector2[] RandomDiagonalWave()
        {
            int diagonalWaveSize = spawnSize * diagonalSpacing; // alright?

            Vector2[] vs     = new Vector2[spawnSize];
            int       corner = SRandom.Next(1, 5);
            int       offset = -spawnSize / 2;

            for (int i = 0; i < spawnSize; i++)
            {
                vs[i] = DiagonalPoint(corner, offset * diagonalWaveSize / spawnSize);
                offset++;
            }
            return(vs);
        }
Exemplo n.º 20
0
        public void Spawn(Vector2 source)
        {
            float rnd  = SRandom.NextFloat();
            int   type = (int)IDs.DEFAULT_ENEMY;

            //if (rnd < Difficulty.CAN_SHOOT_RISK) //! chance of being able to shoot
            //    type = (int)IDs.ENEMYSHOOT;
            //else if (rnd < Difficulty.IS_SPEEDY_RISK) //! chance of being shupeedo
            //    type = (int)IDs.ENEMYSPEED;
            //else if (rnd < Difficulty.IS_ASTEROID_RISK) //! chance of being ASTEROIIIID
            //    type = (int)IDs.ENEMYASTER;
            //if (rnd < 0.2) //!      OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOJJ!
            //    type = (int)IDs.ENEMYASTER;
            ActivateEntities(source, player.Position, type);
        }
Exemplo n.º 21
0
        public override void OnStart()
        {
            Vector2[] points = new Vector2[]
            {
                new Vector2(SRandom.Range(0, .2), SRandom.Range(0, .2)),
                new Vector2(SRandom.Range(-.2, .2), SRandom.Range(-.2, 0)),
                new Vector2(SRandom.Range(-.2, 0), SRandom.Range(-.2, .2))
            };

            renderer.SetPoints(points);
            renderer.MainColor   = color;
            renderer.RenderLayer = layer;

            velocity = new Vector2(SRandom.Range(-.15, .15), SRandom.Range(-.1, .3));
        }
Exemplo n.º 22
0
        private static void SpeedTestRange()
        {
            int count = 50000000;

            ulong[] arr = new ulong[count];

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = SRandom.Next(10000, 100000);
            }
            stopwatch.Stop();
            var time = stopwatch.ElapsedMilliseconds;

            Console.WriteLine(count + " ulongs generated on 1 thread with range method: " + time + "ms");
        }
Exemplo n.º 23
0
        public GeneratorPerlin(int seed, float amplitude = 1, float persistence = 0.5f,
                               float frequency           = 1f, float freqMulti  = 2f, int octaves = 1)
        {
            this.perlin      = new PerlinNoise((uint)seed);
            this.Amplitude   = amplitude;
            this.Persistence = persistence;
            this.Frequency   = frequency;
            this.FreqMulti   = freqMulti;
            this.Octaves     = octaves;

            var rand = new SRandom((uint)seed);

            offsetX = (float)rand.RandomFloatZeroToOne();
            offsetY = (float)rand.RandomFloatZeroToOne();
            offsetZ = (float)rand.RandomFloatZeroToOne();
            offsetW = (float)rand.RandomFloatZeroToOne();
        }
Exemplo n.º 24
0
        public Vector2 GetAsteroidSpawnPoint()
        {
            int     side = SRandom.Next(1, 5);
            Vector2 v    = Vector2.Zero;
            float   x    = 0;
            float   y    = 0;

            if (side < 3)
            {
                x = WindowSize.Width * SRandom.NextFloat();
            }
            else
            {
                y = WindowSize.Height * SRandom.NextFloat();
            }

            v = SidePoint(side, 0, x, y);
            return(v);
        }
Exemplo n.º 25
0
        /*
         * MODES:
         *
         */
        private Vector2[] RandomWaveType()
        {
            Vector2[] vs = new Vector2[spawnSize];

            int waveType = SRandom.Next(0, 9);

            if (waveType >= 8)
            {
                vs = RandomDiagonalWave();
            }
            else if (waveType >= 5)
            {
                vs = RandomSideWave();
            }
            else
            {
                vs = RandomLocation();
            }
            return(vs);
        }
Exemplo n.º 26
0
        public PerlinNoise(uint seed)
        {
            SRandom rand = new SRandom(seed);

            perm = new int[(REPITITION_SIZE + 1) * 2];
            for (int i = 0; i < REPITITION_SIZE; i++)
            {
                perm[i] = i;
            }

            for (int i = 0; i < REPITITION_SIZE; i++)
            {
                int toSwitch = rand.RandomIntLessThan(REPITITION_SIZE + 1);
                int temp     = perm[toSwitch];
                perm[toSwitch] = i;
                perm[i]        = temp;
                perm[toSwitch + REPITITION_SIZE] = i;
                perm[i + REPITITION_SIZE]        = temp;
            }
        }
Exemplo n.º 27
0
        public override void Start()
        {
            base.Start();

            curDir = Direction.Up;

            anim = GetComponent <Animator>();

            var instSteerings = new List <SteeringEffect>(steerings.Count);

            foreach (SteeringEffect s in steerings)
            {
                instSteerings.Add(Instantiate(s));
            }

            steerings = instSteerings;

            velocity = Vector2.zero;

            rand = new SRandom((uint)System.DateTime.Now.Millisecond);
        }
Exemplo n.º 28
0
        //public static void Update(GameTime gameTime)
        //{
        //    sTimer.CountDown(gameTime);
        //}

        public static void PlaySoundEffect(int ID)
        {
            SoundEffectInstance sei = GetSound(ID).CreateInstance();

            if (seis[ID] != null)
            {
                seis[ID].Stop();
                seis[ID].Dispose();
            }
            if (ID == (int)IDs.MENUCLICK)
            {
                sei.Volume = 0.2f;
                sei.Pitch  = 0.1f;
            }
            else if (ID == (int)IDs.EXPLOSIONDEATHSOUND)
            {
                sei.Volume = 0.2f;
                sei.Pitch  = 0.7f;
            }
            else if (ID == (int)IDs.SLOWMOSOUND || ID == (int)IDs.REVERSESLOWMOSOUND)
            {
                sei.Volume = 0.5f;
                sei.Pitch  = 0.5f;
            }
            else if (ID == (int)IDs.PICKUPSOUND)
            {
                sei.Volume = 0.15f;
                sei.Pitch  = SRandom.NextFloat() * 0.3f + 0.7f;
            }
            else
            {
                sei.Pitch += SRandom.NextFloat() * 0.3f - 0.15f;
            }
            sei.Play();
            seis[ID] = sei;
        }
Exemplo n.º 29
0
 private int GerarIndexAleatorioPadrao()
 {
     return(SRandom.Next(0, PastasImagens.Length - 1));
 }
Exemplo n.º 30
0
 protected void Start()
 {
     hardness = tilemap.GetComponent<TilemapHardness>();
     rand = new SRandom((uint)System.DateTime.Now.Millisecond);
 }