2020-02-15 20:01:48 +00:00
|
|
|
|
/*
|
|
|
|
|
Char graphics are how games on the C64 were made. You don't need to do it
|
|
|
|
|
this way, unless for fun. You can just make device context bigger than
|
2020-02-16 04:57:03 +00:00
|
|
|
|
the screen and scroll around.
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
2020-02-16 04:57:03 +00:00
|
|
|
|
See $LK,"::/Demo/Games/RawHide.CC"$ or $LK,"::/Demo/Games/BigGuns.CC"$.
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
|
|
The nice thing about character graphics are the animations.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
|
#define MAP_WIDTH (TEXT_COLS * 2)
|
|
|
|
|
#define MAP_HEIGHT (TEXT_ROWS * 2)
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
|
#define CH_WATER '^'
|
|
|
|
|
#define CH_LAND CH_SPACE
|
|
|
|
|
#define CH_TREE '*'
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
|
|
U16 map[MAP_HEIGHT][MAP_WIDTH];
|
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
|
I64 screen_pix_x, screen_pix_y;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
|
U0 DrawIt(CTask *task, CDC *)
|
2020-02-15 20:01:48 +00:00
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
U16 *ptr;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
I64 i, j, y = screen_pix_y >> 3;
|
|
|
|
|
|
|
|
|
|
gr.hide_col = gr.hide_row = TRUE;
|
|
|
|
|
gr.pan_text_x = 7 - screen_pix_x & 7;
|
|
|
|
|
gr.pan_text_y = 7 - screen_pix_y & 7;
|
|
|
|
|
for (i = 0; i < task->win_height; i++)
|
|
|
|
|
{
|
|
|
|
|
ptr = &map[y++][screen_pix_x >> 3];
|
|
|
|
|
for (j = 0; j < task->win_width; j++)
|
|
|
|
|
//By the time you clip to window and handle Fs->scroll_x, Fs->scroll_y,
|
|
|
|
|
//it is too much trouble to do raw access to gr.text_base like we do
|
|
|
|
|
//in $LK,"::/Demo/Games/Maze.CC"$.
|
|
|
|
|
TextChar(task, FALSE, j, i, *ptr++);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
|
U8 *old_font = text.font;
|
|
|
|
|
U64 waves[4] = {0x0011AA440011AA44, 0x0022558800225588, 0x0044AA110044AA11, 0x0088552200885522};
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
|
|
U0 AnimateEndCB()
|
|
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
|
text.font = old_font;
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Exit;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 AnimateTask(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
I64 i;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
U64 *font = MAlloc(256 * 8);
|
|
|
|
|
|
|
|
|
|
Fs->task_end_cb = &AnimateEndCB;
|
|
|
|
|
MemCopy(font, text.font, 256 * 8);
|
|
|
|
|
text.font = font;
|
|
|
|
|
font[CH_TREE] = 0x18187E7E3C3C18;
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
|
|
|
|
font[CH_WATER] = waves[i++ & 0x3];
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Sleep(200);
|
|
|
|
|
Refresh;
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 ScrollTaskX(I64 sign)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
I64 i;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
|
{
|
|
|
|
|
screen_pix_x = ClampI64(screen_pix_x + sign, 0, (MAP_WIDTH - TEXT_COLS + 1) * FONT_WIDTH);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Refresh;
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 ScrollTaskY(I64 sign)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
I64 i;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
|
{
|
|
|
|
|
screen_pix_y = ClampI64(screen_pix_y + sign, 0, (MAP_HEIGHT - TEXT_ROWS + 2) * FONT_HEIGHT);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Refresh;
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 Init()
|
|
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
|
I64 i, j, x, y;
|
|
|
|
|
|
|
|
|
|
screen_pix_x = (MAP_WIDTH - TEXT_COLS) >> 1 * FONT_WIDTH;
|
|
|
|
|
screen_pix_y = (MAP_HEIGHT - TEXT_ROWS) >> 1 * FONT_HEIGHT;
|
|
|
|
|
|
|
|
|
|
MemSetU16(map, CH_WATER + (BLUE << 4 + LTBLUE) << 8, MAP_WIDTH * MAP_HEIGHT);
|
|
|
|
|
for (i = 1; i < MAP_WIDTH - 1; i++)
|
|
|
|
|
map[0][i] = map[MAP_HEIGHT - 1][i] = '<EFBFBD>' + (BLUE << 4 + RED) << 8;
|
|
|
|
|
for (i = 1; i < MAP_HEIGHT - 1; i++)
|
|
|
|
|
map[i][0] = map[i][MAP_WIDTH - 1] = '<EFBFBD>' + (BLUE << 4 + RED) << 8;
|
|
|
|
|
|
|
|
|
|
map[0][0] = '<EFBFBD>' + (BLUE << 4 + RED) << 8;
|
|
|
|
|
map[0][MAP_WIDTH - 1] = '<EFBFBD>' + (BLUE << 4 + RED) << 8;
|
|
|
|
|
map[MAP_HEIGHT - 1][0] = '<EFBFBD>' + (BLUE << 4 + RED) << 8;
|
|
|
|
|
map[MAP_HEIGHT - 1][MAP_WIDTH - 1] = '<EFBFBD>' + (BLUE << 4 + RED) << 8;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
|
{
|
|
|
|
|
x = MAP_WIDTH * Rand;
|
|
|
|
|
y = MAP_HEIGHT * Rand;
|
|
|
|
|
for (j = 0; j < 1000; j++)
|
|
|
|
|
{
|
|
|
|
|
map[y][x] = CH_LAND + (YELLOW << 4 + BLACK) << 8;
|
|
|
|
|
x = ClampI64(x + RandU16 % 3 - 1, 0, MAP_WIDTH - 1);
|
|
|
|
|
y = ClampI64(y + RandU16 % 3 - 1, 0, MAP_HEIGHT - 1);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-23 23:27:18 +00:00
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
x = MAP_WIDTH * Rand;
|
|
|
|
|
y = MAP_HEIGHT * Rand;
|
|
|
|
|
}
|
|
|
|
|
while (map[y][x].u8[0] != CH_LAND);
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < 100; j++)
|
|
|
|
|
{
|
|
|
|
|
map[y][x] = CH_TREE + (YELLOW << 4 + GREEN) << 8;
|
|
|
|
|
x = ClampI64(x + RandU16 % 3 - 1, 0, MAP_WIDTH - 1);
|
|
|
|
|
y = ClampI64(y + RandU16 % 3 - 1, 0, MAP_HEIGHT - 1);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CleanUp()
|
|
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
|
gr.pan_text_x = gr.pan_text_y = 0;
|
|
|
|
|
gr.hide_col = gr.hide_row = FALSE;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CharDemo()
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
I64 sc;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
2020-12-23 23:27:18 +00:00
|
|
|
|
Fs->text_attr = YELLOW << 4 + BLUE;
|
2020-02-20 23:40:10 +00:00
|
|
|
|
AutoComplete;
|
|
|
|
|
WinBorder;
|
|
|
|
|
WinMax;
|
|
|
|
|
DocCursor;
|
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
|
MenuPush( "File {"
|
2020-02-20 23:40:10 +00:00
|
|
|
|
" Abort(,CH_SHIFT_ESC);"
|
|
|
|
|
" Exit(,CH_ESC);"
|
|
|
|
|
"}"
|
|
|
|
|
"Play {"
|
|
|
|
|
" Restart(,'\n');"
|
|
|
|
|
" Left(,,SC_CURSOR_LEFT);"
|
|
|
|
|
" Right(,,SC_CURSOR_RIGHT);"
|
|
|
|
|
" Up(,,SC_CURSOR_UP);"
|
|
|
|
|
" Down(,,SC_CURSOR_DOWN);"
|
|
|
|
|
"}"
|
|
|
|
|
);
|
|
|
|
|
Init;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
Fs->animate_task = Spawn(&AnimateTask, NULL, "Animate",, Fs);
|
|
|
|
|
Fs->draw_it = &DrawIt;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
|
|
|
|
switch (KeyGet(&sc))
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
case 0:
|
2020-12-23 23:27:18 +00:00
|
|
|
|
switch (sc.u8[0])
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
case SC_CURSOR_LEFT:
|
2020-12-23 23:27:18 +00:00
|
|
|
|
Spawn(&ScrollTaskX, -1, "Scroll",, Fs);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
break;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
case SC_CURSOR_RIGHT:
|
2020-12-23 23:27:18 +00:00
|
|
|
|
Spawn(&ScrollTaskX, 1, "Scroll",, Fs);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
break;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
case SC_CURSOR_UP:
|
2020-12-23 23:27:18 +00:00
|
|
|
|
Spawn(&ScrollTaskY, -1, "Scroll",, Fs);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
break;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
case SC_CURSOR_DOWN:
|
2020-12-23 23:27:18 +00:00
|
|
|
|
Spawn(&ScrollTaskY, 1, "Scroll",, Fs);
|
2020-02-20 23:40:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
case '\n':
|
|
|
|
|
CleanUp;
|
|
|
|
|
Init;
|
|
|
|
|
break;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
case CH_SHIFT_ESC:
|
|
|
|
|
case CH_ESC:
|
|
|
|
|
goto sq_done;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
sq_done: //Don't goto out of try
|
2020-12-23 23:27:18 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
2020-02-20 23:40:10 +00:00
|
|
|
|
PutExcept;
|
|
|
|
|
SettingsPop;
|
|
|
|
|
CleanUp;
|
|
|
|
|
MenuPop;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CharDemo;
|