Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of manworm_ticker_tv by
Revision 4:02e3ae7a3aea, committed 2017-11-19
- Comitter:
- bwang
- Date:
- Sun Nov 19 07:05:01 2017 +0000
- Parent:
- 3:d9edc0575aa3
- Child:
- 5:2859a892497f
- Commit message:
- drav
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Nov 19 05:00:14 2017 +0000
+++ b/main.cpp Sun Nov 19 07:05:01 2017 +0000
@@ -7,11 +7,10 @@
#define Y_MIN 7
#define Y_MAX (V_RES/4 - 15)
-int SX_MIN = 30;
-int SX_MAX = 95;
-int SY_MIN = 10;
-int SY_MAX = 48;
-int PADDLE_LEN = 10;
+#define SX_MIN 30
+#define SX_MAX 95
+#define SY_MIN 10
+#define SY_MAX 48
#define Y_0 ( (Y_MIN + Y_MAX)/2 )
#define X_0 ( (X_MIN + X_MAX)/2 )
@@ -23,6 +22,7 @@
#define BY_0 (V_RES/4 - 15)
#define BX 42
#define BY 15
+#define BY2 9
#define DEMO_LENGTH 600
@@ -148,6 +148,15 @@
1,0,0,0,0,0,
1,0,0,0,0,0,};
+uint8_t chr_R[] = {
+1,1,1,1,1,0,
+1,0,0,0,0,1,
+1,0,0,0,0,1,
+1,0,0,0,1,0,
+1,0,0,1,0,0,
+1,0,0,0,1,0,
+1,0,0,0,0,1,};
+
uint8_t chr_S[] = {
0,1,1,1,1,1,
1,0,0,0,0,0,
@@ -157,6 +166,25 @@
0,0,0,0,0,1,
1,1,1,1,1,0,};
+uint8_t chr_V[] = {
+1,0,0,0,0,1,
+1,0,0,0,0,1,
+1,0,0,0,0,1,
+0,1,0,0,1,0,
+0,1,0,0,1,0,
+0,1,0,0,1,0,
+0,0,1,1,0,0,};
+
+uint8_t sprite_tree[] = {
+0,0,0,1,0,0,0,
+0,0,1,1,1,0,0,
+0,1,1,1,1,1,0,
+1,1,1,1,1,1,1,
+0,1,1,1,1,1,0,
+1,1,1,1,1,1,1,
+0,0,0,1,0,0,0,
+0,0,0,1,0,0,0,};
+
uint16_t l=0; //current line of scan
uint8_t im_line_s[H_RES]; //image sync buffer
@@ -194,6 +222,7 @@
uint8_t im_line_va[H_RES*V_RES]; //image buffer
//pong variables
+#define PADDLE_LEN 10
float p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2;
float p1v = 0.1, p2v = -0.1;
@@ -212,6 +241,12 @@
float uvy[8] = {1,1,1,-1,-1,-1,-1,1};
int ulive[8] = {1,1,1,1,1,1,1,1};
+//tunnel variables
+#define TUN_LEN (SY_MAX - SY_MIN)
+uint8_t tunnel[TUN_LEN];
+float tunnp = 50;
+int tundir = 1;
+
int fdeath_ticker = FDEATH_RESET;
float fs = 0;
@@ -686,14 +721,83 @@
}
}
+void dispsprite(int x0, int y0, uint8_t* chr) {
+ int bmi = 0;
+ for(int y = SY_MIN + y0; y < SY_MIN + y0 + 8; y++)
+ {
+ for(int x = SX_MIN + x0; x < SX_MIN + x0 + 7; x++)
+ {
+ im_line_va[H_RES*y + x] = chr[bmi];
+ bmi++;
+ }
+ }
+}
+
+void disp_tunnel() {
+ for (int y = SY_MIN; y < SY_MAX; y++) {
+ int tunw = 30 * (y) / TUN_LEN;
+ int yy = SY_MAX-(SY_MAX-y)*3/4;
+ for (int x = SX_MIN; x < SX_MIN + tunnel[y - SY_MIN]; x++) im_line_va[H_RES*yy+x] = 1;
+ for (int x = SX_MIN + tunnel[y - SY_MIN]; x < SX_MIN + tunnel[y - SY_MIN] + tunw; x++) im_line_va[H_RES*yy+x] = 0;
+ for (int x = SX_MIN + tunnel[y - SY_MIN] + tunw; x < SX_MAX; x++) im_line_va[H_RES*yy+x] = 1;
+ }
+}
+
+void init_tunnel() {
+ for (int i = 0; i < TUN_LEN; i++) tunnel[i] = 20;
+ disp_tunnel();
+
+ int bmi = 0;
+
+ for(int y = SY_MIN; y < SY_MIN + BY; y++)
+ {
+ for(int x = SX_MIN; x < SX_MIN + BX; x++)
+ {
+ im_line_va[H_RES*y + x + 10] = tv[bmi];
+ bmi++;
+ }
+ }
+ dispsprite(1,2,sprite_tree);
+ dispsprite(50,2,sprite_tree);
+ dispsprite(11,2,sprite_tree);
+}
+
+void update_tunnel() {
+ for (int j = TUN_LEN-1; j > 0; j--) tunnel[j] = tunnel[j-1];
+
+ int x = rand() % 8;
+ if (x == 0) tundir = -tundir;
+ tunnel[0] = tunnel[0]+tundir;
+
+ if (tunnel[0] < 1) {
+ tunnel[0] = 1;
+ tundir = 1;
+ }
+ if (SX_MIN + tunnel[0] + 30 + 1 > SX_MAX) {
+ tunnel[0] = SX_MAX-SX_MIN-30-1;
+ tundir = -1;
+ }
+
+ disp_tunnel();
+
+ int cmd1 = p1_in.read();
+ int cmd2 = p2_in.read();
+ if (cmd1) tunnp+=1;
+ if (cmd2) tunnp-=1;
+ if (tunnp<SX_MIN+1) tunnp = SX_MIN+1;
+ if (tunnp>SX_MAX-1) tunnp = SX_MAX-1;
+ im_line_va[H_RES*SY_MAX+(int)tunnp] = 1;
+
+ wait(0.007);
+}
int main() {
potato:
init_buffers();
t.attach_us(&isr,63);
-
+
int bmi = 0;
- for(int y = SY_MIN; y < SY_MIN + BY; y++)
+ for(int y = SY_MIN; y < SY_MIN + BY2; y++)
{
for(int x = SX_MIN; x < SX_MIN + BX; x++)
{
@@ -702,20 +806,25 @@
}
}
- dispchr(4, BY+2, chr_P);
- dispchr(11, BY+2, chr_A);
- dispchr(18, BY+2, chr_N);
- dispchr(25, BY+2, chr_G);
+ dispchr(4, BY2+1, chr_P);
+ dispchr(11, BY2+1, chr_A);
+ dispchr(18, BY2+1, chr_N);
+ dispchr(25, BY2+1, chr_G);
+
+ dispchr(4, BY2+9, chr_F);
+ dispchr(11, BY2+9, chr_A);
+ dispchr(18, BY2+9, chr_S);
+ dispchr(25, BY2+9, chr_H);
- dispchr(4, BY+10, chr_F);
- dispchr(11, BY+10, chr_A);
- dispchr(18, BY+10, chr_S);
- dispchr(25, BY+10, chr_H);
+ dispchr(4, BY2+17, chr_D);
+ dispchr(11, BY2+17, chr_A);
+ dispchr(18, BY2+17, chr_M);
+ dispchr(25, BY2+17, chr_O);
- dispchr(4, BY+18, chr_D);
- dispchr(11, BY+18, chr_A);
- dispchr(18, BY+18, chr_M);
- dispchr(25, BY+18, chr_O);
+ dispchr(4, BY2+25, chr_D);
+ dispchr(11, BY2+25, chr_R);
+ dispchr(18, BY2+25, chr_A);
+ dispchr(25, BY2+25, chr_V);
int cursor_pos = 0;
@@ -724,7 +833,7 @@
int cmd2 = p2_in.read();
int cursor_x = SX_MIN;
- int cursor_y = SY_MIN + 8*cursor_pos + BY + 5;
+ int cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5;
if (cmd1 || cmd2) im_line_va[H_RES*cursor_y+cursor_x] = 0;
@@ -733,10 +842,10 @@
if (!cmd1 && !cmd2) break;
if (cursor_pos < 0) cursor_pos = 0;
- if (cursor_pos > 2) cursor_pos = 2;
+ if (cursor_pos > 3) cursor_pos = 3;
cursor_x = SX_MIN;
- cursor_y = SY_MIN + 8*cursor_pos + BY + 5;
+ cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5;
im_line_va[H_RES*cursor_y+cursor_x] = 1;
@@ -751,8 +860,14 @@
}
} else if (cursor_pos == 1) {
for (;;) fishy();
+ } else if (cursor_pos == 2) {
+ for (;;) update_image();
} else {
- for (;;) update_image();
+ init_tunnel();
+ for (;;)
+ {
+ update_tunnel();
+ }
}
goto potato;
}
