Explorar o código

Yeah, Text routines

Florian DORMONT %!s(int64=10) %!d(string=hai) anos
pai
achega
6818a2071f
Modificáronse 4 ficheiros con 48 adicións e 1 borrados
  1. BIN=BIN
      art/font.png
  2. 15 0
      include/Text.h
  3. 29 0
      src/Text.cpp
  4. 4 1
      src/main.cpp

BIN=BIN
art/font.png


+ 15 - 0
include/Text.h

@@ -0,0 +1,15 @@
+#ifndef INCLUDE_TEXT_H
+#define INCLUDE_TEXT_H
+
+#include <string>
+
+namespace WalrusRPG { namespace Graphics { namespace Text {
+
+void print_char(char c, unsigned x, unsigned y);
+
+void print_string(const char *str, unsigned x, unsigned y);
+
+}}}
+
+
+#endif

+ 29 - 0
src/Text.cpp

@@ -0,0 +1,29 @@
+#include "sprites.h"
+#include "Graphics.h"
+#include "Text.h"
+#include <string>
+
+#define TEXT WalrusRPG::Graphics::Text
+#define GRAPHICS WalrusRPG::Graphics
+
+void TEXT::print_char(char c, unsigned x, unsigned y) {
+  GRAPHICS::Rect_t rect;
+  rect.w = 8;
+  rect.h = 8;
+  rect.x = (c%16)*8;
+  rect.y = (c/16)*8;
+  draw_sprite_sheet(font, x, y, &rect);
+}
+
+void TEXT::print_string(const char *str, unsigned x, unsigned y) {
+  GRAPHICS::Rect_t rect;
+  rect.w = 8;
+  rect.h = 8;
+  for(unsigned index = 0; str[index]; index++) {
+    char c = str[index];
+    rect.x = (c%16)*8;
+    rect.y = (c/16)*8;
+    draw_sprite_sheet(font, x, y, &rect);
+    x +=8;
+  }
+}

+ 4 - 1
src/main.cpp

@@ -4,10 +4,12 @@
 #include "Pixel.h"
 #include "Map.h"
 #include "Camera.h"
+#include "Text.h"
 #include "misc.h"
 
 using namespace WalrusRPG;
 using namespace WalrusRPG::Graphics;
+using namespace WalrusRPG::Graphics::Text;
 
 void map_loop(unsigned x, unsigned y, Map &map)
 {
@@ -31,7 +33,8 @@ void map_loop(unsigned x, unsigned y, Map &map)
 			Pixel pix(Green);
 			// TODO?: Preset color macros/consts?
 			buffer_fill(pix);
-			map.render(camera, 1);
+			map.render(camera, loop_next);
+			print_string("WalrusRPG test build \001", 0, 0);
 			lcd_vsync();
 			buffer_swap();
 		}