public override void Move(DimensionalManager dm) { while (speed.Count <= dm.GetNumberOfActiveDimensions()) { if (speed.Count >= maxDimensionOfMovement) { break; } speed.Add((float)random.NextDouble()); } base.Move(dm); for (int i = 0; i < dm.GetNumberOfActiveDimensions(); ++i) { pos.Move(i, forwards[i] * speed[i]); if (random.Next(50) == 0 && i > 1) { { float temp = speed[i - 1]; speed[i - 1] = speed[i]; speed[i] = temp; } { int temp = forwards[i - 1]; forwards[i - 1] = forwards[i]; forwards[i] = temp; } } } }
public virtual void Move(DimensionalManager dm) { while (forwards.Count <= dm.GetNumberOfActiveDimensions()) { if (forwards.Count >= maxDimensionOfMovement) { break; } forwards.Add(1); } }
public override void Move(DimensionalManager dm) { base.Move(dm); for (int i = dimToMoveIn; i <= dm.GetNumberOfActiveDimensions(); i += 2) { pos.Move(i, forwards[i] * 1f); if (Math.Abs(pos.GetPosition(i)) >= 3 * GetWidth() && System.DateTime.Now.CompareTo(deathTime) < 0) { forwards[i] = -forwards[i]; } } }
public static bool CheckCollision(Player p, Enemy e, DimensionalManager dm) { int activeDimensions = dm.GetNumberOfActiveDimensions(); Position playerPostion = p.getPosition(); Position enemyPosition = e.GetPosition(); float playerWidth = p.getRadius(); float enemyRadius = e.GetWidth(); float totalDistance = 0.0f; for (int i = 0; i < activeDimensions; ++i) { float distance = Math.Abs(playerPostion.GetPosition(i) - enemyPosition.GetPosition(i)); totalDistance += (distance * distance); } return totalDistance < ((playerWidth + enemyRadius) * (playerWidth + enemyRadius)); }
public void detectInput(KeyboardState kboard, GameTime gameTime, DimensionalManager dm) { /*if (kboard.IsKeyDown(Keys.A)) { velocityXY.X -= acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f ); velocityXY.X = Math.Min(velocityXY.X, -maxVelocity); //pos.Move(currentDimension, -velocity); } else if (kboard.IsKeyDown(Keys.D)) { //pos.Move(currentDimension, velocity); velocityXY.X += acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f ); velocityXY.X = Math.Max(velocityXY.X, maxVelocity); } else if(velocityXY.X > 0) { velocityXY.X -= decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f ); velocityXY.X = Math.Max(velocityXY.X, 0); } else if(velocityXY.X < 0) { velocityXY.X += decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.X = Math.Min(velocityXY.X, 0); }*/ if (kboard.IsKeyDown(Keys.A)) { //pos.Move(currentDimension + 1, -velocity); velocityXY.X -= acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.X = Math.Max(velocityXY.X, -maxVelocity); } else if (kboard.IsKeyDown(Keys.D)) { //pos.Move(currentDimension + 1, velocity); velocityXY.X += acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.X = Math.Min(velocityXY.X, maxVelocity); } else if (velocityXY.X < 0) { velocityXY.X += decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.X = Math.Min(velocityXY.X, 0); } else if (velocityXY.X > 0) { velocityXY.X -= decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.X = Math.Max(velocityXY.X, 0); } if (dm.GetNumberOfActiveDimensions() > currentDimension + 1) { if (kboard.IsKeyDown(Keys.W)) { //pos.Move(currentDimension + 1, -velocity); velocityXY.Y -= acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f ); velocityXY.Y = Math.Max(velocityXY.Y, -maxVelocity); } else if (kboard.IsKeyDown(Keys.S)) { //pos.Move(currentDimension + 1, velocity); velocityXY.Y += acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.Y = Math.Min(velocityXY.Y, maxVelocity); } else if(velocityXY.Y < 0) { velocityXY.Y += decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.Y = Math.Min(velocityXY.Y, 0); } else if(velocityXY.Y > 0) { velocityXY.Y -= decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityXY.Y = Math.Max(velocityXY.Y, 0); } } if (dm.GetNumberOfActiveDimensions() > currentDimension + 3) { if(kboard.IsKeyDown(Keys.Up)) { //pos.Move(currentDimension + 3, -velocityXY); velocityZW.Y -= acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.Y = Math.Max(velocityZW.Y, -maxVelocity); } else if (kboard.IsKeyDown(Keys.Down)) { //pos.Move(currentDimension + 3, velocityXY); velocityZW.Y += acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.Y = Math.Min(velocityZW.Y, maxVelocity); } else if (velocityZW.Y > 0) { velocityZW.Y -= decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.Y = Math.Max(velocityZW.Y, 0); } else if (velocityZW.Y < 0) { velocityZW.Y += decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.Y = Math.Min(velocityZW.Y, 0); } } if (dm.GetNumberOfActiveDimensions() > currentDimension + 2) { if (kboard.IsKeyDown(Keys.Right)) { //pos.Move(currentDimension + 2, velocityXY); velocityZW.X += acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.X = Math.Min(velocityZW.X, maxVelocity); } else if (kboard.IsKeyDown(Keys.Left)) { //pos.Move(currentDimension + 2, -velocityXY); velocityZW.X -= acceleration * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.X = Math.Max(velocityZW.X, -maxVelocity); } else if (velocityZW.X > 0) { velocityZW.X -= decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.X = Math.Max(velocityZW.X, 0); } else if (velocityZW.X < 0) { velocityZW.X += decelartion * ((float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f); velocityZW.X = Math.Min(velocityZW.X, 0); } } pos.Move(currentDimension, velocityXY.X); if(Math.Abs(pos.GetPosition(currentDimension)) > dm.GetScreenWidth() / 2) { pos.Move(currentDimension, -velocityXY.X); velocityXY.X = 0; } pos.Move(currentDimension + 1, velocityXY.Y); if (Math.Abs(pos.GetPosition(currentDimension + 1)) > dm.GetScreenHeight() / 2) { pos.Move(currentDimension + 1, -velocityXY.Y); velocityXY.Y = 0; } pos.Move(currentDimension + 2, velocityZW.X); if (Math.Abs(pos.GetPosition(currentDimension + 2)) > dm.GetScreenWidth() / 2) { pos.Move(currentDimension + 2, -velocityZW.X); velocityZW.X = 0; } pos.Move(currentDimension + 3, velocityZW.Y); if (Math.Abs(pos.GetPosition(currentDimension + 3)) > dm.GetScreenHeight() / 2) { pos.Move(currentDimension + 3, -velocityZW.Y); velocityZW.Y = 0; } if (kboard.IsKeyDown(Keys.Space) && oldState.IsKeyUp(Keys.Space) ) { if (dm.CanIncreaseNumberOfActiveDimensions()) { dm.IncreaseNumberOfActiveDimensions(); } } if (kboard.IsKeyDown(Keys.Tab) && oldState.IsKeyUp(Keys.Tab)) { currentDimension = currentDimension + dimensionsSwitch < dm.GetNumberOfActiveDimensions() ? currentDimension + dimensionsSwitch : 0; } oldState = kboard; }
public void removeEnemies(DimensionalManager dm) { for (int j = 0; j<enemies.Count; ++j) { Enemy en = enemies.ElementAt<Enemy>(j); int count = 0; for (int i = 0; i < dm.GetNumberOfActiveDimensions(); ++i) { if (Math.Abs(en.GetPosition().GetPosition(i)) > (i % 2 == 0 ? dm.GetScreenHeight() : dm.GetScreenWidth())) { ++count; } } if (count == dm.GetNumberOfActiveDimensions()) { Console.WriteLine("Removing enemy: " + en.ToString()); removeEnemy(en); } } }
private void SpawnEnemy(DimensionalManager dm, Player player) { int enemyType = Random.Next(Enum.GetNames(typeof(EnemyType)).Length); Position playerPos = player.getPosition(); float[] position = new float[dm.GetNumberOfActiveDimensions()]; double offSet; Random random = new Random(); for(int i = 0; i< position.Length; ++i) { do { offSet = random.NextDouble() - 0.5; position[i] = i % 2 == 0 ? (float)(playerPos.GetPosition(i) + dm.GetScreenWidth() * offSet) : (float)(playerPos.GetPosition(i) + dm.GetScreenHeight() * offSet); } while (Math.Abs(playerPos.GetPosition(i) - position[i]) < player.getRadius()); } addEnemy( (EnemyType)enemyType, new Position(position) ); }