-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.h
More file actions
69 lines (49 loc) · 1.67 KB
/
GameObject.h
File metadata and controls
69 lines (49 loc) · 1.67 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
#pragma once
#include "SDLGame.h"
#include "Vector2D.h"
#include "Observer.h"
#include "InputHandler.h"
class GameObject : public Observer {
public:
GameObject();
GameObject(SDLGame* game);
virtual ~GameObject();
SDLGame* getGame() const;
void setGame(SDLGame* game);
bool isActive() const;
void setActive(bool active);
bool toggleActive();
double getWidth() const;
void setWidth(double width);
double getHeight() const;
void setHeight(double height);
void scale(double s);
Vector2D getPosition() const;
void setPosition(const Vector2D &pos);
Vector2D getVelocity() const;
void setVelocity(const Vector2D &vel);
Vector2D getAcceleration() const;
void setAcceleration(const Vector2D &vel);
double getRotation() const;
void setRotation(double angle);
virtual void receive(const void* senderObj, const msg::Message& msg);
// some GameObjects cannot be initialized in the constructor,
// for example when we create them using the default constructor
// and without passing the game. This method is supposed to
// be called once they are ready to be initialized. The
// default implementation does nothing.
virtual void init();
// abstract methods to be implemented in sub-classes
virtual void handleInput(Uint32 time) = 0;
virtual void update(Uint32 time) = 0;
virtual void render(Uint32 time) = 0;
protected:
SDLGame* game_; // pointer to the game
bool active_; // indicates if the object is active
double width_; // width
double height_; // height
Vector2D position_; // position (suppose to be left-top corner)
Vector2D velocity_; // velocity
Vector2D acceleration_; // acceleration
double rotation_; // rotation (for the corresponding texture)
};