public void Draw(SpriteBatch spriteBatch, Player player) { foreach (RenderPlane renderPlane in renderPlanes) { renderPlane.Render(enemyManager, player, spriteBatch); } dimensionalUpdateDrawer.Draw(spriteBatch); }
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 Render(EnemyManager enemyManager, Player player, SpriteBatch spriteBatch) { //Draw background square // spriteBatch.Draw(Game1.square, renderTarget, bg); Position playerPos = player.getPosition(); Vector2 pos = GetScaledPosition(getPlanarPosition(playerPos)); renderPosition(spriteBatch, pos, Color.Aquamarine, 32); foreach (Enemy enemy in enemyManager.getEnemies()) { Position enemyPosition = enemy.GetPosition(); Vector2 planarPosition = getPlanarPosition(enemyPosition); //if we are rendering in 1D, the GetSize takes in to account the distance in the y axis float size = 2 * GetSize(enemy); if (IsInRenderFrame(planarPosition, size)) { Vector2 drawPosition = GetScaledPosition(planarPosition); switch (enemy.GetEnemyType()) { case EnemyType.StraightLine: { renderPosition(spriteBatch, drawPosition, Color.Red, size); break; } default: { renderPosition(spriteBatch, drawPosition, Color.Black, size); break; } } } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { player = new Player(new Position(1)); enemyManager = new EnemyManager(); gameState = GameState.fadeIn; fadeState = 0; oldState = Keyboard.GetState(); base.Initialize(); }
public void Update(GameTime gameTime, Player player) { foreach (RenderPlane renderplane in renderPlanes) { renderplane.UpdatePosition(player.getPosition()); } dimensionalUpdateDrawer.Update(gameTime); }
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) ); }
public void Update(GameTime gameTime, DimensionalManager dm, Player player) { timeSinceLastSpawn += gameTime.ElapsedGameTime.Milliseconds; timeSinceLastDimensionChange += gameTime.ElapsedGameTime.Milliseconds; { int spawn = Random.Next(-randomPrecision, randomPrecision); if (timeSinceLastSpawn + spawn > averageTimeBetweenSpawn) { SpawnEnemy(dm, player); timeSinceLastSpawn = 0; } } { int spawn = Random.Next(-randomPrecision, randomPrecision); if (timeSinceLastDimensionChange + spawn > averageTimeBetweenDimChange) { AddDimension(); timeSinceLastDimensionChange = 0; } } removeEnemies(dm); MoveEnemies(dm); }