protected void DrawGrid(int xSpacing, int ySpacing) { var xOffset = 16 + (level.GetScrollX() % 16); var numCols = SosEngine.Core.RenderWidth / xSpacing; var numRows = SosEngine.Core.RenderHeight / ySpacing; SosEngine.Core.FillRectangle( new Rectangle((mouseBx * xSpacing) + level.GetScrollX(), (mouseBy * ySpacing) + 1, xSpacing - 1, ySpacing - 1), activeTileColor ); for (int y = 0; y < numRows; y++) { SosEngine.Core.DrawLine(0, y * ySpacing, SosEngine.Core.RenderWidth, y * ySpacing, gridColor); } for (int x = 0; x < numCols; x++) { SosEngine.Core.DrawLine((x * xSpacing) + xOffset, 0, (x * xSpacing) + xOffset, SosEngine.Core.RenderHeight, gridColor); } /* * for (int y = 0; y < numRows; y++) * { * for (int x = 0; x < numCols; x++) * { * var b = level.GetBlockAtPixel("Block", (x * xSpacing) + xOffset, y * ySpacing); * font.Print(b.ToString(), (x * xSpacing) + xOffset, y * ySpacing); * } * } */ }
protected bool IsVisibleOnScreen() { var screenX = X + level.GetScrollX(); if (screenX > 0 && screenX < SosEngine.Core.RenderWidth) { return(true); } return(false); }
public override void Update(GameTime gameTime) { isLocked = true; // Activate enemies within range foreach (var enemy in sprites.OfType <Enemy>().Where(x => !x.IsActive)) { if (enemy.Position.X + level.GetScrollX() - SosEngine.Core.RenderWidth - (16 * 4) < 0) { enemy.IsActive = true; } } var activeEnemies = sprites.OfType <Enemy>().Where(x => x.IsActive && x.CanCollideWithOtherEnemy); // Check if enemies collide with other enemies foreach (var enemy1 in activeEnemies) { foreach (var enemy2 in activeEnemies) { if (enemy1 != enemy2) { enemy1.CollideWithEnemy(enemy2); } } } // Check if enemies collide with fireballs var fireballs = sprites.OfType <Fireball>(); foreach (var fireball in fireballs) { foreach (var enemy in activeEnemies) { if (enemy.CollideWithFireball(fireball)) { fireball.Explode(); } } } foreach (var sprite in sprites) { sprite.Update(gameTime); } sprites.RemoveAll(x => ((BaseEntity)x).IsFinished); bulletSpawnerManager.Update(gameTime, this); isLocked = false; foreach (var entity in newEntitiesQueue) { AddEntity(entity); } newEntitiesQueue.Clear(); base.Update(gameTime); }
public void AddScore(int scoreToAdd, bool showEffect, int x = 0, int y = 0) { // Score -2 = 1UP if (score > 0) { score += scoreToAdd; } if (showEffect) { if (scoreToAdd == -2 || scoreToAdd == 100 || scoreToAdd == 200 || scoreToAdd == 400 || scoreToAdd == 500 || scoreToAdd == 800 || scoreToAdd == 1000 || scoreToAdd == 2000 || scoreToAdd == 4000 || scoreToAdd == 8000) { if (x == 0) { x = (int)Math.Round(Position.X); } if (y == 0) { y = (int)Math.Round(Position.Y); } EntityManager.AddEntity(new ScoreEffect(Game, x + level.GetScrollX(), y, scoreToAdd)); } } }
protected bool IsVisibleOnScreen() { var screenX = Position.X + level.GetScrollX(); if (screenX + BoundingBox.Width > 0 && screenX < SosEngine.Core.RenderWidth) { return(true); } return(false); }
public Bullet(Game game, int x, int y, int playerX, SosEngine.Level level) : base(game, "bullet_1", x, y, Vector2.Zero, level, 80) { AddFrame("bullet_2", 80); AddFrame("bullet_3", 80); AddFrame("bullet_2", 80); if (playerX < x + level.GetScrollX()) { Position += new Vector2(-24, 0); speed = new Vector2(-1.8f, 0); } else { Position += new Vector2(8, 0); speed = new Vector2(1.8f, 0); Flipped = true; } IsActive = true; }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (KeyPushed(Keys.Escape)) { Game.Exit(); } var ctrlLeft = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Left) || currentKeyboardState.IsKeyDown(Keys.Left); var ctrlRight = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Right) || currentKeyboardState.IsKeyDown(Keys.Right); var ctrlUp = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Up) || currentKeyboardState.IsKeyDown(Keys.Up); var ctrlDown = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.Down) || currentKeyboardState.IsKeyDown(Keys.Down); var ctrlA = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.A) || currentKeyboardState.IsKeyDown(Keys.LeftShift); var ctrlB = SosEngine.Core.IsPlayerInputDown(0, SosEngine.Input.PlayerInput.B) || currentKeyboardState.IsKeyDown(Keys.Space); replay.Update(ref ctrlLeft, ref ctrlRight, ref ctrlUp, ref ctrlDown, ref ctrlA, ref ctrlB); player.SetControls(ctrlLeft, ctrlRight, ctrlUp, ctrlDown, ctrlA, ctrlB); entityManager.PlayerX = (int)Math.Round(player.Position.X); entityManager.SetDrawOffset(level.GetScrollX()); hud.SetData(1, 1, player.Score); }
protected override Rectangle GetBoundingBox() { DrawOffsetX = level.GetScrollX(); return(new Rectangle(rect.X + DrawOffsetX, rect.Y + DrawOffsetY, rect.Width, rect.Height)); }