-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.cpp
72 lines (64 loc) · 2.21 KB
/
Source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include"Header.h"
int main() {
sf::RenderWindow window(sf::VideoMode(1000, 800), "game-1");
sf::Event ev{};
window.setFramerateLimit(60);
sf::Texture texture;
srand(static_cast<unsigned int>(time(0)));
Player1 player1{ sf::Color::Green };
Player2 player2{sf::Color::Red };
Ball ball1{ sf::Color::Cyan };
int kati=1;
int kati2=2;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::W) {
player1.modifyPosition(sf::Keyboard::W,window);
}
}
// Check if a key was released
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::S) {
player1.modifyPosition(sf::Keyboard::S, window);
}
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Up) {
player2.modifyPosition(sf::Keyboard::Up, window);
}
}
// Check if a key was released
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Down) {
player2.modifyPosition(sf::Keyboard::Down, window);
}
}
}
if (ball1.get().intersects(player1.get())) {
kati2 = rand() % 3 + 1;
kati = 1;
ball1.kati3 = 0;
ball1.modifyPosition(window, kati,kati2);
}
else if (ball1.get().intersects(player2.get())) {
kati2 = rand() % 3 + 1;
kati = 2;
ball1.kati3 = 0;
ball1.modifyPosition(window, kati,kati2);
}
ball1.modifyPosition(window, kati,kati2);
// Clear the window
window.clear(sf::Color::Blue);
// Draw the rectangle
player1.draw(window);
player2.draw(window);
ball1.draw(window);
// Display what has been drawn
window.display();
}
}