-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (72 loc) · 2.14 KB
/
main.cpp
File metadata and controls
79 lines (72 loc) · 2.14 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
#include<SFML/System.hpp>
#include<SFML/Graphics.hpp>
#include"spelare.hpp"
#ifndef NAMESPACE_SF
#define NAMESPACE_SF
using namespace sf;
#endif
#ifndef NAMESPACE_STD
#define NAMESPACE_STD
using namespace std;
#endif
int main()
{
int WIDTH=300;
int HEIGHT=300;
double player1shoottimer;
bool Player1ShoottimerReady = true;
RenderWindow App(VideoMode(WIDTH, HEIGHT, 32),"Test");
Spelare spelare1(1, "Albin", WIDTH, HEIGHT);
Spelare spelare2(2, "David", WIDTH, HEIGHT);
Clock clock;
Time ElapsedTime;
Event event;
while(App.isOpen()){
while(App.pollEvent(event)){
if(event.type==Event::Closed){
App.close();
}
if(Keyboard::isKeyPressed(Keyboard::Escape)){
App.close();
}
}
ElapsedTime=clock.getElapsedTime();
clock.restart();
if(Keyboard::isKeyPressed(Keyboard::P)){
spelare2.move(up, ElapsedTime);
}
if(Keyboard::isKeyPressed(Keyboard::L)){
spelare2.move(down, ElapsedTime);
}
if(Keyboard::isKeyPressed(Keyboard::W)){
spelare1.move(up, ElapsedTime);
}
if(Keyboard::isKeyPressed(Keyboard::D)){
spelare1.move(down, ElapsedTime);
}
if(Keyboard::isKeyPressed(Keyboard::K)){
spelare2.shoot();
}
if(Keyboard::isKeyPressed(Keyboard::Space) && Player1ShoottimerReady){
spelare1.shoot();
Player1ShoottimerReady = false;
}
if(!Player1ShoottimerReady){
player1shoottimer += ElapsedTime.asSeconds();
if(player1shoottimer >= 0.1){
Player1ShoottimerReady = true;
player1shoottimer =0;
}
}
spelare1.repair(ElapsedTime);
spelare2.repair(ElapsedTime);
spelare1.bulletCollision(spelare2);
spelare2.bulletCollision(spelare1);
spelare1.flyingBullets(ElapsedTime);
spelare2.flyingBullets(ElapsedTime);
App.clear(Color::White);
spelare1.draw(App);
spelare2.draw(App);
App.display();
}
}