-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_object.cpp
66 lines (54 loc) · 1.6 KB
/
4_object.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
#include <game/window.h>
#include <game/scene.h>
#include <game/animation.h>
#include <game/object.h>
#include <game/state.h>
#include <game/camera.h>
#include <game/clock.h>
#include <game/image.h>
#include <game/sprite.h>
int PLANET_SPRITE = 1;
int PLANET_SPRITE_SPIN_CLIP = 1;
class Planet: public Object {
public:
Animation* animation;
Planet(Sprite* sprite) {
animation = new Animation(
sprite,
1
);
setSize(200, 200);
}
virtual void update(State* state) {
setPosition (state->camera->getWidth()/2 - getWidth()/2,
state->camera->getHeight()/2 - getHeight()/2);
animation->update(state->clock->delta);
}
virtual void render(State* state) {
animation->render(getPosition());
}
};
class MyScene : public Scene {
using Scene::Scene;
public:
virtual void prepare() {
// Define sprite
sprites[PLANET_SPRITE] = (new Sprite(
new Image(renderer, "doc/images/planet.png"),
100, // Frame width
100 // Frame height
))->addClip(
PLANET_SPRITE_SPIN_CLIP, // Clip index
1, // Start frame row in sprite sheet
1, // Start frame cell in sprite sheet
24 // Frame count to generate from row, cell starting position
);
// Create Planet object
addObject(new Planet(sprites[PLANET_SPRITE]));
}
};
int main(int argc, char** argv){
Window* window = new Window("Hello World", 800, 600);
window->setScene(new MyScene(window));
return window->run();
}