[ascii] letters!
This commit is contained in:
@@ -34,4 +34,7 @@
|
||||
(and (= c1.r c2.r) (= c1.g c2.g) (= c1.b c2.b)))
|
||||
|
||||
(defvar Black (object r 0 g 0 b 0))
|
||||
(defvar Red (object r 255 g 0 b 0))
|
||||
(defvar Green (object r 0 g 255 b 0))
|
||||
(defvar Blue (object r 0 g 0 b 255))
|
||||
(defvar White (object r 255 g 255 b 255))
|
@@ -4,4 +4,10 @@
|
||||
:Array<String> rows (for _ (range height) (* (or letter " ") width))])
|
||||
|
||||
(defmethod getChar [x y]
|
||||
(.charAt (nth rows y) x))
|
||||
(.charAt (nth rows y) x))
|
||||
|
||||
(defmethod setChar [x y char]
|
||||
(let [row (nth rows y)
|
||||
left (row.substr 0 x)
|
||||
right (row.substr (+ x 1))]
|
||||
(setNth rows y "${left}${char}${right}")))
|
@@ -14,4 +14,8 @@
|
||||
(backgroundColors.setPixel x y color))
|
||||
|
||||
(defmethod getLetter [x y]
|
||||
(object char (letters.getChar x y) color (letterColors.getPixel x y)))
|
||||
(object char (letters.getChar x y) color (letterColors.getPixel x y)))
|
||||
|
||||
(defmethod setLetter [x y letter]
|
||||
(letters.setChar x y letter.char)
|
||||
(letterColors.setPixel x y letter.color))
|
@@ -6,6 +6,11 @@ import flixel.FlxState;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.system.FlxAssets;
|
||||
import flixel.graphics.frames.FlxBitmapFont;
|
||||
import flixel.math.FlxRect;
|
||||
import flixel.math.FlxPoint;
|
||||
import flixel.text.FlxBitmapText;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class FlxGraphicsBackend implements GraphicsBackend {}
|
||||
|
@@ -1,20 +1,43 @@
|
||||
(defprop &mut :FlxGroup backgroundColors null)
|
||||
(defprop &mut :FlxGroup letters null)
|
||||
(defprop &mut :Int letterWidth 0)
|
||||
(defprop &mut :Int letterHeight 0)
|
||||
(defnew [_state]
|
||||
[:FlxState state _state])
|
||||
(defprop &mut :FlxBitmapFont font null)
|
||||
|
||||
(defnew [_state
|
||||
_fontAsset
|
||||
&opt _letters _region _spacing]
|
||||
[:FlxState state _state
|
||||
:FlxBitmapFontGraphicAsset fontAsset _fontAsset
|
||||
:String fontLetters _letters
|
||||
:FlxRect region _region
|
||||
:FlxPoint spacing _spacing])
|
||||
|
||||
(defmethod :Void initialize [:String title :Int width :Int height :Int _letterWidth :Int _letterHeight]
|
||||
(set letterWidth _letterWidth)
|
||||
(set letterHeight _letterHeight))
|
||||
(set letterHeight _letterHeight)
|
||||
(set font (FlxBitmapFont.fromMonospace fontAsset fontLetters (new FlxPoint letterWidth letterHeight) region spacing)))
|
||||
|
||||
(defmethod :Void draw [:Graphics graphics]
|
||||
(when backgroundColors (backgroundColors.kill))
|
||||
(set backgroundColors (new FlxGroup))
|
||||
(when letters (letters.kill))
|
||||
(set letters (new FlxGroup))
|
||||
(for x (range graphics.width)
|
||||
(for y (range graphics.height)
|
||||
(let [bgc (graphics.getBackgroundColor x y)]
|
||||
(unless (Colors.equal bgc Colors.Black)
|
||||
(let [sprite (new FlxSprite (* letterWidth x) (* letterHeight y))]
|
||||
(backgroundColors.add (sprite.makeGraphic letterWidth letterHeight (FlxColor.fromRGB bgc.r bgc.g bgc.b))))))))
|
||||
(state.add backgroundColors))
|
||||
(backgroundColors.add (sprite.makeGraphic letterWidth letterHeight (FlxColor.fromRGB bgc.r bgc.g bgc.b))))))
|
||||
(let [letter (graphics.getLetter x y)]
|
||||
(unless (= letter.char " ")
|
||||
(let [color letter.color
|
||||
text (new FlxBitmapText font)]
|
||||
(set text.text letter.char)
|
||||
(set text.x (* letterWidth x))
|
||||
(set text.y (* letterHeight y))
|
||||
(set text.useTextColor true)
|
||||
(set text.textColor (FlxColor.fromRGB color.r color.g color.b))
|
||||
(letters.add text))))))
|
||||
(state.add backgroundColors)
|
||||
(state.add letters))
|
Reference in New Issue
Block a user