-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathExample14.cpp
More file actions
119 lines (119 loc) · 2.67 KB
/
Example14.cpp
File metadata and controls
119 lines (119 loc) · 2.67 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//#include<iostream>
//#include"SFML\Graphics.hpp"
//#include"SFML\Window.hpp"
//#include"SFML\System.hpp"
//
//using namespace sf;
//
//int main()
//{
// RenderWindow window(VideoMode(800, 600), "Framerate independent!", Style::Default);
// window.setFramerateLimit(60);
//
// //dt at 60fps = 0,016s
//
// Clock clock;
// float dt;
// float multiplier = 60.f;
//
// RectangleShape shape;
// shape.setFillColor(Color::White);
// shape.setSize(Vector2f(50.f, 50.f));
//
// Vector2f currentVelocity;
// Vector2f direction;
// float maxVelocity = 25.f;
// float acceleration = 1.f;
// float drag = 0.5f;
//
// while (window.isOpen())
// {
// Event event;
// while (window.pollEvent(event))
// {
// if (event.type == Event::Closed)
// window.close();
// if (event.type == Event::KeyPressed && event.key.code == Keyboard::Escape)
// window.close();
// }
//
// dt = clock.restart().asSeconds();
//
// //Update
// //Acceleration
// direction = Vector2f(0.f, 0.f);
// if (Keyboard::isKeyPressed(Keyboard::A))
// {
// direction.x = -1.f;
//
// if (currentVelocity.x > -maxVelocity)
// currentVelocity.x += acceleration * direction.x * dt * multiplier;
// }
// if (Keyboard::isKeyPressed(Keyboard::D))
// {
// direction.x = 1.f;
//
// if (currentVelocity.x < maxVelocity)
// currentVelocity.x += acceleration * direction.x * dt * multiplier;
// }
// if (Keyboard::isKeyPressed(Keyboard::W))
// {
// direction.y = -1.f;
//
// if (currentVelocity.y > -maxVelocity)
// currentVelocity.y += acceleration * direction.y * dt * multiplier;
// }
// if (Keyboard::isKeyPressed(Keyboard::S))
// {
// direction.y = 1.f;
//
// if (currentVelocity.y < maxVelocity)
// currentVelocity.y += acceleration * direction.y * dt * multiplier;
// }
//
// //Drag
// if (currentVelocity.x > 0.f)
// {
// currentVelocity.x -= drag * dt * multiplier;
//
// if (currentVelocity.x < 0.f)
// currentVelocity.x = 0.f;
// }
// else if (currentVelocity.x < 0.f)
// {
// currentVelocity.x += drag * dt * multiplier;
//
// if (currentVelocity.x > 0.f)
// currentVelocity.x = 0.f;
// }
// if (currentVelocity.y > 0.f)
// {
// currentVelocity.y -= drag * dt * multiplier;
//
// if (currentVelocity.y < 0.f)
// currentVelocity.y = 0.f;
// }
// else if (currentVelocity.y < 0.f)
// {
// currentVelocity.y += drag * dt * multiplier;
//
// if (currentVelocity.y > 0.f)
// currentVelocity.y = 0.f;
// }
//
// //Final move
// shape.move(currentVelocity.x * dt * multiplier, currentVelocity.y * dt * multiplier);
//
// //Draw
// window.clear();
//
// //Draw everything
// window.draw(shape);
//
// window.display();
//
// std::cout << "dt: " << dt << "\n";
// }
//
// return 0;
//}