-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp.h
63 lines (49 loc) · 1.53 KB
/
main.cpp.h
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
#include <iostream>
#include "alien.h"
#include "ship.h"
#include "oncollide.h"
#include "bullet.h"
#define WIDTH 800
#define HEIGHT 600
#define ALIEN_NUM 7
using namespace std;
int main()
{
const float shipSpeed = 400.0f;
const int alienSpeedU = 1200;
const int alienSpeedL = 500;
const float bulletSpeed = 600.0f;
bool GameOver = false;
bool gameWin = false;
sf::RenderWindow mainwindow (sf::VideoMode(WIDTH, HEIGHT), "Space Invaders");
mainwindow.setVerticalSyncEnabled(true);
Bullet bullet(0,bulletSpeed); //is bulletID necessary ?
Ship player(shipSpeed);
player.position(WIDTH/2, HEIGHT - player.getSprite().getGlobalBounds().height/2);
Alien enemy[ALIEN_NUM];
for(int i=0; i<ALIEN_NUM; i++)
{
Alien singleEnemy(i , alienSpeedL + (rand()%alienSpeedU));
singleEnemy.position(i*100+50 , singleEnemy.getSprite().getGlobalBounds().height/2);
enemy[i] = singleEnemy;
}
sf::Clock mainClock, alienClock, bulletClock;
alienClock.restart().asSeconds();
bulletClock.restart().asSeconds();
while(mainwindow.isOpen())
{
float time = mainClock.restart().asSeconds();
sf::Event event;
while(mainwindow.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed :
mainwindow.close();
break;
case (sf::Event::KeyPressed && event.key.code == sf::Keyboard::A
}
}
}
return 0;
}