-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrawable.h
73 lines (57 loc) · 1.98 KB
/
drawable.h
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
#ifndef DRAWABLE__H
#define DRAWABLE__H
#include <SDL.h>
#include <iostream>
#include <string>
#include <limits>
#include "vector2f.h"
#include "frame.h"
// 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 float sc):
name(n), position(pos), velocity(vel), scale( sc ) {}
Drawable(const Drawable& s) :
name(s.name), position(s.position), velocity(s.velocity), scale(s.scale)
{ }
virtual ~Drawable() {}
bool operator>(const Drawable& rhs) const {
return scale > rhs.scale;
}
bool operator<(const Drawable& rhs) const {
return scale < rhs.scale;
}
virtual unsigned getPixel(Uint32, Uint32) const = 0;
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; }
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; }
float getScale() const { return scale; }
protected:
std::string name;
Vector2f position;
Vector2f velocity;
float scale;
float getRand(int min, int max) {
return min + (rand() / (std::numeric_limits<int>::max()+1.0f))*(max-min);
}
float getRand(float min, float max) {
return min + (rand() / (std::numeric_limits<int>::max()+1.0f))*(max-min);
}
};
#endif