protected void UpdateMovingState() { float dir = (moveAngleIndex / (float)numMoveAngles) * GMath.FullAngle; Physics.Velocity = Vector2F.CreatePolar(speed, dir) * new Vector2F(1.0f, -1.0f); // Stop moving after a duration. if (moveTimer <= 0) { StopMoving(); return; } // Change direction on collisions. if (changeDirectionsOnCollide && physics.IsColliding) { ChangeDirection(); } // Shoot. if (shootType == ShootType.WhileMoving && projectileType != null && GRandom.NextInt(projectileShootOdds) == 0) { isMoving = false; StartShooting(); //Shoot(); } moveTimer--; }
// Trigger a random seed effect. public static void MysterySeed(Monster monster, Entity sender, EventArgs args) { // Random: burn, stun, damage, gale int rand = GRandom.NextInt(4); SeedEntity seed = (SeedEntity)sender; if (rand == 0) { seed.SeedType = SeedType.Ember; } else if (rand == 1) { seed.SeedType = SeedType.Scent; } else if (rand == 2) { seed.SeedType = SeedType.Pegasus; } else { seed.SeedType = SeedType.Gale; } monster.TriggerInteraction(Monster.GetSeedInteractionType(seed.SeedType), sender, args); }
int GetLowerGrowthSize(Node node, Node[,] grid, int jagedness) { if (node == null || grid == null) { return(-1); } int count = 1; for (int y = node.Position.y - 1; y > node.Position.y - 6; y--) { if (y < 0) { break; } Node down = grid[node.Position.x, y]; if (!down.Solid) { count++; } else { break; } } count -= GRandom.GetInt(0, jagedness); return(count); }
protected void UpdateMovingState() { Physics.Velocity = Directions.ToVector(direction) * speed; // Stop moving after a duration. if (moveTimer <= 0) { StopMoving(); return; } // Change direction on collisions. if (changeDirectionsOnCollide && physics.IsColliding) { ChangeDirection(); } // Shoot. if (shootType == ShootType.WhileMoving && projectileType != null && GRandom.NextInt(projectileShootOdds) == 0) { isMoving = false; StartShooting(); //Shoot(); } moveTimer--; }
public virtual void OnSeedHit(SeedEntity seed) { // For mystery seeds, create the effect for another random seed type. if (seed.SeedType == SeedType.Mystery) { int rand = GRandom.NextInt(4); if (rand == 0) { seed.SeedType = SeedType.Ember; } else if (rand == 1) { seed.SeedType = SeedType.Scent; } else if (rand == 2) { seed.SeedType = SeedType.Pegasus; } else { seed.SeedType = SeedType.Gale; } } seed.TriggerMonsterReaction(this); }
public Dataset Generate(int length) { var dataArray = new Data[length]; for (int i = 0; i < length; i++) { var input = new ShapedArray <double>(InputShape, () => GRandom.Uniform() < 0.5 ? 0.0 : 1.0); int oneCount = 0; input.ForEach(X => oneCount += X == 1.0 ? 1 : 0); bool isEven = oneCount % 2 == 0; double[] outArr; if (IsBinary) { outArr = isEven ? new double[] { 1.0, 0.0 } : new double[] { 0.0, 1.0 }; } else { outArr = isEven ? new double[] { 1.0 } : new double[] { 0.0 }; } dataArray[i] = new Data(input, ShapedArray <double> .FromRef(TargetShape, outArr)); } return(Dataset.FromRef(dataArray)); }
protected void ChangeDirection() { if (GRandom.NextInt(4) == 0) { FacePlayer(); return; } direction = (direction + 1 + GRandom.NextInt(3)) % 4; List <int> possibleDirections = new List <int>(); for (int i = 0; i < Directions.Count; i++) { if (!Physics.IsPlaceMeetingSolid(position + (Directions.ToVector(i) * moveSpeed), Physics.CollisionBox)) { possibleDirections.Add(i); } } if (possibleDirections.Count == 0) { direction = GRandom.NextInt(Directions.Count); } else { direction = possibleDirections[GRandom.NextInt(possibleDirections.Count)]; } }
public override void Update() { // Adjust Z-position and velocity to hover at a certain height. if (Math.Abs(zPosition - GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT) > 2.0f) { if (zPosition < GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT) { Physics.ZVelocity = Math.Min(0.5f, Physics.ZVelocity + 0.05f); } if (zPosition > GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT) { Physics.ZVelocity = Math.Max(-0.5f, Physics.ZVelocity - GameSettings.DEFAULT_GRAVITY); } } else { Physics.ZVelocity = 0.0f; zPosition = GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT; } // Adjust move direction. moveSpeed = physics.Velocity.Length; if (moveSpeed == 0.0f) { direction = GRandom.NextFloat(GMath.FullAngle); } else { direction = Physics.Velocity.Direction; } // Adjust velocity. if (Math.Abs(moveSpeed - maxMoveSpeed) > 0.01f) { moveSpeed += 0.04f * Math.Sign(maxMoveSpeed - moveSpeed); } else { moveSpeed = maxMoveSpeed; } // Update random motion. directionSpeed += 0.05f * GRandom.NextFloat(-30.0f, 30.0f); directionSpeed = GMath.Clamp(directionSpeed, -6.0f, 6.0f); direction += directionSpeed; physics.Velocity = Vector2F.CreatePolar(moveSpeed, direction); // Syncronize facing direction with velocity. if (Physics.Velocity.X > 0.0f) { Graphics.SubStripIndex = 0; } else if (Physics.Velocity.X < 0.0f) { Graphics.SubStripIndex = 1; } base.Update(); }
public Server(int port) : base(port) { Model = new Model(this); Model.Add(new AISystem()); Model.Add(new MovementSystem()); Model.Add(new CollisionSystem()); Model.Add(new ServerCollisionSystem()); Model.Add(new TerrainCollisionSystem()); Model.Add(new MovementBroadcastingSystem()); Model.Add(new WeaponSystem()); Model.Add(new HealthSystem()); for (int i = 0; i < 10; i++) { AddZombie(); } var terrain = Model.Terrain; const int D = 100; for (int t = 0; t < 100; t++) { int x = GRandom.Next(-D, D); int y = GRandom.Next(-D, D); const int dist = 5; int sign = -1; // GRandom.Coin() ? 1 : -1; for (int i = x - dist; i <= x + dist; i++) { for (int j = y - dist; j <= y + dist; j++) { var vertex = terrain[i, j]; vertex.Height += sign * (1 - Math.Pow(Math.Min(1, (new Vec2(i, j) - new Vec2(x, y)).Length / dist), 2)) * 0.3; terrain[i, j] = vertex; } } } for (int i = -D; i < D; i++) { for (int j = -D; j < D; j++) { var vertex = terrain[i, j]; vertex.Texture = GRandom.Probable(0.5 + terrain[i, j].Height) ? Terrain.Textures.Grass : Terrain.Textures.Dirt; vertex.Height += GRandom.NextDouble(0.1, 0.2); terrain[i, j] = vertex; } } for (int i = 0; i < 10; i++) { var e = Model.CreateEntity(true); var v = new Vec3(GRandom.NextDouble(-10, 10), GRandom.NextDouble(-10, 10), 0); v.Z = terrain.GetHeight(v.X, v.Y); e.Set <PositionComponent>(new PositionComponent(v, 0)); e.Set <PhysicsComponent>(new PhysicsComponent(0.5)); e.Set <RenderComponent>(new StaticModelComponent(2, 4, new ResourcedTexture("Misc/tree.png"))); Model.Add(e); } }
//----------------------------------------------------------------------------- // Overridden Methods //----------------------------------------------------------------------------- public override void Initialize() { base.Initialize(); isJumping = false; stopTimer = GRandom.NextInt(stopTime.Min, stopTime.Max); Graphics.PlayAnimation(stopAnimation); }
static void GenerateDatasetForTrainingCVAE() { const int N = 1 << 22; StreamWriter writer = new StreamWriter("ScattersDataSet.ds"); Console.WriteLine("Generating file..."); GRandom rnd = new GRandom(); for (int i = 0; i < N; i++) { if (i % 1000 == 0) { Console.Write("\r "); Console.Write("\rCompleted... " + (i * 100.0f / N).ToString("F2")); } var settings = GenerateNewSettings(rnd); var r = Scattering.GetVPTSampleInSphere(settings, rnd); // code path variables in a compact way float3 zAxis = float3(0, 0, 1); float3 xAxis = abs(r.x.z) > 0.999 ? float3(1, 0, 0) : normalize(cross(r.x, float3(0, 0, 1))); float3 yAxis = cross(zAxis, xAxis); float3x3 normR = transpose(float3x3(xAxis, yAxis, zAxis)); float3 normx = mul(r.x, normR); float3 normw = mul(r.w, normR); float3 normX = mul(r.X, normR); float3 normW = mul(r.W, normR); float3 B = float3(1, 0, 0); float3 T = cross(normx, B); float costheta = normx.z; float beta = dot(normw, T); float alpha = dot(normw, B); writer.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}", settings.Sigma, settings.G, settings.Phi, r.N, costheta, beta, alpha, normX.x, normX.y, normX.z, normW.x, normW.y, normW.z ); } Console.WriteLine(); writer.Close(); Console.WriteLine("Done."); }
static ImageRepository() { _client = new MongoClient(); var db = _client.GetDatabase("grekileaks"); _images = db.GetCollection <StoredImage>("images"); _generator = new GRandom(); ResetInternalPointer(); }
public void EndJump() { Physics.Velocity = Vector2F.Zero; isJumping = false; stopTimer = GRandom.NextInt(stopTime.Min, stopTime.Max); Graphics.PlayAnimation(stopAnimation); OnEndJump(); }
public void SpawnExplosionPuffs() { for (int i = 0; i < PuffCount; i++) { float angle = GRandom.GetFloat(1, 360.0f); float dist = GRandom.GetFloat(2.0f, ExplosionRadius / 2.0f); SpawnExplosionPuff(ExplosionPuffObject, angle, dist, PuffForce); } }
Point getRandomPoint() { var angle = GRandom.Random() * Math.PI * 2; return(new Point( Math.Cos(angle) * (0.1 + GRandom.Random() * 0.9) * this.radius, Math.Sin(angle) * (0.1 + GRandom.Random() * 0.9) * this.radius )); }
//随机步骤 private void RandomStep() { int FormC = GRandom.Next(0, 5); int FormT = GRandom.Next(0, 5); int Count = GRandom.Next(1, 3); MoveTo(FormC, FormT, Count); UpdateView(); }
protected void StartCharging(int chargeDirection) { direction = chargeDirection; isCharging = true; if (chargeType == ChargeType.ChargeForDuration) { moveTimer = GRandom.NextInt(chargeDuration.Min, chargeDuration.Max); } }
protected void FaceRandomDirection() { //direction = GRandom.NextInt(Directions.Count); moveAngleIndex = (moveAngleIndex + 1 + GRandom.NextInt(numMoveAngles - 1)) % numMoveAngles; if (numMoveAngles == 4) { direction = moveAngleIndex; } }
protected void ChangeDirection() { //direction = (direction + 1 + GRandom.NextInt(3)) % 4; moveAngleIndex = GRandom.NextInt(numMoveAngles); if (numMoveAngles == 4) { direction = moveAngleIndex; } }
Node[,] CreateMap() { Node[,] grid = new Node[width, height]; Layers = 7; NoiseData[] data = GetNoiseLayers(Layers, 100, GRandom.GetFloat(0.4f, 0.6f)); SetGrid(grid, data); //grid = TrimGrid(grid); SetNodeTypes(grid); return(grid); }
private void SetSpriteFalling() { if (GRandom.GetBool()) { animator.Play("WormFall"); } else { animator.Play("WormSlide"); } }
void Rebuild() { for (int i = 0; i < segs; i++) { ps[i] = Position + Direction * seglen * i; if (i > 0) { ps[i] += Vec2.Rotate90(Direction * GRandom.NextDouble(-offset, offset)); } } }
protected void StartMoving() { isMoving = true; speed = moveSpeed; moveTimer = GRandom.NextInt(moveTime.Min, moveTime.Max); Graphics.PlayAnimation(animationMove); float dir = (moveAngleIndex / (float)numMoveAngles) * GMath.FullAngle; Physics.Velocity = Vector2F.CreatePolar(moveSpeed, dir) * new Vector2F(1.0f, -1.0f); }
public void Jump() { isJumping = true; Graphics.PlayAnimation(jumpAnimation); Physics.ZVelocity = GRandom.NextFloat(jumpSpeed.Min, jumpSpeed.Max); Physics.Velocity = (RoomControl.Player.Center - Center).Normalized * moveSpeed; AudioSystem.PlaySound(GameData.SOUND_MONSTER_JUMP); OnJump(); }
public Dust(Vec2 pos, double size) { Health = new Health(0.2); Position = pos; Size = size * initk; GrowSpeed *= size; for (int i = 0; i < 5; i++) { particles.Add(Vec2.Rotate(Vec2.OrtX * GRandom.NextDouble(), GRandom.NextDouble(0, 2 * Math.PI))); rots.Add(GRandom.NextDouble(0, 2 * Math.PI)); } }
public Asteroid() { Health = new Health(50); Position = Vec2.Rotate(Vec2.OrtX, GRandom.NextDouble(0, 2 * Math.PI)) * InitDistance; const double spot = Math.PI / 6; Velocity = Vec2.Rotate(Vec2.OrtX, Math.PI + Position.Arg + GRandom.NextDouble(-spot, spot)) * Speed; Size = minSize + (maxSize - minSize) * Math.Pow(GRandom.NextDouble(), 10); Position += World.Current.player.Position; Velocity += World.Current.player.Velocity / 2; Physics = Physics.SolidSphere(Size, 1); }
public override void Update(double dt) { Health.Value -= dt; base.Update(dt); Size *= (1 + GrowSpeed * dt); swapT -= dt; if (swapT < 0) { Rotation = GRandom.NextDouble(0, 2 * Math.PI); swapT = SwapTime; } }
static void GenerateDatasetForTabulationXMethod() { int total = 0; Parallel.For(0, 8, file => { BinaryWriter writer = new BinaryWriter(new FileStream("DataSet" + file + ".bin", FileMode.Create)); GRandom rnd = new GRandom(file); int N = 1 << 24; // 16 million samples per file while (N-- > 0) { var settings = GenerateSettingsForX(rnd); var r = Scattering.GetVPTSampleInSphere(settings, rnd); // code path variables in a compact way float3 zAxis = float3(0, 0, 1); float3 xAxis = abs(r.x.z) > 0.999 ? float3(1, 0, 0) : normalize(cross(r.x, float3(0, 0, 1))); float3 yAxis = cross(zAxis, xAxis); float3x3 normR = transpose(float3x3(xAxis, yAxis, zAxis)); float3 normx = mul(r.x, normR); float3 normw = mul(r.w, normR); float3 normX = mul(r.X, normR); float3 normW = mul(r.W, normR); float3 B = float3(1, 0, 0); float3 T = cross(normx, B); float costheta = normx.z; float beta = dot(normw, T); float alpha = dot(normw, B); writer.Write(settings.Sigma); writer.Write(settings.G); writer.Write(r.N); writer.Write(costheta); writer.Write(beta); writer.Write(alpha); Interlocked.Add(ref total, 1); if (total % 100000 == 0) { Console.WriteLine("Overall progress: {0}%", total * 100.0f / (8 * (1 << 24))); } } writer.Close(); }); }
int GetRandomInt(List <int> list) { if (list == null || list.Count == 0) { return(-1); } int rnd = GRandom.GetIntRaw(0, list.Count);// random.Next(0, list.Count); int num = list[rnd]; list.RemoveAt(rnd); return(num); }
protected void StartMoving() { isMoving = true; speed = moveSpeed; moveTimer = GRandom.NextInt(moveTime.Min, moveTime.Max); Physics.Velocity = Directions.ToVector(direction) * speed; ChangeDirection(); if (!Graphics.IsAnimationPlaying || Graphics.Animation != animationMove) { Graphics.PlayAnimation(animationMove); } }