-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
55 lines (39 loc) · 1.1 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
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
Texture bolaT;
Sprite bola;
float velX = 2;
float velY = 2;
int main(){
if(!bolaT.loadFromFile("Shiny_steel_ball.png")){
cout<< "Error al cargar textura Bola"<< endl;
}
bola.setTexture(bolaT);
bola.setOrigin((float)bolaT.getSize().x/2, (float)bolaT.getSize().y/2);
bola.setPosition(425,250);
bola.setScale(0.01f, 0.01f);
RenderWindow ventana(VideoMode(850,500),"Pong");
ventana.setFramerateLimit(120);
while(ventana.isOpen()){
Event event;
while (ventana.pollEvent(event)) {
if (event.type == Event::Closed) {
ventana.close();
}
}
bola.move(velX,velY);
float ballRadius = (float)bolaT.getSize().x * 0.01f / 2;
if(bola.getPosition().x - ballRadius > 850 || bola.getPosition().x + ballRadius < 0){
velX *= -1;
}
if(bola.getPosition().y - ballRadius > 500 || bola.getPosition().y + ballRadius < 0){
velY *= -1;
}
ventana.clear();
ventana.draw(bola);
ventana.display();
}
return 0;
}