public bool checkCollisionWithWorld(cWorld world, ref Vector2f intersectionOut) { Vector2i posA = new Vector2i((int)this.lastPosition.X, (int)this.lastPosition.Y); //world.ToMapPos(this.lastPosition); Vector2i posB = new Vector2i((int)this.position.X, (int)this.position.Y); // world.ToMapPos(this.Position); bool collided = false; Vector2f intersectionPoint = new Vector2f(0.0f, 0.0f); AppMath.Raytrace(posA.X, posA.Y, posB.X, posB.Y, (x, y) => { collided = world.IsWallAtPos(new Vector2f(x, y)); //world.GetCurrentLevel.IsObstacleAtPos(x, y); intersectionPoint.X = x; // = world.ToWorldPos(new Vector2i(x, y)); intersectionPoint.Y = y; return(collided); } ); intersectionOut.X = intersectionPoint.X; intersectionOut.Y = intersectionPoint.Y; return(collided); }
private cMonster getclosestMonsterColliding(IEnumerable <cMonster> possibleColliders, cBullet bul, Vector2f pos_by, float time) { // int index = -1; double prevDist = Double.MaxValue; double newDist = 0.0; cMonster returner = null; foreach (var mon in possibleColliders) { if (mon.IsKilled) { continue; } // order by distance to find the closest if (cSatCollision.checkAndResolve(bul, mon, time, false)) { newDist = AppMath.Vec2DistanceSqrt(mon.Bounds.center, pos_by); if (newDist < prevDist) { prevDist = newDist; returner = mon; } } } return(returner); }
public void collideParticleRayTrace(Particle p, float step_time, bool drag = true, bool killZero = true) { Vector2i posA = new Vector2i((int)p.LastPos.X, (int)p.LastPos.Y); Vector2i posB = new Vector2i((int)p.Pos.X, (int)p.Pos.Y); bool collided = false; Vector2f intersectionPoint = new Vector2f(0.0f, 0.0f); AppMath.Raytrace(posA.X, posA.Y, posB.X, posB.Y, (x, y) => { collided = this.IsObastacleAtPos(new Vector2f(x, y)); if (collided) { intersectionPoint.X = x; intersectionPoint.Y = y; p.Pos = intersectionPoint; p.LastPos = p.Pos; //if we want to drag to the wall: if (drag) { p.Vel.X = 0.0f; p.Vel.Y = 0.0f; } p.Intersects = true; p.Life = killZero ? 0.0f : p.Life; } return(collided); } ); }
public override void Hit(int amount, cGameObject entity_by) { base.Hit(amount, entity_by); if (this.health <= 0) { this.Kill(entity_by); //this.Scene.ParticleManager.AddNormalBloodExplosion(this.Bounds.center); return; } //this.spriteControl.ChangeState(new cSpriteState(MotionType.FALL, this.spriteControl.getCurrentState().HorizontalFacing)); //this.Scene.ParticleManager.AddLittleBloodExplosion(this.Bounds.center, 3); this.Scene.QueueAction( () => { Scene.Assets.PlaySound("body_hit1", 8); var e = pscene.ParticleManager["explosions"] as cExplosionController; // e.LittleBlood(new Particles.EmissionInfo(this.Bounds.center)); var dir = AppMath.Vec2NormalizeReturn(entity_by.Velocity); float maxLen = (float)AppMath.GetRandomDoubleInRange(10.0, this.Bounds.diagonalLength()); Vector2f end = AppMath.ScaleVector(entity_by.Position, AppMath.Vec2NormalizeReturn(dir), maxLen); // approximately: Vector2f point = AppMath.GetRandomPointOnLine(entity_by.Position, end); e.LittleLine(new Particles.EmissionInfo(point, dir)); }); }
public override bool Fire(Vector2f target) { if (this.isReadForNextShot()) { Vector2f dir = AppMath.Vec2NormalizeReturn(target - owner.Bounds.center); Vector2f toSpreadTarget = AppMath.GetRandomVecBySpread(dir, spread); this.Shot(toSpreadTarget); decreaseAmmo(); owner.Scene.Assets.PlaySound("cg1", 2); /* * this.owner.Scene.QueueAction(() => * { * var e = this.owner.Scene.ParticleManager["explosions"] as cExplosionController; * e.Line(new EmissionInfo(this.owner.Bounds.center, toSpreadTarget)); * * }); */ } return(false); }
private void updateParticle2(float step_time, Particle p, cWorld world) { p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); // p.Vel.X *= p.SlowDown; // p.Vel.Y *= p.SlowDown; AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed); //world.collideParticleSAT(p, step_time, false); //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); p.Opacity -= p.Fade * step_time; }
protected override void initParticle(EmissionInfo emission) { Particle particle = emission.Particle; particle.Pos = emission.StartPosition; particle.LastPos = particle.Pos; particle.ViewPos = particle.Pos; particle.MaxSpeed = AppMath.GetRandomNumber(600, 800); //200,400 | 700, 900 | (400, 600); //3, 8//Math->GetRandomNumber(510, 800); // 2000.0f //------------------------------------------------------------------------------------------------ float angle = (float)AppMath.DegressToRadian(AppMath.GetRandomNumber(0, 360));//sDivisions * m_Angles; particle.Vel = new Vector2f((float)Math.Cos(angle) * particle.MaxSpeed, (float)Math.Sin(angle) * particle.MaxSpeed); //------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------ //particle.m_Vel = sf::Vector2f(Math->GetRandomClamped() * particle.m_MaxSpeed, Math->GetRandomClamped() *particle.m_MaxSpeed); particle.SlowDown = 0.98f; //0.92f; //particle.m_SlowDown = (float)Math->GetRandomDoubleInRange(0.55, 0.7); //0.6f; //phs->AddForce( sf::Vector2f(Math->GetRandomClamped() * phs->MaxSpeed, Math->GetRandomClamped() * phs->MaxSpeed) ); Vector2u uSize = this.renderStates.Texture.Size; particle.Scale = (float)AppMath.GetRandomDoubleInRange(this.minScale, this.maxScale); particle.Dims = new Vector2f(uSize.X * particle.Scale, uSize.Y * particle.Scale); particle.ScaleSpeed = -AppMath.GetRandomNumber(10, 50); particle.Color = Utils.GetRandomRedColor(); particle.Opacity = 255.0f; particle.Life = 1.0f; particle.Fade = 60; //Math->GetRandomNumber(100, 240); particle.Intersects = false; }
public cMachineGun(cGameObject owner, int firing_frequency, string bullet_breed_id = "simple-bullet") : base(owner, firing_frequency, bullet_breed_id) { this.maxAmmo = 300; this.currentAmmo = maxAmmo; this.magazineCapacity = 30; this.timeToReload = 1.5f; this.spread = (float)AppMath.DegressToRadian(4); this.bulletsPerShot = 1; }
private void Form1_Load(object sender, EventArgs e) { AppMath math = new AppMath(); Console.WriteLine(math.CalculateVariance(1)); Console.WriteLine(math.CalculateVariance(1)); Console.WriteLine(math.CalculateVariance(1)); Console.WriteLine(math.CalculateVariance(1)); Console.WriteLine(math.CalculateVariance(1)); }
public cWeapon(cGameObject owner, int firing_frequency, string bullet_breed_id) { this.owner = owner; this.firingFrequency = firing_frequency; this.regulator = new cRegulator(); this.regulator.resetByFrequency(firing_frequency); this.spread = (float)AppMath.DegressToRadian(2); this.bulletsPerShot = 1; this.bulletBreedID = bullet_breed_id; }
public cTile GetTileAtIndex(int index, int layer = TileLayerTypes.WALLS) { if (index >= 0 && index < NumOfTiles) { return(layers[layer][index]); } else { int index2 = AppMath.Clamp <int>(index, 0, NumOfTiles - 1); return(layers[layer][index2]); } }
protected virtual void updateX(float step_time, cWorld world) { acceleration.X = force.X; velocity.X += acceleration.X * step_time; if (acceleration.X < 0.0f) { velocity.X = AppMath.Max <float>(velocity.X, -this.maxWalkSpeed); } else if (acceleration.X > 0.0f) { velocity.X = AppMath.Min <float>(velocity.X, this.maxWalkSpeed); } else // if (isOnGround) { velocity.X = isOnGround ? velocity.X * Constants.GROUND_SLOW_DOWN_FACTOR : velocity.X * Constants.AIR_SLOW_DOWN_FACTOR; } velocity.X = Math.Abs(velocity.X) <= 0.05f ? 0.0f : velocity.X; float delta = velocity.X * step_time; if (delta <= 0.0f) { float wallRightX; if (hasLeftWall2(world, delta, out wallRightX)) { position.X = wallRightX; velocity.X = 0.0f; } else { position.X += delta; } } else { float wallLeftX; if (hasRightWall2(world, delta, out wallLeftX)) { position.X = wallLeftX - Bounds.dims.X; velocity.X = 0.0f; } else { position.X += delta; } } }
public override void Update(float step_time) { cWorld world = particleManager.Scene.World; for (int i = 0; i < pool.CountActive; ++i) { Particle p = pool.get(i); if (!p.Intersects) { /* * p.Dims.Y += p.ScaleSpeed * step_time; //+= * p.Dims.y += p.ScaleSpeed * step_time; //+= */ AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f); p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); p.Vel.X *= p.SlowDown; p.Vel.Y *= p.SlowDown; //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); } p.Opacity -= p.Fade * step_time; if (p.Opacity <= 0.0f) { p.Opacity = 0.0f; pool.deactivate(i); } p.Color.A = (byte)p.Opacity; } }
public override void Update(float step_time) { lastPosition.X = position.X; lastPosition.Y = position.Y; //velocity.Y += (Constants.GRAVITY/2.0f) * step_time; position.X += velocity.X * step_time; position.Y += velocity.Y * step_time; this.Bounds.SetPosByTopLeft(position); this.hitCollisionRect = Bounds; var world = Scene.World; world.collideSAT(this, step_time, false, () => { velocity = new Vector2f(0.0f, 0.0f); this.Scene.QueueAction(() => { this.Scene.Effects.Place(position, "simple-explosion2"); }); this.kill(); }); /* * if (this.checkCollisionWithWorld(owner.Scene.World, ref intersection)) * { * //this.alive = false; // if not set to false, bullets will be shown * position.X = intersection.X; * position.Y = intersection.Y; * velocity = new Vector2f(0.0f, 0.0f); * //cAssetManager.playSound("wallhit", 5); * * this.Scene.QueueAction(() => * { * this.Scene.Effects.Place(intersection, "simple-explosion2"); * }); * * this.kill(); * } */ if (!AppMath.Vec2IsZero(velocity)) { heading = AppMath.Vec2NormalizeReturn(velocity); //orientation = cAppMath.GetAngleOfVector(heading); //Side = Math->Vec2Perp(Heading); } }
public void DeployOn(RenderTarget target, float alpha, AABB region_bounds = null) { /* * // offset fixes texture coord rounding * var offset = 0.25f * Zoom; * center.X += offset; * center.Y += offset; */ //Target = center; //ActualPosition = center; this.ViewPosition = AppMath.Interpolate(ActualPosition, PreviousPosition, alpha); this.View.Center = this.ViewPosition; target.SetView(this.View); }
public void Update(float step_time) { force.Y = (startPosition.Y - position.Y) * SPEED; //cAppMath.Vec2Truncate(ref force, MAX_FORCE); acceleration.Y = force.Y * step_time; velocity.Y += acceleration.Y * step_time; AppMath.Vec2Truncate(ref velocity, MAX_VELOCITY); lastPosition = position; position.Y += velocity.Y * step_time; // * factor; force.Y = 0.0f; }
protected double[] exp(AppMath.BaseFunc F, double x0, double x1) { double[] a = new double[4]; double x0_x1=(x0 - x1); double LogF0_F1=Math.Log(F.Val(x0) / F.Val(x1)); double d = a[3] = (F.Diff(x1) / F.Val(x1) + F.Diff(x0) / F.Val(x0)+2*LogF0_F1/(x1-x0))/Math.Pow(-1*x0_x1,2); double c = a[2] = ((2 * x0 * x0 - x0 * x1 - x1 * x1) * a[3] - F.Diff(x0) / F.Val(x0) - LogF0_F1 / (-1 * x0_x1)) / (-1 * x0_x1); double b = a[1] = 1 / (x1 - x0) * (Math.Log(F.Val(x1) / F.Val(x0)) - a[3] * (Math.Pow(x1, 3) - Math.Pow(x0, 3)) - c * (Math.Pow(x1, 2) - Math.Pow(x0, 2))); //A a[0] = F.Val(x0) * Math.Exp(-1*(d * Math.Pow(x0, 3) + c * Math.Pow(x0, 2) + b * x0)); return a; }
public virtual void checkContactWithPlayer() { cPlayer player = Scene.Player; float d = (float)AppMath.Vec2Distance(player.Bounds.center, this.Bounds.center); if (!this.pulling) { this.pulling = d <= MAX_PULL_DISTANCE; } if (!pickedUp && cCollision.OverlapAABB(player.Bounds, this.HitCollisionRect)) { player.pickUp(pickup); pickedUp = true; } }
public static void Update() { if (shaking) { m_CurrentRadius *= m_DiminishFactor; //diminish radius each frame m_CurrentAngle += (150.0f + AppRandom.GetRandomNumber(0, 60)); //pick new angle float rad = (float)AppMath.DegressToRadian(m_CurrentAngle); m_Offset = new Vector2f((float)Math.Sin(rad) * m_CurrentRadius, (float)Math.Cos(rad) * m_CurrentRadius); //create offset 2d vector m_CurrentCenterPos = m_DefaultCenter + m_Offset; //set centre of viewport if (m_CurrentRadius < m_MinShakeRadius) //2.0f { StopShake(); } } }
public override void Update(float step_time) { double dist = AppMath.Vec2Distance(Scene.Player.Bounds.center, this.Bounds.center); if (dist <= SPOT_DISTANCE) { Vector2f toTarget = AppMath.Vec2NormalizeReturn((Scene.Player.Bounds.center + Scene.Player.Velocity) - this.Bounds.center); float ang = AppMath.GetAngleBetwenVecs(toTarget, gunFacingDirection); Quaternion q = Quaternion.CreateFromAxisAngle(new Vector3f(toTarget.X, toTarget.Y, 0.0f), ang); Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3f(gunFacingDirection.X, gunFacingDirection.Y, 0.0f), ang); q = Quaternion.Slerp(q, q2, ang); gunFacingDirection = new Vector2f(q.X, q.Y); // toTarget; gun.Fire(Scene.Player.Bounds.center /*+ Scene.Player.Velocity * step_time*/); } }
protected bool hasCeiling(cWorld world, float delta, out float bottomY) { bottomY = 0.0f; float predictedPosY = position.Y + delta; Vector2f oldTopLeft = new Vector2f(position.X, position.Y); Vector2f newTopLeft = new Vector2f(position.X, predictedPosY); Vector2f newTopRight = new Vector2f(newTopLeft.X + Bounds.dims.X - 2.0f, newTopLeft.Y); int endY = world.ToMapPos(oldTopLeft).Y; //mMap.GetMapTileYAtPoint(newBottomLeft.y); int begY = Math.Min(world.ToMapPos(newTopLeft).Y, endY); int dist = Math.Max(Math.Abs(endY - begY), 1); int tileIndexX; for (int tileIndexY = begY; tileIndexY <= endY; ++tileIndexY) { var topLeft = AppMath.Interpolate(newTopLeft, oldTopLeft, (float)Math.Abs(endY - tileIndexY) / dist); var topRight = new Vector2f(topLeft.X + Bounds.dims.X - 1, topLeft.Y); for (var checkedTile = topLeft; ; checkedTile.X += Constants.TILE_SIZE) { checkedTile.X = Math.Min(checkedTile.X, topRight.X); tileIndexX = world.ToMapPos(checkedTile).X; if (world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type == TileType.WALL) { bottomY = (((float)tileIndexY) * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y + Constants.TILE_SIZE); return(true); } if (checkedTile.X >= topRight.X) { break; } } } return(false); }
protected override void initParticle(EmissionInfo emission) { Particle particle = emission.Particle; particle.Pos = emission.StartPosition; particle.LastPos = particle.Pos; particle.ViewPos = particle.Pos; particle.MaxSpeed = AppMath.GetRandomNumber(minSpeed, maxSpeed); //700, 900 | (400, 600); //3, 8//Math->GetRandomNumber(510, 800); // 2000.0f if (!AppMath.Vec2IsZero(emission.EmitDirection)) { Vector2f particleDirection = AppMath.GetRandomVecBySpread(emission.EmitDirection, this.maxSpread); particle.Vel = new Vector2f(particleDirection.X * particle.MaxSpeed, particleDirection.Y * particle.MaxSpeed); } else { // float angle = (float)cAppMath.DegressToRadian(cAppMath.GetRandomNumber(0, 360));//sDivisions * m_Angles; particle.Vel = AppMath.GetRandomUnitVec() * particle.MaxSpeed; // particle.Vel = new Vector2f((float)Math.Cos(angle) * particle.MaxSpeed, (float)Math.Sin(angle) * particle.MaxSpeed); } //float dir = Math->GetRandomClamped(); //particle.m_Vel = sf::Vector2f(Math->GetRandomClamped() * particle.m_MaxSpeed, Math->GetRandomClamped() *particle.m_MaxSpeed); particle.SlowDown = slowDown; //0.92f; //particle.m_SlowDown = (float)Math->GetRandomDoubleInRange(0.55, 0.7); //0.6f; //phs->AddForce( sf::Vector2f(Math->GetRandomClamped() * phs->MaxSpeed, Math->GetRandomClamped() * phs->MaxSpeed) ); Vector2u uSize = this.renderStates.Texture.Size; particle.Scale = (float)AppMath.GetRandomDoubleInRange(this.minScale, this.maxScale); particle.Dims = new Vector2f(uSize.X * particle.Scale, uSize.Y * particle.Scale); particle.ScaleSpeed = -AppMath.GetRandomNumber(5, 20); //10.50 particle.Color = Utils.GetRandomBlueColor(); particle.Opacity = 255.0f; particle.Life = 1.0f; particle.Fade = 80; // 90; //Math->GetRandomNumber(100, 240); particle.Intersects = false; }
private void init(Vector2f pos, Vector2f emit_direction) { this.pickedUp = pulling = false; this.heading = emit_direction; this.renderer = pickup.Renderer.DeepCopy(); this.Bounds = new AABB(); this.Bounds.SetDims(this.pickup.HitRectSize); this.Bounds.SetPosByCenter(pos); this.HitCollisionRect = Bounds.ShallowCopy(); this.MaxSpeed = EMIT_SPEED * 2; //*2 this.mass = 100.0f; this.velocity.X = this.heading.X * EMIT_SPEED; this.velocity.Y = this.heading.Y * EMIT_SPEED; orientation = AppMath.GetAngleOfVector(heading); }
public void Update(Vector2f target, AABB region_bounds, float step_time = Constants.STEP_TIME) { this.Target = target; PreviousPosition = ActualPosition; if (Smooth) { Vector2f dir = AppMath.Vec2NormalizeReturn(Target - ActualPosition); float len = (float)AppMath.Vec2Distance(ActualPosition, Target); Vector2f vel = dir * (len * Smoothness); //AppMath.Vec2Truncate(ref vel, 2.0f); //vel += ShakeScreen.Offset; ActualPosition += vel; } else { ActualPosition = Target + ShakeScreen.Offset; } checkBounds(region_bounds); }
/// <summary> /// Calculate the measured phase for simulation /// </summary> /// <param name="antX">Antenna position x</param> /// <param name="antY">Antenna position y</param> /// <param name="tagX">Tag position x</param> /// <param name="tagY">Tag position y</param> /// <param name="freq">Frequency</param> /// <returns>Measured Phase</returns> public double CaculatingSimulationMeasuredPhase(double antX, double antY, double antZ, double tagX, double tagY, double tagZ, int freq) { double simulationMeasuredPhase = Double.MinValue; double waveLength = SARParameter.C / Convert.ToDouble(freq); double distance = Math.Sqrt(Math.Pow(antX - tagX, 2) + Math.Pow(antY - tagY, 2) + Math.Pow(antZ - tagZ, 2)); if (cbPhaseAmbiguity.Checked) { // Phase with ambiguity simulationMeasuredPhase = GeneratePhaseAmbiguity(4 * Math.PI * distance / waveLength) % (2 * Math.PI); } else { // Phase without ambiguity simulationMeasuredPhase = (4 * Math.PI * distance / waveLength) % (2 * Math.PI); } simulationMeasuredPhase = AppMath.GetNormalDistribution(simulationMeasuredPhase + Convert.ToDouble(tbxMu.Text.Trim()), Convert.ToDouble(tbxSigma.Text.Trim())); return(simulationMeasuredPhase); }
/// <summary> /// /// </summary> /// <param name="scene"></param> /// <param name="pos">position</param> /// <param name="owner">owner gameobject ex. cCharacter</param> /// <param name="direction">normalized vector of direction</param> public cBullet(cGameObject owner, BulletBreed breed, Vector2f pos, Vector2f direction) : base(owner.Scene, pos) { this.owner = owner; this.breed = breed; this.alive = true; this.alpha = 255.0f; // proci határozza meg, hogy milyen alaplap foglalat és milyen RAM!! this.heading = direction; this.Bounds = new AABB(); this.Bounds.SetDims(new Vector2f(1.0f, 1.0f)); this.oppositeDir = new Vector2f(-this.heading.X * breed.slugLength, -this.heading.Y * breed.slugLength); this.intersection = new Vector2f(0.0f, 0.0f); this.Bounds.SetPosByTopLeft(pos); this.velocity.X = this.heading.X * breed.startSpeed; this.velocity.Y = this.heading.Y * breed.startSpeed; orientation = AppMath.GetAngleOfVector(heading); this.sprite = new Sprite(this.breed.sprite); // bullet_yellow_sm; bullet_light_gree this.sprite.Rotation = (float)AppMath.RadianToDegress(this.orientation); }
private void empower(Particle particle) { particle.Pos = particle.StartPos; particle.LastPos = particle.Pos; particle.ViewPos = particle.Pos; particle.MaxSpeed = AppMath.GetRandomNumber(30, 50); //200,400 | 700, 900 | (400, 600); //3, 8//Math->GetRandomNumber(510, 800); // 2000.0f //------------------------------------------------------------------------------------------------ float angle = (float)AppMath.DegressToRadian(AppMath.GetRandomNumber(0, 360));//sDivisions * m_Angles; particle.Rotation = angle; // Vector2f dirUnit = cAppMath.GetRandomUnitVec(); Vector2f dirUnit = AppMath.GetRandomVecBySpread(new Vector2f(0.0f, -1.0f), AppMath.DegressToRadian(6)); particle.Vel = dirUnit * particle.MaxSpeed; //------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------ //particle.m_Vel = sf::Vector2f(Math->GetRandomClamped() * particle.m_MaxSpeed, Math->GetRandomClamped() *particle.m_MaxSpeed); particle.SlowDown = 1.0f; //0.92f; //particle.m_SlowDown = (float)Math->GetRandomDoubleInRange(0.55, 0.7); //0.6f; //phs->AddForce( sf::Vector2f(Math->GetRandomClamped() * phs->MaxSpeed, Math->GetRandomClamped() * phs->MaxSpeed) ); Vector2u uSize = this.renderStates.Texture.Size; particle.Scale = (float)AppMath.GetRandomDoubleInRange(this.minScale, this.maxScale); particle.Dims = new Vector2f(uSize.X * particle.Scale, uSize.Y * particle.Scale); particle.ScaleSpeed = (float)AppMath.GetRandomNumber(15, 25) / 100.0f; particle.Color = Utils.GetRandomColor(250, 250, 1, 160, 0, 0); // GetRandomRedColor(); particle.Opacity = 255.0f; particle.Fade = AppRandom.GetRandomNumber(10, 40); particle.Life = 15.0f; particle.Intersects = false; }
/// <summary> /// Main update protocol. /// </summary> /// <param name="step_time"></param> /// <param name="p"></param> /// <param name="world"></param> private void updateParticle1(float step_time, Particle p, cWorld world) { // Particle's update code comes here. p.Dims.X += p.ScaleSpeed * step_time; //+= p.Dims.Y += p.ScaleSpeed * step_time; //+= if (AppMath.Vec2Length(p.Dims) < 0.5f) { p.Dims.X = 0.0f; p.Dims.Y = 0.0f; } p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); p.Vel.X *= p.SlowDown; p.Vel.Y *= p.SlowDown; AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f); // world.collideParticleSAT(p, step_time, false); //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); p.Opacity -= p.Fade * step_time; }
public override bool Fire(Vector2f target) { if (this.isReadForNextShot()) { Vector2f dir = AppMath.Vec2NormalizeReturn(target - owner.Bounds.center); float dirAngle = (float)AppMath.GetAngleOfVector(dir); float unitAngle = spread / bulletsPerShot; float tangle = dirAngle - ((bulletsPerShot / 2.0f) * unitAngle); for (int i = 0; i < bulletsPerShot; ++i) { tangle += i * unitAngle; //Vector2f toSpreadTarget = cAppMath.GetRandomVecBySpread(dir, spread); Vector2f toSpreadTarget = new Vector2f((float)Math.Cos(tangle), (float)Math.Sin(tangle)); this.Shot(toSpreadTarget); } owner.Scene.Assets.PlaySound("shotgun", 3); return(true); } return(false); }
protected bool hasGround(cWorld world, float delta, out float groundY) { /*var oldCenter = lastPosition; * var center = position;*/ groundY = 0.0f; float predictedPosY = position.Y + delta; /* * Vector2f up = new Vector2f(0, -1); * Vector2f bottom = new Vector2f(0, 1); * Vector2f left = new Vector2f(-1, 0); * Vector2f right = new Vector2f(1, 0);*/ Vector2f oldBottomLeft = new Vector2f(position.X, position.Y + Bounds.dims.Y); Vector2f newBottomLeft = new Vector2f(position.X, predictedPosY + Bounds.dims.Y); Vector2f newBottomRight = new Vector2f(newBottomLeft.X + Bounds.dims.X, newBottomLeft.Y); int endY = world.ToMapPos(newBottomLeft).Y; //mMap.GetMapTileYAtPoint(newBottomLeft.y); int begY = Math.Max(world.ToMapPos(oldBottomLeft).Y - 1, endY); int dist = Math.Max(Math.Abs(endY - begY), 1); int tileIndexX; for (int tileIndexY = begY; tileIndexY <= endY; ++tileIndexY) { var bottomLeft = AppMath.Interpolate(newBottomLeft, oldBottomLeft, (float)Math.Abs(endY - tileIndexY) / dist); var bottomRight = new Vector2f(bottomLeft.X + Bounds.dims.X - 1.0f, bottomLeft.Y); // -1, -2.0f for (var checkedTile = bottomLeft; ; checkedTile.X += Constants.TILE_SIZE) { checkedTile.X = Math.Min(checkedTile.X, bottomRight.X); tileIndexX = world.ToMapPos(checkedTile).X; //world.GetCurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; groundY = (int)((float)tileIndexY * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y); TileType tile = world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type; if (tile == TileType.WALL) { isOnOnewWayPlatform = false; return(true); } else if (tile == TileType.ONEWAY_PLATFORM && position.Y <= groundY - Bounds.dims.Y) { isOnOnewWayPlatform = true; return(true); } if (checkedTile.X >= bottomRight.X) { /*if(isOnOnewWayPlatform) * return true;*/ break; } } } return(false); }
public override void BuildVertexBuffer(float alpha) { uint multiplier = 4; uint vNum = ((uint)pool.CountActive * multiplier) + 1; //vertices.Clear(); vertices.Resize(vNum); float division = 2.0f; Vector2u uSize = this.renderStates.Texture.Size; float tsizeX = uSize.X; float tsizeY = uSize.Y; Vector2f newDims = new Vector2f(); for (uint i = 0; i < pool.CountActive; ++i) { Particle p = pool.get((int)i); newDims.X = p.Dims.X / division; newDims.Y = p.Dims.Y / division; p.ViewPos = AppMath.Interpolate(p.Pos, p.LastPos, alpha); uint vertexIndex = i * multiplier; Vector2f v0Pos = new Vector2f(p.ViewPos.X - newDims.X, p.ViewPos.Y - newDims.Y); Vector2f v1Pos = new Vector2f(p.ViewPos.X + newDims.X, p.ViewPos.Y - newDims.Y); Vector2f v2Pos = new Vector2f(p.ViewPos.X + newDims.X, p.ViewPos.Y + newDims.Y); Vector2f v3Pos = new Vector2f(p.ViewPos.X - newDims.X, p.ViewPos.Y + newDims.Y); // Top-left Vertex v0 = new Vertex( v0Pos, p.Color, new Vector2f(0.0f, 0.0f) ); // Top-right Vertex v1 = new Vertex( v1Pos, p.Color, new Vector2f(tsizeX, 0.0f) ); // Bottom-right Vertex v2 = new Vertex( v2Pos, p.Color, new Vector2f(tsizeX, tsizeY) ); //Bottom-left Vertex v3 = new Vertex( v3Pos, p.Color, new Vector2f(0.0f, tsizeY) ); vertices[vertexIndex + 0] = v0; vertices[vertexIndex + 1] = v1; vertices[vertexIndex + 2] = v2; vertices[vertexIndex + 3] = v3; } }
private double findMu(double xl,double xr,AppMath.BaseFunc Function) { double[] coef = exp(Function, xl, xr); double h = (xr - xl) / Convert.ToDouble(100); double Mu = 0,fx; for (double x = xl; x <= xr; x += h) { fx = Math.Abs(Function.Val(x) - AproximFunc(x, coef)); if (fx > Mu) { Mu = fx; } } return Mu; }
public ComboBoxItem(AppMath.BaseFunc func) { this.Text = func.Text; this.Value = func; }