-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.cpp
More file actions
68 lines (60 loc) · 1.59 KB
/
Core.cpp
File metadata and controls
68 lines (60 loc) · 1.59 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
#include "Core.hpp"
#pragma comment (lib ,"imm32.lib")
#include <Windows.h>
namespace rpf {
Core* Core::CORE = nullptr;
int Core::highest_score = 0;
Core::Core() : mode(Mode::IN_GAME), rm(&window) {//mode(Mode::MAIN_MENU)
window.create(sf::VideoMode::VideoMode(rh.s_width, rh.s_height), "Ryan PlatFormer v1.0", sf::Style::Resize | sf::Style::Close);
window.setFramerateLimit(60);
window.setKeyRepeatEnabled(false);
ImmAssociateContext(window.getSystemHandle(), NULL);
now = nullptr;
rh.music.play();
Core::CORE = this;
}
void Core::Run() {
switchMode(Mode::IN_GAME);//start with ...
while (window.isOpen())
this->update();
}
void Core::update() {
sf::Event e;
while (window.pollEvent(e))
if (e.type == sf::Event::Closed)
window.close();
else if (e.type == sf::Event::Resized) {
float screenWidth = 160.f;
float screenHeight = 96.f;
sf::Vector2u size = window.getSize();
float heightRatio = screenHeight / screenWidth;
float widthRatio = screenWidth / screenHeight;
if (size.y * widthRatio <= size.x)
{
size.x = size.y * widthRatio;
}
else if (size.x * heightRatio <= size.y)
{
size.y = size.x * heightRatio;
}
window.setSize(size);
}
else
now->handleEvent(e);
now->update();
rm.Render();
}
void Core::switchMode(Mode mode) {
switch (mode) {
case Mode::IN_GAME:
now = new Game(&rm, &rh);
break;
case Mode::GAME_OVER:
now = new GameOverMenu(&rm, &rh);
break;
case Mode::CLOSED:
window.close();
break;
}
}
}