-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrawable.h
More file actions
80 lines (56 loc) · 2.08 KB
/
drawable.h
File metadata and controls
80 lines (56 loc) · 2.08 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
#ifndef DRAWABLE__H
#define DRAWABLE__H
#include <SDL.h>
#include <iostream>
#include <string>
#include "vector2f.h"
#include "frame.h"
#include <algorithm>
// Drawable is an Abstract Base Class (ABC) that
// specifies the methods that derived classes may
// and must have.
class Drawable {
public:
Drawable(const std::string& n, const Vector2f& pos, const Vector2f& vel, const double &ag, const double &inc,const int& dep):
name(n), position(pos), velocity(vel), angle(ag), angleinc(inc),depth(dep) {}
Drawable(const Drawable& s) :
name(s.name),position(s.position), velocity(s.velocity), angle(s.angle),angleinc(s.angleinc),depth(s.depth)
{ }
virtual ~Drawable() {}
const std::string& getName() const { return name; }
void setName(const std::string& n) { name = n; }
virtual const Frame* getFrame() const = 0;
virtual void draw() const = 0;
virtual void update(Uint32 ticks) = 0;
float X() const { return position[0]; }
void X(float x) { position[0] = x; }
float Y() const { return position[1]; }
void Y(float y) { position[1] = y; }
float velocityX() const { return velocity[0]; }
void velocityX(float vx) { velocity[0] = vx; }
float velocityY() const { return velocity[1]; }
void velocityY(float vy) { velocity[1] = vy; }
double getAngle() const {return angle;}
void setAngle(const double& ag) { angle = ag; }
double getAngleInc() const {return angleinc;}
void setAngleInc(const double& aginc) { angleinc = aginc; }
const Vector2f& getVelocity() const { return velocity; }
void setVelocity(const Vector2f& vel) { velocity = vel; }
const Vector2f& getPosition() const { return position; }
void setPosition(const Vector2f& pos) { position = pos; }
virtual bool collidedWith(const Drawable*) const {
throw std::string("No collidedWith");
}
const int& getDepth() const { return depth; }
bool operator<(const Drawable& d) const {
return getDepth() < d.getDepth();
}
private:
std::string name;
Vector2f position;
Vector2f velocity;
double angle;
double angleinc;
int depth;
};
#endif