-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvd-screensaver.cpp
90 lines (77 loc) · 2.08 KB
/
dvd-screensaver.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <SFML/Graphics.hpp>
#include <iostream>
double x=50;
double y=50;
double xadd=-0.2;
double yadd=0.2;
std::string colors[5] = {"red","green","blue","yellow","cyan"};
std::string color;
int i=0;
int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 700), "DVD-Screensaver");
sf::Sprite sprite;
sf::Texture texture;
texture.loadFromFile("dvd.png");
sprite.setTexture(texture);
sprite.setScale(sf::Vector2f(0.15,0.15));
sprite.setPosition(sf::Vector2f(x,y));
// change the size to 100x100
while (window.isOpen())
{
/*
float currentTime = clock.restart().asSeconds();
float fps = 1.0f/(currentTime);
std::cout << fps << std::endl;
*/
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if(i>=3){
i=0;
}
color=colors[i];
if(x>=1050 || x<=0){
xadd*=-1;
if(color=="red"){
sprite.setColor(sf::Color::Red);
}
else if(color=="green"){
sprite.setColor(sf::Color::Green);
}
else if(color=="blue"){
sprite.setColor(sf::Color::Blue);
}
else if(color=="yellow"){
sprite.setColor(sf::Color::Yellow);
}
else if(color=="cyan"){
sprite.setColor(sf::Color::Cyan);
}
i++;
}
if(y>=550 || y<=0){
yadd*=-1;
if(color=="red"){
sprite.setColor(sf::Color::Red);
}
else if(color=="green"){
sprite.setColor(sf::Color::Green);
}
else if(color=="blue"){
sprite.setColor(sf::Color::Blue);
}
i++;
}
x+=xadd;
y+=yadd;
sprite.setPosition(sf::Vector2f(x,y));
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}