-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawable.h
57 lines (47 loc) · 1.96 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
#ifndef DRAWABLE__H
#define DRAWABLE__H
#include <SDL.h>
#include <iostream>
#include <string>
#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): name(n), position(pos), velocity(vel) {}
Drawable(const Drawable& s) : name(s.name), position(s.position), velocity(s.velocity) {}
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; }
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 checkForCollisions(Drawable* ) { throw std::string("Collision check not implemented"); }
virtual void AvoidCollision() { throw std::string("Avoid collision not implemented"); }
virtual void explode() { throw std::string("explosion not implemented"); }
virtual void projectileHit(){}
virtual unsigned getCurrentFrame() const { return 0;}
virtual void setCurrentFrame(unsigned ) { }
virtual bool isExplosion() const { throw std::string("explosion not implemented"); };
private:
std::string name;
Vector2f position;
Vector2f velocity;
};
int getRandom(int, int);
float getRandFloat(float, float);
#endif