mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-07-09 21:22:02 +00:00
Sprite based graphics
This commit is contained in:
64
src/graphics/sprite.cpp
Normal file
64
src/graphics/sprite.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include "sprite.h"
|
||||
|
||||
Sprite::Sprite(int m_width, int m_height) {
|
||||
width = m_width;
|
||||
height = m_height;
|
||||
sprite = new bool*[width];
|
||||
for (int w = 0; w < width; w++) {
|
||||
sprite[w] = new bool[height];
|
||||
for (int h = 0; h < height; h++) {
|
||||
sprite[w][h] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::SetPixel(int x, int y, bool solid) {
|
||||
sprite[x][y] = solid;
|
||||
}
|
||||
|
||||
int Sprite::GetHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
int Sprite::GetWidth() {
|
||||
return width;
|
||||
|
||||
}
|
||||
|
||||
void Sprite::Draw(DaisyPatch patch, int x, int y) {
|
||||
for (int w = 0; w < width; w++) {
|
||||
for (int h = 0; h < height; h++) {
|
||||
patch.display.DrawPixel(x+w, y+h, sprite[w][h]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::DrawTile(DaisyPatch patch,
|
||||
int x1,
|
||||
int y1,
|
||||
int x2,
|
||||
int y2) {
|
||||
int x_min = std::min(x1, x2);
|
||||
int x_max = std::max(x1, x2);
|
||||
int y_min = std::min(y1, y2);
|
||||
int y_max = std::max(y1, y2);
|
||||
for (int w = x_min; w < x_max; w++) {
|
||||
for (int h = y_min; h < y_max; h++) {
|
||||
patch.display.DrawPixel(w, h, sprite[(w-x_min) % width]
|
||||
[(h-y_min) % height]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool** Sprite::GetSprite() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
void Sprite::SetBlank() {
|
||||
for (int w = 0; w < width; w++) {
|
||||
for (int h = 0; h < height; h++) {
|
||||
sprite[w][h] = false;
|
||||
}
|
||||
}
|
||||
}
|
25
src/graphics/sprite.h
Normal file
25
src/graphics/sprite.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef CASCADE_GRAPHICS_SPRITE_H_
|
||||
#define CASCADE_GRAPHICS_SPRITE_H_
|
||||
|
||||
#include "daisy_patch.h"
|
||||
|
||||
using namespace daisy;
|
||||
|
||||
class Sprite {
|
||||
private:
|
||||
int width, height;
|
||||
bool** sprite;
|
||||
public:
|
||||
Sprite(int, int);
|
||||
void SetPixel(int, int, bool);
|
||||
int GetHeight();
|
||||
int GetWidth();
|
||||
bool** GetSprite();
|
||||
void Draw(DaisyPatch, int, int);
|
||||
void DrawTile(DaisyPatch, int, int, int, int);
|
||||
void SetBlank();
|
||||
};
|
||||
|
||||
#endif // CASCADE_GRAPHICS_SPRITE_H_
|
Reference in New Issue
Block a user