diff --git a/Arkanoidv3.0.sln b/Arkanoidv3.0.sln new file mode 100644 index 0000000..60d33c5 --- /dev/null +++ b/Arkanoidv3.0.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30804.86 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arkanoidv3.0", "Arkanoidv3.0\Arkanoidv3.0.csproj", "{C25DD048-0BCD-4892-822E-4FC29D56E60E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C25DD048-0BCD-4892-822E-4FC29D56E60E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C25DD048-0BCD-4892-822E-4FC29D56E60E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C25DD048-0BCD-4892-822E-4FC29D56E60E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C25DD048-0BCD-4892-822E-4FC29D56E60E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3429E7F4-B6AB-4CFD-AD01-E0DA20829A90} + EndGlobalSection +EndGlobal diff --git a/Arkanoidv3.0/Arkanoidv3.0.csproj b/Arkanoidv3.0/Arkanoidv3.0.csproj new file mode 100644 index 0000000..cc2c30d --- /dev/null +++ b/Arkanoidv3.0/Arkanoidv3.0.csproj @@ -0,0 +1,28 @@ + + + WinExe + netcoreapp3.1 + false + false + true + + + app.manifest + Icon.ico + + + + + + + + + + + + + + ..\..\Textbox_2019\Textbox_2019\bin\Debug\netstandard2.0\Textbox_2019.dll + + + \ No newline at end of file diff --git a/Arkanoidv3.0/Classes/Background.cs b/Arkanoidv3.0/Classes/Background.cs new file mode 100644 index 0000000..39c8fa4 --- /dev/null +++ b/Arkanoidv3.0/Classes/Background.cs @@ -0,0 +1,44 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +namespace Arkanoid.Classes +{ + class Background + { + private Texture2D texture; + private Vector2 position1; + private Vector2 position2; + private int speed; + public Background() + { + texture = null; + position1 = new Vector2(0, 0); + position2 = new Vector2(0, -995); + speed = 1; + + } + public void LoadContent(ContentManager dr) + { + texture = dr.Load("newfon3"); + } + public void Draw(SpriteBatch spr) + { + spr.Draw(texture, position1, Color.White); + spr.Draw(texture, position2, Color.White); + } + public void Update() + { + position1.Y += speed; + position2.Y += speed; + + + if (position1.Y >= 995) + { + position1.Y = 0; + position2.Y = -995; + } + } + + } +} \ No newline at end of file diff --git a/Arkanoidv3.0/Classes/Ball.cs b/Arkanoidv3.0/Classes/Ball.cs new file mode 100644 index 0000000..6103fd7 --- /dev/null +++ b/Arkanoidv3.0/Classes/Ball.cs @@ -0,0 +1,162 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Media; + +using Microsoft.Xna.Framework.Content; + +using Arkanoid.Classes; +using System.IO; +using System; +using System.Linq; + +using MonoGame_Textbox; +using MonoGame_Test; + +namespace Arkanoid.Classes +{ + class Ball + { + private GameObj ball; + Random random = new Random(); + SoundEffect GameOverSong; + SoundEffect PlatformCollideSong; + public int speed1 = -3; + public int speed2 = -3; + Vector2 pos2 = new Vector2(); + + public void LoadContent(ContentManager Content, Vector2 cpos) + { + ball = new GameObj(Content.Load("Ball")); + ball.Position = new Vector2(cpos.X, cpos.Y - 100); + ball.Speed = new Vector2(speed1, speed2); + GameOverSong = Content.Load("GameOver"); + PlatformCollideSong = Content.Load("PlatformCollide"); + } + + public void Draw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(ball.texture, ball.Position, Color.White); + } + + public void UpdateBall(Platform p, Vector2 cpos, string f, Bricks bricks, SoundEffect Explosion, SoundEffect Explosion2, SoundEffect Explosion3, int levels, Cube cub) + { + + Rectangle Next = new Rectangle((int)(ball.Position.X + ball.Speed.X), + (int)(ball.Position.Y + ball.Speed.Y), + ball.Width, ball.Height); + + if (Next.Y <= 0) + { + ball.HorizontalRepulsion(); + } + + if (Next.Y >= 700 - Next.Height) + + { + p.position = new Vector2(400, 500); + ball.Position = new Vector2(cpos.X, cpos.Y - 100); + ball.HorizontalRepulsion(); + Game1.SaveHistory(); + Game1.SaveBestScore(); + Game1.score = 0; + speed1 = -3; + speed2 = -3; + p.speed = 6; + Game1.newFlag = false; + bricks.ResetBricks(levels); + ball.IsAlive = false; + Game1.gameState = GameState.GameOver; + GameOverSong.Play(); + MediaPlayer.Stop(); + } + + if ((Next.X >= 800 - Next.Width) || Next.X <= 0) + { + ball.VerticalRepulsion(); + } + + foreach (var brick in Bricks.bricksArray) + { + if (Next.Intersects(brick.boundingBox) && brick.IsAlive) + { + if (random.Next(0, 2) == 1) + { + if (Game1.levels == 10) + { + if (random.Next(0, 2) == 1) + { + Game1.isBoss = true; + + Game1.xforboss = brick.Position.X; + Game1.yforboss = brick.Position.Y; + if (Game1.isBoss == true) + { + // cub = new cuber(Game1.xforboss,Game1.yforboss); + cub.position = new Vector2(Game1.xforboss, Game1.yforboss); + + if (p.destinationRectangle.Intersects(cub.dest)) + { + Game1.isBoss = false; + + + + } + } + } + + + + + int a = random.Next(0, 5); + if (a == 0) Explosion.Play(); + else if (a == 1) Explosion2.Play(); + else Explosion3.Play(); + brick.IsAlive = false; + + + + //int u = random.Next(0, 5); + //if (u==0) + //{ + + //} + Game1.score++; + } + else + { + int a = random.Next(0, 3); + if (a == 0) Explosion.Play(); + else if (a == 1) Explosion2.Play(); + else Explosion3.Play(); + brick.IsAlive = false; + Game1.score++; + } + + } + Collide(ball, brick.boundingBox); + } + } + ball.Position += ball.Speed; + if (Next.Intersects(p.destinationRectangle)) + { + PlatformCollideSong.Play(); + Collide(ball, p.destinationRectangle); + } + } + + public void Collide(GameObj gameObj, Rectangle rectangle)//отбиться от стенок + { + if (rectangle.Left <= gameObj.boundingBox.Center.X && gameObj.boundingBox.Center.X <= rectangle.Right) + { + gameObj.HorizontalRepulsion(); + } + else if (rectangle.Top <= gameObj.boundingBox.Center.Y && gameObj.boundingBox.Center.Y <= rectangle.Bottom) + { + gameObj.HorizontalRepulsion(); + } + } + + } +} diff --git a/Arkanoidv3.0/Classes/Bricks.cs b/Arkanoidv3.0/Classes/Bricks.cs new file mode 100644 index 0000000..a177c6b --- /dev/null +++ b/Arkanoidv3.0/Classes/Bricks.cs @@ -0,0 +1,185 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using System; + + +namespace Arkanoid.Classes +{ + + class Bricks + { + Random random = new Random(); + private int bricksCountWidth = 10; + private int bricksCountHeight = 5; + + private Texture2D texture; + Color t = Color.White; + public static GameObj[,] bricksArray; + public void LoadContent(ContentManager Content) + { + texture = Content.Load("Brick"); + } + public void ResetBricks(int lvl) + { + bricksArray = new GameObj[bricksCountWidth, bricksCountHeight]; + + for (int i = 0; i < bricksCountWidth; i++) + { + + + for (int j = 0; j < bricksCountHeight; j++) + { + + + + bricksArray[i, j] = new GameObj(texture) + { + + Position = new Vector2(i * 82, j * 31 + 100) + + }; + + + } + } + if (Game1.levels == 1) + { + for (int i = 0; i < 20; i++) + { + int xx = random.Next(0, 9); + int yy = random.Next(0, 5); + bricksArray[xx, yy].IsAlive = false; + } + + } + if (Game1.levels == 0) + { + for (int i = 0; i < 100; i++) + { + int xx = random.Next(0, 9); + int yy = random.Next(0, 5); + bricksArray[xx, yy].IsAlive = false; + } + } + if (Game1.levels == 1) + { + for (int i = 0; i < 27; i++) + { + int xx = random.Next(0, 9); + int yy = random.Next(0, 5); + bricksArray[xx, yy].IsAlive = false; + } + + } + if (Game1.levels >= 2 && lvl <= 6) + { + for (int i = 0; i < 20; i++) + { + int xx = random.Next(0, 9); + int yy = random.Next(0, 5); + bricksArray[xx, yy].IsAlive = false; + } + + } + if (Game1.levels == 7) + { + for (int i = 0; i < 15; i++) + { + int xx = random.Next(0, 9); + int yy = random.Next(0, 5); + bricksArray[xx, yy].IsAlive = false; + } + + } + if (Game1.levels == 8 || lvl == 9) + { + for (int i = 0; i < 10; i++) + { + int xx = random.Next(0, 9); + int yy = random.Next(0, 5); + bricksArray[xx, yy].IsAlive = false; + } + + } + if (Game1.levels == 10) + { + for (int i = 0; i < 0; i++) + { + int xx = random.Next(0, 9); + int yy = random.Next(0, 5); + bricksArray[xx, yy].IsAlive = false; + } + + } + + + + } + public void Update(int lvl) + { + bool flag = false; + for (int i = 0; i < bricksCountWidth; i++) + { + for (int j = 0; j < bricksCountHeight; j++) + { + if (bricksArray[i, j].IsAlive) + { + flag = true; + + } + + } + } + if (flag == false) + { + Game1.gameState = GameState.Win; + Game1.levels++; + ResetBricks(lvl); + } + } + public void Draw(SpriteBatch spriteBatch, int lvl) + { + + + for (int i = 0; i < bricksCountWidth; i++) + { + + for (int j = 0; j < bricksCountHeight; j++) + { + + if (bricksArray[i, j].IsAlive) //Невыбит ли кирпичик + { + if (i > -1 && i < 10 && j == 0) + { + t = Color.Yellow; + } + if (i > -1 && i < 10 && j == 1) + { + t = Color.LightCoral; + } + if (i > -1 && i < 10 && j == 2) + { + t = Color.Pink; + } + if (i > -1 && i < 10 && j == 3) + { + t = Color.Lavender; + } + if (i > -1 && i < 10 && j == 4) + { + t = Color.LightSkyBlue; + } + spriteBatch.Draw(bricksArray[i, j].texture, bricksArray[i, j].Position, t); + } + + } + } + + + + } + + } +} \ No newline at end of file diff --git a/Arkanoidv3.0/Classes/Cube.cs b/Arkanoidv3.0/Classes/Cube.cs new file mode 100644 index 0000000..6ee9450 --- /dev/null +++ b/Arkanoidv3.0/Classes/Cube.cs @@ -0,0 +1,59 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Media; + + +using System.Collections.Generic; +using System.IO; + +using System.Text; + +namespace Arkanoid.Classes +{ + class Cube + { + public Texture2D texture; + public Vector2 position; + public int Width { get { return texture.Width; } } + public int Height { get { return texture.Height; } } + public Rectangle dest; + public int speed = 1; + + + public Cube(float x, float y) + { + position = new Vector2(x, y); + } + public Cube() + { + + } + public void LoadContent(ContentManager dr) + { + texture = dr.Load("cube2"); + + } + public void Update() + { + position.Y += speed; + dest.Y += speed; + dest = new Rectangle((int)position.X, +(int)position.Y, texture.Width, texture.Height); + } + public void Draw(SpriteBatch srt) + { + + + srt.Draw(texture, dest, Color.White); + + + + } + + + } +} diff --git a/Arkanoidv3.0/Classes/GameObj.cs b/Arkanoidv3.0/Classes/GameObj.cs new file mode 100644 index 0000000..d6d577c --- /dev/null +++ b/Arkanoidv3.0/Classes/GameObj.cs @@ -0,0 +1,41 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Arkanoid.Classes +{ + public class GameObj + { + public Color Color; + public Texture2D texture { get; set; } + public Vector2 Position; + public Vector2 Speed; + public int Width { get { return texture.Width; } } + public int Height { get { return texture.Height; } } + public bool IsAlive { get; set; } + public Rectangle boundingBox + { + get + { + return new Rectangle((int)Position.X, (int)Position.Y, Width, Height); + } + } + + + + public GameObj(Texture2D texture) + { + this.texture = texture; + IsAlive = true; + Position = Vector2.Zero; + Speed = Vector2.Zero; + } + public void HorizontalRepulsion() + { + Speed.Y = -Speed.Y; + } + public void VerticalRepulsion() + { + Speed.X = -Speed.X; + } + } +} \ No newline at end of file diff --git a/Arkanoidv3.0/Classes/GameOver.cs b/Arkanoidv3.0/Classes/GameOver.cs new file mode 100644 index 0000000..a6aaf88 --- /dev/null +++ b/Arkanoidv3.0/Classes/GameOver.cs @@ -0,0 +1,51 @@ +using System; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using System.Collections.Generic; +using System.Text; +namespace Arkanoid.Classes +{ + class GameOver + { + private SpriteFont spriteFont; + private Color defaultColor; + public Vector2 Position { get; set; } + public string Text { get; set; } + public Color Color { get; set; } + private bool isReset = false; + private KeyboardState keyboard; + private KeyboardState prevKeyboard; + public GameOver() + { + Position = new Vector2(270, 300); + Text = "GAME OVER!"; + Color = Color.Red; + defaultColor = Color; + } + public void LoadContent(ContentManager manager) + { + spriteFont = manager.Load("GameOverFont"); + + } + public void Draw(SpriteBatch brush) + { + brush.DrawString(spriteFont, Text, Position, Color); + } + public void Update() + { + keyboard = Keyboard.GetState(); + if (prevKeyboard.IsKeyDown(Keys.Enter) && (keyboard != prevKeyboard)) + { + if (keyboard.IsKeyUp(Keys.Enter)) + { + + Game1.gameState = GameState.Menu; + isReset = true; + } + } + prevKeyboard = keyboard; + } + } +} diff --git a/Arkanoidv3.0/Classes/History.cs b/Arkanoidv3.0/Classes/History.cs new file mode 100644 index 0000000..68e5ca8 --- /dev/null +++ b/Arkanoidv3.0/Classes/History.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Media; +using Microsoft.Xna.Framework.Content; +using System.IO; +using System.Linq; + +namespace Arkanoid.Classes +{ + class History + { + private SpriteFont spriteFont; + private Color defaultColor; + Vector2 Position = new Vector2(0, 0); + public string Text { get; set; } = ""; + public Color Color { get; set; } + + public History() + { + Color = Color.Black; + defaultColor = Color; + } + + public void LoadContent(ContentManager Content) + { + spriteFont = Content.Load("GameFont"); + } + public void Draw(SpriteBatch spriteBatch) + { + spriteBatch.DrawString(spriteFont, "Game history:", Position, Color); + Position.Y += 26; + int count = File.ReadAllLines("GameHistory.txt").Length; + int c2 = count; + if (count >= 22) count = 22; + for (int i = 0; i < count; i++) + { + spriteBatch.DrawString(spriteFont, File.ReadLines("GameHistory.txt").ElementAt(c2 - i - 1), Position, Color); + Position.Y += 26; + } + Position.Y = 0; + } + } +} diff --git a/Arkanoidv3.0/Classes/Label.cs b/Arkanoidv3.0/Classes/Label.cs new file mode 100644 index 0000000..3db9a28 --- /dev/null +++ b/Arkanoidv3.0/Classes/Label.cs @@ -0,0 +1,49 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace Arkanoid.Classes +{ + class Label + { + private SpriteFont spriteFont; + private Color color_default; + + public Vector2 Position { get; set; } + public string Text { get; set; } + public Color Color { get; set; } + + public Label() + { + Position = new Vector2(100, 100); + Text = "Label"; + Color = Color.Yellow; + color_default = Color; + } + + public Label(string Text, Vector2 Position, Color Color) + { + this.Text = Text; + this.Position = Position; + this.Color = Color; + color_default = Color; + } + + public void ResetColor() + { + Color = color_default; + } + + + public void LoadContent(ContentManager Content) + { + spriteFont = Content.Load("GameOverFont"); + } + + public void Draw(SpriteBatch spriteBatch) + { + spriteBatch.DrawString(spriteFont, Text, Position, Color); + } + } +} \ No newline at end of file diff --git a/Arkanoidv3.0/Classes/Menu.cs b/Arkanoidv3.0/Classes/Menu.cs new file mode 100644 index 0000000..08770b7 --- /dev/null +++ b/Arkanoidv3.0/Classes/Menu.cs @@ -0,0 +1,122 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; // для ContentManager +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using System.Collections.Generic; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Media; + +namespace Arkanoid.Classes +{ + class Menu + { + private List