[ascii] letters!

This commit is contained in:
2021-04-25 01:39:40 -06:00
parent 1f57aab3b2
commit 5e16fd84f4
8 changed files with 54 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -6,4 +6,5 @@
(defmethod :Void draw [:Void->Graphics graphics]
(when firstDraw
(set firstDraw false)
(.setBackgroundColor (graphics) 5 5 Colors.White)))
(.setBackgroundColor (graphics) 5 5 Colors.White)
(.setLetter (graphics) 10 5 (object char "@" color Colors.Red))))

View File

@@ -3,6 +3,7 @@ package;
import flixel.FlxState;
import asciilib.Game;
import asciilib.backends.flixel.*;
import flixel.graphics.FlxGraphic;
class PlayState extends FlxState
{
@@ -11,7 +12,9 @@ class PlayState extends FlxState
override public function create()
{
super.create();
game = new Game("Beware Yon Death Trap", 40, 24, 8, 12, new DeathTrapLogic(), new FlxGraphicsBackend(this));
game = new Game("Beware Yon Death Trap", 40, 24, 8, 12, new DeathTrapLogic(),
new FlxGraphicsBackend(this, FlxGraphic.fromAssetKey("assets/images/size12.png"),
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.;:/?!@#$%^&*()-_=+[]{}~ÁÉÍÑÓÚÜáéíñóúü¡¿0123456789\"'<>|"));
}
override public function update(elapsed:Float)

View File

@@ -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))

View File

@@ -5,3 +5,9 @@
(defmethod getChar [x y]
(.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}")))

View File

@@ -15,3 +15,7 @@
(defmethod getLetter [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))

View File

@@ -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 {}

View File

@@ -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))