private Vector2 GetRandomWorldPosition() { float x = XNACS1Base.World.WorldDimension.X * XNACS1Base.RandomFloat(0.02f, 0.48f); float y = XNACS1Base.World.WorldDimension.Y * XNACS1Base.RandomFloat(0.02f, 0.48f); return(new Vector2(x, y)); }
public HeroObject() { Radius = 2f; CenterX = XNACS1Base.RandomFloat(XNACS1Base.World.WorldMin.X, XNACS1Base.World.WorldMax.X); CenterY = XNACS1Base.RandomFloat(XNACS1Base.World.WorldMin.Y, XNACS1Base.World.WorldMax.Y); Color = new Color(1f, 0.8f, 0.8f); }
public void InitializeNewBall() { Center = new Vector2(kBallX, kBallY); Velocity = new Vector2(XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity), XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity)); AddToAutoDrawSet(); }
public Debris(Hero hero, List <Enemy> enemies, float minX, float maxX) { float padding = size; float randomX = XNACS1Base.RandomFloat(minX + padding, maxX - padding); float randomY = XNACS1Base.RandomFloat(GameWorld.bottomEdge + padding, GameWorld.topEdge - padding); texture = new XNACS1Rectangle(new Vector2(randomX, randomY), size, size); switch (XNACS1Base.RandomInt(3)) { case 0: texture.Texture = "Beak"; break; case 1: texture.Texture = "Window"; break; case 2: texture.Texture = "Wing2"; texture.Width = texture.Height * 1.8f; break; } obstacle = new Obstacle(hero, enemies, texture.Center, texture.Width * .9f, texture.Height * .9f); }
private void ComputePositionAndVelocity() { // Change the speed without actually change velocity direction!! Speed = kPatrolSpeed * XNACS1Base.RandomFloat(0.8f, 1.2f); // speed has 20% randomness //toNextPosition.Normalize(); // Velocity = speed * toNextPosition; }
public MyBall() : base(new Vector2(kBallX, kBallY), 3f) { Velocity = new Vector2(XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity), XNACS1Base.RandomFloat(kMinVelocity, kMaxVelocity)); ShouldTravel = true; Color = Color.Red; RemoveFromAutoDrawSet(); }
public PowerUp(Hero hero, float minX, float maxX) { this.hero = hero; float padding = hero.getPosition().Width * 2; float randomX = XNACS1Base.RandomFloat(minX + padding, maxX - padding); float randomY = XNACS1Base.RandomFloat(GameWorld.bottomEdge + padding, GameWorld.topEdge - padding); box = new XNACS1Rectangle(new Vector2(randomX, randomY), width, width * 0.39f); }
private void ComputePositionAndVelocity() { Vector2 toNextPosition = mTargetPosition - Center; // this is the vector from Center to the next Position float distantToNextPosition = toNextPosition.Length(); float speed = kPatrolSpeed * XNACS1Base.RandomFloat(0.8f, 1.2f); // speed has 20% randomness toNextPosition.Normalize(); Velocity = speed * toNextPosition; }
/// <summary> /// Spawns a normal ball at the given position /// </summary> /// <param name="postion"></param> public void spawn(Vector2 position) { Vector2 direction = new Vector2(XNACS1Base.RandomFloat(-0.8f, 0.8f), -0.7f); if (direction != Vector2.Zero) { direction.Normalize(); } spawn(position, direction); }
protected override void NewParticle(XNACS1Particle particle) { float theta = XNACS1Base.RandomFloat(0, (float)(2 * Math.PI)); particle.CenterX = CenterX; particle.CenterY = CenterY; Vector2 randomVelocity = new Vector2(XNACS1Base.RandomFloat(-1, 1), XNACS1Base.RandomFloat(-1, 1)); randomVelocity *= 0.2f; particle.Velocity = randomVelocity; particle.ShouldTravel = true; }
public DyePack(Hero hero, float minX, float maxX, Color color) { this.hero = hero; float padding = hero.getPosition().Width * 2; float randomX = XNACS1Base.RandomFloat(minX + padding, maxX - padding); float randomY = XNACS1Base.RandomFloat(GameWorld.bottomEdge + padding, GameWorld.topEdge - padding); box = new XNACS1Rectangle(new Vector2(randomX, randomY), 0.865f * height, height); box.Color = color; box.Texture = getTexture(color); }
public void UpdateEnemyPatrolState(WallSet wall) { float ran = XNACS1Base.RandomFloat(-20f, 20.0f); if (ran < 5) { UpdateEnemyLeftRightDir(wall); } else { UpdateEnemyUpDownDir(wall); } }
private bool UpdateChaseHeroState(HeroObject hero, float distToHero) { bool caught = false; caught = Collided(hero); mTargetPosition = hero.Center; if (caught || (mStateTimer < 0)) { if (caught) { hero.Caught(); } Color = new Color(XNACS1Base.RandomFloat(0f, 0.4f), XNACS1Base.RandomFloat(0f, 0.4f), XNACS1Base.RandomFloat(0f, 0.4f)); // now tansit out of current state ... Vector2 midPt = 0.5f * (XNACS1Base.World.WorldMax - XNACS1Base.World.WorldMin); if (CenterX > midPt.X) { if (CenterY > midPt.Y) { mCurrentState = PatrolState.TopRightRegion; mTargetPosition = RandomTopRightPosition(); } else { mCurrentState = PatrolState.BottomRightRegion; mTargetPosition = RandomBottomRightPosition(); } } else { if (CenterY > midPt.Y) { mCurrentState = PatrolState.TopLeftRegion; mTargetPosition = RandomTopLeftPosition(); } else { mCurrentState = PatrolState.BottomLeftRegion; mTargetPosition = RandomBottomLeftPosition(); } } mStateTimer = kStateTimer; ComputePositionAndVelocity(); } return(caught); }
private int mStateTimer; // interestingly, with "gradual" velocity changing, we cannot // guarantee that we will ever rich the mTargetPosition // (we may ended up orbiting the target), so we set a timer // when timer is up, we transit public PatrolObject() { Radius = 0.7f; ShouldTravel = true; Color = new Color(XNACS1Base.RandomFloat(0f, 0.4f), XNACS1Base.RandomFloat(0f, 0.4f), XNACS1Base.RandomFloat(0f, 0.4f)); Center = RandomTopLeftPosition(); mCurrentState = PatrolState.TopLeftRegion; mTargetPosition = RandomTopRightPosition(); ComputePositionAndVelocity(); }
public override void update() { // remove any dead enemies foreach (Enemy e in enemies.Where(enemy => !enemy.isAlive())) { e.remove(); } enemies.RemoveAll(enemy => !enemy.isAlive()); foreach (Enemy e in enemies) { e.update(); } // prevent generating enemy if (GameWorld.Speed != 0) { newEnemyTimer.update(); } //generate new enemy if (newEnemyTimer.isDone()) { float randomY = XNACS1Base.RandomFloat(GameWorld.topEdge - 5, GameWorld.bottomEdge + 5); Vector2 position = new Vector2(GameWorld.rightEdge + 5, randomY); switch (XNACS1Base.RandomInt(0, 3)) { case 1: enemies.Add(new BrainEnemy(position, 7.5f, hero)); break; case 2: enemies.Add(new RedBeamEnemy(position, 7.5f, hero)); break; default: enemies.Add(new SpiderEnemy(position, 7.5f, hero)); break; } newEnemyTimer.reset(); } }
private void UpdateTopLeftState(HeroObject hero, float distToTarget) { DetectHero(hero); // check if we should transit to ChaseHero if ((mStateTimer < 0) || (distToTarget < 5f)) { mStateTimer = (int)(kStateTimer * XNACS1Base.RandomFloat(0.8f, 1.2f)); // 20% randomness if (XNACS1Base.RandomFloat() > 0.5f) { mCurrentState = PatrolState.BottomLeftRegion; mTargetPosition = RandomBottomLeftPosition(); } else { mCurrentState = PatrolState.TopRightRegion; mTargetPosition = RandomTopRightPosition(); } ComputePositionAndVelocity(); } }
private void UpdateBottomRightState() { Byte g = Color.G; g--; Color = new Color(Color.R, g, Color.B); if ((Center - mTargetPosition).Length() < 1f) { if (XNACS1Base.RandomFloat() > 0.5f) { mCurrentState = PatrolState.TopRightRegion; mTargetPosition = RandomTopRightPosition(); } else { mCurrentState = PatrolState.BottomLeftRegion; mTargetPosition = RandomBottomLeftPosition(); } ComputePositionAndVelocity(); } }
private void UpdateTopLeftState(float distToTarget) { Byte r = Color.R; r++; Color = new Color(r, Color.G, Color.B); if ((mStateTimer < 0) || (distToTarget < 5f)) { mStateTimer = (int)(kStateTimer * XNACS1Base.RandomFloat(0.8f, 1.2f)); // 20% randomness if (XNACS1Base.RandomFloat() > 0.5f) { mCurrentState = PatrolState.BottomLeftRegion; mTargetPosition = RandomBottomLeftPosition(); } else { mCurrentState = PatrolState.TopRightRegion; mTargetPosition = RandomTopRightPosition(); } ComputePositionAndVelocity(); } }
private float randomPosition() { return(XNACS1Base.RandomFloat(Background.height)); }