Skip to content

Commit c1bc781

Browse files
committed
Other: 'Breakout' logo tweaks.
1 parent 7e92c0e commit c1bc781

File tree

3 files changed

+86
-62
lines changed

3 files changed

+86
-62
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,4 @@ Experiments/TheMatrix/matrix
408408
Experiments/Sand/sand
409409
Experiments/Twister/twister
410410
Experiments/BreakOut/breakout
411+
*.bin

Experiments/BreakOut/breakout.c

Lines changed: 85 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,117 @@
11
// zcc +zx -lndos -create-app -DAMALLOC -o breakout breakout.c
2+
// zcc +zx -lndos -DAMALLOC -o breakout.bin breakout.c
23
#include <conio.h>
34
#include <input.h>
45
#include <graphics.h>
56
#include <math.h>
67
#include <arch/zx/spectrum.h>
78

8-
#define L 22
9-
#define WALL 2
10-
#define DARK_C INK_BLUE
11-
#define LIGHT_C INK_CYAN
12-
9+
/** Generic functions */
1310
static unsigned char* attrMem = 22528;
14-
static uint8_t* grid;
11+
static uint8_t ticks = 0;
1512

16-
static void plot_shade(uint8_t x, uint8_t y, uint8_t density)
13+
static void plot_shade(uint8_t x, uint8_t y, uint8_t density255)
1714
{
18-
if (density == 0)
19-
return;
20-
if (density >= 100)
21-
{
15+
// Plot this pixel based on the density.
16+
if (density255 == 255 || (uint8_t)rand() < density255)
2217
plot(x, y);
23-
return;
24-
}
25-
26-
// Convert density to a range from 0 to 100 for comparison
27-
uint8_t threshold = (uint8_t)((density * 255) / 100);
28-
29-
// Use rand() to decide whether to plot this pixel based on the density
30-
if ((rand() % 256) < threshold) {
31-
plot(x, y); // Plot if within the density threshold
32-
}
3318
}
3419

35-
static void c_plot_shade(uint8_t x, uint8_t y, uint8_t density)
20+
static void c_plot_shade(uint8_t x, uint8_t y, uint8_t density255)
3621
{
3722
x <<= 2;
3823
y <<= 2;
3924

4025
for (uint8_t i = 0; i < 4; ++i)
4126
{
27+
const uint8_t py = y + i;
4228
for (uint8_t j = 0; j < 4; ++j)
43-
plot_shade(x + i, y + j, density);
29+
plot_shade(x + i, py, density255);
4430
}
4531
}
4632

4733
static void drawLogo(uint8_t x, uint8_t y)
4834
{
49-
const char* logo[23] =
50-
{
51-
" ********** ",
52-
"..***....*** ",
53-
" .*** ..***",
54-
" .*** .***",
55-
" .*** *** ",
56-
" ********** ",
57-
".......... ",
58-
" ",
59-
" *********** ",
60-
".*...***...* ",
61-
". .*** . ",
62-
" .*** ",
63-
" .*** ",
64-
" ***** ",
65-
" ..... ",
66-
" ",
67-
" ********* ",
68-
" ***.....***",
69-
" *** ... ",
70-
".*** ",
71-
"..*** ***",
72-
" ..********* ",
73-
" ......... "
74-
};
75-
const uint8_t c[] = { WHITE, LIGHTGRAY, LIGHTCYAN, LIGHTGREEN, LIGHTMAGENTA, LIGHTRED, RED, RED };
76-
for (uint8_t j = 0; j < 23 * 2; ++j)
35+
if (ticks > 30)
36+
return;
37+
38+
if (ticks == 0)
7739
{
78-
textcolor(c[(j >> 1) % 8]);
79-
for (uint8_t i = 0; i < 13; ++i)
40+
// Seed the pixels - Initially all black.
41+
const char* logo[23] =
8042
{
81-
switch (logo[j >> 1][i])
43+
" **********",
44+
"..***....***",
45+
" .*** ..***",
46+
" .*** .***",
47+
" .*** ***",
48+
" **********",
49+
"..........",
50+
"",
51+
" ***********",
52+
".*...***...*",
53+
". .*** .",
54+
" .***",
55+
" .***",
56+
" *****",
57+
" .....",
58+
"",
59+
" *********",
60+
" ***.....***",
61+
" *** ...",
62+
".***",
63+
"..*** ***",
64+
" ..*********",
65+
" ........."
66+
};
67+
68+
for (uint8_t j = 0; j < 23 * 2; ++j)
69+
{
70+
textcolor(BLACK);
71+
uint8_t* l = logo[j >> 1];
72+
const uint8_t w = strlen((const char*)l);
73+
const uint8_t py = j + y;
74+
for (uint8_t px = x; px < x + w; ++px)
8275
{
83-
case '*':
84-
c_plot(i + x, j + y);
85-
break;
86-
case '.':
87-
c_plot_shade(i + x, j + y, 15);
88-
break;
76+
switch (*l++)
77+
{
78+
case '*':
79+
c_plot(px, py);
80+
break;
81+
case '.':
82+
c_plot_shade(px, py, 40);
83+
break;
84+
}
8985
}
9086
}
87+
88+
++ticks;
89+
return;
9190
}
91+
92+
// Apply the color over time.
93+
y >>= 1;
94+
x >>= 1;
95+
96+
static const uint8_t logoC[] = { INK_WHITE + BRIGHT, INK_WHITE, INK_CYAN, INK_GREEN, INK_MAGENTA, INK_MAGENTA, INK_RED, INK_RED };
97+
uint8_t j = ticks, i = 0;
98+
while (j >= 0 && i < 7)
99+
{
100+
attrMem[((j + y) << 5) + x + i] = logoC[j & 0x07];
101+
--j; ++i;
102+
}
103+
104+
++ticks;
92105
}
93106

107+
/** App-specific **/
108+
#define L 22
109+
#define WALL 2
110+
#define DARK_C INK_BLUE
111+
#define LIGHT_C INK_CYAN
112+
113+
static uint8_t* grid;
114+
94115
static unsigned int gridToScreen(uint8_t x, uint8_t y)
95116
{
96117
return ((y + 1) << 5) + 9 + x;
@@ -198,13 +219,12 @@ void main()
198219
textbackground(BLACK);
199220
textcolor(WHITE);
200221
clrscr();
222+
ticks = 0;
201223

202224
// Footer.
203225
gotoxy(40, 23);
204226
printf("Breakout (@DeanTheCoder)");
205227

206-
drawLogo(3, 1);
207-
208228
// Init the grid.
209229
grid = malloc(L * L);
210230
memset(grid, 1, L * L); // Clear all.
@@ -238,6 +258,9 @@ void main()
238258
in_GetKeyReset();
239259
while (!in_GetKey())
240260
{
261+
// Refresh the logo.
262+
drawLogo(3, 1);
263+
241264
// Move ballz.
242265
for (uint8_t phase = 0; phase < 4; ++phase)
243266
{

Experiments/BreakOut/breakout.tap

6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)