/// <summary> /// Initialize the internal state of your game /// </summary> protected override void InitializeWorld() { mTarget = new XNACS1Circle(new Vector2(50, 30), 1f); mTarget.Color = Color.Red; mSocccer = new MySoccer(); }
// fire the weapon public virtual void fire() { XNACS1Circle bullet = new XNACS1Circle(hero.getPosition().Center, bulletSize); bullet.Color = hero.getColor(); bullets.Enqueue(bullet); }
private void CreateBall(Vector2 pos) { mBall = new XNACS1Circle(pos, mBallRadius, "SoccerBall"); mBall.VelocityDirection = mBallVelocity; mBall.Speed = mBallSpeed; mBall.ShouldTravel = true; }
public shot(Vector2 center, bool hit) { bullet = new XNACS1Circle(center, 1f, "bullet"); this.hit = hit; shotLife = 25; emitter = new XNACS1ParticleEmitter.FireEmitter(center, 30, 0.5f, "bullet", Color.OrangeRed, 20f, 3f, new Vector2(-1, 0)); }
public shot(Vector2 center, bool hit) { bullet = new XNACS1Circle(center, .75f, "wizardShot"); bullet.Speed = 1f; this.hit = hit; shotLife = 40; emitter = new XNACS1ParticleEmitter.FireEmitter(center, 10, 0.3f, "wizardShot", Color.Green, 1f, 3f, new Vector2(-1, 0)); }
private XNACS1Circle starAt(float xPos) { Vector2 position = new Vector2(xPos, randomPosition()); XNACS1Circle star = new XNACS1Circle(position, size); star.Color = randomStarColor(); return(star); }
public void reflect(XNACS1Circle other) { if (other != null) { pushOutCircle(other); reflectHelper(other); } }
public shot(Vector2 center, bool hit) { bullet = new XNACS1Circle(center, .75f, "violetlight"); bullet.Speed = 1f; this.hit = hit; shotLife = 15; emitter = new XNACS1ParticleEmitter.FireEmitter(center, 10, 0.3f, "violetlight", Color.Pink, 1f, 3f, new Vector2(-1, 0)); }
public void reflect(XNACS1Circle other) { if (other != null) { reflectOutCircle(other); //pushOutCircle(other); //reflectionVelocityResolution(other); } }
private float kDrawSize = 8f; // draw size ... public VectorComponents() { // Create first to show on bottom! mStart = new XNACS1Circle(); mStart.Radius = 0.5f; mStart.Color = Color.Black; mVec = new XNACS1Rectangle(); mTangent = new XNACS1Rectangle(); mNormal = new XNACS1Rectangle(); }
public Bullet(Vector2 genaratePosition, Vector2 currentSpeed, float radius, Hero currentHero, List <Enemy> currentEnemy) { this.position = new XNACS1Circle(genaratePosition, radius); this.position.Color = Game.randomColor(); explosions = new List <Explosion>(); // set object into motion; this.alive = true; this.hero = currentHero; this.enemies = currentEnemy; this.speed = currentSpeed; }
public Explosion(Hero h, Enemy e) { splash = new XNACS1Circle(e.getPosition().Center, splashRadius); timer = new Timer(duration); splash.Color = h.getColor(); splash.Visible = false; splash.RemoveFromAutoDrawSet(); emitter = new ExplosionEmitter(e.getPosition().Center, duration, 0.6f, h.getColor()); emitter.DrawHalo(20); emitter.AutoRemoveDeadParticles = true; }
/// <summary> /// You should initialize/allocate instance variables here! /// </summary> protected override void InitializeWorld() { World.SetWorldCoordinate(new Vector2(0, 0), 100); mBall = new XNACS1Circle(new Vector2(20f, 20f), 1); mBall.Texture = "SoccerBall"; mBall.ShouldTravel = true; mCurrentSpeed = 0.1f; mCurrentDir = new Vector2(); SetRandomBallVelocityDir(); }
private void PlotSineCurve() { mPlotSet.RemoveAllFromSet(); ComputeFrequencyScale(); for (int x = 0; x < World.WorldDimension.X; x++) { float y = mInitPos.Y + GetYValue(x); XNACS1Circle c = new XNACS1Circle(new Vector2(x, y), 0.2f); mPlotSet.AddToSet(c); } mTravel.TopOfAutoDrawSet(); }
public override void fire() { base.fire(); XNACS1Circle bullet = new XNACS1Circle(hero.getPosition().Center, bulletSize); bullet.Color = hero.getColor(); angledBullets.Enqueue(bullet); bullet = new XNACS1Circle(hero.getPosition().Center, bulletSize); bullet.Color = hero.getColor(); angledBullets.Enqueue(bullet); }
public ShowVector(Vector2 startPos, Vector2 dir, float size) { mDir = dir; mSize = size; mVec = new XNACS1Rectangle(); mVecInX = new XNACS1Rectangle(); mVecInY = new XNACS1Rectangle(); // Create last to show on top! mStart = new XNACS1Circle(startPos, kVecWidth / 3); mStart.Color = Color.Red; UpdateEndPoints(); }
protected override void InitializeWorld() { World.SetWorldCoordinate(new Vector2(0, 0), 100f); mPeriods = 2f; ComputeFrequencyScale(); mAmplitude = 10f; mInitPos = new Vector2(0, World.WorldDimension.Y / 2f); mTravel = new XNACS1Circle(mInitPos, 2f); mTravel.Color = Color.Black; mPlotSet = new XNACS1PrimitiveSet(); mConstantSpeed = false; PlotSineCurve(); }
protected void pushOutCircle(XNACS1Circle other) { if (other != null) { // pushout Vector2 dist = other.Center - Center; if (dist.Length() != 0) { Vector2 direction = new Vector2(dist.X, dist.Y); direction.Normalize(); float totalRadius = other.Radius + Radius; other.CenterX += (totalRadius - dist.Length()) * direction.X; other.CenterY += (totalRadius - dist.Length()) * direction.Y; } } }
protected override void InitializeWorld() { World.SetWorldCoordinate(new Vector2(-5f, 0f), kDistanceCovered + kUnits); // Create the road mile posts ... for (int i = 0; i < kUnits; i++) { int centerX = (i * kUnits) + (kUnits / 2); XNACS1Rectangle r = new XNACS1Rectangle(new Vector2((float)centerX, kRoadY), kUnits, 1); r.Color = kRoadColor[i]; r.Label = centerX.ToString(); } mBall = new XNACS1Circle(new Vector2(kDistanceCovered + 1f, kRoadY), 2f); mBall.ShouldTravel = true; mBall.RemoveFromAutoDrawSet(); }
public void update() { // move stars, and redraw foreach (XNACS1Circle star in stars) { star.CenterX -= speed; star.TopOfAutoDrawSet(); } // recycle stars to right edge of screen if (stars.First().CenterX <= GameWorld.leftEdge) { XNACS1Circle star = stars.Dequeue(); star.CenterX = GameWorld.rightEdge; star.CenterY = randomPosition(); stars.Enqueue(star); } }
protected override void InitializeWorld() { World.SetWorldCoordinate(new Vector2(-kWorldSize, -kWorldSize * (9f / 16f)), (2f * kWorldSize)); mRoad = new XNACS1Rectangle[10]; // Create the road mile posts ... for (int i = 0; i < kUnits; i++) { mRoad[i] = new XNACS1Rectangle(kInitPosition, kUnits, kRoadWidth); mRoad[i].Color = kRoadColor[i]; mRoad[i].Label = ((i * kUnits) + (kUnits / 2)).ToString(); } mBall = new XNACS1Circle(kInitPosition, 2f); mBall.ShouldTravel = true; mBall.RemoveFromAutoDrawSet(); mDistanceTravelled = kWorldSize * 2f; GenerateRandomBallVelocityDirection(); ComputeBallSpeed(); }
public FunctionPath(Vector2 origin, float w, float h, float xCoverage, float yCoverage) { mShowPlots = true; mPlotBox = new PlotBox(origin, w, h); mFunctionXCoverage = xCoverage; mFunctionYCoverage = yCoverage; mPlotDist = mPlotBox.Width / kNumPlotPoints; mXTravelDistance = 0f; mTravel = new XNACS1Circle(Vector2.Zero, kTravelRatio * mPlotDist); mTravel.Center = mPlotBox.GetBoxPosition(mXTravelDistance, GetYValue(mXTravelDistance)); mTravel.Color = Color.Black; mConstantSpeed = false; mPlotSet = new XNACS1PrimitiveSet(); PlotFunction(); mTravel.TopOfAutoDrawSet(); }
public override void update() { // we have to maintain our own bullet queue because Weapon class will otherwise // just move bullet horizontally for (int i = 0; i < angledBullets.Count; i++) { XNACS1Circle b = angledBullets.ElementAt(i); b.CenterX += bulletSpeed; if (i % 2 == 0) { b.CenterY -= bulletSpeed / 2; } else { b.CenterY += bulletSpeed / 2; } } while (angledBullets.Count > 0 && (angledBullets.First().CenterX - angledBullets.First().Radius) > GameWorld.rightEdge) { angledBullets.Dequeue().RemoveFromAutoDrawSet(); } foreach (XNACS1Circle b in angledBullets) { foreach (Enemy e in enemies) { if (e.getPosition().Collided(b) && b.Visible) { e.gotShot(b.Color); b.Visible = false; explosions.Add(new Explosion(hero, e)); } } } base.update(); }
protected void PlotFunction() { mPlotSet.RemoveAllFromSet(); mPlotDist = mPlotBox.Width / kNumPlotPoints; for (float xDist = 0f; xDist < mPlotBox.Width; xDist += mPlotDist) { float nextY = GetYValue(xDist); Vector2 p = mPlotBox.GetBoxPosition(xDist, nextY); XNACS1Circle c = new XNACS1Circle(p, kPlotPtRatio * mPlotDist); if (mPlotBox.Collided(c)) { mPlotSet.AddToSet(c); } else { c.RemoveFromAutoDrawSet(); } } mTravel.TopOfAutoDrawSet(); if (!mShowPlots) { mPlotSet.RemoveAllFromAutoDrawSet(); } }
// Pushes out a circle while reflecting it based on its velocity. protected void reflectOutCircle(XNACS1Circle other) { if (other != null) { float topD = 0f, bottomD = 0f, leftD = 0f, rightD = 0f; if (other.VelocityY > 0f) { // flying upwards // check for bottom penetration topD = (other.CenterY + other.Radius) - MinBound.Y; } else { // flying downwards // check for top penetration bottomD = MaxBound.Y - (other.CenterY - other.Radius); } if (other.VelocityX > 0) { // flying towards right // check for left penetration leftD = (other.CenterX + other.Radius) - MinBound.X; } else { // flying towards left // check for right penetration rightD = MaxBound.X - (other.CenterX - other.Radius); } if (topD > 0) { if (leftD > 0) { if (topD < leftD) { other.CenterY = CenterY - other.Radius - (Height / 2f); // push up from top other.VelocityY *= -1f; } else { other.CenterX = CenterX - other.Radius - (Width / 2f); // push towards left other.VelocityX *= -1f; } } else if (rightD > 0) { if (topD < rightD) { other.CenterY = CenterY - other.Radius - (Height / 2f); // push up from top other.VelocityY *= -1f; } else { other.CenterX = CenterX + other.Radius + (Width / 2f); // push towards right other.VelocityX *= -1f; } } } else if (bottomD > 0) { if (leftD > 0) { if (bottomD < leftD) { other.CenterY = CenterY + other.Radius + (Height / 2f); // push up from bottom other.VelocityY *= -1f; } else { other.CenterX = CenterX - other.Radius - (Width / 2f); // push towards left other.VelocityX *= -1f; } } else if (rightD > 0) { if (bottomD < rightD) { other.CenterY = CenterY + other.Radius + (Height / 2f); // push up from bottom other.VelocityY *= -1f; } else { other.CenterX = CenterX + other.Radius + (Width / 2f); // push towards right other.VelocityX *= -1f; } } } } }
public void CreateTarget() { m_Target = new XNACS1Circle(new Vector2(30f, 30f), 2f, "SoccerBall"); }
public void DestroyTarget() { m_Target.RemoveFromAutoDrawSet(); m_Target = null; }
protected void pushOutCircle(XNACS1Circle other) { if (other != null) { float topD = 0f, bottomD = 0f, leftD = 0f, rightD = 0f; if (other.VelocityY > 0f) { // flying upwards // check for bottom penetration topD = (other.CenterY + other.Radius) - MinBound.Y; } else { // flying downwards // check for top penetration bottomD = MaxBound.Y - (other.CenterY - other.Radius); } if (other.VelocityX > 0) { // flying towards right // check for left penetration leftD = (other.CenterX + other.Radius) - MinBound.X; } else { // flying towards left // check for right penetration rightD = MaxBound.X - (other.CenterX - other.Radius); } if (topD > 0) { if (leftD > 0) { if (topD < leftD) { other.CenterY = CenterY - other.Radius - (Height / 2f); // push up from top } else { other.CenterX = CenterX - other.Radius - (Width / 2f); // push towards left } } else if (rightD > 0) { if (topD < rightD) { other.CenterY = CenterY - other.Radius - (Height / 2f); // push up from top } else { other.CenterX = CenterX + other.Radius + (Width / 2f); // push towards right } } } else if (bottomD > 0) { if (leftD > 0) { if (bottomD < leftD) { other.CenterY = CenterY + other.Radius + (Height / 2f); // push up from bottom } else { other.CenterX = CenterX - other.Radius - (Width / 2f); // push towards left } } else if (rightD > 0) { if (bottomD < rightD) { other.CenterY = CenterY + other.Radius + (Height / 2f); // push up from bottom } else { other.CenterX = CenterX + other.Radius + (Width / 2f); // push towards right } } } /* * Vector2 otherCenter = new Vector2(other.CenterX, other.CenterY); * float left = CenterX - (Width / 2); * float right = CenterX + (Width / 2); * float top = CenterY + (Width / 2); * float bottom = CenterY - (Width / 2); * otherCenter.X = MathHelper.Clamp(otherCenter.X, left, right); * otherCenter.Y = MathHelper.Clamp(otherCenter.Y, top, bottom); * Vector2 direction = other.Center - otherCenter; * float dist = other.Radius - direction.Length(); * direction.Normalize(); * other.Center += dist * direction; */ } }
public Cursor() { oHitbox = new XNACS1Circle(new Vector2(), fCursorRadius); oHitbox.Color = Color.Red; //oHitbox.Visible = false; }
public void DestroyBall() { mBall.RemoveFromAutoDrawSet(); mBall = null; }