-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
67 lines (61 loc) · 1.97 KB
/
main.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
#include <SFML/Graphics.hpp>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#define set setSize(sf::Vector2f(2.5,2.5))
#define setPos setPosition
#define windowY 1000
#define windowX 500
int main()
{
sf::RenderWindow window(sf::VideoMode(windowX, windowY), "SFML works!");
sf::RectangleShape star[100];
srand(time(NULL));
for(int index=0;index<100;index++) {
star[index].set;
star[index].setPos((rand()+windowX)%windowX,(rand()+windowY)%windowY);
}
int starSpeed[100];
for(int index=0;index<100;index++) {
starSpeed[index]=((rand()%20)+10);
}
sf::Texture texture;
texture.loadFromFile("images/ship.png");
sf::Sprite player;
player.setTexture(texture);
player.setPosition(350,350);
const int fast = 5, still = 0;
float rotationAngle = 90;
sf::Vector2f pos;
sf::Time t1 = sf::microseconds(800000);
float sec = t1.asSeconds();
while (window.isOpen())
{
window.clear();
sf::Event event;
while (window.pollEvent(event))
{
if (event.type=sf::Event::KeyPressed)
switch(event.key.code) {
case sf::Keyboard::Right:player.move(fast,still);
break;
case sf::Keyboard::Left:player.move(-fast,still);
break;
case sf::Keyboard::Up:player.move(still,-fast);
break;
case sf::Keyboard::Down:player.move(still,fast);
break;
}
}
for(int index=0;index<100;index++){
pos=star[index].getPosition();
star[index].move(still,.1);
window.draw(star[index]);
if (pos.y>=windowY)
star[index].setPos((rand()+500)%500,0);
}
window.draw(player);
window.display();
}
return 0;
}