Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Game.h"
- #include "Player.h"
- #include "ball.h"
- #include "Human.h"
- #include "Computer.h"
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- using namespace sf;
- Game::Game()
- {
- //App = new RenderWindow(VideoMode(800, 600, 32), "Pong");
- App.Create(VideoMode(800, 600, 32), "Pong");
- SoundBuffer scoreSoundBuffer;
- scoreSoundBuffer.LoadFromFile("datas/pong/score.wav");
- scoreSound.SetBuffer(scoreSoundBuffer);
- Image backgroundI;
- backgroundI.LoadFromFile("datas/pong/background.png");
- background.SetImage(backgroundI);
- ball = new Ball();
- player1 = new Human(&App, 1);
- player2 = new Computer (&App, 2, ball);
- }
- void Game::run()
- {
- bool IsPlaying = true;
- while (App.IsOpened())
- {
- // Handle events
- Event Event;
- while (App.GetEvent(Event))
- {
- // Window closed or escape key pressed : exit
- if ((Event.Type == Event::Closed) ||
- ((Event.Type == Event::KeyPressed) && (Event.Key.Code == Key::Escape)))
- {
- App.Close();
- break;
- }
- }
- if (IsPlaying)
- {
- player1->refresh();
- player2->refresh();
- IsPlaying = ball->refresh(player1->getPaddleSpriteP(), player2->getPaddleSpriteP());
- }
- // Clear the window
- App.Clear();
- // Draw the background, paddles and ball sprites
- App.Draw(background);
- App.Draw(player1->getPaddleSprite());
- App.Draw(player2->getPaddleSprite());
- App.Draw(ball->getSprite());
- // Display things on screen
- App.Display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement