public void ChangeState(State state) { if (state is GameState) { currentGameState = state; } if (state is ConfirmExitState && _currentState is GameState) { var gameState = _currentState as GameState; saveCaretaker.AddMemento(gameState.Save()); } if (state is GameState && _currentState is ConfirmExitState) { var gameState = state as GameState; gameState.ReadSave(saveCaretaker.GetMemento()); } if (state is GameState && _currentState is MenuState) { var gameState = state as GameState; gameState.ReadSave(saveCaretaker.GetMemento()); } if (!(state is GameState) && _currentState is GameState && Champion.GetInstance().health > 0) { var gameState = _currentState as GameState; saveCaretaker.AddMemento(gameState.Save()); } _nextState = state; }
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { champ = Champion.GetInstance(); string points = "Great job! You got " + champ.points + " points!"; string signature = "Please enter your three letter signature: "; Vector2 vector1 = new Vector2(625, 270); Vector2 vector2 = new Vector2(525, 320); Vector2 vector3 = new Vector2(780, 370); spriteBatch.Begin(); spriteBatch.DrawString(_font, points, vector1, Color.White); if (isNewRecord) { spriteBatch.DrawString(_font, signature, vector2, Color.White); name = ReadCharacter(name); spriteBatch.DrawString(_font, name, vector3, Color.White); } foreach (var component in _components) { component.Draw(gameTime, spriteBatch); } spriteBatch.End(); }
public void CollisionBorder() { Champion champion = Champion.GetInstance(); while (!_spriteIterator.IsDone) { var border = _spriteIterator.Next <Border>(); if (border != null) { if (champion.Velocity.X > 0 && champion.IsTouchingLeft(border)) { champion.Velocity.X = border.Rectangle.Left - champion.Rectangle.Right; } if (champion.Velocity.X < 0 && champion.IsTouchingRight(border)) { champion.Velocity.X = border.Rectangle.Right - champion.Rectangle.Left; } if (champion.Velocity.Y > 0 && champion.IsTouchingTop(border)) { champion.Velocity.Y = border.Rectangle.Top - champion.Rectangle.Bottom; } if (champion.Velocity.Y < 0 && champion.IsTouchingBottom(border)) { champion.Velocity.Y = border.Rectangle.Bottom - champion.Rectangle.Top; } } } _spriteIterator.First(); }
public GameState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content, bool newGame) : base(game, graphicsDevice, content) { this.newGame = newGame; _font = content.Load <SpriteFont>("Components/Font"); _champ = Champion.GetInstance(); _champ.SetSoundManagerContent(content); _champ.Attach(game); if (game.getEasyLevel() == true) { level_generator = new EasyLevelGenerator(content); } else { level_generator = new HardLevelGenerator(content); } inputManager = InputManager.GetInstance(); Champion.SetContent(content); if (newGame) { _champ.ResetValues(); SetLevel(); } if (_champ.level == 1) { _champ.SetValuesToStandard(); } _game.PlaySong("gameplay"); }
public NewRecordState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content) : base(game, graphicsDevice, content) { champ = Champion.GetInstance(); var buttonTexture = _content.Load <Texture2D>("Components/Button"); _font = _content.Load <SpriteFont>("Components/Font"); var submitButton = new Button(buttonTexture, _font) { Position = new Vector2(550, 570), Text = "Submit your score" }; var backButton = new Button(buttonTexture, _font) { Position = new Vector2(550, 570), Text = "Go to main menu" }; _components = new List <Component>(); backButton.OnClick += BackButton_Click; submitButton.OnClick += SubmitButton_Click; navigationMenu = new NavigationMenu(new List <Component> { backButton, submitButton }); _components = new List <Component>() { navigationMenu }; var list = RankingFile.getPlacements(); if (list.Count < 10 || list[list.Count - 1].score < champ.points) { navigationMenu = new NavigationMenu(new List <Component> { submitButton }); _components = new List <Component>() { navigationMenu }; isNewRecord = true; } else { navigationMenu = new NavigationMenu(new List <Component> { backButton }); _components = new List <Component>() { navigationMenu }; isNewRecord = false; } }
public void CollisionGap() { Champion champion = Champion.GetInstance(); if (champion.Position.Y <= -1 || champion.Position.Y >= (Screen.getHeight() - 1) * 16) { champion.LoseHealth(); } }
public void CollisionBlock() { Champion champion = Champion.GetInstance(); while (!_spriteIterator.IsDone) { var block = _spriteIterator.Next <Block>(); if (block != null) { if (champion.Velocity.X > 0 && champion.IsTouchingLeft(block)) { champion.Velocity.X = block.Rectangle.Left - champion.Rectangle.Right; } if (champion.Velocity.X < 0 && champion.IsTouchingRight(block)) { champion.Velocity.X = block.Rectangle.Right - champion.Rectangle.Left; } if (champion.Velocity.Y > 0 && champion.IsTouchingTop(block)) { champion.Velocity.Y = block.Rectangle.Top - champion.Rectangle.Bottom; if (block.level_type == Block.LevelType.Magma) { champion.LoseHealth(); } if (block.level_type == Block.LevelType.Ice) { champion.Speed += block.Speed; if (champion.Speed <= 0) { champion.LoseHealth(); } } } if (champion.Velocity.Y < 0 && champion.IsTouchingBottom(block)) { champion.Velocity.Y = block.Rectangle.Bottom - champion.Rectangle.Top; if (block.level_type == Block.LevelType.Magma) { champion.LoseHealth(); } if (block.level_type == Block.LevelType.Ice) { champion.Speed += block.Speed; if (champion.Speed <= 0) { champion.LoseHealth(); } } } } } _spriteIterator.First(); }
public override void BuildLevel(int height, int width) { char sign = ' '; board_builder = new MagmaLevelBuilder(this.content); if (pick == 1) { board_builder = new IceLevelBuilder(this.content); } if (pick == 2) { board_builder = new JungleLevelBuilder(this.content); } board_builder.GenerateBackground(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { sign = this.level_array[i, j]; if (sign == 'b') { board_builder.GenerateBorder(); } else if (sign == '\u2588') { board_builder.GenerateBlock(); } else if (sign == '$') { board_builder.GenerateCoin(); } else if (sign == '/') { board_builder.GenerateLeftThorn(); } else if (sign == '?') { board_builder.GenerateRightThorn(); } else if (sign == '#') { board_builder.GenerateThorn(); } board_builder.GenerateDoors(height, width); board_builder.x += 16; } board_builder.x = 0; board_builder.y += 16; } sprite_collection = board_builder.GetLevel(); Champion.GetInstance().SetCollection(sprite_collection); }
public void CollisionThorn() { Champion champion = Champion.GetInstance(); while (!_spriteIterator.IsDone) { var thorn = _spriteIterator.Next <Thorn>(); if (thorn != null) { if (champion.Rectangle.Intersects(thorn.Rectangle)) { champion.LoseHealth(); } } } _spriteIterator.First(); }
public override void Update(GameTime gameTime) { if (inputManager.ActionWasJustPressed("Back")) { _game.ChangeState(new ConfirmExitState(_game, _graphicsDevice, _content)); return; } if (Champion.GetInstance().health <= 0) { _champ.level = 1; _champ.NotifyObservers(); _game.ChangeState(new NewRecordState(_game, _graphicsDevice, _content)); return; } Champion.GetInstance().Update(); }
public void CreateLevelLogic(int height, int width) { this.level_array = new char[height, width]; FillArray(); this.level_array = CreateBorder(height, width); this.level_array = CreateBlocks(height, width); this.level_array = CreateThorns(height, width); this.level_array = CreateGaps(height, width); this.level_array = CreateCoins(height, width); BuildLevel(height, width); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Console.Write(this.level_array[i, j]); } Console.WriteLine(); } Champion.GetInstance().SetCollection(sprite_collection); }
public void CollisionCoin() { Champion champion = Champion.GetInstance(); while (!_spriteIterator.IsDone) { var coin = _spriteIterator.Next <Coin>(); if (coin != null) { var tmp_coin = coin.Rectangle.Center; var rect = new Rectangle(tmp_coin.X, tmp_coin.Y, 1, 1); if (champion.Rectangle.Intersects(rect)) { champion.points += 10; GameState.RemoveCoinFromArray(coin.Rectangle.Y / 16, coin.Rectangle.X / 16); _spriteIterator.RemoveCoin(coin); } } } _spriteIterator.First(); }
public void CollisionDoor() { Champion champion = Champion.GetInstance(); while (!_spriteIterator.IsDone) { var door = _spriteIterator.Next <Door>(); if (door != null) { if (champion.Rectangle.Intersects(door.Rectangle)) { champion.SetPositionStart(); champion.points += 30; champion.level++; champion.health = 3; champion.ResetValues(); GameState.SetLevel(); } } } _spriteIterator.First(); }
protected override char[,] CreateBlocks(int height, int width) { char[,] buffer = this.level_array; Random rnd = new Random(); List <bool> blockDirection = new List <bool> { true, false }; int tmp_number = rnd.Next(6, width / 4); int last_block_width = 10; int blocks_gap = 6; int tmp_helper = 0; int double_block, direction, block_width, block_height; for (int k = 0; k < tmp_number; k++) { direction = rnd.Next(blockDirection.Count); block_width = rnd.Next(2, width / 4); block_height = rnd.Next(height / 3, height - 5); if (k == 0) { direction = 0; } else { double_block = rnd.Next(0, 100); if (double_block % 2 == 0 && Champion.GetInstance().level > 5) //tutaj musi byc level z Championa { direction = 2; tmp_helper = rnd.Next(4, height - 4); block_height = tmp_helper; } } if (last_block_width + block_width >= width - 6) { block_width = width - last_block_width - 5; direction = 0; } if (block_width > 0) { this.blockList.Add(new BlocksList(last_block_width, last_block_width + block_width, direction, block_height)); //lista spritów } switch (direction) { case 0: for (int i = height - 2; i > height - block_height; i--) { for (int j = last_block_width; j < last_block_width + block_width; j++) { buffer[i, j] = '\u2588'; } } last_block_width = last_block_width + block_width + blocks_gap; break; case 1: for (int i = 1; i < block_height; i++) { for (int j = last_block_width; j < last_block_width + block_width; j++) { buffer[i, j] = '\u2588'; } } last_block_width = last_block_width + blocks_gap + block_width; break; case 2: for (int i = 1; i < height - 1; i++) { for (int j = last_block_width; j < last_block_width + block_width; j++) { buffer[i, j] = '\u2588'; } } for (int i = tmp_helper; i < tmp_helper + 4; i++) { for (int j = last_block_width; j < last_block_width + block_width; j++) { buffer[i, j] = ' '; } } last_block_width = last_block_width + blocks_gap + block_width; break; } } return(buffer); }
protected override char[,] CreateThorns(int height, int width) { Random rnd = new Random(); char[,] buffer = this.level_array; foreach (BlocksList b in blockList) { int torn_sets_number = rnd.Next(1, 6); int torn_number = 0; int position = 0; int starting_block = 0; if (torn_sets_number >= 1 && b.getDirection() != BlocksList.direction_full && Champion.GetInstance().level >= 0) { torn_number = rnd.Next(1, b.getWidth()); if (b.getDirection() == BlocksList.direction_down) { position = height - b.getHeight(); } else if (b.getDirection() == BlocksList.direction_up) { position = b.getHeight(); } starting_block = rnd.Next(b.getStartX(), b.getFinishX() - (b.getWidth() / 2)); for (int i = starting_block; i < starting_block + torn_number && i < b.getFinishX(); i++) { if (b.getDirection() == BlocksList.direction_down) { buffer[position, i] = '#'; } else { buffer[position, i] = '&'; } } } if (torn_sets_number >= 2 && b.getDirection() != BlocksList.direction_full && Champion.GetInstance().level >= 3) { torn_number = rnd.Next(3, b.getHeight()); position = b.getStartX() - 1; if (b.getDirection() == BlocksList.direction_down) { starting_block = rnd.Next(height - b.getHeight() + 1, height - 2); for (int i = starting_block; i < starting_block + torn_number && i < height - 2; i++) { buffer[i, position] = '/'; } } else { starting_block = rnd.Next(1, b.getHeight()); for (int i = starting_block; i < starting_block + torn_number && i < b.getHeight(); i++) { buffer[i, position] = '/'; } } } if (torn_sets_number == 3 && b.getDirection() != BlocksList.direction_full && Champion.GetInstance().level >= 6) { torn_number = rnd.Next(3, b.getHeight()); position = b.getFinishX(); if (b.getDirection() == BlocksList.direction_down) { starting_block = rnd.Next(height - b.getHeight() + 1, height - 2); for (int i = starting_block; i < starting_block + torn_number && i < height - 2; i++) { buffer[i, position] = '?'; } } else { starting_block = rnd.Next(1, b.getHeight()); for (int i = starting_block; i < starting_block + torn_number && i < b.getHeight(); i++) { buffer[i, position] = '?'; } } } if (b.getDirection() == BlocksList.direction_full && Champion.GetInstance().level > 10) { starting_block = rnd.Next(1, height / 2); torn_number = rnd.Next(1, height - 2); int sides = rnd.Next(0, 4); if (sides == 0) { position = b.getStartX() - 1; for (int i = starting_block; i < starting_block + torn_number && i < height - 2; i++) { if (buffer[i, position + 1] != ' ') { buffer[i, position] = '/'; } else { break; } } } else { position = b.getFinishX(); for (int i = starting_block; i < starting_block + torn_number && i < height - 2; i++) { if (buffer[i, position - 1] != ' ') { buffer[i, position] = '?'; } else { break; } } } } } return(buffer); }