-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·175 lines (155 loc) · 3.84 KB
/
main.cpp
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include <stdexcept>
#include <SDL.h>
#include "Sirius/Sirius.h"
class GameObject2: public Sirius::Entity
{
float x,y;
float dx, dy;
public:
GameObject2(float px, float py, float _dx, float _dy)
{
x = px;
y = py;
dx = _dx;
dy = _dy;
}
void begin()
{
graphic = Sirius::Image::Create(resources->getTexture("smiley2"));
position.x = (int)x;
position.y = (int)y;
}
void end()
{
}
void update(float delta)
{
x += delta*dx;
y += delta*dy;
position.x = (int)x;
position.y = (int)y;
if(x >= renderer->getWidth() / 2)
{
x = 0;
y = 0;
game->switchScene("level1");
}
}
};
class GameObject: public Sirius::Entity
{
float x,y;
float dx, dy;
public:
GameObject(float px, float py, float _dx, float _dy)
{
x = px;
y = py;
dx = _dx;
dy = _dy;
}
void begin()
{
graphic = Sirius::Image::Create(resources->getTexture("smiley1"));
position.x = (int)x;
position.y = (int)y;
}
void end()
{
}
void update(float delta)
{
x += delta*dx;
y += delta*dy;
position.x = (int)x;
position.y = (int)y;
if(x >= renderer->getHeight())
{
x = 0;
y = 0;
game->switchScene("level2");
}
}
};
class GameScene2: public Sirius::Scene
{
int fps;
float time;
public:
GameScene2(){ fps = 0; time = 0.0f;}
void begin()
{
renderer->setScaleFilter(Sirius::ScaleFilter::Linear);
renderer->setLogicalSize(1024,600);
resources->addTexture("smiley2","smiley2.bmp");
addEntity("object", Sirius::Entity::Create(std::make_shared<GameObject2>(0.0f,0.0f,50.0f,50.0f)));
renderer->setBackgroundColor(0,0,0);
}
void update(float delta)
{
fps += 1;
time += delta;
if(time > 1.0f)
{
//std::cout << "Scene2 FPS : " << fps << std::endl;
fps = 0;
time = 0.0f;
}
}
void end()
{
removeAllEntities();
resources->clear();
}
};
class GameScene: public Sirius::Scene
{
int fps;
float time;
public:
GameScene(){ fps = 0; time = 0.0f;}
void begin()
{
renderer->setScaleFilter(Sirius::ScaleFilter::Linear);
renderer->setLogicalSize(512,300);
resources->addTexture("smiley1","smiley.bmp");
addEntity("object", Sirius::Entity::Create(std::make_shared<GameObject>(0.0f,0.0f,100.0f,80.0f)));
renderer->setBackgroundColor(255,255,255);
}
void update(float delta)
{
fps += 1;
time += delta;
if(time > 1.0f)
{
//std::cout << "Scene1 FPS : " << fps << std::endl;
fps = 0;
time = 0.0f;
}
}
void end()
{
removeAllEntities();
resources->clear();
}
};
int main(int argc, char **argv)
{
try
{
Sirius::GamePtr game = Sirius::Game::initialize(1024,600);
Sirius::ScenePtr scene = Sirius::Scene::Create<GameScene>();
Sirius::ScenePtr scene2 = Sirius::Scene::Create<GameScene2>();
game->addScene("level1",scene);
game->addScene("level2",scene2);
game->run("level1");
game->removeAllScenes();
Sirius::Game::terminate();
}
catch(std::runtime_error e)
{
Sirius::Utility::Log::Error(e.what());
}
return 0;
}