public void Draw(SpriteBatch sb, Character character, Level level) { if (!character.alive) { DrawMessage(sb, new Vector2(800 / 2, 600 / 2), "DEAD"); DrawMessage(sb, new Vector2(800 / 2, 600 * 0.8f), "PRESS SPACE TO RESTART"); } }
public void DrawCamRelated(SpriteBatch sb, Character character, Level level) { if (!character.alive) { } else { int[,] grid = level.grid; //Get current cell int col = (int)Math.Floor(character.position.X / (Level.CELL_SIZE * 2)); int row = (int)Math.Floor(character.position.Y / (Level.CELL_SIZE * 2)); for (int i = col - 2; i < col + 1; i++) { for (int j = row - 2; j < row + 1; j++) { if (i > -1 && i < grid.GetLength(0) && j > -1 && j < grid.GetLength(1)) { Cell cell = (Cell)grid[i, j]; Vector2 pos; switch (cell) { case Cell.None: break; case Cell.Start: pos = new Vector2(i * (Level.CELL_SIZE * 2) + Level.CELL_SIZE, j * (Level.CELL_SIZE * 2)); DrawMessage(sb, pos, "START"); break; case Cell.End: pos = new Vector2(i * (Level.CELL_SIZE * 2) + Level.CELL_SIZE, j * (Level.CELL_SIZE * 2)); DrawMessage(sb, pos, "PRESS SPACE"); break; case Cell.Spikes: break; case Cell.Dirt: break; case Cell.DirtFloor: break; case Cell.DirtSky: break; case Cell.Stone: break; case Cell.StoneFloor: break; case Cell.StoneSky: break; default: break; } } } } } }
public void Update(float time, InputManager input, Level level) { if (alive) { //Gravity if (inAir) { velocity.Y += 0.003f * time; } //Friction float maxSpeed = 0.4f; float friction = 0.003f; if (velocity.X > 0f) { velocity.X -= friction * time; if (velocity.X < 0f) { velocity.X = 0; SetAnim("idle"); } } if (velocity.X < 0f) { velocity.X += friction * time; if (velocity.X > 0f) { velocity.X = 0; SetAnim("idle"); } } position.X += velocity.X * time; collRect.X = (int)position.X; collRect.Y = (int)position.Y; level.DoXCollision(this); position.Y += velocity.Y * time; collRect.X = (int)position.X; collRect.Y = (int)position.Y; level.DoYCollision(this); if (!inAir) { if (!level.HasFloor(this)) { FallOff(); } } current += time; if (current > interval) { current = 0; currentFrame++; if (currentFrame > animations[currentAnim].Length - 1) { currentFrame = 0; } } if (input.KeyDown(Keys.Left)) { flipped = true; velocity.X -= speed; if (!inAir) { SetAnim("walk"); } if (velocity.X < -maxSpeed) { velocity.X = -maxSpeed; } } if (input.KeyDown(Keys.Right)) { flipped = false; velocity.X += speed; if (!inAir) { SetAnim("walk"); } if (velocity.X > maxSpeed) { velocity.X = maxSpeed; } } if (input.KeyClicked(Keys.Space)) { Jump(); } } }
public void DrawSignMessages(SpriteBatch sb, Character character, Level level) { if (character.alive) { foreach (Sign s in level.signs) { if (Vector2.Distance(character.position, new Vector2(s.col * (Level.CELL_SIZE * 2f), s.row * (Level.CELL_SIZE * 2f))) < 100f) { DrawMessage(sb, new Vector2(800 / 2, 600 * 0.7f), s.text); } } } }
public void Start() { level = new Level(); pMan = new ParticleManager(); character = new Character(); currentLevel--; NextLevel(); }