-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathExample09.cpp
More file actions
117 lines (117 loc) · 2.55 KB
/
Example09.cpp
File metadata and controls
117 lines (117 loc) · 2.55 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
//#include<iostream>
//#include"SFML\Graphics.hpp"
//#include"SFML\Window.hpp"
//#include"SFML\System.hpp"
//#include<cstdlib>
//
//using namespace sf;
//
//int main()
//{
// srand(time(NULL));
//
// sf::RenderWindow window(VideoMode(640, 480), "Cat do(d)ge");
// window.setFramerateLimit(60);
//
// //Cat
// Texture catTex;
// Sprite cat;
//
// if (!catTex.loadFromFile("Textures/cat.png"))
// throw "Could not load cat.png!";
//
// cat.setTexture(catTex);
// cat.setScale(Vector2f(0.2f, 0.2f));
// int catSpawnTimer = 15;
//
// std::vector<Sprite> cats;
// cats.push_back(Sprite(cat));
//
// //Doge
// Texture dogeTex;
// Sprite doge;
// int hp = 10;
// RectangleShape hpBar;
// hpBar.setFillColor(Color::Red);
// hpBar.setSize(Vector2f((float)hp * 20.f, 20.f));
// hpBar.setPosition(200.f, 10.f);
//
// if(!dogeTex.loadFromFile("Textures/doge.png"))
// throw "Could not load doge.png!";
//
// doge.setTexture(dogeTex);
// doge.setScale(Vector2f(0.3f, 0.3f));
//
// //GAME LOOP
// while (window.isOpen() && hp > 0)
// {
// 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();
// }
//
// //UPDATE
// //DOGE(PLAYER)
// doge.setPosition(doge.getPosition().x, Mouse::getPosition(window).y);
//
// if (doge.getPosition().y > window.getSize().y - doge.getGlobalBounds().height)
// doge.setPosition(doge.getPosition().x, window.getSize().y - doge.getGlobalBounds().height);
//
// if (doge.getPosition().y < 0)
// doge.setPosition(doge.getPosition().x, 0);
//
// //CATS(ENEMIES)
// for (size_t i = 0; i < cats.size(); i++)
// {
// cats[i].move(-7.f, 0.f);
//
// if (cats[i].getPosition().x < 0 - cat.getGlobalBounds().width)
// cats.erase(cats.begin() + i);
// }
//
// if (catSpawnTimer < 40)
// catSpawnTimer++;
//
// if (catSpawnTimer >= 40)
// {
// cat.setPosition(window.getSize().x, rand()%int(window.getSize().y - cat.getGlobalBounds().height));
// cats.push_back(Sprite(cat));
// catSpawnTimer = 0;
// }
//
// //COLLISION
// for (size_t i = 0; i < cats.size(); i++)
// {
// if (doge.getGlobalBounds().intersects(cats[i].getGlobalBounds()))
// {
// hp--;
// cats.erase(cats.begin() + i);
// }
// }
//
// //UI
// hpBar.setSize(Vector2f((float)hp * 20.f, 20.f));
//
// //DRAW
// window.clear();
//
// window.draw(doge);
//
// for (size_t i = 0; i < cats.size(); i++)
// {
// window.draw(cats[i]);
// }
//
// //UI
// window.draw(hpBar);
//
// window.display();
// }
//
// return 0;
//}