Bayley Wang
/
manworm_tv_raster
cube
Fork of manworm_tv_gpu by
main.cpp@7:25acb844f424, 2017-11-20 (annotated)
- Committer:
- bwang
- Date:
- Mon Nov 20 10:54:42 2017 +0000
- Revision:
- 7:25acb844f424
- Parent:
- 6:0a34891a82c7
- Child:
- 8:caeb6582cdc1
broken mode7
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 | 6:0a34891a82c7 | 115 | uint8_t chr_L[] = { |
bwang | 6:0a34891a82c7 | 116 | 1,0,0,0,0,0, |
bwang | 6:0a34891a82c7 | 117 | 1,0,0,0,0,0, |
bwang | 6:0a34891a82c7 | 118 | 1,0,0,0,0,0, |
bwang | 6:0a34891a82c7 | 119 | 1,0,0,0,0,0, |
bwang | 6:0a34891a82c7 | 120 | 1,0,0,0,0,0, |
bwang | 6:0a34891a82c7 | 121 | 1,0,0,0,0,0, |
bwang | 6:0a34891a82c7 | 122 | 1,1,1,1,1,1,}; |
bwang | 6:0a34891a82c7 | 123 | |
bwang | 3:d9edc0575aa3 | 124 | uint8_t chr_M[] = { |
bwang | 3:d9edc0575aa3 | 125 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 126 | 1,1,0,0,1,1, |
bwang | 3:d9edc0575aa3 | 127 | 1,0,1,1,0,1, |
bwang | 3:d9edc0575aa3 | 128 | 1,0,1,1,0,1, |
bwang | 3:d9edc0575aa3 | 129 | 1,0,0,0,0,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_N[] = { |
bwang | 3:d9edc0575aa3 | 134 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 135 | 1,1,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 136 | 1,0,1,0,0,1, |
bwang | 3:d9edc0575aa3 | 137 | 1,0,0,1,0,1, |
bwang | 3:d9edc0575aa3 | 138 | 1,0,0,0,1,1, |
bwang | 3:d9edc0575aa3 | 139 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 140 | 1,0,0,0,0,1,}; |
bwang | 3:d9edc0575aa3 | 141 | |
bwang | 3:d9edc0575aa3 | 142 | uint8_t chr_O[] = { |
bwang | 3:d9edc0575aa3 | 143 | 0,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,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 147 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 148 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 149 | 0,1,1,1,1,0,}; |
bwang | 3:d9edc0575aa3 | 150 | |
bwang | 3:d9edc0575aa3 | 151 | uint8_t chr_P[] = { |
bwang | 3:d9edc0575aa3 | 152 | 1,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 153 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 154 | 1,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 155 | 1,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 156 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 157 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 158 | 1,0,0,0,0,0,}; |
bwang | 3:d9edc0575aa3 | 159 | |
bwang | 4:02e3ae7a3aea | 160 | uint8_t chr_R[] = { |
bwang | 4:02e3ae7a3aea | 161 | 1,1,1,1,1,0, |
bwang | 4:02e3ae7a3aea | 162 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 163 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 164 | 1,0,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 165 | 1,0,0,1,0,0, |
bwang | 4:02e3ae7a3aea | 166 | 1,0,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 167 | 1,0,0,0,0,1,}; |
bwang | 4:02e3ae7a3aea | 168 | |
bwang | 3:d9edc0575aa3 | 169 | uint8_t chr_S[] = { |
bwang | 3:d9edc0575aa3 | 170 | 0,1,1,1,1,1, |
bwang | 3:d9edc0575aa3 | 171 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 172 | 1,0,0,0,0,0, |
bwang | 3:d9edc0575aa3 | 173 | 0,1,1,1,1,0, |
bwang | 3:d9edc0575aa3 | 174 | 0,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 175 | 0,0,0,0,0,1, |
bwang | 3:d9edc0575aa3 | 176 | 1,1,1,1,1,0,}; |
dicarloj | 0:7757ab3f7206 | 177 | |
bwang | 4:02e3ae7a3aea | 178 | uint8_t chr_V[] = { |
bwang | 4:02e3ae7a3aea | 179 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 180 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 181 | 1,0,0,0,0,1, |
bwang | 4:02e3ae7a3aea | 182 | 0,1,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 183 | 0,1,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 184 | 0,1,0,0,1,0, |
bwang | 4:02e3ae7a3aea | 185 | 0,0,1,1,0,0,}; |
bwang | 4:02e3ae7a3aea | 186 | |
bwang | 6:0a34891a82c7 | 187 | uint8_t chr_W[] = { |
bwang | 6:0a34891a82c7 | 188 | 1,0,0,0,0,1, |
bwang | 6:0a34891a82c7 | 189 | 1,0,0,0,0,1, |
bwang | 6:0a34891a82c7 | 190 | 1,0,0,0,0,1, |
bwang | 6:0a34891a82c7 | 191 | 1,0,1,1,0,1, |
bwang | 6:0a34891a82c7 | 192 | 1,0,1,1,0,1, |
bwang | 6:0a34891a82c7 | 193 | 1,1,0,0,1,1, |
bwang | 6:0a34891a82c7 | 194 | 1,0,0,0,0,1,}; |
bwang | 6:0a34891a82c7 | 195 | |
bwang | 4:02e3ae7a3aea | 196 | uint8_t sprite_tree[] = { |
bwang | 4:02e3ae7a3aea | 197 | 0,0,0,1,0,0,0, |
bwang | 4:02e3ae7a3aea | 198 | 0,0,1,1,1,0,0, |
bwang | 4:02e3ae7a3aea | 199 | 0,1,1,1,1,1,0, |
bwang | 4:02e3ae7a3aea | 200 | 1,1,1,1,1,1,1, |
bwang | 4:02e3ae7a3aea | 201 | 0,1,1,1,1,1,0, |
bwang | 4:02e3ae7a3aea | 202 | 1,1,1,1,1,1,1, |
bwang | 4:02e3ae7a3aea | 203 | 0,0,0,1,0,0,0, |
bwang | 4:02e3ae7a3aea | 204 | 0,0,0,1,0,0,0,}; |
bwang | 4:02e3ae7a3aea | 205 | |
bwang | 5:2859a892497f | 206 | uint8_t sprite_man[] = { |
bwang | 5:2859a892497f | 207 | 0,0,0,1,0,0,0, |
bwang | 5:2859a892497f | 208 | 0,0,1,1,1,0,0, |
bwang | 5:2859a892497f | 209 | 0,0,0,1,0,0,1, |
bwang | 5:2859a892497f | 210 | 0,1,1,1,1,1,0, |
bwang | 5:2859a892497f | 211 | 1,0,1,1,1,0,0, |
bwang | 5:2859a892497f | 212 | 0,0,1,1,1,0,0, |
bwang | 5:2859a892497f | 213 | 0,1,0,0,0,1,0, |
bwang | 5:2859a892497f | 214 | 0,1,0,0,0,1,0}; |
bwang | 5:2859a892497f | 215 | |
bwang | 6:0a34891a82c7 | 216 | uint8_t sprite_manl[] = { |
bwang | 6:0a34891a82c7 | 217 | 0,0,0,1,0,0,0, |
bwang | 6:0a34891a82c7 | 218 | 0,0,1,1,1,0,0, |
bwang | 7:25acb844f424 | 219 | 1,0,0,1,0,0,0, |
bwang | 6:0a34891a82c7 | 220 | 0,1,1,1,1,1,0, |
bwang | 7:25acb844f424 | 221 | 0,0,1,1,1,0,1, |
bwang | 6:0a34891a82c7 | 222 | 0,0,1,1,1,0,0, |
bwang | 6:0a34891a82c7 | 223 | 0,1,0,0,0,1,0, |
bwang | 6:0a34891a82c7 | 224 | 0,1,0,0,0,0,0}; |
bwang | 6:0a34891a82c7 | 225 | |
bwang | 6:0a34891a82c7 | 226 | uint8_t sprite_manr[] = { |
bwang | 6:0a34891a82c7 | 227 | 0,0,0,1,0,0,0, |
bwang | 6:0a34891a82c7 | 228 | 0,0,1,1,1,0,0, |
bwang | 6:0a34891a82c7 | 229 | 0,0,0,1,0,0,1, |
bwang | 6:0a34891a82c7 | 230 | 0,1,1,1,1,1,0, |
bwang | 6:0a34891a82c7 | 231 | 1,0,1,1,1,0,0, |
bwang | 6:0a34891a82c7 | 232 | 0,0,1,1,1,0,0, |
bwang | 6:0a34891a82c7 | 233 | 0,1,0,0,0,1,0, |
bwang | 6:0a34891a82c7 | 234 | 0,0,0,0,0,1,0}; |
bwang | 6:0a34891a82c7 | 235 | |
bwang | 6:0a34891a82c7 | 236 | uint8_t *menu[] = { |
bwang | 6:0a34891a82c7 | 237 | chr_P,chr_A,chr_N,chr_G, |
bwang | 6:0a34891a82c7 | 238 | chr_F,chr_A,chr_S,chr_H, |
bwang | 6:0a34891a82c7 | 239 | chr_D,chr_A,chr_M,chr_O, |
bwang | 6:0a34891a82c7 | 240 | chr_D,chr_R,chr_A,chr_V, |
bwang | 6:0a34891a82c7 | 241 | chr_W,chr_A,chr_L,chr_F, |
bwang | 6:0a34891a82c7 | 242 | }; |
bwang | 6:0a34891a82c7 | 243 | |
dicarloj | 0:7757ab3f7206 | 244 | uint16_t l=0; //current line of scan |
dicarloj | 0:7757ab3f7206 | 245 | |
dicarloj | 0:7757ab3f7206 | 246 | uint8_t im_line_s[H_RES]; //image sync buffer |
dicarloj | 0:7757ab3f7206 | 247 | |
dicarloj | 0:7757ab3f7206 | 248 | uint8_t bl_line_s[H_RES]; //lower 1/4 of screen sync buffer |
dicarloj | 0:7757ab3f7206 | 249 | uint8_t bl_line_v[H_RES]; //lower 1/4 of screen video buffer |
dicarloj | 0:7757ab3f7206 | 250 | uint8_t vb_line_s[H_RES]; //vertical sync, sync buffer |
dicarloj | 0:7757ab3f7206 | 251 | uint8_t vb_line_v[H_RES]; //vertical sync, video buffer |
dicarloj | 0:7757ab3f7206 | 252 | |
dicarloj | 0:7757ab3f7206 | 253 | float cube_a[3] = {15.f, 0.f, 0.f}; |
dicarloj | 0:7757ab3f7206 | 254 | |
dicarloj | 0:7757ab3f7206 | 255 | |
dicarloj | 0:7757ab3f7206 | 256 | float cube_pts[8][3] = { {SIDE,SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 257 | {-SIDE,SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 258 | {-SIDE,-SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 259 | {SIDE,-SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 260 | {SIDE,-SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 261 | {-SIDE,-SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 262 | {-SIDE,SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 263 | {SIDE,SIDE,-HSIDE} }; |
dicarloj | 0:7757ab3f7206 | 264 | |
dicarloj | 0:7757ab3f7206 | 265 | float x_rot[3][3] = { {1.f, 0.f, 0.f}, |
dicarloj | 0:7757ab3f7206 | 266 | {0.f, COS_V, -SIN_V}, |
dicarloj | 0:7757ab3f7206 | 267 | {0.f, SIN_V, COS_V} }; |
dicarloj | 0:7757ab3f7206 | 268 | |
dicarloj | 0:7757ab3f7206 | 269 | float y_rot[3][3] = { {COS_V, 0.f, SIN_V}, |
dicarloj | 0:7757ab3f7206 | 270 | {0.f, 1.f, 0.f}, |
dicarloj | 0:7757ab3f7206 | 271 | {-SIN_V, 0, COS_V} }; |
dicarloj | 0:7757ab3f7206 | 272 | |
dicarloj | 0:7757ab3f7206 | 273 | float z_rot[3][3] = { {COS_V, -SIN_V, 0.f}, |
dicarloj | 0:7757ab3f7206 | 274 | {SIN_V, COS_V, 0.f}, |
dicarloj | 0:7757ab3f7206 | 275 | {0.f, 0.f, 1.f} }; |
dicarloj | 0:7757ab3f7206 | 276 | |
dicarloj | 0:7757ab3f7206 | 277 | |
dicarloj | 0:7757ab3f7206 | 278 | uint8_t im_line_va[H_RES*V_RES]; //image buffer |
dicarloj | 0:7757ab3f7206 | 279 | |
bwang | 1:24fd07a24094 | 280 | //pong variables |
bwang | 4:02e3ae7a3aea | 281 | #define PADDLE_LEN 10 |
bwang | 1:24fd07a24094 | 282 | float p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2; |
bwang | 1:24fd07a24094 | 283 | float p1v = 0.1, p2v = -0.1; |
bwang | 1:24fd07a24094 | 284 | |
bwang | 1:24fd07a24094 | 285 | float bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 1:24fd07a24094 | 286 | float bxv = 0.03, byv = 0.03; |
bwang | 1:24fd07a24094 | 287 | |
bwang | 2:1d16e99f334b | 288 | int s1 = 0, s2 = 0; |
bwang | 2:1d16e99f334b | 289 | |
bwang | 3:d9edc0575aa3 | 290 | //fish variables |
bwang | 3:d9edc0575aa3 | 291 | #define FDEATH_RESET 30000 |
bwang | 3:d9edc0575aa3 | 292 | 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 | 293 | float uv = 0.005; |
bwang | 3:d9edc0575aa3 | 294 | float ux[8] = {53,70,78,78,70,53,45,45}; |
bwang | 3:d9edc0575aa3 | 295 | float uy[8] = {10,10,20,35,50,50,35,20}; |
bwang | 3:d9edc0575aa3 | 296 | float uvx[8] = {-1,1,1,1,1,-1,-1,-1}; |
bwang | 3:d9edc0575aa3 | 297 | float uvy[8] = {1,1,1,-1,-1,-1,-1,1}; |
bwang | 3:d9edc0575aa3 | 298 | int ulive[8] = {1,1,1,1,1,1,1,1}; |
bwang | 3:d9edc0575aa3 | 299 | |
bwang | 6:0a34891a82c7 | 300 | int fdeath_ticker = FDEATH_RESET; |
bwang | 6:0a34891a82c7 | 301 | float fs = 0; |
bwang | 6:0a34891a82c7 | 302 | |
bwang | 4:02e3ae7a3aea | 303 | //tunnel variables |
bwang | 4:02e3ae7a3aea | 304 | #define TUN_LEN (SY_MAX - SY_MIN) |
bwang | 4:02e3ae7a3aea | 305 | uint8_t tunnel[TUN_LEN]; |
bwang | 4:02e3ae7a3aea | 306 | float tunnp = 50; |
bwang | 4:02e3ae7a3aea | 307 | int tundir = 1; |
bwang | 6:0a34891a82c7 | 308 | int leg_ctr = 0; |
bwang | 4:02e3ae7a3aea | 309 | |
bwang | 6:0a34891a82c7 | 310 | //raycaster variables |
bwang | 6:0a34891a82c7 | 311 | #define mapWidth 24 |
bwang | 6:0a34891a82c7 | 312 | #define mapHeight 24 |
bwang | 6:0a34891a82c7 | 313 | |
bwang | 6:0a34891a82c7 | 314 | uint8_t worldMap[mapWidth][mapHeight]= |
bwang | 6:0a34891a82c7 | 315 | { |
bwang | 6:0a34891a82c7 | 316 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, |
bwang | 6:0a34891a82c7 | 317 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 318 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 319 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 320 | {1,0,0,0,0,0,2,2,2,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 321 | {1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 322 | {1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,3,0,0,0,3,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 323 | {1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 324 | {1,0,0,0,0,0,2,2,0,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 325 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 326 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 327 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 328 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 329 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 330 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 331 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 332 | {1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 333 | {1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 334 | {1,4,0,0,0,0,5,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 335 | {1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 336 | {1,4,0,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 337 | {1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 338 | {1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
bwang | 6:0a34891a82c7 | 339 | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} |
bwang | 6:0a34891a82c7 | 340 | }; |
bwang | 6:0a34891a82c7 | 341 | |
bwang | 6:0a34891a82c7 | 342 | float posX = 12, posY = 12; |
bwang | 6:0a34891a82c7 | 343 | float dirX = -1, dirY = 0; |
bwang | 6:0a34891a82c7 | 344 | float planeX = 0, planeY = 0.66; |
bwang | 6:0a34891a82c7 | 345 | float rc_cos = cosf(0.03f); |
bwang | 6:0a34891a82c7 | 346 | float rc_sin = sinf(0.03f); |
bwang | 3:d9edc0575aa3 | 347 | |
bwang | 7:25acb844f424 | 348 | //mode7 variables |
bwang | 7:25acb844f424 | 349 | float m7_theta = 0.8f; |
bwang | 7:25acb844f424 | 350 | float m7_x = mapWidth/2, m7_y=mapHeight/2; |
bwang | 7:25acb844f424 | 351 | |
bwang | 2:1d16e99f334b | 352 | DigitalIn p1_in(A1); |
bwang | 2:1d16e99f334b | 353 | DigitalIn p2_in(A0); |
bwang | 1:24fd07a24094 | 354 | |
dicarloj | 0:7757ab3f7206 | 355 | void make_checkerboard() |
dicarloj | 0:7757ab3f7206 | 356 | { |
dicarloj | 0:7757ab3f7206 | 357 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 358 | for(int j = 0; j < V_RES; j++) |
bwang | 1:24fd07a24094 | 359 | im_line_va[i+j*H_RES] = 0*((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard |
dicarloj | 0:7757ab3f7206 | 360 | |
dicarloj | 0:7757ab3f7206 | 361 | } |
dicarloj | 0:7757ab3f7206 | 362 | |
bwang | 3:d9edc0575aa3 | 363 | void clr() |
bwang | 3:d9edc0575aa3 | 364 | { |
bwang | 3:d9edc0575aa3 | 365 | for(int i = 0; i < H_RES; i++) |
bwang | 3:d9edc0575aa3 | 366 | for(int j = 0; j < V_RES; j++) |
bwang | 3:d9edc0575aa3 | 367 | im_line_va[i+j*H_RES] = 0; |
bwang | 3:d9edc0575aa3 | 368 | |
bwang | 3:d9edc0575aa3 | 369 | } |
bwang | 3:d9edc0575aa3 | 370 | |
dicarloj | 0:7757ab3f7206 | 371 | void init_buffers() |
dicarloj | 0:7757ab3f7206 | 372 | { |
bwang | 3:d9edc0575aa3 | 373 | clr(); |
dicarloj | 0:7757ab3f7206 | 374 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 375 | { |
dicarloj | 0:7757ab3f7206 | 376 | im_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 377 | bl_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 378 | bl_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 379 | vb_line_s[i] = 0; |
dicarloj | 0:7757ab3f7206 | 380 | vb_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 381 | } |
dicarloj | 0:7757ab3f7206 | 382 | im_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 383 | im_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 384 | im_line_s[2] = 0; |
dicarloj | 0:7757ab3f7206 | 385 | bl_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 386 | vb_line_s[0] = 1; |
dicarloj | 0:7757ab3f7206 | 387 | bl_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 388 | vb_line_s[1] = 1; |
dicarloj | 0:7757ab3f7206 | 389 | |
dicarloj | 0:7757ab3f7206 | 390 | |
dicarloj | 0:7757ab3f7206 | 391 | |
dicarloj | 0:7757ab3f7206 | 392 | } |
dicarloj | 0:7757ab3f7206 | 393 | void isr() |
dicarloj | 0:7757ab3f7206 | 394 | { |
dicarloj | 0:7757ab3f7206 | 395 | uint8_t nop = 0; //use nops or use wait_us |
dicarloj | 0:7757ab3f7206 | 396 | uint8_t* sptr; //pointer to sync buffer for line |
dicarloj | 0:7757ab3f7206 | 397 | uint8_t* vptr; //pointer to video buffer for line |
dicarloj | 0:7757ab3f7206 | 398 | if(l < V_RES){ vptr = im_line_va + ((l/4)*H_RES); sptr = im_line_s; nop = 1; } //pick line buffers |
dicarloj | 0:7757ab3f7206 | 399 | else if(l < 254){ vptr = bl_line_v; sptr = bl_line_s; nop = 0; } |
dicarloj | 0:7757ab3f7206 | 400 | else{ vptr = vb_line_v; sptr = vb_line_s; nop = 1;} |
dicarloj | 0:7757ab3f7206 | 401 | uint8_t lmax = nop?H_RES:12; //number of columns |
dicarloj | 0:7757ab3f7206 | 402 | for(uint8_t i = 0; i < lmax; i++) //loop over each column |
dicarloj | 0:7757ab3f7206 | 403 | { |
dicarloj | 0:7757ab3f7206 | 404 | vout = vptr[i]; //set output pins |
dicarloj | 0:7757ab3f7206 | 405 | sout = sptr[i]; |
dicarloj | 0:7757ab3f7206 | 406 | if(nop) //nop delay |
dicarloj | 0:7757ab3f7206 | 407 | { |
dicarloj | 0:7757ab3f7206 | 408 | 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 | 409 | } |
dicarloj | 0:7757ab3f7206 | 410 | else {wait_us(1); if(i > 2) i++;} //wait delay |
dicarloj | 0:7757ab3f7206 | 411 | |
dicarloj | 0:7757ab3f7206 | 412 | |
dicarloj | 0:7757ab3f7206 | 413 | } |
dicarloj | 0:7757ab3f7206 | 414 | //move to next line |
dicarloj | 0:7757ab3f7206 | 415 | l++; |
dicarloj | 0:7757ab3f7206 | 416 | if(l > 255) l = 0; |
dicarloj | 0:7757ab3f7206 | 417 | } |
dicarloj | 0:7757ab3f7206 | 418 | |
dicarloj | 0:7757ab3f7206 | 419 | //coordinates for bouncing ball |
dicarloj | 0:7757ab3f7206 | 420 | |
dicarloj | 0:7757ab3f7206 | 421 | |
dicarloj | 0:7757ab3f7206 | 422 | |
dicarloj | 0:7757ab3f7206 | 423 | int k = 0; |
dicarloj | 0:7757ab3f7206 | 424 | uint16_t px = X_0*10; |
dicarloj | 0:7757ab3f7206 | 425 | uint16_t py = Y_0*10; |
dicarloj | 0:7757ab3f7206 | 426 | uint16_t vx = 10; |
dicarloj | 0:7757ab3f7206 | 427 | uint16_t vy = 10; |
dicarloj | 0:7757ab3f7206 | 428 | uint16_t px2 = X_0*10 + 80; |
dicarloj | 0:7757ab3f7206 | 429 | uint16_t py2 = Y_0*10 - 40; |
dicarloj | 0:7757ab3f7206 | 430 | uint16_t vx2 = 3; |
dicarloj | 0:7757ab3f7206 | 431 | uint16_t vy2 = -4; |
dicarloj | 0:7757ab3f7206 | 432 | |
dicarloj | 0:7757ab3f7206 | 433 | int16_t sign(int16_t a) |
dicarloj | 0:7757ab3f7206 | 434 | { |
dicarloj | 0:7757ab3f7206 | 435 | if(a > 0) return 1; |
dicarloj | 0:7757ab3f7206 | 436 | if(a < 0) return -1; |
dicarloj | 0:7757ab3f7206 | 437 | return 0; |
dicarloj | 0:7757ab3f7206 | 438 | } |
dicarloj | 0:7757ab3f7206 | 439 | |
dicarloj | 0:7757ab3f7206 | 440 | void draw_vert(int16_t y0, int16_t y1, int16_t x0) |
dicarloj | 0:7757ab3f7206 | 441 | { |
dicarloj | 0:7757ab3f7206 | 442 | for(int16_t i = y0; i < y1; i++) |
dicarloj | 0:7757ab3f7206 | 443 | im_line_va[H_RES*i + x0] = 1; |
dicarloj | 0:7757ab3f7206 | 444 | } |
dicarloj | 0:7757ab3f7206 | 445 | |
dicarloj | 0:7757ab3f7206 | 446 | void draw_horiz(int16_t x0, int16_t x1, int16_t y0) |
dicarloj | 0:7757ab3f7206 | 447 | { |
dicarloj | 0:7757ab3f7206 | 448 | for(int16_t i = x0; i < x1; i++) |
dicarloj | 0:7757ab3f7206 | 449 | im_line_va[H_RES*y0 + i] = 1; |
dicarloj | 0:7757ab3f7206 | 450 | } |
dicarloj | 0:7757ab3f7206 | 451 | |
dicarloj | 0:7757ab3f7206 | 452 | int16_t imin(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 453 | { |
dicarloj | 0:7757ab3f7206 | 454 | if(a<b) return a; |
dicarloj | 0:7757ab3f7206 | 455 | return b; |
dicarloj | 0:7757ab3f7206 | 456 | } |
dicarloj | 0:7757ab3f7206 | 457 | |
dicarloj | 0:7757ab3f7206 | 458 | int16_t imax(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 459 | { |
dicarloj | 0:7757ab3f7206 | 460 | if(a>b) return a; |
dicarloj | 0:7757ab3f7206 | 461 | return b; |
dicarloj | 0:7757ab3f7206 | 462 | } |
dicarloj | 0:7757ab3f7206 | 463 | |
dicarloj | 0:7757ab3f7206 | 464 | void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1) |
dicarloj | 0:7757ab3f7206 | 465 | { |
dicarloj | 0:7757ab3f7206 | 466 | if(x0 > x1){ x0 = x0 ^ x1; x1 = x1^x0; x0 = x0^x1;y0 = y0 ^ y1; y1 = y1^y0; y0 = y0^y1; } |
dicarloj | 0:7757ab3f7206 | 467 | if(x0 == x1){draw_vert(y0,y1,x0);} |
dicarloj | 0:7757ab3f7206 | 468 | if(y0 == y1){draw_horiz(x0,x1,y0);} |
dicarloj | 0:7757ab3f7206 | 469 | int16_t dx = x1 - x0; |
dicarloj | 0:7757ab3f7206 | 470 | int16_t dy = y1 - y0; |
dicarloj | 0:7757ab3f7206 | 471 | float derr = fabs((float)(dy)/(float)(dx)); |
dicarloj | 0:7757ab3f7206 | 472 | float err = 0.f; |
dicarloj | 0:7757ab3f7206 | 473 | int16_t y = y0; |
dicarloj | 0:7757ab3f7206 | 474 | for(int16_t x = x0; x < x1; x++) |
dicarloj | 0:7757ab3f7206 | 475 | { |
dicarloj | 0:7757ab3f7206 | 476 | //plotxy |
dicarloj | 0:7757ab3f7206 | 477 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 478 | err += derr; |
dicarloj | 0:7757ab3f7206 | 479 | while(err >= 0.5f) |
dicarloj | 0:7757ab3f7206 | 480 | { |
dicarloj | 0:7757ab3f7206 | 481 | y += sign(dy); |
dicarloj | 0:7757ab3f7206 | 482 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 483 | err -= 1.f; |
dicarloj | 0:7757ab3f7206 | 484 | } |
dicarloj | 0:7757ab3f7206 | 485 | } |
dicarloj | 0:7757ab3f7206 | 486 | } |
dicarloj | 0:7757ab3f7206 | 487 | |
dicarloj | 0:7757ab3f7206 | 488 | void draw_cube(float cp[][3]) |
dicarloj | 0:7757ab3f7206 | 489 | { |
dicarloj | 0:7757ab3f7206 | 490 | for(uint8_t i = 0; i < 7; i++) |
dicarloj | 0:7757ab3f7206 | 491 | { |
dicarloj | 0:7757ab3f7206 | 492 | 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 | 493 | } |
dicarloj | 0:7757ab3f7206 | 494 | 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 | 495 | 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 | 496 | 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 | 497 | 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 | 498 | 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 | 499 | } |
dicarloj | 0:7757ab3f7206 | 500 | |
dicarloj | 0:7757ab3f7206 | 501 | void apply_rot(float cp[][3], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 502 | { |
dicarloj | 0:7757ab3f7206 | 503 | for(uint8_t pti = 0; pti < 8; pti++) |
dicarloj | 0:7757ab3f7206 | 504 | { |
dicarloj | 0:7757ab3f7206 | 505 | float* cpt = cp[pti]; |
dicarloj | 0:7757ab3f7206 | 506 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 507 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 508 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 509 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 510 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 511 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 512 | } |
dicarloj | 0:7757ab3f7206 | 513 | } |
dicarloj | 0:7757ab3f7206 | 514 | |
dicarloj | 0:7757ab3f7206 | 515 | void apply_xf_rot(float cpt[], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 516 | { |
dicarloj | 0:7757ab3f7206 | 517 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 518 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 519 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 520 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 521 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 522 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 523 | } |
dicarloj | 0:7757ab3f7206 | 524 | |
dicarloj | 0:7757ab3f7206 | 525 | void draw_v_check(int8_t r,uint8_t tt) |
dicarloj | 0:7757ab3f7206 | 526 | { |
dicarloj | 0:7757ab3f7206 | 527 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 528 | for(int j = 0; j < V_RES; j++) |
dicarloj | 0:7757ab3f7206 | 529 | im_line_va[i+j*H_RES] = (((i > 20) && (i < 98)) && ( tt ^(((j%(r*2))>=r) ^ ((i%(r*2)))>=r))); //checkerboard |
dicarloj | 0:7757ab3f7206 | 530 | } |
dicarloj | 0:7757ab3f7206 | 531 | |
dicarloj | 0:7757ab3f7206 | 532 | |
dicarloj | 0:7757ab3f7206 | 533 | int jjj = 0; |
dicarloj | 0:7757ab3f7206 | 534 | int f_count = DEMO_LENGTH + 10; |
dicarloj | 0:7757ab3f7206 | 535 | void draw_cube_spin(int kkkk); |
dicarloj | 0:7757ab3f7206 | 536 | //update bouncing balls |
dicarloj | 0:7757ab3f7206 | 537 | |
dicarloj | 0:7757ab3f7206 | 538 | void draw_blank() |
dicarloj | 0:7757ab3f7206 | 539 | { |
dicarloj | 0:7757ab3f7206 | 540 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 541 | { |
dicarloj | 0:7757ab3f7206 | 542 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 543 | { |
dicarloj | 0:7757ab3f7206 | 544 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 545 | } |
dicarloj | 0:7757ab3f7206 | 546 | } |
dicarloj | 0:7757ab3f7206 | 547 | } |
dicarloj | 0:7757ab3f7206 | 548 | |
dicarloj | 0:7757ab3f7206 | 549 | void wipe(); |
dicarloj | 0:7757ab3f7206 | 550 | |
dicarloj | 0:7757ab3f7206 | 551 | void update_image() |
dicarloj | 0:7757ab3f7206 | 552 | { |
dicarloj | 0:7757ab3f7206 | 553 | //delay |
dicarloj | 0:7757ab3f7206 | 554 | k++; |
dicarloj | 0:7757ab3f7206 | 555 | if(k%4000) return; |
dicarloj | 0:7757ab3f7206 | 556 | f_count++; |
dicarloj | 0:7757ab3f7206 | 557 | if(f_count < DEMO_LENGTH/2) |
dicarloj | 0:7757ab3f7206 | 558 | { |
dicarloj | 0:7757ab3f7206 | 559 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 560 | } |
dicarloj | 0:7757ab3f7206 | 561 | else if(f_count < DEMO_LENGTH) |
dicarloj | 0:7757ab3f7206 | 562 | { |
bwang | 1:24fd07a24094 | 563 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 564 | } |
bwang | 1:24fd07a24094 | 565 | else if(f_count < DEMO_LENGTH * 1.22) |
dicarloj | 0:7757ab3f7206 | 566 | { |
dicarloj | 0:7757ab3f7206 | 567 | for(int k = 1; k < 10; k++) |
bwang | 1:24fd07a24094 | 568 | //for(int kk = 1; kk < 3; kk++) |
dicarloj | 0:7757ab3f7206 | 569 | { |
dicarloj | 0:7757ab3f7206 | 570 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 571 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 572 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 573 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 574 | } |
dicarloj | 0:7757ab3f7206 | 575 | |
dicarloj | 0:7757ab3f7206 | 576 | draw_v_check(1,0); |
dicarloj | 0:7757ab3f7206 | 577 | wipe(); |
dicarloj | 0:7757ab3f7206 | 578 | f_count = 0; |
dicarloj | 0:7757ab3f7206 | 579 | } |
dicarloj | 0:7757ab3f7206 | 580 | } |
dicarloj | 0:7757ab3f7206 | 581 | |
dicarloj | 0:7757ab3f7206 | 582 | void wipe() |
dicarloj | 0:7757ab3f7206 | 583 | { |
dicarloj | 0:7757ab3f7206 | 584 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 585 | { |
dicarloj | 0:7757ab3f7206 | 586 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 587 | { |
dicarloj | 0:7757ab3f7206 | 588 | im_line_va[v*H_RES+h] = 1; |
dicarloj | 0:7757ab3f7206 | 589 | } |
bwang | 1:24fd07a24094 | 590 | wait(.01); |
dicarloj | 0:7757ab3f7206 | 591 | } |
dicarloj | 0:7757ab3f7206 | 592 | |
dicarloj | 0:7757ab3f7206 | 593 | for(int v = Y_MAX+15; v > Y_MIN; v--) |
dicarloj | 0:7757ab3f7206 | 594 | { |
dicarloj | 0:7757ab3f7206 | 595 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 596 | { |
dicarloj | 0:7757ab3f7206 | 597 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 598 | } |
bwang | 1:24fd07a24094 | 599 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 600 | } |
dicarloj | 0:7757ab3f7206 | 601 | |
dicarloj | 0:7757ab3f7206 | 602 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 603 | { |
dicarloj | 0:7757ab3f7206 | 604 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 605 | { |
dicarloj | 0:7757ab3f7206 | 606 | im_line_va[v*H_RES + h] = 1; |
dicarloj | 0:7757ab3f7206 | 607 | } |
bwang | 1:24fd07a24094 | 608 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 609 | } |
dicarloj | 0:7757ab3f7206 | 610 | |
dicarloj | 0:7757ab3f7206 | 611 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 612 | { |
dicarloj | 0:7757ab3f7206 | 613 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 614 | { |
dicarloj | 0:7757ab3f7206 | 615 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 616 | } |
bwang | 1:24fd07a24094 | 617 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 618 | } |
dicarloj | 0:7757ab3f7206 | 619 | |
dicarloj | 0:7757ab3f7206 | 620 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 621 | { |
dicarloj | 0:7757ab3f7206 | 622 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 623 | { |
dicarloj | 0:7757ab3f7206 | 624 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 625 | } |
dicarloj | 0:7757ab3f7206 | 626 | } |
dicarloj | 0:7757ab3f7206 | 627 | } |
dicarloj | 0:7757ab3f7206 | 628 | |
dicarloj | 0:7757ab3f7206 | 629 | void draw_cube_spin(int kkkk) |
dicarloj | 0:7757ab3f7206 | 630 | { |
dicarloj | 0:7757ab3f7206 | 631 | draw_line_inv = kkkk; |
dicarloj | 0:7757ab3f7206 | 632 | //blank |
dicarloj | 0:7757ab3f7206 | 633 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 634 | { |
dicarloj | 0:7757ab3f7206 | 635 | for(uint16_t v = Y_MIN; v < Y_MAX; v++) |
dicarloj | 0:7757ab3f7206 | 636 | { |
dicarloj | 0:7757ab3f7206 | 637 | if( (h > 22) && (h < 76+18)) |
dicarloj | 0:7757ab3f7206 | 638 | im_line_va[v*H_RES + h] = kkkk; |
dicarloj | 0:7757ab3f7206 | 639 | } |
dicarloj | 0:7757ab3f7206 | 640 | } |
dicarloj | 0:7757ab3f7206 | 641 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 642 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 643 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 644 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 645 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 646 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 647 | apply_rot(cube_pts,z_rot); |
dicarloj | 0:7757ab3f7206 | 648 | //draw ball |
dicarloj | 0:7757ab3f7206 | 649 | im_line_va[(py/10)*H_RES + (px/10)] = 1; |
dicarloj | 0:7757ab3f7206 | 650 | draw_line(X_0,Y_0,(px/10),(py/10)); |
dicarloj | 0:7757ab3f7206 | 651 | draw_cube(cube_pts); |
dicarloj | 0:7757ab3f7206 | 652 | |
dicarloj | 0:7757ab3f7206 | 653 | //update position/check for bounces |
dicarloj | 0:7757ab3f7206 | 654 | px += vx; |
dicarloj | 0:7757ab3f7206 | 655 | py += vy; |
dicarloj | 0:7757ab3f7206 | 656 | px2 += vx2; |
dicarloj | 0:7757ab3f7206 | 657 | py2 += vy2; |
dicarloj | 0:7757ab3f7206 | 658 | if(px/10 > (X_MAX-2) || px/10 < (X_MIN+1)) vx = -vx; |
dicarloj | 0:7757ab3f7206 | 659 | if(py/10 > (Y_MAX-2) || py/10 < (Y_MIN+1)) vy = -vy; |
dicarloj | 0:7757ab3f7206 | 660 | if(px2/10 > (X_MAX-2) || px2/10 < (X_MIN+1)) vx2 = -vx2; |
dicarloj | 0:7757ab3f7206 | 661 | if(py2/10 > (Y_MAX-2) || py2/10 < (Y_MIN+1)) vy2 = -vy2; |
dicarloj | 0:7757ab3f7206 | 662 | if(k%(8000*50)) return; |
dicarloj | 0:7757ab3f7206 | 663 | |
dicarloj | 0:7757ab3f7206 | 664 | jjj = !jjj; |
dicarloj | 0:7757ab3f7206 | 665 | int bmi = 0; |
dicarloj | 0:7757ab3f7206 | 666 | for(int y = BY_0; y < BY_0 + BY; y++) |
dicarloj | 0:7757ab3f7206 | 667 | { |
dicarloj | 0:7757ab3f7206 | 668 | for(int x = BX_0; x < BX_0 + BX; x++) |
dicarloj | 0:7757ab3f7206 | 669 | { |
dicarloj | 0:7757ab3f7206 | 670 | im_line_va[H_RES*y + x] = kkkk^(miters[bmi]*jjj + (!jjj)*tv[bmi]); |
dicarloj | 0:7757ab3f7206 | 671 | bmi++; |
dicarloj | 0:7757ab3f7206 | 672 | } |
dicarloj | 0:7757ab3f7206 | 673 | } |
dicarloj | 0:7757ab3f7206 | 674 | } |
dicarloj | 0:7757ab3f7206 | 675 | |
bwang | 3:d9edc0575aa3 | 676 | int flappy_pong() { |
bwang | 3:d9edc0575aa3 | 677 | |
bwang | 3:d9edc0575aa3 | 678 | //clear frame |
bwang | 3:d9edc0575aa3 | 679 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 3:d9edc0575aa3 | 680 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 0; |
bwang | 3:d9edc0575aa3 | 681 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 0; |
bwang | 3:d9edc0575aa3 | 682 | } |
bwang | 3:d9edc0575aa3 | 683 | im_line_va[H_RES*(int)by+(int)bx] = 0; |
bwang | 3:d9edc0575aa3 | 684 | //read inputs |
bwang | 3:d9edc0575aa3 | 685 | int cmd1 = p1_in.read(); |
bwang | 3:d9edc0575aa3 | 686 | int cmd2 = p2_in.read(); |
bwang | 3:d9edc0575aa3 | 687 | if (cmd1 == 0) p1v = 0.1; else p1v = -0.1f; |
bwang | 3:d9edc0575aa3 | 688 | if (cmd2 == 0) p2v = 0.1; else p2v = -0.1f; |
bwang | 3:d9edc0575aa3 | 689 | |
bwang | 3:d9edc0575aa3 | 690 | p1 += p1v; |
bwang | 3:d9edc0575aa3 | 691 | p2 += p2v; |
bwang | 3:d9edc0575aa3 | 692 | bx += bxv; |
bwang | 3:d9edc0575aa3 | 693 | by += byv; |
bwang | 3:d9edc0575aa3 | 694 | |
bwang | 3:d9edc0575aa3 | 695 | if (p1 < SY_MIN) p1 = SY_MIN; |
bwang | 3:d9edc0575aa3 | 696 | if (p1 > SY_MAX-PADDLE_LEN) p1 = SY_MAX-PADDLE_LEN; |
bwang | 3:d9edc0575aa3 | 697 | if (p2 < SY_MIN) p2 = SY_MIN; |
bwang | 3:d9edc0575aa3 | 698 | if (p2 > SY_MAX-PADDLE_LEN) p2 = SY_MAX-PADDLE_LEN; |
bwang | 3:d9edc0575aa3 | 699 | |
bwang | 3:d9edc0575aa3 | 700 | if (bx < SX_MIN) { |
bwang | 3:d9edc0575aa3 | 701 | bxv = -bxv; |
bwang | 3:d9edc0575aa3 | 702 | bx = SX_MIN; |
bwang | 3:d9edc0575aa3 | 703 | if (by < p1 - 3 || by > p1 + PADDLE_LEN + 3) { |
bwang | 3:d9edc0575aa3 | 704 | im_line_va[H_RES*(SY_MIN-2)+2*s1+SX_MIN] = 1; |
bwang | 3:d9edc0575aa3 | 705 | bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 3:d9edc0575aa3 | 706 | s1++; |
bwang | 3:d9edc0575aa3 | 707 | if (s1>14) return 0; |
bwang | 3:d9edc0575aa3 | 708 | } |
bwang | 3:d9edc0575aa3 | 709 | } |
bwang | 3:d9edc0575aa3 | 710 | if (bx > SX_MAX) { |
bwang | 3:d9edc0575aa3 | 711 | bxv = -bxv; |
bwang | 3:d9edc0575aa3 | 712 | bx = SX_MAX; |
bwang | 3:d9edc0575aa3 | 713 | if (by < p2 - 3 || by > p2 + PADDLE_LEN + 3) { |
bwang | 3:d9edc0575aa3 | 714 | im_line_va[H_RES*(SY_MAX+2)+2*s2+SX_MIN] = 1; |
bwang | 3:d9edc0575aa3 | 715 | bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 3:d9edc0575aa3 | 716 | s2++; |
bwang | 3:d9edc0575aa3 | 717 | if (s2>14) return 0; |
bwang | 3:d9edc0575aa3 | 718 | } |
bwang | 3:d9edc0575aa3 | 719 | } |
bwang | 3:d9edc0575aa3 | 720 | if (by < SY_MIN) {byv = -byv; by = SY_MIN;} |
bwang | 3:d9edc0575aa3 | 721 | if (by > SY_MAX) {byv = -byv; by = SY_MAX;} |
bwang | 3:d9edc0575aa3 | 722 | |
bwang | 1:24fd07a24094 | 723 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 724 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1; |
bwang | 1:24fd07a24094 | 725 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1; |
bwang | 1:24fd07a24094 | 726 | } |
bwang | 1:24fd07a24094 | 727 | im_line_va[H_RES*(int)by+(int)bx] = 1; |
bwang | 3:d9edc0575aa3 | 728 | |
bwang | 3:d9edc0575aa3 | 729 | wait(1/1200.0f); |
bwang | 3:d9edc0575aa3 | 730 | return 1; |
bwang | 3:d9edc0575aa3 | 731 | } |
bwang | 3:d9edc0575aa3 | 732 | |
bwang | 3:d9edc0575aa3 | 733 | int fishy() { |
bwang | 3:d9edc0575aa3 | 734 | uint16_t xstart, ystart, xend, yend; |
bwang | 3:d9edc0575aa3 | 735 | float s = sinf(ftheta); |
bwang | 3:d9edc0575aa3 | 736 | float c = cosf(ftheta); |
bwang | 3:d9edc0575aa3 | 737 | |
bwang | 3:d9edc0575aa3 | 738 | xstart = (uint16_t) fx; |
bwang | 3:d9edc0575aa3 | 739 | ystart = (uint16_t) fy; |
bwang | 3:d9edc0575aa3 | 740 | |
bwang | 3:d9edc0575aa3 | 741 | |
bwang | 3:d9edc0575aa3 | 742 | for(int x = xstart-5; x < xstart + 5; x++) { |
bwang | 3:d9edc0575aa3 | 743 | for (int y = ystart - 5; y < ystart + 5; y++) { |
bwang | 3:d9edc0575aa3 | 744 | im_line_va[H_RES*y+x] = 0; |
bwang | 3:d9edc0575aa3 | 745 | } |
bwang | 3:d9edc0575aa3 | 746 | } |
bwang | 3:d9edc0575aa3 | 747 | for (int i = 0; i < 8; i++) { |
bwang | 3:d9edc0575aa3 | 748 | int index = H_RES*(int)uy[i]+(int)ux[i]; |
bwang | 3:d9edc0575aa3 | 749 | im_line_va[index] = 0; |
bwang | 3:d9edc0575aa3 | 750 | } |
bwang | 3:d9edc0575aa3 | 751 | |
bwang | 3:d9edc0575aa3 | 752 | float fx_old = fx, fy_old = fy; |
bwang | 3:d9edc0575aa3 | 753 | fx += fv * s; |
bwang | 3:d9edc0575aa3 | 754 | fy += fv * c; |
bwang | 3:d9edc0575aa3 | 755 | int cmd = p1_in.read(); |
bwang | 3:d9edc0575aa3 | 756 | if (cmd) ftheta += fa; else ftheta -= fa; |
bwang | 3:d9edc0575aa3 | 757 | if (ftheta >= 2 * 3.1415926) ftheta -= 2 * 3.1415926; |
bwang | 3:d9edc0575aa3 | 758 | if (ftheta < 0) ftheta += 2 * 3.1415926; |
bwang | 3:d9edc0575aa3 | 759 | |
bwang | 3:d9edc0575aa3 | 760 | s = sinf(ftheta); |
bwang | 3:d9edc0575aa3 | 761 | c = cosf(ftheta); |
bwang | 3:d9edc0575aa3 | 762 | |
bwang | 3:d9edc0575aa3 | 763 | xstart = (uint16_t)fx; |
bwang | 3:d9edc0575aa3 | 764 | ystart = (uint16_t)fy; |
bwang | 3:d9edc0575aa3 | 765 | xend = (uint16_t)(fx+s*4); |
bwang | 3:d9edc0575aa3 | 766 | yend = (uint16_t)(fy+c*4); |
bwang | 3:d9edc0575aa3 | 767 | |
bwang | 3:d9edc0575aa3 | 768 | if (xstart < SX_MIN || xstart > SX_MAX || |
bwang | 3:d9edc0575aa3 | 769 | ystart < SY_MIN || ystart > SY_MAX || |
bwang | 3:d9edc0575aa3 | 770 | xend < SX_MIN || xend > SX_MAX || |
bwang | 3:d9edc0575aa3 | 771 | yend < SY_MIN || yend > SY_MAX) { |
bwang | 3:d9edc0575aa3 | 772 | fx = fx_old; |
bwang | 3:d9edc0575aa3 | 773 | fy = fy_old; |
bwang | 3:d9edc0575aa3 | 774 | xstart = (uint16_t)fx; |
bwang | 3:d9edc0575aa3 | 775 | ystart = (uint16_t)fy; |
bwang | 3:d9edc0575aa3 | 776 | xend = (uint16_t)(fx+s*4); |
bwang | 3:d9edc0575aa3 | 777 | yend = (uint16_t)(fy+c*4); |
bwang | 3:d9edc0575aa3 | 778 | } |
bwang | 3:d9edc0575aa3 | 779 | |
bwang | 3:d9edc0575aa3 | 780 | draw_line(xstart, ystart, xend, yend); |
bwang | 3:d9edc0575aa3 | 781 | for (int i = 0; i < 8; i++) { |
bwang | 3:d9edc0575aa3 | 782 | if (!ulive[i]) continue; |
bwang | 3:d9edc0575aa3 | 783 | if (xstart == (int)ux[i] && ystart == (int)uy[i]) { |
bwang | 3:d9edc0575aa3 | 784 | fdeath_ticker = FDEATH_RESET; |
bwang | 3:d9edc0575aa3 | 785 | fs+=1; |
bwang | 3:d9edc0575aa3 | 786 | ulive[i] = 0; |
bwang | 3:d9edc0575aa3 | 787 | } |
bwang | 3:d9edc0575aa3 | 788 | ux[i]+= uv*uvx[i]; |
bwang | 3:d9edc0575aa3 | 789 | uy[i]+= uv*uvy[i]; |
bwang | 3:d9edc0575aa3 | 790 | if (ux[i] < SX_MIN) {ux[i] = SX_MIN; uvx[i] = -uvx[i];} |
bwang | 3:d9edc0575aa3 | 791 | if (ux[i] > SX_MAX) {ux[i] = SX_MAX; uvx[i] = -uvx[i];} |
bwang | 3:d9edc0575aa3 | 792 | if (uy[i] < SY_MIN) {uy[i] = SY_MIN; uvy[i] = -uvy[i];} |
bwang | 3:d9edc0575aa3 | 793 | if (uy[i] > SY_MAX) {uy[i] = SY_MAX; uvy[i] = -uvy[i];} |
bwang | 3:d9edc0575aa3 | 794 | |
bwang | 3:d9edc0575aa3 | 795 | int index = H_RES*(int)uy[i]+(int)ux[i]; |
bwang | 3:d9edc0575aa3 | 796 | im_line_va[index] = 1; |
bwang | 3:d9edc0575aa3 | 797 | } |
bwang | 3:d9edc0575aa3 | 798 | for (int i = 0; i < 8; i++) { |
bwang | 3:d9edc0575aa3 | 799 | im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 0; |
bwang | 3:d9edc0575aa3 | 800 | } |
bwang | 3:d9edc0575aa3 | 801 | for (int i = 0; i < fs; i++) { |
bwang | 3:d9edc0575aa3 | 802 | im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 1; |
bwang | 3:d9edc0575aa3 | 803 | } |
bwang | 3:d9edc0575aa3 | 804 | fdeath_ticker--; |
bwang | 3:d9edc0575aa3 | 805 | if (fdeath_ticker < 0) fs -= 0.0001f; |
bwang | 3:d9edc0575aa3 | 806 | if (fs < 0) fs = 0; |
bwang | 3:d9edc0575aa3 | 807 | |
bwang | 3:d9edc0575aa3 | 808 | return 1; |
bwang | 3:d9edc0575aa3 | 809 | } |
bwang | 3:d9edc0575aa3 | 810 | |
bwang | 3:d9edc0575aa3 | 811 | void dispchr(int x0, int y0, uint8_t* chr) { |
bwang | 3:d9edc0575aa3 | 812 | int bmi = 0; |
bwang | 3:d9edc0575aa3 | 813 | for(int y = SY_MIN + y0; y < SY_MIN + y0 + 7; y++) |
bwang | 1:24fd07a24094 | 814 | { |
bwang | 3:d9edc0575aa3 | 815 | for(int x = SX_MIN + x0; x < SX_MIN + x0 + 6; x++) |
bwang | 3:d9edc0575aa3 | 816 | { |
bwang | 3:d9edc0575aa3 | 817 | im_line_va[H_RES*y + x] = chr[bmi]; |
bwang | 3:d9edc0575aa3 | 818 | bmi++; |
bwang | 1:24fd07a24094 | 819 | } |
bwang | 3:d9edc0575aa3 | 820 | } |
bwang | 3:d9edc0575aa3 | 821 | } |
bwang | 3:d9edc0575aa3 | 822 | |
bwang | 4:02e3ae7a3aea | 823 | void dispsprite(int x0, int y0, uint8_t* chr) { |
bwang | 4:02e3ae7a3aea | 824 | int bmi = 0; |
bwang | 4:02e3ae7a3aea | 825 | for(int y = SY_MIN + y0; y < SY_MIN + y0 + 8; y++) |
bwang | 4:02e3ae7a3aea | 826 | { |
bwang | 4:02e3ae7a3aea | 827 | for(int x = SX_MIN + x0; x < SX_MIN + x0 + 7; x++) |
bwang | 4:02e3ae7a3aea | 828 | { |
bwang | 5:2859a892497f | 829 | if (chr[bmi]) im_line_va[H_RES*y + x] = chr[bmi]; |
bwang | 4:02e3ae7a3aea | 830 | bmi++; |
bwang | 4:02e3ae7a3aea | 831 | } |
bwang | 4:02e3ae7a3aea | 832 | } |
bwang | 4:02e3ae7a3aea | 833 | } |
bwang | 4:02e3ae7a3aea | 834 | |
bwang | 4:02e3ae7a3aea | 835 | void disp_tunnel() { |
bwang | 4:02e3ae7a3aea | 836 | for (int y = SY_MIN; y < SY_MAX; y++) { |
bwang | 4:02e3ae7a3aea | 837 | int tunw = 30 * (y) / TUN_LEN; |
bwang | 4:02e3ae7a3aea | 838 | int yy = SY_MAX-(SY_MAX-y)*3/4; |
bwang | 5:2859a892497f | 839 | 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 | 840 | 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 | 841 | 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 | 842 | } |
bwang | 4:02e3ae7a3aea | 843 | } |
bwang | 4:02e3ae7a3aea | 844 | |
bwang | 4:02e3ae7a3aea | 845 | void init_tunnel() { |
bwang | 4:02e3ae7a3aea | 846 | for (int i = 0; i < TUN_LEN; i++) tunnel[i] = 20; |
bwang | 4:02e3ae7a3aea | 847 | disp_tunnel(); |
bwang | 4:02e3ae7a3aea | 848 | |
bwang | 4:02e3ae7a3aea | 849 | int bmi = 0; |
bwang | 4:02e3ae7a3aea | 850 | |
bwang | 4:02e3ae7a3aea | 851 | for(int y = SY_MIN; y < SY_MIN + BY; y++) |
bwang | 4:02e3ae7a3aea | 852 | { |
bwang | 4:02e3ae7a3aea | 853 | for(int x = SX_MIN; x < SX_MIN + BX; x++) |
bwang | 4:02e3ae7a3aea | 854 | { |
bwang | 4:02e3ae7a3aea | 855 | im_line_va[H_RES*y + x + 10] = tv[bmi]; |
bwang | 4:02e3ae7a3aea | 856 | bmi++; |
bwang | 4:02e3ae7a3aea | 857 | } |
bwang | 4:02e3ae7a3aea | 858 | } |
bwang | 4:02e3ae7a3aea | 859 | dispsprite(1,2,sprite_tree); |
bwang | 4:02e3ae7a3aea | 860 | dispsprite(50,2,sprite_tree); |
bwang | 4:02e3ae7a3aea | 861 | dispsprite(11,2,sprite_tree); |
bwang | 4:02e3ae7a3aea | 862 | } |
bwang | 4:02e3ae7a3aea | 863 | |
bwang | 4:02e3ae7a3aea | 864 | void update_tunnel() { |
bwang | 4:02e3ae7a3aea | 865 | for (int j = TUN_LEN-1; j > 0; j--) tunnel[j] = tunnel[j-1]; |
bwang | 4:02e3ae7a3aea | 866 | |
bwang | 5:2859a892497f | 867 | int x = rand() % 48; |
bwang | 4:02e3ae7a3aea | 868 | if (x == 0) tundir = -tundir; |
bwang | 5:2859a892497f | 869 | if (x > 24) tunnel[0] = tunnel[0]+tundir; |
bwang | 4:02e3ae7a3aea | 870 | |
bwang | 4:02e3ae7a3aea | 871 | if (tunnel[0] < 1) { |
bwang | 4:02e3ae7a3aea | 872 | tunnel[0] = 1; |
bwang | 4:02e3ae7a3aea | 873 | tundir = 1; |
bwang | 4:02e3ae7a3aea | 874 | } |
bwang | 4:02e3ae7a3aea | 875 | if (SX_MIN + tunnel[0] + 30 + 1 > SX_MAX) { |
bwang | 4:02e3ae7a3aea | 876 | tunnel[0] = SX_MAX-SX_MIN-30-1; |
bwang | 4:02e3ae7a3aea | 877 | tundir = -1; |
bwang | 4:02e3ae7a3aea | 878 | } |
bwang | 4:02e3ae7a3aea | 879 | |
bwang | 4:02e3ae7a3aea | 880 | disp_tunnel(); |
bwang | 4:02e3ae7a3aea | 881 | |
bwang | 4:02e3ae7a3aea | 882 | int cmd1 = p1_in.read(); |
bwang | 4:02e3ae7a3aea | 883 | int cmd2 = p2_in.read(); |
bwang | 5:2859a892497f | 884 | if (cmd1) tunnp+=1.0f; |
bwang | 5:2859a892497f | 885 | if (cmd2) tunnp-=1.0f; |
bwang | 5:2859a892497f | 886 | if (tunnp<SX_MIN+8) tunnp = SX_MIN+8; |
bwang | 5:2859a892497f | 887 | if (tunnp>SX_MAX-8) tunnp = SX_MAX-8; |
bwang | 6:0a34891a82c7 | 888 | leg_ctr++; |
bwang | 6:0a34891a82c7 | 889 | if (leg_ctr == 50) leg_ctr = 0; |
bwang | 6:0a34891a82c7 | 890 | if (leg_ctr < 25) dispsprite((int)(tunnp-SX_MIN), 31, sprite_manl); |
bwang | 6:0a34891a82c7 | 891 | else dispsprite((int)(tunnp-SX_MIN), 31, sprite_manr); |
bwang | 4:02e3ae7a3aea | 892 | |
bwang | 5:2859a892497f | 893 | wait(0.01); |
bwang | 4:02e3ae7a3aea | 894 | } |
bwang | 6:0a34891a82c7 | 895 | |
bwang | 6:0a34891a82c7 | 896 | void update_rc() { |
bwang | 6:0a34891a82c7 | 897 | int cmd1 = p1_in.read(); |
bwang | 6:0a34891a82c7 | 898 | int cmd2 = p2_in.read(); |
bwang | 6:0a34891a82c7 | 899 | if (!cmd1) { |
bwang | 6:0a34891a82c7 | 900 | float oldDirX = dirX; |
bwang | 6:0a34891a82c7 | 901 | dirX = dirX * rc_cos - dirY * rc_sin; |
bwang | 6:0a34891a82c7 | 902 | dirY = oldDirX * rc_sin + dirY * rc_cos; |
bwang | 6:0a34891a82c7 | 903 | float oldPlaneX = planeX; |
bwang | 6:0a34891a82c7 | 904 | planeX = planeX * rc_cos - planeY * rc_sin; |
bwang | 6:0a34891a82c7 | 905 | planeY = oldPlaneX * rc_sin + planeY * rc_cos; |
bwang | 6:0a34891a82c7 | 906 | } |
bwang | 6:0a34891a82c7 | 907 | if (!cmd2) { |
bwang | 6:0a34891a82c7 | 908 | float oldDirX = dirX; |
bwang | 6:0a34891a82c7 | 909 | dirX = dirX * rc_cos + dirY * rc_sin; |
bwang | 6:0a34891a82c7 | 910 | dirY = -oldDirX * rc_sin + dirY * rc_cos; |
bwang | 6:0a34891a82c7 | 911 | float oldPlaneX = planeX; |
bwang | 6:0a34891a82c7 | 912 | planeX = planeX * rc_cos + planeY * rc_sin; |
bwang | 6:0a34891a82c7 | 913 | planeY = -oldPlaneX * rc_sin + planeY * rc_cos; |
bwang | 6:0a34891a82c7 | 914 | } |
bwang | 6:0a34891a82c7 | 915 | if(worldMap[int(posX + dirX * 0.01f)][int(posY)] == false) posX += dirX * 0.01f; |
bwang | 6:0a34891a82c7 | 916 | if(worldMap[int(posX)][int(posY + dirY * 0.01f)] == false) posY += dirY * 0.01f; |
bwang | 6:0a34891a82c7 | 917 | |
bwang | 6:0a34891a82c7 | 918 | int w = SX_MAX-SX_MIN; |
bwang | 6:0a34891a82c7 | 919 | int h = SY_MAX-SY_MIN; |
bwang | 6:0a34891a82c7 | 920 | for (int x = 0; x < SX_MAX - SX_MIN; x++) { |
bwang | 6:0a34891a82c7 | 921 | float cameraX = 2 * x / float(w) - 1; //x-coordinate in camera space |
bwang | 6:0a34891a82c7 | 922 | float rayPosX = posX; |
bwang | 6:0a34891a82c7 | 923 | float rayPosY = posY; |
bwang | 6:0a34891a82c7 | 924 | float rayDirX = dirX + planeX * cameraX; |
bwang | 6:0a34891a82c7 | 925 | float rayDirY = dirY + planeY * cameraX; |
bwang | 6:0a34891a82c7 | 926 | |
bwang | 6:0a34891a82c7 | 927 | int mapX = int(rayPosX); |
bwang | 6:0a34891a82c7 | 928 | int mapY = int(rayPosY); |
bwang | 6:0a34891a82c7 | 929 | |
bwang | 6:0a34891a82c7 | 930 | float sideDistX, sideDistY; |
bwang | 6:0a34891a82c7 | 931 | |
bwang | 6:0a34891a82c7 | 932 | float deltaDistX = sqrtf(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX)); |
bwang | 6:0a34891a82c7 | 933 | float deltaDistY = sqrtf(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY)); |
bwang | 6:0a34891a82c7 | 934 | float perpWallDist; |
bwang | 6:0a34891a82c7 | 935 | |
bwang | 6:0a34891a82c7 | 936 | int stepX, stepY; |
bwang | 6:0a34891a82c7 | 937 | int hit = 0, side; |
bwang | 6:0a34891a82c7 | 938 | if (rayDirX < 0) { |
bwang | 6:0a34891a82c7 | 939 | stepX = -1; |
bwang | 6:0a34891a82c7 | 940 | sideDistX = (rayPosX - mapX) * deltaDistX; |
bwang | 6:0a34891a82c7 | 941 | } else { |
bwang | 6:0a34891a82c7 | 942 | stepX = 1; |
bwang | 6:0a34891a82c7 | 943 | sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX; |
bwang | 6:0a34891a82c7 | 944 | } |
bwang | 6:0a34891a82c7 | 945 | if (rayDirY < 0) { |
bwang | 6:0a34891a82c7 | 946 | stepY = -1; |
bwang | 6:0a34891a82c7 | 947 | sideDistY = (rayPosY - mapY) * deltaDistY; |
bwang | 6:0a34891a82c7 | 948 | } else { |
bwang | 6:0a34891a82c7 | 949 | stepY = 1; |
bwang | 6:0a34891a82c7 | 950 | sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY; |
bwang | 6:0a34891a82c7 | 951 | } |
bwang | 6:0a34891a82c7 | 952 | |
bwang | 6:0a34891a82c7 | 953 | while (hit == 0) |
bwang | 6:0a34891a82c7 | 954 | { |
bwang | 6:0a34891a82c7 | 955 | //jump to next map square, OR in x-direction, OR in y-direction |
bwang | 6:0a34891a82c7 | 956 | if (sideDistX < sideDistY) |
bwang | 6:0a34891a82c7 | 957 | { |
bwang | 6:0a34891a82c7 | 958 | sideDistX += deltaDistX; |
bwang | 6:0a34891a82c7 | 959 | mapX += stepX; |
bwang | 6:0a34891a82c7 | 960 | side = 0; |
bwang | 6:0a34891a82c7 | 961 | } |
bwang | 6:0a34891a82c7 | 962 | else |
bwang | 6:0a34891a82c7 | 963 | { |
bwang | 6:0a34891a82c7 | 964 | sideDistY += deltaDistY; |
bwang | 6:0a34891a82c7 | 965 | mapY += stepY; |
bwang | 6:0a34891a82c7 | 966 | side = 1; |
bwang | 6:0a34891a82c7 | 967 | } |
bwang | 6:0a34891a82c7 | 968 | //Check if ray has hit a wall |
bwang | 6:0a34891a82c7 | 969 | if (worldMap[mapX][mapY] > 0) hit = 1; |
bwang | 6:0a34891a82c7 | 970 | } |
bwang | 6:0a34891a82c7 | 971 | //Calculate distance projected on camera direction (oblique distance will give fisheye effect!) |
bwang | 6:0a34891a82c7 | 972 | if (side == 0) perpWallDist = (mapX - rayPosX + (1 - stepX) / 2) / rayDirX; |
bwang | 6:0a34891a82c7 | 973 | else perpWallDist = (mapY - rayPosY + (1 - stepY) / 2) / rayDirY; |
bwang | 6:0a34891a82c7 | 974 | |
bwang | 6:0a34891a82c7 | 975 | //Calculate height of line to draw on screen |
bwang | 6:0a34891a82c7 | 976 | int drawStart,drawEnd; |
bwang | 6:0a34891a82c7 | 977 | int lineHeight = (int)(h / perpWallDist); |
bwang | 6:0a34891a82c7 | 978 | if (lineHeight > h) { |
bwang | 6:0a34891a82c7 | 979 | drawStart = 0; |
bwang | 6:0a34891a82c7 | 980 | drawEnd = h; |
bwang | 6:0a34891a82c7 | 981 | } else { |
bwang | 6:0a34891a82c7 | 982 | drawStart = -lineHeight / 2 + h / 2; |
bwang | 6:0a34891a82c7 | 983 | drawEnd = lineHeight / 2 + h / 2; |
bwang | 6:0a34891a82c7 | 984 | } |
bwang | 6:0a34891a82c7 | 985 | if (side == 0) { |
bwang | 6:0a34891a82c7 | 986 | for(int y = 0; y < drawStart; y++) { |
bwang | 6:0a34891a82c7 | 987 | im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0; |
bwang | 6:0a34891a82c7 | 988 | } |
bwang | 6:0a34891a82c7 | 989 | for(int y = drawStart;y < drawEnd;y++) { |
bwang | 6:0a34891a82c7 | 990 | im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 1; |
bwang | 6:0a34891a82c7 | 991 | } |
bwang | 6:0a34891a82c7 | 992 | for(int y = drawEnd; y < h; y++) { |
bwang | 6:0a34891a82c7 | 993 | im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0; |
bwang | 6:0a34891a82c7 | 994 | } |
bwang | 6:0a34891a82c7 | 995 | } else { |
bwang | 6:0a34891a82c7 | 996 | for(int y = 0; y < h; y++) im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0; |
bwang | 6:0a34891a82c7 | 997 | im_line_va[H_RES*(drawStart+SY_MIN)+x+SX_MIN] = 1; |
bwang | 6:0a34891a82c7 | 998 | im_line_va[H_RES*(drawEnd-1+SY_MIN)+x+SX_MIN] = 1; |
bwang | 6:0a34891a82c7 | 999 | } |
bwang | 6:0a34891a82c7 | 1000 | } |
bwang | 6:0a34891a82c7 | 1001 | } |
bwang | 6:0a34891a82c7 | 1002 | |
bwang | 7:25acb844f424 | 1003 | void update_m7() { |
bwang | 7:25acb844f424 | 1004 | int w = SX_MAX-SX_MIN; |
bwang | 7:25acb844f424 | 1005 | int h = SY_MAX-SY_MIN; |
bwang | 7:25acb844f424 | 1006 | float c = cosf(m7_theta); |
bwang | 7:25acb844f424 | 1007 | float s = sinf(m7_theta); |
bwang | 7:25acb844f424 | 1008 | for (int y = 0; y < h; y++) { |
bwang | 7:25acb844f424 | 1009 | for (int x = 0; x < w; x++) { |
bwang | 7:25acb844f424 | 1010 | float xx, yy; |
bwang | 7:25acb844f424 | 1011 | yy = y; |
bwang | 7:25acb844f424 | 1012 | xx = (x-w/2)*(h-yy)/h+w/2; |
bwang | 7:25acb844f424 | 1013 | xx = xx * (float) mapWidth / w - m7_x; |
bwang | 7:25acb844f424 | 1014 | yy = yy * (float) mapHeight / h - 2*m7_y; |
bwang | 7:25acb844f424 | 1015 | |
bwang | 7:25acb844f424 | 1016 | float xx_old = xx; |
bwang | 7:25acb844f424 | 1017 | float yy_old = yy; |
bwang | 7:25acb844f424 | 1018 | xx = xx_old*c-yy_old*s; |
bwang | 7:25acb844f424 | 1019 | yy = xx_old*s+yy_old*c; |
bwang | 7:25acb844f424 | 1020 | xx *= 1.0f; |
bwang | 7:25acb844f424 | 1021 | yy *= 1.0f; |
bwang | 7:25acb844f424 | 1022 | |
bwang | 7:25acb844f424 | 1023 | xx += m7_x; |
bwang | 7:25acb844f424 | 1024 | yy += m7_y; |
bwang | 7:25acb844f424 | 1025 | |
bwang | 7:25acb844f424 | 1026 | if (xx < 0 || xx >= mapWidth+1 || yy < 0 || yy > mapHeight+1) { |
bwang | 7:25acb844f424 | 1027 | im_line_va[H_RES*(SY_MIN+y)+x+SX_MIN] = 0; |
bwang | 7:25acb844f424 | 1028 | } else if (worldMap[(int)yy][(int)xx] == 0) { |
bwang | 7:25acb844f424 | 1029 | im_line_va[H_RES*(SY_MIN+y)+x+SX_MIN] = 0; |
bwang | 7:25acb844f424 | 1030 | } else { |
bwang | 7:25acb844f424 | 1031 | im_line_va[H_RES*(SY_MIN+y)+x+SX_MIN] = 1; |
bwang | 7:25acb844f424 | 1032 | } |
bwang | 7:25acb844f424 | 1033 | } |
bwang | 7:25acb844f424 | 1034 | } |
bwang | 7:25acb844f424 | 1035 | int cmd1 = p1_in.read(); |
bwang | 7:25acb844f424 | 1036 | int cmd2 = p2_in.read(); |
bwang | 7:25acb844f424 | 1037 | if (!cmd1) m7_theta+=0.03f; |
bwang | 7:25acb844f424 | 1038 | if (!cmd2) m7_theta-=0.03f; |
bwang | 7:25acb844f424 | 1039 | } |
bwang | 7:25acb844f424 | 1040 | |
bwang | 3:d9edc0575aa3 | 1041 | int main() { |
bwang | 3:d9edc0575aa3 | 1042 | potato: |
bwang | 3:d9edc0575aa3 | 1043 | init_buffers(); |
bwang | 3:d9edc0575aa3 | 1044 | t.attach_us(&isr,63); |
bwang | 6:0a34891a82c7 | 1045 | |
bwang | 7:25acb844f424 | 1046 | for(;;){update_m7();} |
bwang | 7:25acb844f424 | 1047 | |
bwang | 3:d9edc0575aa3 | 1048 | int bmi = 0; |
bwang | 3:d9edc0575aa3 | 1049 | |
bwang | 4:02e3ae7a3aea | 1050 | for(int y = SY_MIN; y < SY_MIN + BY2; y++) |
bwang | 3:d9edc0575aa3 | 1051 | { |
bwang | 3:d9edc0575aa3 | 1052 | for(int x = SX_MIN; x < SX_MIN + BX; x++) |
bwang | 3:d9edc0575aa3 | 1053 | { |
bwang | 3:d9edc0575aa3 | 1054 | im_line_va[H_RES*y + x] = miters[bmi]; |
bwang | 3:d9edc0575aa3 | 1055 | bmi++; |
bwang | 3:d9edc0575aa3 | 1056 | } |
bwang | 3:d9edc0575aa3 | 1057 | } |
bwang | 3:d9edc0575aa3 | 1058 | |
bwang | 3:d9edc0575aa3 | 1059 | int cursor_pos = 0; |
bwang | 6:0a34891a82c7 | 1060 | int menu_offs = 0; |
bwang | 3:d9edc0575aa3 | 1061 | |
bwang | 3:d9edc0575aa3 | 1062 | for (;;) { |
bwang | 1:24fd07a24094 | 1063 | int cmd1 = p1_in.read(); |
bwang | 1:24fd07a24094 | 1064 | int cmd2 = p2_in.read(); |
bwang | 3:d9edc0575aa3 | 1065 | |
bwang | 3:d9edc0575aa3 | 1066 | int cursor_x = SX_MIN; |
bwang | 4:02e3ae7a3aea | 1067 | int cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5; |
bwang | 1:24fd07a24094 | 1068 | |
bwang | 3:d9edc0575aa3 | 1069 | if (cmd1 || cmd2) im_line_va[H_RES*cursor_y+cursor_x] = 0; |
bwang | 1:24fd07a24094 | 1070 | |
bwang | 3:d9edc0575aa3 | 1071 | if (!cmd1) cursor_pos++; |
bwang | 3:d9edc0575aa3 | 1072 | if (!cmd2) cursor_pos--; |
bwang | 3:d9edc0575aa3 | 1073 | if (!cmd1 && !cmd2) break; |
bwang | 1:24fd07a24094 | 1074 | |
bwang | 3:d9edc0575aa3 | 1075 | if (cursor_pos < 0) cursor_pos = 0; |
bwang | 6:0a34891a82c7 | 1076 | if (cursor_pos > 4) cursor_pos = 4; |
bwang | 6:0a34891a82c7 | 1077 | if (cursor_pos > 3) menu_offs = cursor_pos - 3; else menu_offs = 0; |
bwang | 1:24fd07a24094 | 1078 | |
bwang | 3:d9edc0575aa3 | 1079 | cursor_x = SX_MIN; |
bwang | 6:0a34891a82c7 | 1080 | if (cursor_pos < 4) cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5; |
bwang | 6:0a34891a82c7 | 1081 | else cursor_y = SY_MIN + 8*3 + BY2 + 5; |
bwang | 6:0a34891a82c7 | 1082 | |
bwang | 6:0a34891a82c7 | 1083 | for(int y = 0; y < 4; y++) { |
bwang | 6:0a34891a82c7 | 1084 | for(int x = 0; x < 4; x++) { |
bwang | 6:0a34891a82c7 | 1085 | dispchr(4+7*x,BY2+1+8*y,menu[4*(y+menu_offs)+x]); |
bwang | 6:0a34891a82c7 | 1086 | } |
bwang | 6:0a34891a82c7 | 1087 | } |
bwang | 1:24fd07a24094 | 1088 | |
bwang | 3:d9edc0575aa3 | 1089 | im_line_va[H_RES*cursor_y+cursor_x] = 1; |
bwang | 3:d9edc0575aa3 | 1090 | |
bwang | 3:d9edc0575aa3 | 1091 | wait(0.1); |
bwang | 1:24fd07a24094 | 1092 | } |
bwang | 1:24fd07a24094 | 1093 | |
bwang | 3:d9edc0575aa3 | 1094 | init_buffers(); |
bwang | 2:1d16e99f334b | 1095 | |
bwang | 3:d9edc0575aa3 | 1096 | if (cursor_pos == 0) { |
bwang | 3:d9edc0575aa3 | 1097 | for (;;) { |
bwang | 3:d9edc0575aa3 | 1098 | if (!flappy_pong()) break; |
bwang | 3:d9edc0575aa3 | 1099 | } |
bwang | 3:d9edc0575aa3 | 1100 | } else if (cursor_pos == 1) { |
bwang | 3:d9edc0575aa3 | 1101 | for (;;) fishy(); |
bwang | 4:02e3ae7a3aea | 1102 | } else if (cursor_pos == 2) { |
bwang | 4:02e3ae7a3aea | 1103 | for (;;) update_image(); |
bwang | 6:0a34891a82c7 | 1104 | } else if (cursor_pos == 3) { |
bwang | 4:02e3ae7a3aea | 1105 | init_tunnel(); |
bwang | 4:02e3ae7a3aea | 1106 | for (;;) |
bwang | 4:02e3ae7a3aea | 1107 | { |
bwang | 4:02e3ae7a3aea | 1108 | update_tunnel(); |
bwang | 4:02e3ae7a3aea | 1109 | } |
bwang | 6:0a34891a82c7 | 1110 | } else if (cursor_pos == 4) { |
bwang | 6:0a34891a82c7 | 1111 | for (;;) { |
bwang | 6:0a34891a82c7 | 1112 | update_rc(); |
bwang | 6:0a34891a82c7 | 1113 | } |
dicarloj | 0:7757ab3f7206 | 1114 | } |
bwang | 3:d9edc0575aa3 | 1115 | goto potato; |
dicarloj | 0:7757ab3f7206 | 1116 | } |