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 81 82 83 84 85 86 87 88 89
|
//Level.hpp
#ifndef LEVEL_HPP
#define LEVEL_HPP
#include <prg_interactive.hpp>
#include "../inc/rect.hpp"
using namespace prg;
class Level
{
public:
Level();
void Update();
void DrawLevel(Canvas& canvas);
private:
Rect square;
};
#endif // LEVEL_HPP
//level.cpp
#include "../inc/level.hpp"
Level::Level()
{
square = Rect(100,100,100,100);
}
void Level::Update()
{
}
void Level::DrawLevel(Canvas& canvas)
{
square.Draw(canvas);
}
//Rect.hpp
#ifndef RECT_HPP
#define RECT_HPP
#include "../inc/Vector3.hpp"
#include <prg_interactive.hpp>
using namespace prg;
struct Size
{
int width, height;
};
class Rect
{
public:
Rect();
void CreateSquare();
void Draw(Canvas& canvas);
private:
Vector3 location_;
Size size_;
Image square;
};
#endif // RECT_HPP
//rect.cpp
#include "../inc/rect.hpp"
Rect::Rect()
{
size_.width = width;
size_.height = height;
location_ = Vector3((double)x, (double)y);
CreateSquare();
}
void Rect::CreateSquare()
{
square = Image(size_.width, size_.height, Colour(255,0,255));
for (int y = 0; y < square.getHeight(); y++)
{
for (int x = 0; x < square.getWidth(); x++)
{
square.setPixel(x, y, Colour(0,255,0));
}
}
}
void Rect::Draw(Canvas& canvas)
{
canvas.blit(square, 0, 0, square.getWidth(), square.getHeight(), location_.getX(), location_.getY());
}
|