foxygit / fake-08-xbox360 Log in
commit 3a7379b939f0d3313e751931b7a25831b03326cd
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Sat Apr 18 09:59:36 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Sat Apr 18 09:59:36 2020 -0600

    Implement basic sprite drawing
---
 source/console.cpp       |  3 ++-
 source/fakecart.cpp      |  2 ++
 source/graphics.cpp      | 13 ++++++++++++-
 source/graphics.h        |  6 ++++++
 source/picoglobalapi.cpp |  3 +++
 source/picoglobalapi.h   |  1 +
 6 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/source/console.cpp b/source/console.cpp
index 9dbeab1..13b7a18 100644
--- a/source/console.cpp
+++ b/source/console.cpp
@@ -27,7 +27,8 @@ void Console::LoadCart(std::string filename){
     Cart cart = Cart(filename);

     _loadedCart = &cart;
-
+
+    _graphics->setSpriteSheet(_loadedCart->SpriteSheetString);
 }

 void Console::FlipBuffer(uint8_t* fb){
diff --git a/source/fakecart.cpp b/source/fakecart.cpp
index b069b05..ff84b2a 100644
--- a/source/fakecart.cpp
+++ b/source/fakecart.cpp
@@ -51,6 +51,8 @@ void _draw() {
     circfill(100, 100, 15, 9);

     print("test str", 64, 64, 7);
+
+    spr(7, 40, 40, 1, 1, false, false);
 }

 void _update() {
diff --git a/source/graphics.cpp b/source/graphics.cpp
index aea2da8..8a0c7e4 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -51,10 +51,15 @@ void copy_data_to_sprites(uint8_t sprite_data[128 * 128], std::string data) {

 //call initialize to make sure defaults are correct
 Graphics::Graphics(std::string fontdata) {
-	Logger::Write("Copying data to spritesheet\n");
+	Logger::Write("Copying data to font spritesheet\n");
 	copy_data_to_sprites(fontSpriteData, fontdata);
 }

+void Graphics::setSpriteSheet(std::string spritesheetstring){
+	Logger::Write("Copying data to spritesheet\n");
+	copy_data_to_sprites(spriteSheetData, spritesheetstring);
+}
+
 //start helper methods
 //based on tac08 implementation of blitter()
 void Graphics::copySpriteToScreen(
@@ -267,6 +272,12 @@ short Graphics::print(std::string str, short x, short y, uint16_t c) {
 	return x;
 }

+void Graphics::spr(int n, int x, int y, int w, int h, bool flip_x, bool flip_y) {
+	int spr_x = (n % 16) * 8;
+	int spr_y = (n / 16) * 8;
+	copySpriteToScreen(spriteSheetData, x, y, spr_x, spr_y, w * 8, h * 8, flip_x, flip_y);
+}
+
 void Graphics::flipBuffer(uint8_t* fb) {
 	short x, y;
     for(x = 0; x < 400; x++) {
diff --git a/source/graphics.h b/source/graphics.h
index 1d63a49..3d54452 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -41,6 +41,7 @@ class Graphics {
 	uint8_t _pico8_fb[128*128];
 	GraphicsState* _graphicsState;
 	uint8_t fontSpriteData[128 * 128];
+	uint8_t spriteSheetData[128 * 128];

 	void copySpriteToScreen(
 		uint8_t spritebuffer[],
@@ -63,6 +64,9 @@ class Graphics {

 	public:
 	Graphics(std::string fontdata);
+
+	void setSpriteSheet(std::string spritesheetstring);
+
 	void cls();

 	void pset(short x, short y, uint8_t col);
@@ -79,8 +83,10 @@ class Graphics {
 	void rectfill(short x1, short y1, short x2, short y2, uint8_t col);

 	short print(std::string str, short x, short y, uint16_t c);
+	void spr(int n, int x, int y, int w, int h, bool flip_x, bool flip_y);

 	void flipBuffer(uint8_t* fb);

+
 };

diff --git a/source/picoglobalapi.cpp b/source/picoglobalapi.cpp
index 061931e..b232069 100644
--- a/source/picoglobalapi.cpp
+++ b/source/picoglobalapi.cpp
@@ -39,3 +39,6 @@ void rectfill(short x1, short y1, short x2, short y2, uint8_t col){
 short print(std::string str, short x, short y, uint16_t c){
     return _graphicsForApi->print(str, x, y, c);
 }
+void spr(int n, int x, int y, int w, int h, bool flip_x, bool flip_y) {
+    _graphicsForApi->spr(n, x, y, w, h, flip_x, flip_y);
+}
diff --git a/source/picoglobalapi.h b/source/picoglobalapi.h
index b2db7ff..1a192db 100644
--- a/source/picoglobalapi.h
+++ b/source/picoglobalapi.h
@@ -17,4 +17,5 @@ void circfill(short ox, short oy, short r, uint8_t col);
 void rect(short x1, short y1, short x2, short y2, uint8_t col);
 void rectfill(short x1, short y1, short x2, short y2, uint8_t col);
 short print(std::string str, short x, short y, uint16_t c);
+void spr(int n, int x, int y, int w, int h, bool flip_x, bool flip_y);