Bayley Wang
/
manworm_tv_raster
cube
Fork of manworm_tv_gpu by
main.cpp@5:2859a892497f, 2017-11-20 (annotated)
- Committer:
- bwang
- Date:
- Mon Nov 20 02:32:57 2017 +0000
- Revision:
- 5:2859a892497f
- Parent:
- 4:02e3ae7a3aea
- Child:
- 6:0a34891a82c7
drav now has man, less wavy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dicarloj | 0:7757ab3f7206 | 1 | #include "mbed.h" |
dicarloj | 0:7757ab3f7206 | 2 | #define V_RES 220 |
dicarloj | 0:7757ab3f7206 | 3 | #define H_RES 100 |
dicarloj | 0:7757ab3f7206 | 4 | #include <math.h> |
dicarloj | 0:7757ab3f7206 | 5 | #define X_MIN 24 |
dicarloj | 0:7757ab3f7206 | 6 | #define X_MAX (76+18) |
dicarloj | 0:7757ab3f7206 | 7 | #define Y_MIN 7 |
dicarloj | 0:7757ab3f7206 | 8 | #define Y_MAX (V_RES/4 - 15) |
dicarloj | 0:7757ab3f7206 | 9 | |
bwang | 4:02e3ae7a3aea | 10 | #define SX_MIN 30 |
bwang | 4:02e3ae7a3aea | 11 | #define SX_MAX 95 |
bwang | 4:02e3ae7a3aea | 12 | #define SY_MIN 10 |
bwang | 4:02e3ae7a3aea | 13 | #define SY_MAX 48 |
bwang | 1:24fd07a24094 | 14 | |
dicarloj | 0:7757ab3f7206 | 15 | #define Y_0 ( (Y_MIN + Y_MAX)/2 ) |
dicarloj | 0:7757ab3f7206 | 16 | #define X_0 ( (X_MIN + X_MAX)/2 ) |
dicarloj | 0:7757ab3f7206 | 17 | #define SIDE 8 |
dicarloj | 0:7757ab3f7206 | 18 | #define HSIDE 8 |
dicarloj | 0:7757ab3f7206 | 19 | #define SIN_V (0.03) |
dicarloj | 0:7757ab3f7206 | 20 | #define COS_V (0.99955f) |
dicarloj | 0:7757ab3f7206 | 21 | #define BX_0 30 |
dicarloj | 0:7757ab3f7206 | 22 | #define BY_0 (V_RES/4 - 15) |
dicarloj | 0:7757ab3f7206 | 23 | #define BX 42 |
dicarloj | 0:7757ab3f7206 | 24 | #define BY 15 |
bwang | 4:02e3ae7a3aea | 25 | #define BY2 9 |
dicarloj | 0:7757ab3f7206 | 26 | #define DEMO_LENGTH 600 |
dicarloj | 0:7757ab3f7206 | 27 | |
dicarloj | 0:7757ab3f7206 | 28 | |
dicarloj | 0:7757ab3f7206 | 29 | DigitalOut sout(D8); //sync |
dicarloj | 0:7757ab3f7206 | 30 | DigitalOut vout(D7); //video |
dicarloj | 0:7757ab3f7206 | 31 | Ticker t; |
dicarloj | 0:7757ab3f7206 | 32 | uint8_t draw_line_inv = 0; |
dicarloj | 0:7757ab3f7206 | 33 | //9x42 |
dicarloj | 0:7757ab3f7206 | 34 | uint8_t miters[] = { |
dicarloj | 0:7757ab3f7206 | 35 | 1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 36 | 1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 37 | 1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 38 | 1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 39 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 40 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0, |
dicarloj | 0:7757ab3f7206 | 41 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0, |
dicarloj | 0:7757ab3f7206 | 42 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 43 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 45 | 0,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 46 | 1,1,1,1,1,0,1,0,0,1,1,0,1,1,0,0,1,0,1,1,0,0,0,1,1,0,1,1,0,1,1,0,1,1,0,0,0,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 47 | 1,0,1,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 48 | 1,0,1,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 49 | 1,0,1,0,1,0,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 50 | |
dicarloj | 0:7757ab3f7206 | 51 | }; |
dicarloj | 0:7757ab3f7206 | 52 | |
dicarloj | 0:7757ab3f7206 | 53 | uint8_t tv[] = { |
dicarloj | 0:7757ab3f7206 | 54 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 55 | 0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 56 | 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 57 | 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 58 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 59 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 60 | 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 61 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 62 | 0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 63 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 64 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 65 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 66 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 67 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 68 | 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0}; |
dicarloj | 0:7757ab3f7206 | 69 | |
bwang | 3:d9edc0575aa3 | 70 | uint8_t chr_A[] = { |
bwang | 3:d9edc0575aa3 | 71 | 0,0,1,1,0,0, |
bwang | 3:d9edc0575aa3 | 72 | 0,1,0,0,1,0, |
bwang | 3:d9edc0575aa3 | 73 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 74 | 1,1,1,1,1,1, |
bwang | 3:d9edc0575aa3 | 75 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 76 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 77 | 1,0,0,0,0,1,}; |
dicarloj | 0:7757ab3f7206 | 78 | |
bwang | 3:d9edc0575aa3 | 79 | uint8_t chr_D[] = { |
bwang | 3:d9edc0575aa3 | 80 | 1,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 81 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 82 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 83 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 84 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 85 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 86 | 1,1,1,1,1,0,}; |
bwang | 3:d9edc0575aa3 | 87 | |
bwang | 3:d9edc0575aa3 | 88 | uint8_t chr_F[] = { |
bwang | 3:d9edc0575aa3 | 89 | 1,1,1,1,1,1, |
bwang | 3:d9edc0575aa3 | 90 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 91 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 92 | 1,1,1,1,1,1, |
bwang | 3:d9edc0575aa3 | 93 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 94 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 95 | 1,0,0,0,0,0,}; |
bwang | 3:d9edc0575aa3 | 96 | |
bwang | 3:d9edc0575aa3 | 97 | uint8_t chr_G[] = { |
bwang | 3:d9edc0575aa3 | 98 | 0,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 99 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 100 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 101 | 1,0,0,1,1,1, |
bwang | 3:d9edc0575aa3 | 102 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 103 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 104 | 0,1,1,1,1,0,}; |
bwang | 3:d9edc0575aa3 | 105 | |
bwang | 3:d9edc0575aa3 | 106 | uint8_t chr_H[] = { |
bwang | 3:d9edc0575aa3 | 107 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 108 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 109 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 110 | 1,1,1,1,1,1, |
bwang | 3:d9edc0575aa3 | 111 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 112 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 113 | 1,0,0,0,0,1,}; |
bwang | 3:d9edc0575aa3 | 114 | |
bwang | 3:d9edc0575aa3 | 115 | uint8_t chr_M[] = { |
bwang | 3:d9edc0575aa3 | 116 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 117 | 1,1,0,0,1,1, |
bwang | 3:d9edc0575aa3 | 118 | 1,0,1,1,0,1, |
bwang | 3:d9edc0575aa3 | 119 | 1,0,1,1,0,1, |
bwang | 3:d9edc0575aa3 | 120 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 121 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 122 | 1,0,0,0,0,1,}; |
bwang | 3:d9edc0575aa3 | 123 | |
bwang | 3:d9edc0575aa3 | 124 | uint8_t chr_N[] = { |
bwang | 3:d9edc0575aa3 | 125 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 126 | 1,1,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 127 | 1,0,1,0,0,1, |
bwang | 3:d9edc0575aa3 | 128 | 1,0,0,1,0,1, |
bwang | 3:d9edc0575aa3 | 129 | 1,0,0,0,1,1, |
bwang | 3:d9edc0575aa3 | 130 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 131 | 1,0,0,0,0,1,}; |
bwang | 3:d9edc0575aa3 | 132 | |
bwang | 3:d9edc0575aa3 | 133 | uint8_t chr_O[] = { |
bwang | 3:d9edc0575aa3 | 134 | 0,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 135 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 136 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 137 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 138 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 139 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 140 | 0,1,1,1,1,0,}; |
bwang | 3:d9edc0575aa3 | 141 | |
bwang | 3:d9edc0575aa3 | 142 | uint8_t chr_P[] = { |
bwang | 3:d9edc0575aa3 | 143 | 1,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 144 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 145 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 146 | 1,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 147 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 148 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 149 | 1,0,0,0,0,0,}; |
bwang | 3:d9edc0575aa3 | 150 | |
bwang | 4:02e3ae7a3aea | 151 | uint8_t chr_R[] = { |
bwang | 4:02e3ae7a3aea | 152 | 1,1,1,1,1,0, |
bwang | 4:02e3ae7a3aea | 153 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 154 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 155 | 1,0,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 156 | 1,0,0,1,0,0, |
bwang | 4:02e3ae7a3aea | 157 | 1,0,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 158 | 1,0,0,0,0,1,}; |
bwang | 4:02e3ae7a3aea | 159 | |
bwang | 3:d9edc0575aa3 | 160 | uint8_t chr_S[] = { |
bwang | 3:d9edc0575aa3 | 161 | 0,1,1,1,1,1, |
bwang | 3:d9edc0575aa3 | 162 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 163 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 164 | 0,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 165 | 0,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 166 | 0,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 167 | 1,1,1,1,1,0,}; |
dicarloj | 0:7757ab3f7206 | 168 | |
bwang | 4:02e3ae7a3aea | 169 | uint8_t chr_V[] = { |
bwang | 4:02e3ae7a3aea | 170 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 171 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 172 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 173 | 0,1,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 174 | 0,1,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 175 | 0,1,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 176 | 0,0,1,1,0,0,}; |
bwang | 4:02e3ae7a3aea | 177 | |
bwang | 4:02e3ae7a3aea | 178 | uint8_t sprite_tree[] = { |
bwang | 4:02e3ae7a3aea | 179 | 0,0,0,1,0,0,0, |
bwang | 4:02e3ae7a3aea | 180 | 0,0,1,1,1,0,0, |
bwang | 4:02e3ae7a3aea | 181 | 0,1,1,1,1,1,0, |
bwang | 4:02e3ae7a3aea | 182 | 1,1,1,1,1,1,1, |
bwang | 4:02e3ae7a3aea | 183 | 0,1,1,1,1,1,0, |
bwang | 4:02e3ae7a3aea | 184 | 1,1,1,1,1,1,1, |
bwang | 4:02e3ae7a3aea | 185 | 0,0,0,1,0,0,0, |
bwang | 4:02e3ae7a3aea | 186 | 0,0,0,1,0,0,0,}; |
bwang | 4:02e3ae7a3aea | 187 | |
bwang | 5:2859a892497f | 188 | uint8_t sprite_man[] = { |
bwang | 5:2859a892497f | 189 | 0,0,0,1,0,0,0, |
bwang | 5:2859a892497f | 190 | 0,0,1,1,1,0,0, |
bwang | 5:2859a892497f | 191 | 0,0,0,1,0,0,1, |
bwang | 5:2859a892497f | 192 | 0,1,1,1,1,1,0, |
bwang | 5:2859a892497f | 193 | 1,0,1,1,1,0,0, |
bwang | 5:2859a892497f | 194 | 0,0,1,1,1,0,0, |
bwang | 5:2859a892497f | 195 | 0,1,0,0,0,1,0, |
bwang | 5:2859a892497f | 196 | 0,1,0,0,0,1,0}; |
bwang | 5:2859a892497f | 197 | |
dicarloj | 0:7757ab3f7206 | 198 | uint16_t l=0; //current line of scan |
dicarloj | 0:7757ab3f7206 | 199 | |
dicarloj | 0:7757ab3f7206 | 200 | uint8_t im_line_s[H_RES]; //image sync buffer |
dicarloj | 0:7757ab3f7206 | 201 | |
dicarloj | 0:7757ab3f7206 | 202 | uint8_t bl_line_s[H_RES]; //lower 1/4 of screen sync buffer |
dicarloj | 0:7757ab3f7206 | 203 | uint8_t bl_line_v[H_RES]; //lower 1/4 of screen video buffer |
dicarloj | 0:7757ab3f7206 | 204 | uint8_t vb_line_s[H_RES]; //vertical sync, sync buffer |
dicarloj | 0:7757ab3f7206 | 205 | uint8_t vb_line_v[H_RES]; //vertical sync, video buffer |
dicarloj | 0:7757ab3f7206 | 206 | |
dicarloj | 0:7757ab3f7206 | 207 | float cube_a[3] = {15.f, 0.f, 0.f}; |
dicarloj | 0:7757ab3f7206 | 208 | |
dicarloj | 0:7757ab3f7206 | 209 | |
dicarloj | 0:7757ab3f7206 | 210 | float cube_pts[8][3] = { {SIDE,SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 211 | {-SIDE,SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 212 | {-SIDE,-SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 213 | {SIDE,-SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 214 | {SIDE,-SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 215 | {-SIDE,-SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 216 | {-SIDE,SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 217 | {SIDE,SIDE,-HSIDE} }; |
dicarloj | 0:7757ab3f7206 | 218 | |
dicarloj | 0:7757ab3f7206 | 219 | float x_rot[3][3] = { {1.f, 0.f, 0.f}, |
dicarloj | 0:7757ab3f7206 | 220 | {0.f, COS_V, -SIN_V}, |
dicarloj | 0:7757ab3f7206 | 221 | {0.f, SIN_V, COS_V} }; |
dicarloj | 0:7757ab3f7206 | 222 | |
dicarloj | 0:7757ab3f7206 | 223 | float y_rot[3][3] = { {COS_V, 0.f, SIN_V}, |
dicarloj | 0:7757ab3f7206 | 224 | {0.f, 1.f, 0.f}, |
dicarloj | 0:7757ab3f7206 | 225 | {-SIN_V, 0, COS_V} }; |
dicarloj | 0:7757ab3f7206 | 226 | |
dicarloj | 0:7757ab3f7206 | 227 | float z_rot[3][3] = { {COS_V, -SIN_V, 0.f}, |
dicarloj | 0:7757ab3f7206 | 228 | {SIN_V, COS_V, 0.f}, |
dicarloj | 0:7757ab3f7206 | 229 | {0.f, 0.f, 1.f} }; |
dicarloj | 0:7757ab3f7206 | 230 | |
dicarloj | 0:7757ab3f7206 | 231 | |
dicarloj | 0:7757ab3f7206 | 232 | uint8_t im_line_va[H_RES*V_RES]; //image buffer |
dicarloj | 0:7757ab3f7206 | 233 | |
bwang | 1:24fd07a24094 | 234 | //pong variables |
bwang | 4:02e3ae7a3aea | 235 | #define PADDLE_LEN 10 |
bwang | 1:24fd07a24094 | 236 | float p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2; |
bwang | 1:24fd07a24094 | 237 | float p1v = 0.1, p2v = -0.1; |
bwang | 1:24fd07a24094 | 238 | |
bwang | 1:24fd07a24094 | 239 | float bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 1:24fd07a24094 | 240 | float bxv = 0.03, byv = 0.03; |
bwang | 1:24fd07a24094 | 241 | |
bwang | 2:1d16e99f334b | 242 | int s1 = 0, s2 = 0; |
bwang | 2:1d16e99f334b | 243 | |
bwang | 3:d9edc0575aa3 | 244 | //fish variables |
bwang | 3:d9edc0575aa3 | 245 | #define FDEATH_RESET 30000 |
bwang | 3:d9edc0575aa3 | 246 | float fx = (SX_MAX+SX_MIN)/2.f, fy = (SY_MIN+SY_MAX)/2.f, fv = 0.02f, ftheta = 0.0, fa = 0.002; |
bwang | 3:d9edc0575aa3 | 247 | float uv = 0.005; |
bwang | 3:d9edc0575aa3 | 248 | float ux[8] = {53,70,78,78,70,53,45,45}; |
bwang | 3:d9edc0575aa3 | 249 | float uy[8] = {10,10,20,35,50,50,35,20}; |
bwang | 3:d9edc0575aa3 | 250 | float uvx[8] = {-1,1,1,1,1,-1,-1,-1}; |
bwang | 3:d9edc0575aa3 | 251 | float uvy[8] = {1,1,1,-1,-1,-1,-1,1}; |
bwang | 3:d9edc0575aa3 | 252 | int ulive[8] = {1,1,1,1,1,1,1,1}; |
bwang | 3:d9edc0575aa3 | 253 | |
bwang | 4:02e3ae7a3aea | 254 | //tunnel variables |
bwang | 4:02e3ae7a3aea | 255 | #define TUN_LEN (SY_MAX - SY_MIN) |
bwang | 4:02e3ae7a3aea | 256 | uint8_t tunnel[TUN_LEN]; |
bwang | 4:02e3ae7a3aea | 257 | float tunnp = 50; |
bwang | 4:02e3ae7a3aea | 258 | int tundir = 1; |
bwang | 4:02e3ae7a3aea | 259 | |
bwang | 3:d9edc0575aa3 | 260 | int fdeath_ticker = FDEATH_RESET; |
bwang | 3:d9edc0575aa3 | 261 | float fs = 0; |
bwang | 3:d9edc0575aa3 | 262 | |
bwang | 2:1d16e99f334b | 263 | DigitalIn p1_in(A1); |
bwang | 2:1d16e99f334b | 264 | DigitalIn p2_in(A0); |
bwang | 1:24fd07a24094 | 265 | |
dicarloj | 0:7757ab3f7206 | 266 | void make_checkerboard() |
dicarloj | 0:7757ab3f7206 | 267 | { |
dicarloj | 0:7757ab3f7206 | 268 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 269 | for(int j = 0; j < V_RES; j++) |
bwang | 1:24fd07a24094 | 270 | im_line_va[i+j*H_RES] = 0*((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard |
dicarloj | 0:7757ab3f7206 | 271 | |
dicarloj | 0:7757ab3f7206 | 272 | } |
dicarloj | 0:7757ab3f7206 | 273 | |
bwang | 3:d9edc0575aa3 | 274 | void clr() |
bwang | 3:d9edc0575aa3 | 275 | { |
bwang | 3:d9edc0575aa3 | 276 | for(int i = 0; i < H_RES; i++) |
bwang | 3:d9edc0575aa3 | 277 | for(int j = 0; j < V_RES; j++) |
bwang | 3:d9edc0575aa3 | 278 | im_line_va[i+j*H_RES] = 0; |
bwang | 3:d9edc0575aa3 | 279 | |
bwang | 3:d9edc0575aa3 | 280 | } |
bwang | 3:d9edc0575aa3 | 281 | |
dicarloj | 0:7757ab3f7206 | 282 | void init_buffers() |
dicarloj | 0:7757ab3f7206 | 283 | { |
bwang | 3:d9edc0575aa3 | 284 | clr(); |
dicarloj | 0:7757ab3f7206 | 285 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 286 | { |
dicarloj | 0:7757ab3f7206 | 287 | im_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 288 | bl_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 289 | bl_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 290 | vb_line_s[i] = 0; |
dicarloj | 0:7757ab3f7206 | 291 | vb_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 292 | } |
dicarloj | 0:7757ab3f7206 | 293 | im_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 294 | im_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 295 | im_line_s[2] = 0; |
dicarloj | 0:7757ab3f7206 | 296 | bl_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 297 | vb_line_s[0] = 1; |
dicarloj | 0:7757ab3f7206 | 298 | bl_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 299 | vb_line_s[1] = 1; |
dicarloj | 0:7757ab3f7206 | 300 | |
dicarloj | 0:7757ab3f7206 | 301 | |
dicarloj | 0:7757ab3f7206 | 302 | |
dicarloj | 0:7757ab3f7206 | 303 | } |
dicarloj | 0:7757ab3f7206 | 304 | void isr() |
dicarloj | 0:7757ab3f7206 | 305 | { |
dicarloj | 0:7757ab3f7206 | 306 | uint8_t nop = 0; //use nops or use wait_us |
dicarloj | 0:7757ab3f7206 | 307 | uint8_t* sptr; //pointer to sync buffer for line |
dicarloj | 0:7757ab3f7206 | 308 | uint8_t* vptr; //pointer to video buffer for line |
dicarloj | 0:7757ab3f7206 | 309 | if(l < V_RES){ vptr = im_line_va + ((l/4)*H_RES); sptr = im_line_s; nop = 1; } //pick line buffers |
dicarloj | 0:7757ab3f7206 | 310 | else if(l < 254){ vptr = bl_line_v; sptr = bl_line_s; nop = 0; } |
dicarloj | 0:7757ab3f7206 | 311 | else{ vptr = vb_line_v; sptr = vb_line_s; nop = 1;} |
dicarloj | 0:7757ab3f7206 | 312 | uint8_t lmax = nop?H_RES:12; //number of columns |
dicarloj | 0:7757ab3f7206 | 313 | for(uint8_t i = 0; i < lmax; i++) //loop over each column |
dicarloj | 0:7757ab3f7206 | 314 | { |
dicarloj | 0:7757ab3f7206 | 315 | vout = vptr[i]; //set output pins |
dicarloj | 0:7757ab3f7206 | 316 | sout = sptr[i]; |
dicarloj | 0:7757ab3f7206 | 317 | if(nop) //nop delay |
dicarloj | 0:7757ab3f7206 | 318 | { |
dicarloj | 0:7757ab3f7206 | 319 | asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");//asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop"); |
dicarloj | 0:7757ab3f7206 | 320 | } |
dicarloj | 0:7757ab3f7206 | 321 | else {wait_us(1); if(i > 2) i++;} //wait delay |
dicarloj | 0:7757ab3f7206 | 322 | |
dicarloj | 0:7757ab3f7206 | 323 | |
dicarloj | 0:7757ab3f7206 | 324 | } |
dicarloj | 0:7757ab3f7206 | 325 | //move to next line |
dicarloj | 0:7757ab3f7206 | 326 | l++; |
dicarloj | 0:7757ab3f7206 | 327 | if(l > 255) l = 0; |
dicarloj | 0:7757ab3f7206 | 328 | } |
dicarloj | 0:7757ab3f7206 | 329 | |
dicarloj | 0:7757ab3f7206 | 330 | //coordinates for bouncing ball |
dicarloj | 0:7757ab3f7206 | 331 | |
dicarloj | 0:7757ab3f7206 | 332 | |
dicarloj | 0:7757ab3f7206 | 333 | |
dicarloj | 0:7757ab3f7206 | 334 | int k = 0; |
dicarloj | 0:7757ab3f7206 | 335 | uint16_t px = X_0*10; |
dicarloj | 0:7757ab3f7206 | 336 | uint16_t py = Y_0*10; |
dicarloj | 0:7757ab3f7206 | 337 | uint16_t vx = 10; |
dicarloj | 0:7757ab3f7206 | 338 | uint16_t vy = 10; |
dicarloj | 0:7757ab3f7206 | 339 | uint16_t px2 = X_0*10 + 80; |
dicarloj | 0:7757ab3f7206 | 340 | uint16_t py2 = Y_0*10 - 40; |
dicarloj | 0:7757ab3f7206 | 341 | uint16_t vx2 = 3; |
dicarloj | 0:7757ab3f7206 | 342 | uint16_t vy2 = -4; |
dicarloj | 0:7757ab3f7206 | 343 | |
dicarloj | 0:7757ab3f7206 | 344 | int16_t sign(int16_t a) |
dicarloj | 0:7757ab3f7206 | 345 | { |
dicarloj | 0:7757ab3f7206 | 346 | if(a > 0) return 1; |
dicarloj | 0:7757ab3f7206 | 347 | if(a < 0) return -1; |
dicarloj | 0:7757ab3f7206 | 348 | return 0; |
dicarloj | 0:7757ab3f7206 | 349 | } |
dicarloj | 0:7757ab3f7206 | 350 | |
dicarloj | 0:7757ab3f7206 | 351 | void draw_vert(int16_t y0, int16_t y1, int16_t x0) |
dicarloj | 0:7757ab3f7206 | 352 | { |
dicarloj | 0:7757ab3f7206 | 353 | for(int16_t i = y0; i < y1; i++) |
dicarloj | 0:7757ab3f7206 | 354 | im_line_va[H_RES*i + x0] = 1; |
dicarloj | 0:7757ab3f7206 | 355 | } |
dicarloj | 0:7757ab3f7206 | 356 | |
dicarloj | 0:7757ab3f7206 | 357 | void draw_horiz(int16_t x0, int16_t x1, int16_t y0) |
dicarloj | 0:7757ab3f7206 | 358 | { |
dicarloj | 0:7757ab3f7206 | 359 | for(int16_t i = x0; i < x1; i++) |
dicarloj | 0:7757ab3f7206 | 360 | im_line_va[H_RES*y0 + i] = 1; |
dicarloj | 0:7757ab3f7206 | 361 | } |
dicarloj | 0:7757ab3f7206 | 362 | |
dicarloj | 0:7757ab3f7206 | 363 | int16_t imin(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 364 | { |
dicarloj | 0:7757ab3f7206 | 365 | if(a<b) return a; |
dicarloj | 0:7757ab3f7206 | 366 | return b; |
dicarloj | 0:7757ab3f7206 | 367 | } |
dicarloj | 0:7757ab3f7206 | 368 | |
dicarloj | 0:7757ab3f7206 | 369 | int16_t imax(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 370 | { |
dicarloj | 0:7757ab3f7206 | 371 | if(a>b) return a; |
dicarloj | 0:7757ab3f7206 | 372 | return b; |
dicarloj | 0:7757ab3f7206 | 373 | } |
dicarloj | 0:7757ab3f7206 | 374 | |
dicarloj | 0:7757ab3f7206 | 375 | void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1) |
dicarloj | 0:7757ab3f7206 | 376 | { |
dicarloj | 0:7757ab3f7206 | 377 | if(x0 > x1){ x0 = x0 ^ x1; x1 = x1^x0; x0 = x0^x1;y0 = y0 ^ y1; y1 = y1^y0; y0 = y0^y1; } |
dicarloj | 0:7757ab3f7206 | 378 | if(x0 == x1){draw_vert(y0,y1,x0);} |
dicarloj | 0:7757ab3f7206 | 379 | if(y0 == y1){draw_horiz(x0,x1,y0);} |
dicarloj | 0:7757ab3f7206 | 380 | int16_t dx = x1 - x0; |
dicarloj | 0:7757ab3f7206 | 381 | int16_t dy = y1 - y0; |
dicarloj | 0:7757ab3f7206 | 382 | float derr = fabs((float)(dy)/(float)(dx)); |
dicarloj | 0:7757ab3f7206 | 383 | float err = 0.f; |
dicarloj | 0:7757ab3f7206 | 384 | int16_t y = y0; |
dicarloj | 0:7757ab3f7206 | 385 | for(int16_t x = x0; x < x1; x++) |
dicarloj | 0:7757ab3f7206 | 386 | { |
dicarloj | 0:7757ab3f7206 | 387 | //plotxy |
dicarloj | 0:7757ab3f7206 | 388 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 389 | err += derr; |
dicarloj | 0:7757ab3f7206 | 390 | while(err >= 0.5f) |
dicarloj | 0:7757ab3f7206 | 391 | { |
dicarloj | 0:7757ab3f7206 | 392 | y += sign(dy); |
dicarloj | 0:7757ab3f7206 | 393 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 394 | err -= 1.f; |
dicarloj | 0:7757ab3f7206 | 395 | } |
dicarloj | 0:7757ab3f7206 | 396 | } |
dicarloj | 0:7757ab3f7206 | 397 | } |
dicarloj | 0:7757ab3f7206 | 398 | |
dicarloj | 0:7757ab3f7206 | 399 | void draw_cube(float cp[][3]) |
dicarloj | 0:7757ab3f7206 | 400 | { |
dicarloj | 0:7757ab3f7206 | 401 | for(uint8_t i = 0; i < 7; i++) |
dicarloj | 0:7757ab3f7206 | 402 | { |
dicarloj | 0:7757ab3f7206 | 403 | draw_line((int16_t)cp[i][0]+cube_a[0]+X_0,(int16_t)cp[i][1]+cube_a[1]+Y_0,(int16_t)cp[i+1][0]+cube_a[0]+X_0,(int16_t)cp[i+1][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 404 | } |
dicarloj | 0:7757ab3f7206 | 405 | draw_line((int16_t)cp[0][0]+cube_a[0]+X_0,(int16_t)cp[0][1]+cube_a[1]+Y_0,(int16_t)cp[3][0]+cube_a[0]+X_0,(int16_t)cp[3][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 406 | draw_line((int16_t)cp[4][0]+cube_a[0]+X_0,(int16_t)cp[4][1]+cube_a[1]+Y_0,(int16_t)cp[7][0]+cube_a[0]+X_0,(int16_t)cp[7][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 407 | draw_line((int16_t)cp[0][0]+cube_a[0]+X_0,(int16_t)cp[0][1]+cube_a[1]+Y_0,(int16_t)cp[7][0]+cube_a[0]+X_0,(int16_t)cp[7][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 408 | draw_line((int16_t)cp[1][0]+cube_a[0]+X_0,(int16_t)cp[1][1]+cube_a[1]+Y_0,(int16_t)cp[6][0]+cube_a[0]+X_0,(int16_t)cp[6][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 409 | draw_line((int16_t)cp[2][0]+cube_a[0]+X_0,(int16_t)cp[2][1]+cube_a[1]+Y_0,(int16_t)cp[5][0]+cube_a[0]+X_0,(int16_t)cp[5][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 410 | } |
dicarloj | 0:7757ab3f7206 | 411 | |
dicarloj | 0:7757ab3f7206 | 412 | void apply_rot(float cp[][3], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 413 | { |
dicarloj | 0:7757ab3f7206 | 414 | for(uint8_t pti = 0; pti < 8; pti++) |
dicarloj | 0:7757ab3f7206 | 415 | { |
dicarloj | 0:7757ab3f7206 | 416 | float* cpt = cp[pti]; |
dicarloj | 0:7757ab3f7206 | 417 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 418 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 419 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 420 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 421 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 422 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 423 | } |
dicarloj | 0:7757ab3f7206 | 424 | } |
dicarloj | 0:7757ab3f7206 | 425 | |
dicarloj | 0:7757ab3f7206 | 426 | void apply_xf_rot(float cpt[], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 427 | { |
dicarloj | 0:7757ab3f7206 | 428 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 429 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 430 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 431 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 432 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 433 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 434 | } |
dicarloj | 0:7757ab3f7206 | 435 | |
dicarloj | 0:7757ab3f7206 | 436 | void draw_v_check(int8_t r,uint8_t tt) |
dicarloj | 0:7757ab3f7206 | 437 | { |
dicarloj | 0:7757ab3f7206 | 438 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 439 | for(int j = 0; j < V_RES; j++) |
dicarloj | 0:7757ab3f7206 | 440 | im_line_va[i+j*H_RES] = (((i > 20) && (i < 98)) && ( tt ^(((j%(r*2))>=r) ^ ((i%(r*2)))>=r))); //checkerboard |
dicarloj | 0:7757ab3f7206 | 441 | } |
dicarloj | 0:7757ab3f7206 | 442 | |
dicarloj | 0:7757ab3f7206 | 443 | |
dicarloj | 0:7757ab3f7206 | 444 | int jjj = 0; |
dicarloj | 0:7757ab3f7206 | 445 | int f_count = DEMO_LENGTH + 10; |
dicarloj | 0:7757ab3f7206 | 446 | void draw_cube_spin(int kkkk); |
dicarloj | 0:7757ab3f7206 | 447 | //update bouncing balls |
dicarloj | 0:7757ab3f7206 | 448 | |
dicarloj | 0:7757ab3f7206 | 449 | void draw_blank() |
dicarloj | 0:7757ab3f7206 | 450 | { |
dicarloj | 0:7757ab3f7206 | 451 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 452 | { |
dicarloj | 0:7757ab3f7206 | 453 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 454 | { |
dicarloj | 0:7757ab3f7206 | 455 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 456 | } |
dicarloj | 0:7757ab3f7206 | 457 | } |
dicarloj | 0:7757ab3f7206 | 458 | } |
dicarloj | 0:7757ab3f7206 | 459 | |
dicarloj | 0:7757ab3f7206 | 460 | void wipe(); |
dicarloj | 0:7757ab3f7206 | 461 | |
dicarloj | 0:7757ab3f7206 | 462 | void update_image() |
dicarloj | 0:7757ab3f7206 | 463 | { |
dicarloj | 0:7757ab3f7206 | 464 | //delay |
dicarloj | 0:7757ab3f7206 | 465 | k++; |
dicarloj | 0:7757ab3f7206 | 466 | if(k%4000) return; |
dicarloj | 0:7757ab3f7206 | 467 | f_count++; |
dicarloj | 0:7757ab3f7206 | 468 | if(f_count < DEMO_LENGTH/2) |
dicarloj | 0:7757ab3f7206 | 469 | { |
dicarloj | 0:7757ab3f7206 | 470 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 471 | } |
dicarloj | 0:7757ab3f7206 | 472 | else if(f_count < DEMO_LENGTH) |
dicarloj | 0:7757ab3f7206 | 473 | { |
bwang | 1:24fd07a24094 | 474 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 475 | } |
bwang | 1:24fd07a24094 | 476 | else if(f_count < DEMO_LENGTH * 1.22) |
dicarloj | 0:7757ab3f7206 | 477 | { |
dicarloj | 0:7757ab3f7206 | 478 | for(int k = 1; k < 10; k++) |
bwang | 1:24fd07a24094 | 479 | //for(int kk = 1; kk < 3; kk++) |
dicarloj | 0:7757ab3f7206 | 480 | { |
dicarloj | 0:7757ab3f7206 | 481 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 482 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 483 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 484 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 485 | } |
dicarloj | 0:7757ab3f7206 | 486 | |
dicarloj | 0:7757ab3f7206 | 487 | draw_v_check(1,0); |
dicarloj | 0:7757ab3f7206 | 488 | wipe(); |
dicarloj | 0:7757ab3f7206 | 489 | f_count = 0; |
dicarloj | 0:7757ab3f7206 | 490 | } |
dicarloj | 0:7757ab3f7206 | 491 | } |
dicarloj | 0:7757ab3f7206 | 492 | |
dicarloj | 0:7757ab3f7206 | 493 | void wipe() |
dicarloj | 0:7757ab3f7206 | 494 | { |
dicarloj | 0:7757ab3f7206 | 495 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 496 | { |
dicarloj | 0:7757ab3f7206 | 497 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 498 | { |
dicarloj | 0:7757ab3f7206 | 499 | im_line_va[v*H_RES+h] = 1; |
dicarloj | 0:7757ab3f7206 | 500 | } |
bwang | 1:24fd07a24094 | 501 | wait(.01); |
dicarloj | 0:7757ab3f7206 | 502 | } |
dicarloj | 0:7757ab3f7206 | 503 | |
dicarloj | 0:7757ab3f7206 | 504 | for(int v = Y_MAX+15; v > Y_MIN; v--) |
dicarloj | 0:7757ab3f7206 | 505 | { |
dicarloj | 0:7757ab3f7206 | 506 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 507 | { |
dicarloj | 0:7757ab3f7206 | 508 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 509 | } |
bwang | 1:24fd07a24094 | 510 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 511 | } |
dicarloj | 0:7757ab3f7206 | 512 | |
dicarloj | 0:7757ab3f7206 | 513 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 514 | { |
dicarloj | 0:7757ab3f7206 | 515 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 516 | { |
dicarloj | 0:7757ab3f7206 | 517 | im_line_va[v*H_RES + h] = 1; |
dicarloj | 0:7757ab3f7206 | 518 | } |
bwang | 1:24fd07a24094 | 519 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 520 | } |
dicarloj | 0:7757ab3f7206 | 521 | |
dicarloj | 0:7757ab3f7206 | 522 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 523 | { |
dicarloj | 0:7757ab3f7206 | 524 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 525 | { |
dicarloj | 0:7757ab3f7206 | 526 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 527 | } |
bwang | 1:24fd07a24094 | 528 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 529 | } |
dicarloj | 0:7757ab3f7206 | 530 | |
dicarloj | 0:7757ab3f7206 | 531 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 532 | { |
dicarloj | 0:7757ab3f7206 | 533 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 534 | { |
dicarloj | 0:7757ab3f7206 | 535 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 536 | } |
dicarloj | 0:7757ab3f7206 | 537 | } |
dicarloj | 0:7757ab3f7206 | 538 | } |
dicarloj | 0:7757ab3f7206 | 539 | |
dicarloj | 0:7757ab3f7206 | 540 | void draw_cube_spin(int kkkk) |
dicarloj | 0:7757ab3f7206 | 541 | { |
dicarloj | 0:7757ab3f7206 | 542 | draw_line_inv = kkkk; |
dicarloj | 0:7757ab3f7206 | 543 | //blank |
dicarloj | 0:7757ab3f7206 | 544 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 545 | { |
dicarloj | 0:7757ab3f7206 | 546 | for(uint16_t v = Y_MIN; v < Y_MAX; v++) |
dicarloj | 0:7757ab3f7206 | 547 | { |
dicarloj | 0:7757ab3f7206 | 548 | if( (h > 22) && (h < 76+18)) |
dicarloj | 0:7757ab3f7206 | 549 | im_line_va[v*H_RES + h] = kkkk; |
dicarloj | 0:7757ab3f7206 | 550 | } |
dicarloj | 0:7757ab3f7206 | 551 | } |
dicarloj | 0:7757ab3f7206 | 552 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 553 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 554 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 555 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 556 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 557 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 558 | apply_rot(cube_pts,z_rot); |
dicarloj | 0:7757ab3f7206 | 559 | //draw ball |
dicarloj | 0:7757ab3f7206 | 560 | im_line_va[(py/10)*H_RES + (px/10)] = 1; |
dicarloj | 0:7757ab3f7206 | 561 | draw_line(X_0,Y_0,(px/10),(py/10)); |
dicarloj | 0:7757ab3f7206 | 562 | draw_cube(cube_pts); |
dicarloj | 0:7757ab3f7206 | 563 | |
dicarloj | 0:7757ab3f7206 | 564 | //update position/check for bounces |
dicarloj | 0:7757ab3f7206 | 565 | px += vx; |
dicarloj | 0:7757ab3f7206 | 566 | py += vy; |
dicarloj | 0:7757ab3f7206 | 567 | px2 += vx2; |
dicarloj | 0:7757ab3f7206 | 568 | py2 += vy2; |
dicarloj | 0:7757ab3f7206 | 569 | if(px/10 > (X_MAX-2) || px/10 < (X_MIN+1)) vx = -vx; |
dicarloj | 0:7757ab3f7206 | 570 | if(py/10 > (Y_MAX-2) || py/10 < (Y_MIN+1)) vy = -vy; |
dicarloj | 0:7757ab3f7206 | 571 | if(px2/10 > (X_MAX-2) || px2/10 < (X_MIN+1)) vx2 = -vx2; |
dicarloj | 0:7757ab3f7206 | 572 | if(py2/10 > (Y_MAX-2) || py2/10 < (Y_MIN+1)) vy2 = -vy2; |
dicarloj | 0:7757ab3f7206 | 573 | if(k%(8000*50)) return; |
dicarloj | 0:7757ab3f7206 | 574 | |
dicarloj | 0:7757ab3f7206 | 575 | jjj = !jjj; |
dicarloj | 0:7757ab3f7206 | 576 | int bmi = 0; |
dicarloj | 0:7757ab3f7206 | 577 | for(int y = BY_0; y < BY_0 + BY; y++) |
dicarloj | 0:7757ab3f7206 | 578 | { |
dicarloj | 0:7757ab3f7206 | 579 | for(int x = BX_0; x < BX_0 + BX; x++) |
dicarloj | 0:7757ab3f7206 | 580 | { |
dicarloj | 0:7757ab3f7206 | 581 | im_line_va[H_RES*y + x] = kkkk^(miters[bmi]*jjj + (!jjj)*tv[bmi]); |
dicarloj | 0:7757ab3f7206 | 582 | bmi++; |
dicarloj | 0:7757ab3f7206 | 583 | } |
dicarloj | 0:7757ab3f7206 | 584 | } |
dicarloj | 0:7757ab3f7206 | 585 | } |
dicarloj | 0:7757ab3f7206 | 586 | |
bwang | 3:d9edc0575aa3 | 587 | int flappy_pong() { |
bwang | 3:d9edc0575aa3 | 588 | |
bwang | 3:d9edc0575aa3 | 589 | //clear frame |
bwang | 3:d9edc0575aa3 | 590 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 3:d9edc0575aa3 | 591 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 0; |
bwang | 3:d9edc0575aa3 | 592 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 0; |
bwang | 3:d9edc0575aa3 | 593 | } |
bwang | 3:d9edc0575aa3 | 594 | im_line_va[H_RES*(int)by+(int)bx] = 0; |
bwang | 3:d9edc0575aa3 | 595 | //read inputs |
bwang | 3:d9edc0575aa3 | 596 | int cmd1 = p1_in.read(); |
bwang | 3:d9edc0575aa3 | 597 | int cmd2 = p2_in.read(); |
bwang | 3:d9edc0575aa3 | 598 | if (cmd1 == 0) p1v = 0.1; else p1v = -0.1f; |
bwang | 3:d9edc0575aa3 | 599 | if (cmd2 == 0) p2v = 0.1; else p2v = -0.1f; |
bwang | 3:d9edc0575aa3 | 600 | |
bwang | 3:d9edc0575aa3 | 601 | p1 += p1v; |
bwang | 3:d9edc0575aa3 | 602 | p2 += p2v; |
bwang | 3:d9edc0575aa3 | 603 | bx += bxv; |
bwang | 3:d9edc0575aa3 | 604 | by += byv; |
bwang | 3:d9edc0575aa3 | 605 | |
bwang | 3:d9edc0575aa3 | 606 | if (p1 < SY_MIN) p1 = SY_MIN; |
bwang | 3:d9edc0575aa3 | 607 | if (p1 > SY_MAX-PADDLE_LEN) p1 = SY_MAX-PADDLE_LEN; |
bwang | 3:d9edc0575aa3 | 608 | if (p2 < SY_MIN) p2 = SY_MIN; |
bwang | 3:d9edc0575aa3 | 609 | if (p2 > SY_MAX-PADDLE_LEN) p2 = SY_MAX-PADDLE_LEN; |
bwang | 3:d9edc0575aa3 | 610 | |
bwang | 3:d9edc0575aa3 | 611 | if (bx < SX_MIN) { |
bwang | 3:d9edc0575aa3 | 612 | bxv = -bxv; |
bwang | 3:d9edc0575aa3 | 613 | bx = SX_MIN; |
bwang | 3:d9edc0575aa3 | 614 | if (by < p1 - 3 || by > p1 + PADDLE_LEN + 3) { |
bwang | 3:d9edc0575aa3 | 615 | im_line_va[H_RES*(SY_MIN-2)+2*s1+SX_MIN] = 1; |
bwang | 3:d9edc0575aa3 | 616 | bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 3:d9edc0575aa3 | 617 | s1++; |
bwang | 3:d9edc0575aa3 | 618 | if (s1>14) return 0; |
bwang | 3:d9edc0575aa3 | 619 | } |
bwang | 3:d9edc0575aa3 | 620 | } |
bwang | 3:d9edc0575aa3 | 621 | if (bx > SX_MAX) { |
bwang | 3:d9edc0575aa3 | 622 | bxv = -bxv; |
bwang | 3:d9edc0575aa3 | 623 | bx = SX_MAX; |
bwang | 3:d9edc0575aa3 | 624 | if (by < p2 - 3 || by > p2 + PADDLE_LEN + 3) { |
bwang | 3:d9edc0575aa3 | 625 | im_line_va[H_RES*(SY_MAX+2)+2*s2+SX_MIN] = 1; |
bwang | 3:d9edc0575aa3 | 626 | bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 3:d9edc0575aa3 | 627 | s2++; |
bwang | 3:d9edc0575aa3 | 628 | if (s2>14) return 0; |
bwang | 3:d9edc0575aa3 | 629 | } |
bwang | 3:d9edc0575aa3 | 630 | } |
bwang | 3:d9edc0575aa3 | 631 | if (by < SY_MIN) {byv = -byv; by = SY_MIN;} |
bwang | 3:d9edc0575aa3 | 632 | if (by > SY_MAX) {byv = -byv; by = SY_MAX;} |
bwang | 3:d9edc0575aa3 | 633 | |
bwang | 1:24fd07a24094 | 634 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 635 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1; |
bwang | 1:24fd07a24094 | 636 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1; |
bwang | 1:24fd07a24094 | 637 | } |
bwang | 1:24fd07a24094 | 638 | im_line_va[H_RES*(int)by+(int)bx] = 1; |
bwang | 3:d9edc0575aa3 | 639 | |
bwang | 3:d9edc0575aa3 | 640 | wait(1/1200.0f); |
bwang | 3:d9edc0575aa3 | 641 | return 1; |
bwang | 3:d9edc0575aa3 | 642 | } |
bwang | 3:d9edc0575aa3 | 643 | |
bwang | 3:d9edc0575aa3 | 644 | int fishy() { |
bwang | 3:d9edc0575aa3 | 645 | uint16_t xstart, ystart, xend, yend; |
bwang | 3:d9edc0575aa3 | 646 | float s = sinf(ftheta); |
bwang | 3:d9edc0575aa3 | 647 | float c = cosf(ftheta); |
bwang | 3:d9edc0575aa3 | 648 | |
bwang | 3:d9edc0575aa3 | 649 | xstart = (uint16_t) fx; |
bwang | 3:d9edc0575aa3 | 650 | ystart = (uint16_t) fy; |
bwang | 3:d9edc0575aa3 | 651 | |
bwang | 3:d9edc0575aa3 | 652 | |
bwang | 3:d9edc0575aa3 | 653 | for(int x = xstart-5; x < xstart + 5; x++) { |
bwang | 3:d9edc0575aa3 | 654 | for (int y = ystart - 5; y < ystart + 5; y++) { |
bwang | 3:d9edc0575aa3 | 655 | im_line_va[H_RES*y+x] = 0; |
bwang | 3:d9edc0575aa3 | 656 | } |
bwang | 3:d9edc0575aa3 | 657 | } |
bwang | 3:d9edc0575aa3 | 658 | for (int i = 0; i < 8; i++) { |
bwang | 3:d9edc0575aa3 | 659 | int index = H_RES*(int)uy[i]+(int)ux[i]; |
bwang | 3:d9edc0575aa3 | 660 | im_line_va[index] = 0; |
bwang | 3:d9edc0575aa3 | 661 | } |
bwang | 3:d9edc0575aa3 | 662 | |
bwang | 3:d9edc0575aa3 | 663 | float fx_old = fx, fy_old = fy; |
bwang | 3:d9edc0575aa3 | 664 | fx += fv * s; |
bwang | 3:d9edc0575aa3 | 665 | fy += fv * c; |
bwang | 3:d9edc0575aa3 | 666 | int cmd = p1_in.read(); |
bwang | 3:d9edc0575aa3 | 667 | if (cmd) ftheta += fa; else ftheta -= fa; |
bwang | 3:d9edc0575aa3 | 668 | if (ftheta >= 2 * 3.1415926) ftheta -= 2 * 3.1415926; |
bwang | 3:d9edc0575aa3 | 669 | if (ftheta < 0) ftheta += 2 * 3.1415926; |
bwang | 3:d9edc0575aa3 | 670 | |
bwang | 3:d9edc0575aa3 | 671 | s = sinf(ftheta); |
bwang | 3:d9edc0575aa3 | 672 | c = cosf(ftheta); |
bwang | 3:d9edc0575aa3 | 673 | |
bwang | 3:d9edc0575aa3 | 674 | xstart = (uint16_t)fx; |
bwang | 3:d9edc0575aa3 | 675 | ystart = (uint16_t)fy; |
bwang | 3:d9edc0575aa3 | 676 | xend = (uint16_t)(fx+s*4); |
bwang | 3:d9edc0575aa3 | 677 | yend = (uint16_t)(fy+c*4); |
bwang | 3:d9edc0575aa3 | 678 | |
bwang | 3:d9edc0575aa3 | 679 | if (xstart < SX_MIN || xstart > SX_MAX || |
bwang | 3:d9edc0575aa3 | 680 | ystart < SY_MIN || ystart > SY_MAX || |
bwang | 3:d9edc0575aa3 | 681 | xend < SX_MIN || xend > SX_MAX || |
bwang | 3:d9edc0575aa3 | 682 | yend < SY_MIN || yend > SY_MAX) { |
bwang | 3:d9edc0575aa3 | 683 | fx = fx_old; |
bwang | 3:d9edc0575aa3 | 684 | fy = fy_old; |
bwang | 3:d9edc0575aa3 | 685 | xstart = (uint16_t)fx; |
bwang | 3:d9edc0575aa3 | 686 | ystart = (uint16_t)fy; |
bwang | 3:d9edc0575aa3 | 687 | xend = (uint16_t)(fx+s*4); |
bwang | 3:d9edc0575aa3 | 688 | yend = (uint16_t)(fy+c*4); |
bwang | 3:d9edc0575aa3 | 689 | } |
bwang | 3:d9edc0575aa3 | 690 | |
bwang | 3:d9edc0575aa3 | 691 | draw_line(xstart, ystart, xend, yend); |
bwang | 3:d9edc0575aa3 | 692 | for (int i = 0; i < 8; i++) { |
bwang | 3:d9edc0575aa3 | 693 | if (!ulive[i]) continue; |
bwang | 3:d9edc0575aa3 | 694 | if (xstart == (int)ux[i] && ystart == (int)uy[i]) { |
bwang | 3:d9edc0575aa3 | 695 | fdeath_ticker = FDEATH_RESET; |
bwang | 3:d9edc0575aa3 | 696 | fs+=1; |
bwang | 3:d9edc0575aa3 | 697 | ulive[i] = 0; |
bwang | 3:d9edc0575aa3 | 698 | } |
bwang | 3:d9edc0575aa3 | 699 | ux[i]+= uv*uvx[i]; |
bwang | 3:d9edc0575aa3 | 700 | uy[i]+= uv*uvy[i]; |
bwang | 3:d9edc0575aa3 | 701 | if (ux[i] < SX_MIN) {ux[i] = SX_MIN; uvx[i] = -uvx[i];} |
bwang | 3:d9edc0575aa3 | 702 | if (ux[i] > SX_MAX) {ux[i] = SX_MAX; uvx[i] = -uvx[i];} |
bwang | 3:d9edc0575aa3 | 703 | if (uy[i] < SY_MIN) {uy[i] = SY_MIN; uvy[i] = -uvy[i];} |
bwang | 3:d9edc0575aa3 | 704 | if (uy[i] > SY_MAX) {uy[i] = SY_MAX; uvy[i] = -uvy[i];} |
bwang | 3:d9edc0575aa3 | 705 | |
bwang | 3:d9edc0575aa3 | 706 | int index = H_RES*(int)uy[i]+(int)ux[i]; |
bwang | 3:d9edc0575aa3 | 707 | im_line_va[index] = 1; |
bwang | 3:d9edc0575aa3 | 708 | } |
bwang | 3:d9edc0575aa3 | 709 | for (int i = 0; i < 8; i++) { |
bwang | 3:d9edc0575aa3 | 710 | im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 0; |
bwang | 3:d9edc0575aa3 | 711 | } |
bwang | 3:d9edc0575aa3 | 712 | for (int i = 0; i < fs; i++) { |
bwang | 3:d9edc0575aa3 | 713 | im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 1; |
bwang | 3:d9edc0575aa3 | 714 | } |
bwang | 3:d9edc0575aa3 | 715 | fdeath_ticker--; |
bwang | 3:d9edc0575aa3 | 716 | if (fdeath_ticker < 0) fs -= 0.0001f; |
bwang | 3:d9edc0575aa3 | 717 | if (fs < 0) fs = 0; |
bwang | 3:d9edc0575aa3 | 718 | |
bwang | 3:d9edc0575aa3 | 719 | return 1; |
bwang | 3:d9edc0575aa3 | 720 | } |
bwang | 3:d9edc0575aa3 | 721 | |
bwang | 3:d9edc0575aa3 | 722 | void dispchr(int x0, int y0, uint8_t* chr) { |
bwang | 3:d9edc0575aa3 | 723 | int bmi = 0; |
bwang | 3:d9edc0575aa3 | 724 | for(int y = SY_MIN + y0; y < SY_MIN + y0 + 7; y++) |
bwang | 1:24fd07a24094 | 725 | { |
bwang | 3:d9edc0575aa3 | 726 | for(int x = SX_MIN + x0; x < SX_MIN + x0 + 6; x++) |
bwang | 3:d9edc0575aa3 | 727 | { |
bwang | 3:d9edc0575aa3 | 728 | im_line_va[H_RES*y + x] = chr[bmi]; |
bwang | 3:d9edc0575aa3 | 729 | bmi++; |
bwang | 1:24fd07a24094 | 730 | } |
bwang | 3:d9edc0575aa3 | 731 | } |
bwang | 3:d9edc0575aa3 | 732 | } |
bwang | 3:d9edc0575aa3 | 733 | |
bwang | 4:02e3ae7a3aea | 734 | void dispsprite(int x0, int y0, uint8_t* chr) { |
bwang | 4:02e3ae7a3aea | 735 | int bmi = 0; |
bwang | 4:02e3ae7a3aea | 736 | for(int y = SY_MIN + y0; y < SY_MIN + y0 + 8; y++) |
bwang | 4:02e3ae7a3aea | 737 | { |
bwang | 4:02e3ae7a3aea | 738 | for(int x = SX_MIN + x0; x < SX_MIN + x0 + 7; x++) |
bwang | 4:02e3ae7a3aea | 739 | { |
bwang | 5:2859a892497f | 740 | if (chr[bmi]) im_line_va[H_RES*y + x] = chr[bmi]; |
bwang | 4:02e3ae7a3aea | 741 | bmi++; |
bwang | 4:02e3ae7a3aea | 742 | } |
bwang | 4:02e3ae7a3aea | 743 | } |
bwang | 4:02e3ae7a3aea | 744 | } |
bwang | 4:02e3ae7a3aea | 745 | |
bwang | 4:02e3ae7a3aea | 746 | void disp_tunnel() { |
bwang | 4:02e3ae7a3aea | 747 | for (int y = SY_MIN; y < SY_MAX; y++) { |
bwang | 4:02e3ae7a3aea | 748 | int tunw = 30 * (y) / TUN_LEN; |
bwang | 4:02e3ae7a3aea | 749 | int yy = SY_MAX-(SY_MAX-y)*3/4; |
bwang | 5:2859a892497f | 750 | for (int x = SX_MIN; x < SX_MIN + tunnel[y - SY_MIN]; x++) im_line_va[H_RES*yy+x] = (x&1)^(y&1); |
bwang | 4:02e3ae7a3aea | 751 | 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; |
bwang | 5:2859a892497f | 752 | for (int x = SX_MIN + tunnel[y - SY_MIN] + tunw; x < SX_MAX; x++) im_line_va[H_RES*yy+x] = (x&1)^(y&1); |
bwang | 4:02e3ae7a3aea | 753 | } |
bwang | 4:02e3ae7a3aea | 754 | } |
bwang | 4:02e3ae7a3aea | 755 | |
bwang | 4:02e3ae7a3aea | 756 | void init_tunnel() { |
bwang | 4:02e3ae7a3aea | 757 | for (int i = 0; i < TUN_LEN; i++) tunnel[i] = 20; |
bwang | 4:02e3ae7a3aea | 758 | disp_tunnel(); |
bwang | 4:02e3ae7a3aea | 759 | |
bwang | 4:02e3ae7a3aea | 760 | int bmi = 0; |
bwang | 4:02e3ae7a3aea | 761 | |
bwang | 4:02e3ae7a3aea | 762 | for(int y = SY_MIN; y < SY_MIN + BY; y++) |
bwang | 4:02e3ae7a3aea | 763 | { |
bwang | 4:02e3ae7a3aea | 764 | for(int x = SX_MIN; x < SX_MIN + BX; x++) |
bwang | 4:02e3ae7a3aea | 765 | { |
bwang | 4:02e3ae7a3aea | 766 | im_line_va[H_RES*y + x + 10] = tv[bmi]; |
bwang | 4:02e3ae7a3aea | 767 | bmi++; |
bwang | 4:02e3ae7a3aea | 768 | } |
bwang | 4:02e3ae7a3aea | 769 | } |
bwang | 4:02e3ae7a3aea | 770 | dispsprite(1,2,sprite_tree); |
bwang | 4:02e3ae7a3aea | 771 | dispsprite(50,2,sprite_tree); |
bwang | 4:02e3ae7a3aea | 772 | dispsprite(11,2,sprite_tree); |
bwang | 4:02e3ae7a3aea | 773 | } |
bwang | 4:02e3ae7a3aea | 774 | |
bwang | 4:02e3ae7a3aea | 775 | void update_tunnel() { |
bwang | 4:02e3ae7a3aea | 776 | for (int j = TUN_LEN-1; j > 0; j--) tunnel[j] = tunnel[j-1]; |
bwang | 4:02e3ae7a3aea | 777 | |
bwang | 5:2859a892497f | 778 | int x = rand() % 48; |
bwang | 4:02e3ae7a3aea | 779 | if (x == 0) tundir = -tundir; |
bwang | 5:2859a892497f | 780 | if (x > 24) tunnel[0] = tunnel[0]+tundir; |
bwang | 4:02e3ae7a3aea | 781 | |
bwang | 4:02e3ae7a3aea | 782 | if (tunnel[0] < 1) { |
bwang | 4:02e3ae7a3aea | 783 | tunnel[0] = 1; |
bwang | 4:02e3ae7a3aea | 784 | tundir = 1; |
bwang | 4:02e3ae7a3aea | 785 | } |
bwang | 4:02e3ae7a3aea | 786 | if (SX_MIN + tunnel[0] + 30 + 1 > SX_MAX) { |
bwang | 4:02e3ae7a3aea | 787 | tunnel[0] = SX_MAX-SX_MIN-30-1; |
bwang | 4:02e3ae7a3aea | 788 | tundir = -1; |
bwang | 4:02e3ae7a3aea | 789 | } |
bwang | 4:02e3ae7a3aea | 790 | |
bwang | 4:02e3ae7a3aea | 791 | disp_tunnel(); |
bwang | 4:02e3ae7a3aea | 792 | |
bwang | 4:02e3ae7a3aea | 793 | int cmd1 = p1_in.read(); |
bwang | 4:02e3ae7a3aea | 794 | int cmd2 = p2_in.read(); |
bwang | 5:2859a892497f | 795 | if (cmd1) tunnp+=1.0f; |
bwang | 5:2859a892497f | 796 | if (cmd2) tunnp-=1.0f; |
bwang | 5:2859a892497f | 797 | if (tunnp<SX_MIN+8) tunnp = SX_MIN+8; |
bwang | 5:2859a892497f | 798 | if (tunnp>SX_MAX-8) tunnp = SX_MAX-8; |
bwang | 5:2859a892497f | 799 | dispsprite((int)(tunnp-SX_MIN), 31, sprite_man); |
bwang | 4:02e3ae7a3aea | 800 | |
bwang | 5:2859a892497f | 801 | wait(0.01); |
bwang | 4:02e3ae7a3aea | 802 | } |
bwang | 3:d9edc0575aa3 | 803 | int main() { |
bwang | 3:d9edc0575aa3 | 804 | potato: |
bwang | 3:d9edc0575aa3 | 805 | init_buffers(); |
bwang | 3:d9edc0575aa3 | 806 | t.attach_us(&isr,63); |
bwang | 4:02e3ae7a3aea | 807 | |
bwang | 3:d9edc0575aa3 | 808 | int bmi = 0; |
bwang | 3:d9edc0575aa3 | 809 | |
bwang | 4:02e3ae7a3aea | 810 | for(int y = SY_MIN; y < SY_MIN + BY2; y++) |
bwang | 3:d9edc0575aa3 | 811 | { |
bwang | 3:d9edc0575aa3 | 812 | for(int x = SX_MIN; x < SX_MIN + BX; x++) |
bwang | 3:d9edc0575aa3 | 813 | { |
bwang | 3:d9edc0575aa3 | 814 | im_line_va[H_RES*y + x] = miters[bmi]; |
bwang | 3:d9edc0575aa3 | 815 | bmi++; |
bwang | 3:d9edc0575aa3 | 816 | } |
bwang | 3:d9edc0575aa3 | 817 | } |
bwang | 3:d9edc0575aa3 | 818 | |
bwang | 4:02e3ae7a3aea | 819 | dispchr(4, BY2+1, chr_P); |
bwang | 4:02e3ae7a3aea | 820 | dispchr(11, BY2+1, chr_A); |
bwang | 4:02e3ae7a3aea | 821 | dispchr(18, BY2+1, chr_N); |
bwang | 4:02e3ae7a3aea | 822 | dispchr(25, BY2+1, chr_G); |
bwang | 4:02e3ae7a3aea | 823 | |
bwang | 4:02e3ae7a3aea | 824 | dispchr(4, BY2+9, chr_F); |
bwang | 4:02e3ae7a3aea | 825 | dispchr(11, BY2+9, chr_A); |
bwang | 4:02e3ae7a3aea | 826 | dispchr(18, BY2+9, chr_S); |
bwang | 4:02e3ae7a3aea | 827 | dispchr(25, BY2+9, chr_H); |
bwang | 3:d9edc0575aa3 | 828 | |
bwang | 4:02e3ae7a3aea | 829 | dispchr(4, BY2+17, chr_D); |
bwang | 4:02e3ae7a3aea | 830 | dispchr(11, BY2+17, chr_A); |
bwang | 4:02e3ae7a3aea | 831 | dispchr(18, BY2+17, chr_M); |
bwang | 4:02e3ae7a3aea | 832 | dispchr(25, BY2+17, chr_O); |
bwang | 3:d9edc0575aa3 | 833 | |
bwang | 4:02e3ae7a3aea | 834 | dispchr(4, BY2+25, chr_D); |
bwang | 4:02e3ae7a3aea | 835 | dispchr(11, BY2+25, chr_R); |
bwang | 4:02e3ae7a3aea | 836 | dispchr(18, BY2+25, chr_A); |
bwang | 4:02e3ae7a3aea | 837 | dispchr(25, BY2+25, chr_V); |
bwang | 3:d9edc0575aa3 | 838 | |
bwang | 3:d9edc0575aa3 | 839 | int cursor_pos = 0; |
bwang | 3:d9edc0575aa3 | 840 | |
bwang | 3:d9edc0575aa3 | 841 | for (;;) { |
bwang | 1:24fd07a24094 | 842 | int cmd1 = p1_in.read(); |
bwang | 1:24fd07a24094 | 843 | int cmd2 = p2_in.read(); |
bwang | 3:d9edc0575aa3 | 844 | |
bwang | 3:d9edc0575aa3 | 845 | int cursor_x = SX_MIN; |
bwang | 4:02e3ae7a3aea | 846 | int cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5; |
bwang | 1:24fd07a24094 | 847 | |
bwang | 3:d9edc0575aa3 | 848 | if (cmd1 || cmd2) im_line_va[H_RES*cursor_y+cursor_x] = 0; |
bwang | 1:24fd07a24094 | 849 | |
bwang | 3:d9edc0575aa3 | 850 | if (!cmd1) cursor_pos++; |
bwang | 3:d9edc0575aa3 | 851 | if (!cmd2) cursor_pos--; |
bwang | 3:d9edc0575aa3 | 852 | if (!cmd1 && !cmd2) break; |
bwang | 1:24fd07a24094 | 853 | |
bwang | 3:d9edc0575aa3 | 854 | if (cursor_pos < 0) cursor_pos = 0; |
bwang | 4:02e3ae7a3aea | 855 | if (cursor_pos > 3) cursor_pos = 3; |
bwang | 1:24fd07a24094 | 856 | |
bwang | 3:d9edc0575aa3 | 857 | cursor_x = SX_MIN; |
bwang | 4:02e3ae7a3aea | 858 | cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5; |
bwang | 1:24fd07a24094 | 859 | |
bwang | 3:d9edc0575aa3 | 860 | im_line_va[H_RES*cursor_y+cursor_x] = 1; |
bwang | 3:d9edc0575aa3 | 861 | |
bwang | 3:d9edc0575aa3 | 862 | wait(0.1); |
bwang | 1:24fd07a24094 | 863 | } |
bwang | 1:24fd07a24094 | 864 | |
bwang | 3:d9edc0575aa3 | 865 | init_buffers(); |
bwang | 2:1d16e99f334b | 866 | |
bwang | 3:d9edc0575aa3 | 867 | if (cursor_pos == 0) { |
bwang | 3:d9edc0575aa3 | 868 | for (;;) { |
bwang | 3:d9edc0575aa3 | 869 | if (!flappy_pong()) break; |
bwang | 3:d9edc0575aa3 | 870 | } |
bwang | 3:d9edc0575aa3 | 871 | } else if (cursor_pos == 1) { |
bwang | 3:d9edc0575aa3 | 872 | for (;;) fishy(); |
bwang | 4:02e3ae7a3aea | 873 | } else if (cursor_pos == 2) { |
bwang | 4:02e3ae7a3aea | 874 | for (;;) update_image(); |
bwang | 3:d9edc0575aa3 | 875 | } else { |
bwang | 4:02e3ae7a3aea | 876 | init_tunnel(); |
bwang | 4:02e3ae7a3aea | 877 | for (;;) |
bwang | 4:02e3ae7a3aea | 878 | { |
bwang | 4:02e3ae7a3aea | 879 | update_tunnel(); |
bwang | 4:02e3ae7a3aea | 880 | } |
dicarloj | 0:7757ab3f7206 | 881 | } |
bwang | 3:d9edc0575aa3 | 882 | goto potato; |
dicarloj | 0:7757ab3f7206 | 883 | } |