add basic character movement

This commit is contained in:
2025-02-28 21:28:00 -05:00
parent d3975abc2b
commit 67b83b9115
3 changed files with 38 additions and 13 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

+38 -13
View File
@@ -5,13 +5,15 @@ using namespace std;
int main() { int main() {
terminal_open(); terminal_open();
terminal_set("window: size=40x20, title='Terminal Trainers'"); terminal_set("window: size=225x65, title='Terminal Trainers'");
int x = 10;
int y = 10;
int mapHeight = 20;
int mapLength = 40; int x = 20;
int y = 20;
int mapHeight = 100;
int mapLength = 100;
int mapSize = mapHeight * mapLength; int mapSize = mapHeight * mapLength;
char map[mapSize + mapHeight]; char map[mapSize + mapHeight];
@@ -39,21 +41,44 @@ int main() {
bool running = true; bool running = true;
terminal_refresh();
terminal_set("0xE000: characters.png, size=16x16, spacing=0x0, resize=32x32, transparent=#EBEBEB");
terminal_put(x, y, 0xE001);
while (running) { while (running) {
terminal_refresh();
terminal_clear(); terminal_clear();
terminal_print_ext(0, 0, 40, 20, TK_ALIGN_LEFT, map);
terminal_put(x, y, 0x20AC);
terminal_refresh(); //terminal_print_ext(0, 0, mapLength, mapHeight, TK_ALIGN_LEFT, map);
// terminal_put(x, y, 0x20AC);
//terminal_put(x, y, 0xE000);
int key = terminal_read(); int key = terminal_read();
if (key == TK_ESCAPE) running = false; if (key == TK_ESCAPE) {
else if (key == TK_UP || key == TK_W) y--; running = false;
else if (key == TK_DOWN || key == TK_S) y++; }else if (key == TK_UP || key == TK_W) {
else if (key == TK_LEFT || key == TK_A) x--; y--;
else if (key == TK_RIGHT || key == TK_D) x++;
terminal_put(x, y, 0xE001);
terminal_refresh();
}else if (key == TK_DOWN || key == TK_S) {
y++;
terminal_put(x, y, 0xE000);
terminal_refresh();
}else if (key == TK_LEFT || key == TK_A) {
x--;
terminal_put(x, y, 0xE002);
}else if (key == TK_RIGHT || key == TK_D) {
x++;
terminal_put(x, y, 0xE002);
}
} }
terminal_close(); terminal_close();