Original link: https://blog.codingnow.com/2022/05/roguelike_lua.html
I love RogueLike games, I mean literally Rogue -like games. In this kind of game, the screen is the least important part, as long as it can clearly express the interactive meaning required by the game.
I have a special hobby for game interfaces that are pieced together with characters. When I was a child, I started making games in text mode. Today, if you just want to verify the prototype of a game, a Rogue style, text mode interactive interface, it may be the easiest. Because you don’t have to deliberately prepare art materials, consider how these materials work with the code, and formulate complicated workflows. Creating a little interesting ascii art for a game not only doesn’t take too long, it may be a fun tweak in the coding process.
When working on an experimental module in a project some time ago, I tried to make a simple Lua library to help me build interactions with text mode. Recently, I encountered a more complex requirement and evaluated it. It may be more convenient to build a more complete RogueLike library based on SDL2 once and for all.
So last week I spent two days doing something like this: https://github.com/cloudwu/rogue .
Its core is a text mode sprite. Supports piecing together Sprites with the CP437 character set under IBM Dos and a subset of Simplified Chinese in Unicode, of course the interface uses the modern UTF-8 standard. Can support 256 layers, and the color described by RGB (instead of the traditional 16-color palette in text mode).
The support of Chinese characters is a little tricky. Each slot in the internal virtual text frame buffer stores the complete Unicode code point and whether it belongs to the left or right half of the Chinese character. In this way, there will be no problem of garbled characters in the lower half of the text mode in the past.
The sprite adopts the retained mode, that is, as long as the sprite is created, it will always be on the internal linked list and will be drawn every frame. This is different from many traditional similar libraries. The traditional method is generally immediate mode, that is, you need to draw a specific sprite for each frame, and it will not be displayed if you don’t call draw.
I’ve thought about some kind of blending mode that differentiates between map and sprite. Maps use retained mode, and characters use immediate mode. But I think it will increase the interface complexity. This is enough for now.
While writing this toy, I am reminded from time to time of those little games I played on Apple ][ in middle school. From that time on, I gradually realized that it is necessary to extract the common requirements in the program and make them into common modules; the game program is a designed state machine; the data should be separated from the program; the design of the data structure is the most important part of programming. Important link; tools should be written for organizing data…
What a wonderful development experience.
This article is reprinted from: https://blog.codingnow.com/2022/05/roguelike_lua.html
This site is for inclusion only, and the copyright belongs to the original author.