Advertisement
Ciszko

C# SIATKOWKA

May 9th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 47.51 KB | None | 0 0
  1. GAME
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using SFML.Audio;
  9. using SFML.Graphics;
  10. using SFML.System;
  11. using SFML.Window;
  12.  
  13. namespace Siatkowkaa2
  14. {
  15.     public class Game
  16.     {
  17.         enum GameState
  18.         {
  19.             VsAI,
  20.             VsPlayer,
  21.             Menu,
  22.             WinningScreen,
  23.             Closing
  24.         };
  25.  
  26.         public RenderWindow Window = new RenderWindow(new VideoMode(1000, 600), "Siatkowka", Styles.Titlebar | Styles.Close);
  27.         public const float TICK = 0.03F;
  28.         private GameState gameState;
  29.  
  30.         // ########################### OBIEKTY W GRZE ##########################
  31.  
  32.         private Player Player = new Player(new Vector2f(750, 462.5F), new Vector2f(100, 175), 8, 7);
  33.         private Player Player2;
  34.         private Player NotAI = new Player(new Vector2f(250, 462.5F), new Vector2f(100, 175), 8, 7);
  35.         private Player AI1 = new Player(new Vector2f(250, 462.5F), new Vector2f(100, 175), 6, 7);
  36.         private Player AI2 = new Player(new Vector2f(230, 462.5F), new Vector2f(100, 175), 8, 7);
  37.         private Player AI3 = new Player(new Vector2f(250, 462.5F), new Vector2f(150, 230), 8, 6);
  38.         private Ball Ball = new Ball(80, new Vector2f(750, 220));
  39.         private Net Net = new Net(new Vector2f(15, 350));
  40.  
  41.         // ############################ TEKSTURY ################################
  42.  
  43.         private Texture BackgroundTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/background.png");
  44.         private Texture PlayerTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/PlayerTextures/tex.png");
  45.         private Texture BallTex = new Texture(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Textures\ball2.png");
  46.         private Texture Player2Tex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/PlayerTextures/tex.png");
  47.         private Texture NetTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/net2.png");
  48.         private Texture MenuBackgroundTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/menubackground.png");
  49.         private Texture GraczVsGraczTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/graczvsgracz1.png");
  50.         private Texture GraczVsKomputerTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/graczvskomputer.png");
  51.         private Texture ExitButtonTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/exitbutton.png");
  52.         private Texture Button1Tex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/1.png");
  53.         private Texture Button2Tex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/2.png");
  54.         private Texture Button3Tex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/3.png");
  55.         private Texture LevelButtonTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/poziom.png");
  56.         private Texture BallHelpTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/ball2.png");
  57.         private Texture PointsButtonTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/maxpunkty.png");
  58.         private Texture Points15ButtonTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/15.png");
  59.         private Texture Points20ButtonTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/20.png");
  60.         private Texture Points25ButtonTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/25.png");
  61.         private Texture EndGameTex = new Texture(@"F:/Visual/Siatkowka/Siatkowka/Textures/endgame.png");
  62.         private Font ScoreFont = new Font(@"F:/Visual/Siatkowka/Siatkowka/scoreboard.ttf");
  63.  
  64.  
  65.         // ############################ SPRITE'Y ################################
  66.  
  67.         private Sprite PlayerSprite = new Sprite();
  68.         private Sprite Player2Sprite = new Sprite();
  69.         private Sprite Background = new Sprite();
  70.         private Sprite MenuBackground = new Sprite();
  71.         private Sprite GraczVsGracz = new Sprite();
  72.         private Sprite GraczVsKomputer = new Sprite();
  73.         private Sprite ExitButton = new Sprite();
  74.         private Sprite Button1 = new Sprite();
  75.         private Sprite Button2 = new Sprite();
  76.         private Sprite Button3 = new Sprite();
  77.         private Sprite LevelButton = new Sprite();
  78.         private Sprite PointsButton = new Sprite();
  79.         private Sprite Points15Button = new Sprite();
  80.         private Sprite Points20Button = new Sprite();
  81.         private Sprite Points25Button = new Sprite();
  82.         private Sprite EndGame = new Sprite();
  83.         private RectangleShape BallHelp = new RectangleShape();
  84.  
  85.         // ############################## DZWIEKI ###############################
  86.  
  87.         private SoundBuffer WinningGameBuf = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\winninggame.wav");
  88.         private SoundBuffer LosingGameBuf = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\losinggame.wav");
  89.         private Sound WinningGame = new Sound();
  90.         private Sound LosingGame = new Sound();
  91.         private Music GameMusic = new Music(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\backgroundmusic.ogg");
  92.        
  93.  
  94.         // ############################## INNE #################################
  95.         private int MaxPoints { get; set; } = 15;
  96.         private int TickCounter;
  97.         private int RandomNumber;
  98.         private int Strenght;
  99.         private int WhoIsActualPlayer = 0;
  100.         private int LeftPlayerTex = 0;
  101.         private int LeftPlayer2Tex = 200;
  102.         private bool FirstTouch = false;
  103.         private bool IsBallOnScreen = true;
  104.         private bool GameOver = false;
  105.         private bool RightIsWinner = false;
  106.         private Vector2f BallLeftPosition = new Vector2f(750, 230);
  107.         private Vector2f BallRightPosition = new Vector2f(250, 230);
  108.         private string Score_s;
  109.         private string winer;
  110.         private Text ScoreText;
  111.         private Text kopa;
  112.         private Time T;
  113.  
  114.  
  115.  
  116.  
  117.         public Game()
  118.         {
  119.             // ############################# PODPINANIE TESKTUR ##############################
  120.             gameState = GameState.Menu;
  121.             Ball.Texture = BallTex;
  122.             Net.Texture = NetTex;
  123.             Player.Texture = PlayerTex;
  124.             Player.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  125.            // Player2.Texture = Player2Tex;
  126.             //Player2.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  127.             NotAI.Texture = Player2Tex;
  128.             NotAI.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  129.             AI1.Texture = Player2Tex;
  130.             AI1.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  131.             AI2.Texture = Player2Tex;
  132.             AI2.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  133.             AI3.Texture = Player2Tex;
  134.             AI3.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  135.             PlayerSprite.Texture = PlayerTex;
  136.             Player2Sprite.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  137.             BallHelp.Texture = BallHelpTex;
  138.             Background.Texture = BackgroundTex;
  139.             Background.Scale = new Vector2f(0.84F, 0.69F);
  140.             EndGame.Texture = EndGameTex;
  141.             EndGame.Scale = new Vector2f(1.613F, 1.818F);
  142.  
  143.             // ############## WYNIK ################
  144.  
  145.             ScoreText = new Text(Score_s, ScoreFont);
  146.             ScoreText.Position = new Vector2f (437, 0);
  147.             ScoreText.CharacterSize = 50;
  148.  
  149.             // ############### KONIEC GRY ###############
  150.             if (gameState == GameState.WinningScreen)
  151.             {
  152.                 if (RightIsWinner == true)
  153.                 {
  154.                     Player.Position = new Vector2f(800, 163);
  155.                     Player2.Position = new Vector2f(182, 242);
  156.                 }
  157.                 else
  158.                 {
  159.                     Player2.Position = new Vector2f(800, 163);
  160.                     Player.Position = new Vector2f(192, 242);
  161.                 }
  162.             }
  163.             // ##################### INNE ################################
  164.             GameMusic.Loop = true;
  165.             GameMusic.Volume = 15;
  166.             WinningGame.SoundBuffer = WinningGameBuf;
  167.             LosingGame.SoundBuffer = LosingGameBuf;
  168.             WinningGame.Volume = 50;
  169.             LosingGame.Volume = 50;
  170.             Player2 = NotAI;
  171.         }
  172.         public void ProcEvents()
  173.         {
  174.             Window.Closed += (sender, arg) => Window.Close();
  175.  
  176.             Window.KeyReleased += Window_KeyReleased;
  177.  
  178.             void Window_KeyReleased(object sender, KeyEventArgs e)
  179.             {
  180.                 if (e.Code == Keyboard.Key.Right && gameState == GameState.Menu)
  181.                 {
  182.                     LeftPlayerTex += 200;
  183.                     if (LeftPlayerTex == -200) LeftPlayerTex = 1800;
  184.                     if (LeftPlayerTex == 2000) LeftPlayerTex = 0;
  185.                     Player.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  186.                     PlayerSprite.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  187.                 }
  188.                 if (e.Code == Keyboard.Key.Left && gameState == GameState.Menu)
  189.                 {
  190.                     LeftPlayerTex += -200;
  191.                     if (LeftPlayerTex == -200) LeftPlayerTex = 1800;
  192.                     if (LeftPlayerTex == 2000) LeftPlayerTex = 0;
  193.                     Player.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  194.                     PlayerSprite.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  195.                 }
  196.                 if (e.Code == Keyboard.Key.D && gameState == GameState.Menu)
  197.                 {
  198.                     LeftPlayer2Tex += 200;
  199.                     if (LeftPlayer2Tex == -200) LeftPlayer2Tex = 1800;
  200.                     if (LeftPlayer2Tex == 2000) LeftPlayer2Tex = 0;
  201.                     Player2.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  202.                     Player2Sprite.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  203.                     NotAI.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  204.                     AI1.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  205.                     AI2.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  206.                     AI3.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  207.                 }
  208.                 if (e.Code == Keyboard.Key.A && gameState == GameState.Menu)
  209.                 {
  210.                     LeftPlayerTex += -200;
  211.                     if (LeftPlayer2Tex == -200) LeftPlayer2Tex = 1800;
  212.                     if (LeftPlayer2Tex == 2000) LeftPlayer2Tex = 0;
  213.                     Player2.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  214.                     Player2Sprite.TextureRect = new IntRect(LeftPlayerTex, 0, 200, 375);
  215.                     NotAI.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  216.                     AI1.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  217.                     AI2.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  218.                     AI3.TextureRect = new IntRect(LeftPlayer2Tex, 0, 200, 375);
  219.                 }
  220.  
  221.             }
  222.         }
  223.         public void Update(Time DeltaTime)
  224.         {
  225.             float DeltaT = DeltaTime.AsSeconds();
  226.  
  227.             TickCounter++;
  228.             if (TickCounter == 200) TickCounter = 0;
  229.  
  230.             if (TickCounter % 50 == 0) // losowanie liczby do funkcji DzwiekOdbicia()
  231.             {
  232.                 Random Randololo = new Random();
  233.                 RandomNumber = Randololo.Next(1, 9);
  234.             }
  235.  
  236.             // WYSWIETLANIE WYNIKU
  237.  
  238.             if (Player2.Score > 9) ScoreText.Position = new Vector2f(410, 0);
  239.             Score_s = Player2.Score.ToString() + " : " + Player.Score.ToString();
  240.             ScoreText.DisplayedString = Score_s;
  241.  
  242.  
  243.             // ############################# PLAYER 1 PORUSZANIE #######################
  244.             if (gameState == GameState.VsAI || gameState == GameState.VsPlayer)
  245.             {
  246.                 if (Player.Position.Y < Player.StartingPosition.Y)
  247.                 {
  248.                     float FallSpeed = 2;
  249.                     Player.MovementVector = Player.MovementVector + new Vector2f(0, 600) * DeltaT * FallSpeed;
  250.  
  251.                     // jesli player jest na ziemi, upewnij sie zeby nie wypadl za ekran
  252.                     if ((Player.Position.Y + Player.MovementVector.Y * DeltaT) >= Player.StartingPosition.Y)
  253.                     {
  254.                         Player.Position = new Vector2f(Player.Position.X, Player.StartingPosition.Y);
  255.                         Player.MovementVector = new Vector2f(0, 0);
  256.                     }
  257.                 }
  258.                 if (Player.Position.Y > Player.StartingPosition.Y) // po punkcie
  259.                 {
  260.                     Player.Position = new Vector2f(Player.Position.X, Player.StartingPosition.Y);
  261.                     Player.MovementVector = new Vector2f(0, 0);
  262.                 }
  263.                 // skakanie
  264.                 else if (Keyboard.IsKeyPressed(Keyboard.Key.Up) && Player.Position.Y == Player.StartingPosition.Y)
  265.                 {
  266.                     Player.MovementVector = new Vector2f(0, -700);
  267.                 }
  268.                 // sterowanie lewo prawo
  269.                 if (Keyboard.IsKeyPressed(Keyboard.Key.Left) && !Player.GetGlobalBounds().Intersects(Net.GetGlobalBounds())) Player.Move(new Vector2f(-Player.Speed, 0));
  270.                 if (Keyboard.IsKeyPressed(Keyboard.Key.Right) && Player.Position.X + Player.Size.X /2 < 1000) Player.Move(new Vector2f(Player.Speed, 0));
  271.  
  272.  
  273.                 // ############################# PLAYER 2 PORUSZANIE #######################
  274.  
  275.                 if (Player2.Position.Y < Player2.StartingPosition.Y)
  276.                 {
  277.                     float FallSpeed = 2;
  278.                     Player2.MovementVector = Player2.MovementVector + new Vector2f(0, 600) * DeltaT * FallSpeed;
  279.  
  280.                     // jesli player jest na ziemi, upewnij sie zeby nie wypadl za ekran
  281.                     if ((Player2.Position.Y + Player2.MovementVector.Y * DeltaT) >= Player2.StartingPosition.Y)
  282.                     {
  283.                         Player2.Position = new Vector2f(Player2.Position.X, Player2.StartingPosition.Y);
  284.                         Player2.MovementVector = new Vector2f(0, 0);
  285.                     }
  286.                 }
  287.                 if (Player2.Position.Y > Player2.StartingPosition.Y) // po punkcie
  288.                 {
  289.                     Player2.Position = new Vector2f(Player2.Position.X, Player2.StartingPosition.Y);
  290.                     Player2.MovementVector = new Vector2f(0, 0);
  291.                 }
  292.                 // skakanie
  293.  
  294.                 else if (Player2.Position.Y == Player2.StartingPosition.Y)
  295.                 {
  296.                     if (Keyboard.IsKeyPressed(Keyboard.Key.W) && WhoIsActualPlayer == 0) Player2.MovementVector = new Vector2f(0, -700);
  297.                     else if (WhoIsActualPlayer != 0 && Ball.Position.X > 100) Player2.MovementVector = new Vector2f(0, -700);
  298.                 }
  299.                     // sterowanie lewo prawo
  300.  
  301.                     if (Keyboard.IsKeyPressed(Keyboard.Key.D) && !Player2.GetGlobalBounds().Intersects(Net.GetGlobalBounds()) && WhoIsActualPlayer == 0) Player2.Move(new Vector2f(Player2.Speed, 0));
  302.                     if (Keyboard.IsKeyPressed(Keyboard.Key.A) && Player2.Position.X - Player2.Size.X / 2 > 0 && WhoIsActualPlayer == 0 ) Player2.Move(new Vector2f(-Player2.Speed, 0));
  303.                
  304.                 // ############################# BOTY  PORUSZANIE #######################
  305.                 if (WhoIsActualPlayer != 0)
  306.                 {
  307.                     if (Ball.Position.X < 490 && Player2.Position.X + Player2.Size.X /2 < 500 && Player2.Position.X - Player2.Size.X/2 > 0)
  308.                     {
  309.                         if (Player2.Position.X + Player2.Size.X /2 < Ball.Position.X - 15)
  310.                         {
  311.                             Player2.Move(Player2.Speed, 0);
  312.                         }
  313.                         else if (Player2.Position.X - Player2.Size.X /2 > Ball.Position.X - 15)
  314.                         {
  315.                             Player2.Move(-Player2.Speed, 0);
  316.                         }
  317.                         else if (Math.Abs(Player2.Position.X - Ball.Position.X) < 15)
  318.                         {
  319.                             Player2.Move(-Player2.Speed, 0);
  320.                         }
  321.                     }
  322.                 }
  323.  
  324.  
  325.  
  326.                 // ############# PUNKTY #############
  327.                 if (Player2.Score >= MaxPoints && Player2.Score > Player.Score + 1 )
  328.                 {
  329.                     gameState = GameState.Menu;
  330.                     GameOver = true;
  331.                     RightIsWinner = false;
  332.                 }
  333.                 if (Player.Score >= MaxPoints && Player.Score > Player2.Score + 1)
  334.                 {
  335.                     gameState = GameState.Menu;
  336.                     GameOver = true;
  337.                     RightIsWinner = true;
  338.                 }
  339.  
  340.  
  341.  
  342.                 if (GameOver == true)// koniec gry
  343.                 {
  344.                     if (!RightIsWinner && WhoIsActualPlayer != 0) LosingGame.Play();
  345.                     else WinningGame.Play();
  346.                     if (RightIsWinner == true) // gracz po prawej
  347.                     {
  348.                         Player.Position = new Vector2f (790, 123);
  349.                         Player2.Position = new Vector2f(192, 202);
  350.                         Player.ResetScore();
  351.                         Player2.ResetScore();
  352.                         FirstTouch = false;
  353.                         Ball.BallReset();
  354.                     }
  355.                     else // gracz po lewej
  356.                     {
  357.                         Player2.Position = new Vector2f(790, 123);
  358.                         Player.Position = new Vector2f(192, 202);
  359.                         Player.ResetScore();
  360.                         Player2.ResetScore();
  361.                         FirstTouch = false;
  362.                         Ball.BallReset();
  363.                     }
  364.                 }
  365.  
  366.                 if (Keyboard.IsKeyPressed(Keyboard.Key.U)) Player.AddScore(3);
  367.                 if (Keyboard.IsKeyPressed(Keyboard.Key.Y))
  368.                 {
  369.                     Player2.AddScore(3);
  370.                     AI1.AddScore(3);
  371.                     AI2.AddScore(3);
  372.                     AI3.AddScore(3);
  373.                 }
  374.                 // ############################## PIŁKA ###############################
  375.  
  376.                 // znacznik pilki poza ekranem
  377.                 if (Ball.Position.Y + Ball.BallRadius < 0)
  378.                 {
  379.                     IsBallOnScreen = false;
  380.                     BallHelp.Size = new Vector2f(-1500 / (Ball.Position.Y), -1500 / (Ball.Position.Y));
  381.                     BallHelp.Origin = new Vector2f(BallHelp.Size.X / 2, 0);
  382.                     BallHelp.Position = new Vector2f(Ball.Position.X, 5);
  383.                 }
  384.                 else if (Ball.Position.Y + Ball.BallRadius > 0) IsBallOnScreen = true;
  385.  
  386.                 // grawitacja pilki
  387.  
  388.                 if (Ball.Position.Y + Ball.BallRadius < 600 && FirstTouch == true)
  389.                 {
  390.                     float BallFallSpeed = 1;
  391.                     Ball.MovementVector = Ball.MovementVector + new Vector2f(0, 500) * DeltaT * BallFallSpeed;
  392.                 }
  393.  
  394.                 // pilka dotyka ziemi
  395.  
  396.                 if (Ball.Position.Y + Ball.BallRadius >= 600)
  397.                 {
  398.                     if (Ball.Position.X < 500)
  399.                     {
  400.                         FirstTouch = false;
  401.                         Ball.MovementVector = new Vector2f(0, 0);
  402.                         Ball.Position = BallLeftPosition;
  403.                         Player.HitCounter = 0;
  404.                         Player2.HitCounter = 0;
  405.                         Player2.AddScore(1); // punkty
  406.                         Player.Position = Player.StartingPosition;
  407.                         Player2.Position = Player2.StartingPosition;
  408.                         Ball.DzwiekOdbicia(RandomNumber);
  409.                     }
  410.                     else if (Ball.Position.X > 500)
  411.                     {
  412.                         FirstTouch = false;
  413.                         Ball.MovementVector = new Vector2f(0, 0);
  414.                         Ball.Position = BallRightPosition;
  415.                         Player.HitCounter = 0;
  416.                         Player2.HitCounter = 0;
  417.                         Player.AddScore(1); // punkty
  418.                         Player.Position = Player.StartingPosition;
  419.                         Player2.Position = Player2.StartingPosition;
  420.                         Ball.DzwiekOdbicia(RandomNumber);
  421.                     }
  422.                 }
  423.                 // kolizja pilka <-> sciana
  424.                 if (Ball.Position.X + Ball.BallRadius >= 1000)
  425.                 {
  426.                     Ball.MovementVector = new Vector2f(-Ball.MovementVector.X, Ball.MovementVector.Y);
  427.                     while (Ball.Position.X + Ball.BallRadius > 1000)
  428.                     {
  429.                         Ball.Move(-2, 0);
  430.                     }
  431.                 }
  432.                 if (Ball.Position.X - Ball.BallRadius <= 0)
  433.                 {
  434.                     Ball.MovementVector = new Vector2f(-Ball.MovementVector.X, Ball.MovementVector.Y);
  435.                     while (Ball.Position.X - Ball.BallRadius < 0)
  436.                     {
  437.                         Ball.Move(2, 0);
  438.                     }
  439.                 }
  440.                 // kolizja pilka <-> siatka
  441.  
  442.                 if (Ball.Position.Y < Net.Position.Y - 2 && (Math.Sqrt((Math.Pow(Net.Position.X - Ball.Position.X, 2) + Math.Pow(Net.Position.Y - Ball.Position.Y, 2)))) <= Ball.BallRadius + Net.Size.X /2 && Ball.MovementVector.Y > 0 )
  443.                 {
  444.                     while ((Math.Sqrt((Math.Pow(Net.Position.X - Ball.Position.X, 2) + Math.Pow(Net.Position.Y - Ball.Position.Y, 2)))) <= Ball.BallRadius + Net.Size.X / 2 && Ball.MovementVector.Y > 0)
  445.                     {
  446.                         Ball.Move(((Ball.Position.X - Net.Position.X) * 1 / 20), ((Ball.Position.Y - Net.Position.Y) * 1 / 20));
  447.                     }
  448.                     Ball.MovementVector = new Vector2f((Ball.Position.X - Net.Position.X) * 3, -Ball.MovementVector.Y);
  449.                     Net.DzwiekOdbicia(RandomNumber);
  450.                 }
  451.                 if (Ball.Position.Y >= Net.Position.Y && Ball.GetGlobalBounds().Intersects(Net.GetGlobalBounds()))
  452.                 {
  453.                     while (Ball.Position.X - Ball.BallRadius < Net.Position.X + Net.Size.X / 2 && Ball.Position.X + Ball.BallRadius >Net.Position.X + Net.Size.X / 2 )
  454.                     {
  455.                         Ball.Move(1, 0);
  456.                     }
  457.                     while (Ball.Position.X + Ball.BallRadius > Net.Position.X - Net.Size.X / 2 && Ball.Position.X - Ball.BallRadius < Net.Position.X - Net.Size.X / 2)
  458.                     {
  459.                         Ball.Move(-1, 0);
  460.                     }
  461.                     Ball.MovementVector = new Vector2f(-Ball.MovementVector.X, Ball.MovementVector.Y);
  462.                     Net.DzwiekOdbicia(RandomNumber);
  463.                 }
  464.                 // ########## PILKA <-> PLAYER 1 #####################
  465.  
  466.                 // gorna czesc gracza
  467.  
  468.                 if ((Ball.Position.Y < Player.Position.Y - 10) && (Math.Sqrt((Math.Pow(Player.Position.X - Ball.Position.X, 2) + Math.Pow(Player.Position.Y - Ball.Position.Y, 2)))) <= Ball.BallRadius + (Player.Size.X) / 2 && Player.HitCounter != 3)
  469.                 {
  470.                     FirstTouch = true;
  471.                     while ((Math.Sqrt((Math.Pow(Player.Position.X - Ball.Position.X, 2) + Math.Pow(Player.Position.Y - Ball.Position.Y, 2)))) <= Ball.BallRadius + (Player.Size.X) / 2)
  472.                     {
  473.                         Ball.Move((Ball.Position.X - Player.Position.X) * 1 / 20, (Ball.Position.Y - Player.Position.Y) * 1 / 20);
  474.                     }
  475.                     if (Player.MovementVector.Y < -600 && Player.MovementVector.Y != 0)// gracz nie spada za szubko
  476.                     {
  477.                         Ball.MovementVector = new Vector2f((Ball.Position.X - Player.Position.X) * Player.Strenght, (Player.MovementVector.Y + Ball.Position.Y - Player.Position.Y));
  478.                     }
  479.                     else if (Player.MovementVector.Y == 0)
  480.                     {
  481.                         Ball.MovementVector = new Vector2f((Ball.Position.X - Player.Position.X) * Player.Strenght, (Player.MovementVector.Y + Ball.Position.Y - Player.Position.Y) * Player.Strenght);
  482.                     }
  483.                     else Ball.MovementVector = new Vector2f((Ball.Position.X - Player.Position.X) * Player.Strenght, (Ball.Position.Y - Player.Position.Y) * 6);
  484.                     Player2.HitCounter = 0;
  485.                     Player.HitCounter += 1;
  486.                     Player.DzwiekOdbicia(RandomNumber);
  487.                 }
  488.                 // dolna czesc gracza
  489.  
  490.                 if ((Ball.Position.Y >= Player.Position.Y - 10) && Ball.GetGlobalBounds().Intersects(Player.GetGlobalBounds()) && Player.HitCounter != 3)
  491.                 {
  492.                     FirstTouch = true; // serwis
  493.                     if (Math.Abs(Ball.MovementVector.X) < 200) // pilka nie leci zbyt wolno
  494.                     {
  495.                         if (Ball.Position.X < Player.Position.X) Ball.MovementVector = new Vector2f(-200, Ball.MovementVector.Y);
  496.                         else Ball.MovementVector = new Vector2f(200, Ball.MovementVector.Y);
  497.                     }
  498.                     else Ball.MovementVector = new Vector2f(-(Ball.MovementVector.X), Ball.MovementVector.Y);
  499.                     while (Ball.GetGlobalBounds().Intersects(Player.GetGlobalBounds()))
  500.                     {
  501.                         Ball.Move((Ball.Position.X - Player.Position.X) * 1 / 20, (Ball.Position.Y - Player.Position.Y) * 1 / 20);
  502.                     }
  503.                     Player2.HitCounter = 0;
  504.                     Player.HitCounter += 1;
  505.                     Player.DzwiekOdbicia(RandomNumber);
  506.  
  507.                 }
  508.                 Console.WriteLine(Ball.MovementVector.Y);
  509.                 // ########## PILKA <-> PLAYER 2 #####################
  510.  
  511.                 // gorna czesc gracza
  512.                 if ((Ball.Position.Y < Player2.Position.Y - 10) && (Math.Sqrt((Math.Pow(Player2.Position.X - Ball.Position.X, 2) + Math.Pow(Player2.Position.Y - Ball.Position.Y, 2)))) <= Ball.BallRadius + (Player2.Size.X) / 2 && Player2.HitCounter != 3)
  513.                 {
  514.                     FirstTouch = true;
  515.                     while ((Math.Sqrt((Math.Pow(Player2.Position.X - Ball.Position.X, 2) + Math.Pow(Player2.Position.Y - Ball.Position.Y, 2)))) <= Ball.BallRadius + (Player2.Size.X) / 2)
  516.                     {
  517.                         Ball.Move((Ball.Position.X - Player2.Position.X) * 1 / 20, (Ball.Position.Y - Player2.Position.Y) * 1 / 20);
  518.                     }
  519.                     if (Player2.MovementVector.Y < -600 && Player2.MovementVector.Y != 0)
  520.                     {
  521.                         Ball.MovementVector = new Vector2f((Ball.Position.X - Player2.Position.X) * Player2.Strenght, (Player2.MovementVector.Y + Ball.Position.Y - Player2.Position.Y));
  522.                     }
  523.                     else if (Player2.MovementVector.Y == 0)
  524.                     {
  525.                         Ball.MovementVector = new Vector2f((Ball.Position.X - Player2.Position.X) * Player2.Strenght, (Player2.MovementVector.Y + Ball.Position.Y - Player2.Position.Y) * 0.66F * Player2.Strenght);
  526.                     }
  527.                     else Ball.MovementVector = new Vector2f((Ball.Position.X - Player2.Position.X) * Player2.Strenght, (Ball.Position.Y - Player2.Position.Y) * Player2.Strenght);
  528.                     Player.HitCounter = 0;
  529.                     Player2.HitCounter += 1;
  530.                     Player2.DzwiekOdbicia(RandomNumber);
  531.                 }
  532.                 // dolna czesc gracza
  533.                 if ((Ball.Position.Y >= Player2.Position.Y - 10) && Ball.GetGlobalBounds().Intersects(Player2.GetGlobalBounds()) && Player2.HitCounter != 3)
  534.                 {
  535.                     FirstTouch = true; // serwis
  536.                     if (Math.Abs(Ball.MovementVector.X) < 200) // pilka nie leci zbyt wolno
  537.                     {
  538.                         if (Ball.Position.X < Player2.Position.X) Ball.MovementVector = new Vector2f(-200, Ball.MovementVector.Y);
  539.                         else Ball.MovementVector = new Vector2f(200, Ball.MovementVector.Y);
  540.                     }
  541.                     else Ball.MovementVector = new Vector2f(-(Ball.MovementVector.X), Ball.MovementVector.Y);
  542.                     while (Ball.GetGlobalBounds().Intersects(Player2.GetGlobalBounds()))
  543.                     {
  544.                         Ball.Move((Ball.Position.X - Player2.Position.X) * 1 / 20, (Ball.Position.Y - Player2.Position.Y) * 1 / 20);
  545.                     }
  546.                     Player.HitCounter = 0;
  547.                     Player2.HitCounter += 1;
  548.                     Player.DzwiekOdbicia(RandomNumber);
  549.  
  550.                 }
  551.                 // ############################### PORUSZANIE WSZYSTKIM #################
  552.                 Player.Move(Player.MovementVector * DeltaT);
  553.                 Player2.Move(Player2.MovementVector * DeltaT);
  554.                 Ball.Move(Ball.MovementVector * DeltaT * 0.8F);
  555.  
  556.                 if (Keyboard.IsKeyPressed(Keyboard.Key.M))
  557.                 {
  558.                     gameState = GameState.Menu;
  559.                 }
  560.             }
  561.         }
  562.         public void DisplayMenu()
  563.         {
  564.             // ############################ PODPINANIE TEKSTUR ###########################
  565.             MenuBackground.Texture = MenuBackgroundTex;
  566.             GraczVsGracz.Texture = GraczVsGraczTex;
  567.             GraczVsKomputer.Texture = GraczVsKomputerTex;
  568.             ExitButton.Texture = ExitButtonTex;
  569.             Button1.Texture = Button1Tex;
  570.             Button2.Texture = Button2Tex;
  571.             Button3.Texture = Button3Tex;
  572.             LevelButton.Texture = LevelButtonTex;
  573.             Points15Button.Texture = Points15ButtonTex;
  574.             Points20Button.Texture = Points20ButtonTex;
  575.             Points25Button.Texture = Points25ButtonTex;
  576.             PointsButton.Texture = PointsButtonTex;
  577.             // ############################### SKALA I POZYCJA ##############################
  578.             GraczVsGracz.Position = new Vector2f(20, 260);
  579.             GraczVsGracz.Scale = new Vector2f(0.6F, 0.6F);
  580.             GraczVsKomputer.Position = new Vector2f(20, 330);
  581.             GraczVsKomputer.Scale = new Vector2f(0.6F, 0.6F);
  582.             ExitButton.Position = new Vector2f(5, 545);
  583.             ExitButton.Scale = new Vector2f(0.3F, 0.3F);
  584.             LevelButton.Position = new Vector2f(20, 330);
  585.             LevelButton.Scale = new Vector2f(0.6F, 0.6F);
  586.             PointsButton.Position = new Vector2f(20, 400);
  587.             PointsButton.Scale = new Vector2f(0.6F, 0.6F);
  588.             Points15Button.Position = new Vector2f(20, 470);
  589.             Points15Button.Scale = new Vector2f(0.6F, 0.6F);
  590.             Points20Button.Position = new Vector2f(140, 470);
  591.             Points20Button.Scale = new Vector2f(0.6F, 0.6F);
  592.             Points25Button.Position = new Vector2f(260, 470);
  593.             Points25Button.Scale = new Vector2f(0.6F, 0.6F);
  594.             Button1.Position = new Vector2f(20, 400);
  595.             Button1.Scale = new Vector2f(0.6F, 0.6F);
  596.             Button2.Position = new Vector2f(140, 400);
  597.             Button2.Scale = new Vector2f(0.6F, 0.6F);
  598.             Button3.Position = new Vector2f(260, 400);
  599.             Button3.Scale = new Vector2f(0.6F, 0.6F);
  600.  
  601.  
  602.             // ############################## INNE #####################################
  603.  
  604.             bool DrawPoints = false;
  605.             bool DrawLevel = false;
  606.  
  607.             Clock C = new Clock();
  608.             float _T = T.AsSeconds();
  609.  
  610.  
  611.  
  612.             while (true)
  613.             {
  614.                 // zamykanie okna
  615.                 Window.DispatchEvents();
  616.                 ProcEvents();
  617.  
  618.  
  619.                 // gracz vs gracz
  620.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && GraczVsGracz.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) || Keyboard.IsKeyPressed(Keyboard.Key.R))
  621.                 {
  622.                     WhoIsActualPlayer = 0;
  623.                     Player2 = NotAI;
  624.                     Player.ResetScore();
  625.                     FirstTouch = false;
  626.                     Ball.BallReset();
  627.                     Player.Position = Player.StartingPosition;
  628.                     Player.HitCounter = 0;
  629.                     gameState = GameState.VsPlayer;
  630.                 }
  631.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && GraczVsKomputer.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y))
  632.                 {
  633.                     DrawLevel = true;
  634.                     DrawPoints = false;
  635.                 }
  636.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && Button1.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) && DrawLevel)
  637.                 {
  638.                     WhoIsActualPlayer = 1;
  639.                     Player2 = AI1;
  640.                     Player.ResetScore();
  641.                     FirstTouch = false;
  642.                     Ball.BallReset();
  643.                     Player.Position = Player.StartingPosition;
  644.                     Player.HitCounter = 0;
  645.                     Player2.Position = Player2.StartingPosition;
  646.                     Player2.HitCounter = 0;
  647.                     gameState = GameState.VsAI;
  648.                 }
  649.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && Button2.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) && DrawLevel)
  650.                 {
  651.                     WhoIsActualPlayer = 2;
  652.                     Player2 = AI2;
  653.                     Player.ResetScore();
  654.                     FirstTouch = false;
  655.                     Ball.BallReset();
  656.                     Player.Position = Player.StartingPosition;
  657.                     Player.HitCounter = 0;
  658.                     Player2.Position = Player2.StartingPosition;
  659.                     Player2.HitCounter = 0;
  660.                     gameState = GameState.VsAI;
  661.                 }
  662.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && Button3.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) && DrawLevel)
  663.                 {
  664.                     WhoIsActualPlayer = 3;
  665.                     Player2 = AI3;
  666.                     Player.ResetScore();
  667.                     FirstTouch = false;
  668.                     Ball.BallReset();
  669.                     Player.Position = Player.StartingPosition;
  670.                     Player.HitCounter = 0;
  671.                     Player2.Position = Player2.StartingPosition;
  672.                     Player2.HitCounter = 0;
  673.                     gameState = GameState.VsAI;
  674.                 }
  675.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && PointsButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) && !DrawLevel)
  676.                 {
  677.                     DrawPoints = true;
  678.                 }
  679.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && Points15Button.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) && !DrawLevel)
  680.                 {
  681.                     MaxPoints = 15;
  682.                     gameState = GameState.Menu;
  683.                     DrawPoints = false;
  684.                 }
  685.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && Points20Button.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) && !DrawLevel)
  686.                 {
  687.                     MaxPoints = 20;
  688.                     gameState = GameState.Menu;
  689.                     DrawPoints = false;
  690.                 }
  691.                 if (Mouse.IsButtonPressed(Mouse.Button.Left) && Points25Button.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y))
  692.                 {
  693.                     MaxPoints = 25;
  694.                     gameState = GameState.Menu;
  695.                     DrawPoints = false;
  696.                 }
  697.                 if ((Mouse.IsButtonPressed(Mouse.Button.Left) && ExitButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) || Keyboard.IsKeyPressed(Keyboard.Key.Escape))
  698.                 {
  699.                     gameState = GameState.Closing;
  700.                 }
  701.                 if (Keyboard.IsKeyPressed(Keyboard.Key.Return))
  702.                 {
  703.                     GameOver = false;
  704.                     gameState = GameState.Menu;
  705.                     WinningGame.Stop();
  706.                     LosingGame.Stop();
  707.                 }
  708.                 if (gameState != GameState.Menu)
  709.                 {
  710.                     return;
  711.                 }
  712.                 Window.Clear();
  713.  
  714.                 // rysowanie menu
  715.  
  716.                 Window.Draw(MenuBackground);
  717.                 Window.Draw(GraczVsGracz);
  718.                 Window.Draw(GraczVsKomputer);
  719.                 Window.Draw(ExitButton);
  720.                 //Window.Draw(PlayerSprite);
  721.                 if (!DrawLevel) Window.Draw(PointsButton);
  722.                 if (DrawLevel)
  723.                 {
  724.                     Window.Draw(LevelButton);
  725.                     Window.Draw(Button1);
  726.                     Window.Draw(Button2);
  727.                     Window.Draw(Button3);
  728.                 }
  729.                 if (DrawPoints)
  730.                 {
  731.                     Window.Draw(Points15Button);
  732.                     Window.Draw(Points20Button);
  733.                     Window.Draw(Points25Button);
  734.                 }
  735.                 if (GameOver == true)
  736.                 {
  737.                     Window.Draw(EndGame);
  738.                     Window.Draw(Player);
  739.                     Window.Draw(Player2);
  740.                 }
  741.                 Window.Display();
  742.  
  743.                 while (C.ElapsedTime < T) ;
  744.                 C.Restart();
  745.                
  746.             }
  747.  
  748.  
  749.  
  750.         }
  751.  
  752.         public void Render()
  753.         {
  754.             Window.Clear();
  755.             Window.Draw(Background);
  756.             Window.Draw(Player);
  757.             Window.Draw(Player2);
  758.             Window.Draw(Ball);
  759.             Window.Draw(Net);
  760.             if (!IsBallOnScreen) Window.Draw(BallHelp);
  761.             Window.Draw(ScoreText);
  762.             Window.Display();
  763.         }
  764.         public void RunGame()
  765.         {
  766.             Time TimeSinceLastUpdate = Time.Zero;
  767.             Time TimePerFrame = Time.FromSeconds(TICK);
  768.             Clock Clock = new Clock();
  769.            
  770.  
  771.             while (Window.IsOpen)
  772.             {
  773.                 TimeSinceLastUpdate += Clock.Restart();
  774.                 while (TimeSinceLastUpdate > TimePerFrame)
  775.                 {
  776.                     TimeSinceLastUpdate -= TimePerFrame;
  777.                     Window.DispatchEvents();
  778.                     Update(TimePerFrame);
  779.                     if (gameState != GameState.VsPlayer || gameState!= GameState.VsAI)
  780.                     {
  781.                         return;
  782.                     }
  783.                 }
  784.  
  785.                 Render();
  786.                 ProcEvents();
  787.             }
  788.         }
  789.  
  790.         public void Run()
  791.         {
  792.             GameMusic.Play();
  793.             while (true)
  794.             {
  795.                 switch (gameState)
  796.                 {
  797.                     case GameState.Menu:
  798.                         DisplayMenu();
  799.                         break;
  800.                     case GameState.VsAI:
  801.                         RunGame();
  802.                         break;
  803.                     case GameState.VsPlayer:
  804.                         RunGame();
  805.                         break;
  806.                     case GameState.Closing:
  807.                         Window.Close();
  808.                         return;
  809.                     case GameState.WinningScreen:
  810.                         break;
  811.                 }
  812.             }
  813.         }
  814.     }
  815. }
  816.  
  817.  
  818. BALL
  819.  
  820. using System;
  821. using System.Collections.Generic;
  822. using System.Linq;
  823. using System.Text;
  824. using System.Threading.Tasks;
  825. using SFML.Audio;
  826. using SFML.Graphics;
  827. using SFML.System;
  828. using SFML.Window;
  829.  
  830.  
  831. namespace Siatkowkaa2
  832. {
  833.     class Ball : Entity
  834.     {
  835.         public float BallRadius { get; set; }
  836.         private SoundBuffer GroundHitBuf1 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\groundHit1.wav");
  837.         private SoundBuffer GroundHitBuf2 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\groundHit2.wav");
  838.         private SoundBuffer GroundHitBuf3 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\point.wav");
  839.         private Sound GroundHit1 = new Sound();
  840.         private Sound GroundHit2 = new Sound();
  841.         private Sound GroundHit3 = new Sound();
  842.  
  843.  
  844.         public void BallReset()
  845.         {
  846.             this.MovementVector = new Vector2f(0, 0);
  847.             this.Position = new Vector2f(750, 200);
  848.         }
  849.         public Ball(float ballradius, Vector2f position)
  850.         {
  851.             Size = new Vector2f(ballradius, ballradius);
  852.             Origin = new Vector2f(ballradius / 2, ballradius / 2);
  853.             Position = position;
  854.             BallRadius = ballradius/2;
  855.             GroundHit1.SoundBuffer = GroundHitBuf1;
  856.             GroundHit2.SoundBuffer = GroundHitBuf2;
  857.             GroundHit3.SoundBuffer = GroundHitBuf3;
  858.             GroundHit1.Volume = 20;
  859.             GroundHit2.Volume = 20;
  860.             GroundHit3.Volume = 20;
  861.  
  862.         }
  863.         override public void DzwiekOdbicia(int random)
  864.         {
  865.             if (random < 4) GroundHit1.Play();
  866.             if (random > 4) GroundHit3.Play();
  867.             else if (random == 4) GroundHit2.Play();
  868.         }
  869.     }
  870. }
  871.  
  872.  
  873. PLAYER
  874.  
  875.  
  876.  
  877. using System;
  878. using System.Collections.Generic;
  879. using System.Linq;
  880. using System.Text;
  881. using System.Threading.Tasks;
  882. using SFML.Audio;
  883. using SFML.Graphics;
  884. using SFML.System;
  885. using SFML.Window;
  886.  
  887. namespace Siatkowkaa2
  888. {
  889.     class Player : Entity
  890.     {
  891.         public Vector2f StartingPosition { get; set; }
  892.         public RectangleShape Shape;
  893.         public int Score { get; private set; } = 0;
  894.         public float Speed { get; set; }
  895.         public int HitCounter { get; set; } = 0;
  896.         public int Strenght { get; set; }
  897.         private SoundBuffer BallHitBuf1 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit1.wav");
  898.         private SoundBuffer BallHitBuf2 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit2.wav");
  899.         private SoundBuffer BallHitBuf3 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit3.wav");
  900.         private SoundBuffer BallHitBuf4 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit4.wav");
  901.         private SoundBuffer BallHitBuf5 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit5.wav");
  902.         private SoundBuffer BallHitBuf6 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit6.wav");
  903.         private SoundBuffer BallHitBuf7 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit7.wav");
  904.         private SoundBuffer BallHitBuf8 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit8.wav");
  905.         private SoundBuffer BallHitBuf9 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\hit9.wav");
  906.  
  907.  
  908.         private Sound BallHit1 = new Sound();
  909.         private Sound BallHit2 = new Sound();
  910.         private Sound BallHit3 = new Sound();
  911.         private Sound BallHit4 = new Sound();
  912.         private Sound BallHit5 = new Sound();
  913.         private Sound BallHit6 = new Sound();
  914.         private Sound BallHit7 = new Sound();
  915.         private Sound BallHit8 = new Sound();
  916.         private Sound BallHit9 = new Sound();
  917.  
  918.         public void AddScore(int Amount)
  919.         {
  920.             Score += Amount;
  921.         }
  922.         public Player(Vector2f position, Vector2f size, float speed, int strenght)
  923.         {
  924.             this.Size = size;
  925.             this.Origin = new Vector2f(size.X / 2, size.X / 2);
  926.             this.Position = position;
  927.             this.StartingPosition = position;
  928.             this.Speed = speed;
  929.             Strenght = strenght;
  930.             BallHit1.SoundBuffer = BallHitBuf1;
  931.             BallHit2.SoundBuffer = BallHitBuf2;
  932.             BallHit3.SoundBuffer = BallHitBuf3;
  933.             BallHit4.SoundBuffer = BallHitBuf4;
  934.             BallHit5.SoundBuffer = BallHitBuf5;
  935.             BallHit6.SoundBuffer = BallHitBuf6;
  936.             BallHit7.SoundBuffer = BallHitBuf7;
  937.             BallHit8.SoundBuffer = BallHitBuf8;
  938.             BallHit9.SoundBuffer = BallHitBuf9;
  939.             BallHit1.Volume = 30;
  940.             BallHit2.Volume = 30;
  941.             BallHit3.Volume = 30;
  942.             BallHit4.Volume = 30;
  943.             BallHit5.Volume = 30;
  944.             BallHit6.Volume = 30;
  945.             BallHit7.Volume = 30;
  946.             BallHit8.Volume = 30;
  947.             BallHit9.Volume = 30;
  948.  
  949.  
  950.         }
  951.         public void ResetScore()
  952.         {
  953.             Score = 0;
  954.         }
  955.         override public void DzwiekOdbicia(int random)
  956.         {
  957.             switch (random)
  958.             {
  959.                 case 1:
  960.                     BallHit1.Play();
  961.                     break;
  962.                 case 2:
  963.                     BallHit2.Play();
  964.                     break;
  965.                 case 3:
  966.                     BallHit3.Play();
  967.                     break;
  968.                 case 4:
  969.                     BallHit4.Play();
  970.                     break;
  971.                 case 5:
  972.                     BallHit5.Play();
  973.                     break;
  974.                 case 6:
  975.                     BallHit6.Play();
  976.                     break;
  977.                 case 7:
  978.                     BallHit7.Play();
  979.                     break;
  980.                 case 8:
  981.                     BallHit8.Play();
  982.                     break;
  983.                 case 9:
  984.                     BallHit9.Play();
  985.                     break;
  986.             }
  987.         }
  988.  
  989.     }
  990. }
  991.  
  992.  
  993. NET
  994.  
  995.  
  996. using System;
  997. using System.Collections.Generic;
  998. using System.Linq;
  999. using System.Text;
  1000. using System.Threading.Tasks;
  1001. using SFML.Audio;
  1002. using SFML.Graphics;
  1003. using SFML.System;
  1004. using SFML.Window;
  1005.  
  1006.  
  1007. namespace Siatkowkaa2
  1008. {
  1009.     class Net : Entity
  1010.     {
  1011.         RectangleShape Shape;
  1012.         private SoundBuffer NetHitBuf1 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\nethit.wav");
  1013.         private SoundBuffer NetHitBuf2 = new SoundBuffer(@"F:\Visual\Siatkowkaa2\Siatkowkaa2\Resources\Sounds\nethit2.wav");
  1014.         private Sound NetHit1 = new Sound();
  1015.         private Sound NetHit2 = new Sound();
  1016.  
  1017.         public Net(Vector2f size)
  1018.         {
  1019.             Size = size;
  1020.             Origin = new Vector2f(size.X / 2, size.X / 2);
  1021.             Position = new Vector2f(500, 600 - size.Y + size.X);
  1022.             NetHit1.SoundBuffer = NetHitBuf1;
  1023.             NetHit2.SoundBuffer = NetHitBuf2;
  1024.             NetHit1.Volume = 20;
  1025.             NetHit2.Volume = 20;
  1026.         }
  1027.         override public void DzwiekOdbicia(int random)
  1028.         {
  1029.             if (random < 5) NetHit1.Play();
  1030.             else NetHit2.Play();
  1031.         }
  1032.  
  1033.     }
  1034. }
  1035.  
  1036.  
  1037. ENTITY
  1038.  
  1039.  
  1040. using System;
  1041. using System.Collections.Generic;
  1042. using System.Linq;
  1043. using System.Text;
  1044. using System.Threading.Tasks;
  1045. using SFML.Audio;
  1046. using SFML.Graphics;
  1047. using SFML.System;
  1048. using SFML.Window;
  1049.  
  1050.  
  1051. namespace Siatkowkaa2
  1052. {
  1053.     class Entity : RectangleShape
  1054.     {
  1055.         public Vector2f MovementVector {get; set; }
  1056.         public virtual void DzwiekOdbicia(int random)
  1057.         { }
  1058.  
  1059.         public void Move(Vector2f offset)
  1060.         {
  1061.             Position += offset;
  1062.         }
  1063.         public void Move(float offsetX, float offsetY)
  1064.         {
  1065.             Position += new Vector2f(offsetX, offsetY);
  1066.         }
  1067.         public Entity()
  1068.         {
  1069.             MovementVector = new Vector2f(0.0f, 0.0f);
  1070.         }
  1071.     }
  1072. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement