-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (66 loc) · 1.93 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (66 loc) · 1.93 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
#include "cannon.hpp"
int main()
{
// Load all resources
sf::Font font;
sf::Texture bg;
if (!font.loadFromFile("assets/Erewhon-Regular.otf")
|| !bg.loadFromFile("assets/background.png"))
return 1;
// Setup window
sf::RenderWindow window(sf::VideoMode(1280, 720), "Cannon Game");
window.setFramerateLimit(60);
// Setup background
Level level(bg, 0.0f, -500.0f, 1280.0f, 615.0f);
// Setup cannon
Cannon cannon(50.0f, 575.0f, 50.0f, 25.0f);
// Begin SFML rendering procedure
while(window.isOpen())
{
//Poll window
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
return 0;
default:
break;
}
}
// Monitor Keys
if (window.hasFocus())
HandleControls(level, cannon);
// Update World
float velocity;
if (level.GetVelocity(&velocity))
{
cannon.InitProjectile(velocity);
level.InitPositionStats(font);
}
// If projectile is spawned, update the trajectory and output position stats
if (CannonBall *projectile = cannon.projectile.get())
{
// If the projectile has collided, destroy all of its resources
// else show and update the position stats
if (projectile->UpdateTrajectory(level))
{
cannon.DestroyProjectile();
level.DestroyPositionStats();
level.DestroyVelocityBar();
}
else
{
level.UpdatePositionStats(projectile);
}
}
//Draw Screen
window.clear();
level.Render(window);
cannon.Render(window);
window.display();
}
return 0;
}