cube

Dependencies:   mbed

Fork of manworm_tv_gpu by Jared DiCarlo

Committer:
bwang
Date:
Mon Nov 20 06:28:29 2017 +0000
Revision:
6:0a34891a82c7
Parent:
5:2859a892497f
Child:
7:25acb844f424
walf, menu scrolling; drav now has man, animated legs

Who changed what in which revision?

UserRevisionLine numberNew 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 6:0a34891a82c7 219 0,0,0,1,0,0,1,
bwang 6:0a34891a82c7 220 0,1,1,1,1,1,0,
bwang 6:0a34891a82c7 221 1,0,1,1,1,0,0,
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 2:1d16e99f334b 348 DigitalIn p1_in(A1);
bwang 2:1d16e99f334b 349 DigitalIn p2_in(A0);
bwang 1:24fd07a24094 350
dicarloj 0:7757ab3f7206 351 void make_checkerboard()
dicarloj 0:7757ab3f7206 352 {
dicarloj 0:7757ab3f7206 353 for(int i = 0; i < H_RES; i++)
dicarloj 0:7757ab3f7206 354 for(int j = 0; j < V_RES; j++)
bwang 1:24fd07a24094 355 im_line_va[i+j*H_RES] = 0*((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard
dicarloj 0:7757ab3f7206 356
dicarloj 0:7757ab3f7206 357 }
dicarloj 0:7757ab3f7206 358
bwang 3:d9edc0575aa3 359 void clr()
bwang 3:d9edc0575aa3 360 {
bwang 3:d9edc0575aa3 361 for(int i = 0; i < H_RES; i++)
bwang 3:d9edc0575aa3 362 for(int j = 0; j < V_RES; j++)
bwang 3:d9edc0575aa3 363 im_line_va[i+j*H_RES] = 0;
bwang 3:d9edc0575aa3 364
bwang 3:d9edc0575aa3 365 }
bwang 3:d9edc0575aa3 366
dicarloj 0:7757ab3f7206 367 void init_buffers()
dicarloj 0:7757ab3f7206 368 {
bwang 3:d9edc0575aa3 369 clr();
dicarloj 0:7757ab3f7206 370 for(int i = 0; i < H_RES; i++)
dicarloj 0:7757ab3f7206 371 {
dicarloj 0:7757ab3f7206 372 im_line_s[i] = 1;
dicarloj 0:7757ab3f7206 373 bl_line_s[i] = 1;
dicarloj 0:7757ab3f7206 374 bl_line_v[i] = 0;
dicarloj 0:7757ab3f7206 375 vb_line_s[i] = 0;
dicarloj 0:7757ab3f7206 376 vb_line_v[i] = 0;
dicarloj 0:7757ab3f7206 377 }
dicarloj 0:7757ab3f7206 378 im_line_s[0] = 0;
dicarloj 0:7757ab3f7206 379 im_line_s[1] = 0;
dicarloj 0:7757ab3f7206 380 im_line_s[2] = 0;
dicarloj 0:7757ab3f7206 381 bl_line_s[0] = 0;
dicarloj 0:7757ab3f7206 382 vb_line_s[0] = 1;
dicarloj 0:7757ab3f7206 383 bl_line_s[1] = 0;
dicarloj 0:7757ab3f7206 384 vb_line_s[1] = 1;
dicarloj 0:7757ab3f7206 385
dicarloj 0:7757ab3f7206 386
dicarloj 0:7757ab3f7206 387
dicarloj 0:7757ab3f7206 388 }
dicarloj 0:7757ab3f7206 389 void isr()
dicarloj 0:7757ab3f7206 390 {
dicarloj 0:7757ab3f7206 391 uint8_t nop = 0; //use nops or use wait_us
dicarloj 0:7757ab3f7206 392 uint8_t* sptr; //pointer to sync buffer for line
dicarloj 0:7757ab3f7206 393 uint8_t* vptr; //pointer to video buffer for line
dicarloj 0:7757ab3f7206 394 if(l < V_RES){ vptr = im_line_va + ((l/4)*H_RES); sptr = im_line_s; nop = 1; } //pick line buffers
dicarloj 0:7757ab3f7206 395 else if(l < 254){ vptr = bl_line_v; sptr = bl_line_s; nop = 0; }
dicarloj 0:7757ab3f7206 396 else{ vptr = vb_line_v; sptr = vb_line_s; nop = 1;}
dicarloj 0:7757ab3f7206 397 uint8_t lmax = nop?H_RES:12; //number of columns
dicarloj 0:7757ab3f7206 398 for(uint8_t i = 0; i < lmax; i++) //loop over each column
dicarloj 0:7757ab3f7206 399 {
dicarloj 0:7757ab3f7206 400 vout = vptr[i]; //set output pins
dicarloj 0:7757ab3f7206 401 sout = sptr[i];
dicarloj 0:7757ab3f7206 402 if(nop) //nop delay
dicarloj 0:7757ab3f7206 403 {
dicarloj 0:7757ab3f7206 404 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 405 }
dicarloj 0:7757ab3f7206 406 else {wait_us(1); if(i > 2) i++;} //wait delay
dicarloj 0:7757ab3f7206 407
dicarloj 0:7757ab3f7206 408
dicarloj 0:7757ab3f7206 409 }
dicarloj 0:7757ab3f7206 410 //move to next line
dicarloj 0:7757ab3f7206 411 l++;
dicarloj 0:7757ab3f7206 412 if(l > 255) l = 0;
dicarloj 0:7757ab3f7206 413 }
dicarloj 0:7757ab3f7206 414
dicarloj 0:7757ab3f7206 415 //coordinates for bouncing ball
dicarloj 0:7757ab3f7206 416
dicarloj 0:7757ab3f7206 417
dicarloj 0:7757ab3f7206 418
dicarloj 0:7757ab3f7206 419 int k = 0;
dicarloj 0:7757ab3f7206 420 uint16_t px = X_0*10;
dicarloj 0:7757ab3f7206 421 uint16_t py = Y_0*10;
dicarloj 0:7757ab3f7206 422 uint16_t vx = 10;
dicarloj 0:7757ab3f7206 423 uint16_t vy = 10;
dicarloj 0:7757ab3f7206 424 uint16_t px2 = X_0*10 + 80;
dicarloj 0:7757ab3f7206 425 uint16_t py2 = Y_0*10 - 40;
dicarloj 0:7757ab3f7206 426 uint16_t vx2 = 3;
dicarloj 0:7757ab3f7206 427 uint16_t vy2 = -4;
dicarloj 0:7757ab3f7206 428
dicarloj 0:7757ab3f7206 429 int16_t sign(int16_t a)
dicarloj 0:7757ab3f7206 430 {
dicarloj 0:7757ab3f7206 431 if(a > 0) return 1;
dicarloj 0:7757ab3f7206 432 if(a < 0) return -1;
dicarloj 0:7757ab3f7206 433 return 0;
dicarloj 0:7757ab3f7206 434 }
dicarloj 0:7757ab3f7206 435
dicarloj 0:7757ab3f7206 436 void draw_vert(int16_t y0, int16_t y1, int16_t x0)
dicarloj 0:7757ab3f7206 437 {
dicarloj 0:7757ab3f7206 438 for(int16_t i = y0; i < y1; i++)
dicarloj 0:7757ab3f7206 439 im_line_va[H_RES*i + x0] = 1;
dicarloj 0:7757ab3f7206 440 }
dicarloj 0:7757ab3f7206 441
dicarloj 0:7757ab3f7206 442 void draw_horiz(int16_t x0, int16_t x1, int16_t y0)
dicarloj 0:7757ab3f7206 443 {
dicarloj 0:7757ab3f7206 444 for(int16_t i = x0; i < x1; i++)
dicarloj 0:7757ab3f7206 445 im_line_va[H_RES*y0 + i] = 1;
dicarloj 0:7757ab3f7206 446 }
dicarloj 0:7757ab3f7206 447
dicarloj 0:7757ab3f7206 448 int16_t imin(int16_t a, int16_t b)
dicarloj 0:7757ab3f7206 449 {
dicarloj 0:7757ab3f7206 450 if(a<b) return a;
dicarloj 0:7757ab3f7206 451 return b;
dicarloj 0:7757ab3f7206 452 }
dicarloj 0:7757ab3f7206 453
dicarloj 0:7757ab3f7206 454 int16_t imax(int16_t a, int16_t b)
dicarloj 0:7757ab3f7206 455 {
dicarloj 0:7757ab3f7206 456 if(a>b) return a;
dicarloj 0:7757ab3f7206 457 return b;
dicarloj 0:7757ab3f7206 458 }
dicarloj 0:7757ab3f7206 459
dicarloj 0:7757ab3f7206 460 void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
dicarloj 0:7757ab3f7206 461 {
dicarloj 0:7757ab3f7206 462 if(x0 > x1){ x0 = x0 ^ x1; x1 = x1^x0; x0 = x0^x1;y0 = y0 ^ y1; y1 = y1^y0; y0 = y0^y1; }
dicarloj 0:7757ab3f7206 463 if(x0 == x1){draw_vert(y0,y1,x0);}
dicarloj 0:7757ab3f7206 464 if(y0 == y1){draw_horiz(x0,x1,y0);}
dicarloj 0:7757ab3f7206 465 int16_t dx = x1 - x0;
dicarloj 0:7757ab3f7206 466 int16_t dy = y1 - y0;
dicarloj 0:7757ab3f7206 467 float derr = fabs((float)(dy)/(float)(dx));
dicarloj 0:7757ab3f7206 468 float err = 0.f;
dicarloj 0:7757ab3f7206 469 int16_t y = y0;
dicarloj 0:7757ab3f7206 470 for(int16_t x = x0; x < x1; x++)
dicarloj 0:7757ab3f7206 471 {
dicarloj 0:7757ab3f7206 472 //plotxy
dicarloj 0:7757ab3f7206 473 im_line_va[H_RES*y + x] = !draw_line_inv;
dicarloj 0:7757ab3f7206 474 err += derr;
dicarloj 0:7757ab3f7206 475 while(err >= 0.5f)
dicarloj 0:7757ab3f7206 476 {
dicarloj 0:7757ab3f7206 477 y += sign(dy);
dicarloj 0:7757ab3f7206 478 im_line_va[H_RES*y + x] = !draw_line_inv;
dicarloj 0:7757ab3f7206 479 err -= 1.f;
dicarloj 0:7757ab3f7206 480 }
dicarloj 0:7757ab3f7206 481 }
dicarloj 0:7757ab3f7206 482 }
dicarloj 0:7757ab3f7206 483
dicarloj 0:7757ab3f7206 484 void draw_cube(float cp[][3])
dicarloj 0:7757ab3f7206 485 {
dicarloj 0:7757ab3f7206 486 for(uint8_t i = 0; i < 7; i++)
dicarloj 0:7757ab3f7206 487 {
dicarloj 0:7757ab3f7206 488 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 489 }
dicarloj 0:7757ab3f7206 490 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 491 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 492 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 493 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 494 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 495 }
dicarloj 0:7757ab3f7206 496
dicarloj 0:7757ab3f7206 497 void apply_rot(float cp[][3], float r[][3])
dicarloj 0:7757ab3f7206 498 {
dicarloj 0:7757ab3f7206 499 for(uint8_t pti = 0; pti < 8; pti++)
dicarloj 0:7757ab3f7206 500 {
dicarloj 0:7757ab3f7206 501 float* cpt = cp[pti];
dicarloj 0:7757ab3f7206 502 float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2];
dicarloj 0:7757ab3f7206 503 float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2];
dicarloj 0:7757ab3f7206 504 float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2];
dicarloj 0:7757ab3f7206 505 cpt[0] = xn;
dicarloj 0:7757ab3f7206 506 cpt[1] = yn;
dicarloj 0:7757ab3f7206 507 cpt[2] = zn;
dicarloj 0:7757ab3f7206 508 }
dicarloj 0:7757ab3f7206 509 }
dicarloj 0:7757ab3f7206 510
dicarloj 0:7757ab3f7206 511 void apply_xf_rot(float cpt[], float r[][3])
dicarloj 0:7757ab3f7206 512 {
dicarloj 0:7757ab3f7206 513 float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2];
dicarloj 0:7757ab3f7206 514 float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2];
dicarloj 0:7757ab3f7206 515 float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2];
dicarloj 0:7757ab3f7206 516 cpt[0] = xn;
dicarloj 0:7757ab3f7206 517 cpt[1] = yn;
dicarloj 0:7757ab3f7206 518 cpt[2] = zn;
dicarloj 0:7757ab3f7206 519 }
dicarloj 0:7757ab3f7206 520
dicarloj 0:7757ab3f7206 521 void draw_v_check(int8_t r,uint8_t tt)
dicarloj 0:7757ab3f7206 522 {
dicarloj 0:7757ab3f7206 523 for(int i = 0; i < H_RES; i++)
dicarloj 0:7757ab3f7206 524 for(int j = 0; j < V_RES; j++)
dicarloj 0:7757ab3f7206 525 im_line_va[i+j*H_RES] = (((i > 20) && (i < 98)) && ( tt ^(((j%(r*2))>=r) ^ ((i%(r*2)))>=r))); //checkerboard
dicarloj 0:7757ab3f7206 526 }
dicarloj 0:7757ab3f7206 527
dicarloj 0:7757ab3f7206 528
dicarloj 0:7757ab3f7206 529 int jjj = 0;
dicarloj 0:7757ab3f7206 530 int f_count = DEMO_LENGTH + 10;
dicarloj 0:7757ab3f7206 531 void draw_cube_spin(int kkkk);
dicarloj 0:7757ab3f7206 532 //update bouncing balls
dicarloj 0:7757ab3f7206 533
dicarloj 0:7757ab3f7206 534 void draw_blank()
dicarloj 0:7757ab3f7206 535 {
dicarloj 0:7757ab3f7206 536 for(uint16_t h = X_MIN; h < X_MAX; h++)
dicarloj 0:7757ab3f7206 537 {
dicarloj 0:7757ab3f7206 538 for(uint16_t v = Y_MIN; v < Y_MAX+15; v++)
dicarloj 0:7757ab3f7206 539 {
dicarloj 0:7757ab3f7206 540 im_line_va[v*H_RES + h] = 0;
dicarloj 0:7757ab3f7206 541 }
dicarloj 0:7757ab3f7206 542 }
dicarloj 0:7757ab3f7206 543 }
dicarloj 0:7757ab3f7206 544
dicarloj 0:7757ab3f7206 545 void wipe();
dicarloj 0:7757ab3f7206 546
dicarloj 0:7757ab3f7206 547 void update_image()
dicarloj 0:7757ab3f7206 548 {
dicarloj 0:7757ab3f7206 549 //delay
dicarloj 0:7757ab3f7206 550 k++;
dicarloj 0:7757ab3f7206 551 if(k%4000) return;
dicarloj 0:7757ab3f7206 552 f_count++;
dicarloj 0:7757ab3f7206 553 if(f_count < DEMO_LENGTH/2)
dicarloj 0:7757ab3f7206 554 {
dicarloj 0:7757ab3f7206 555 draw_cube_spin(0);
dicarloj 0:7757ab3f7206 556 }
dicarloj 0:7757ab3f7206 557 else if(f_count < DEMO_LENGTH)
dicarloj 0:7757ab3f7206 558 {
bwang 1:24fd07a24094 559 draw_cube_spin(0);
dicarloj 0:7757ab3f7206 560 }
bwang 1:24fd07a24094 561 else if(f_count < DEMO_LENGTH * 1.22)
dicarloj 0:7757ab3f7206 562 {
dicarloj 0:7757ab3f7206 563 for(int k = 1; k < 10; k++)
bwang 1:24fd07a24094 564 //for(int kk = 1; kk < 3; kk++)
dicarloj 0:7757ab3f7206 565 {
dicarloj 0:7757ab3f7206 566 draw_v_check(k,1);
dicarloj 0:7757ab3f7206 567 draw_v_check(k,1);
dicarloj 0:7757ab3f7206 568 draw_v_check(k,0);
dicarloj 0:7757ab3f7206 569 draw_v_check(k,0);
dicarloj 0:7757ab3f7206 570 }
dicarloj 0:7757ab3f7206 571
dicarloj 0:7757ab3f7206 572 draw_v_check(1,0);
dicarloj 0:7757ab3f7206 573 wipe();
dicarloj 0:7757ab3f7206 574 f_count = 0;
dicarloj 0:7757ab3f7206 575 }
dicarloj 0:7757ab3f7206 576 }
dicarloj 0:7757ab3f7206 577
dicarloj 0:7757ab3f7206 578 void wipe()
dicarloj 0:7757ab3f7206 579 {
dicarloj 0:7757ab3f7206 580 for(int v = Y_MIN; v < Y_MAX+15; v++)
dicarloj 0:7757ab3f7206 581 {
dicarloj 0:7757ab3f7206 582 for(uint16_t h = X_MIN; h < X_MAX; h++)
dicarloj 0:7757ab3f7206 583 {
dicarloj 0:7757ab3f7206 584 im_line_va[v*H_RES+h] = 1;
dicarloj 0:7757ab3f7206 585 }
bwang 1:24fd07a24094 586 wait(.01);
dicarloj 0:7757ab3f7206 587 }
dicarloj 0:7757ab3f7206 588
dicarloj 0:7757ab3f7206 589 for(int v = Y_MAX+15; v > Y_MIN; v--)
dicarloj 0:7757ab3f7206 590 {
dicarloj 0:7757ab3f7206 591 for(uint16_t h = X_MIN; h < X_MAX; h++)
dicarloj 0:7757ab3f7206 592 {
dicarloj 0:7757ab3f7206 593 im_line_va[v*H_RES+h] = 0;
dicarloj 0:7757ab3f7206 594 }
bwang 1:24fd07a24094 595 wait(.005);
dicarloj 0:7757ab3f7206 596 }
dicarloj 0:7757ab3f7206 597
dicarloj 0:7757ab3f7206 598 for(uint16_t h = X_MIN; h < X_MAX; h++)
dicarloj 0:7757ab3f7206 599 {
dicarloj 0:7757ab3f7206 600 for(uint16_t v = Y_MIN; v < Y_MAX+15; v++)
dicarloj 0:7757ab3f7206 601 {
dicarloj 0:7757ab3f7206 602 im_line_va[v*H_RES + h] = 1;
dicarloj 0:7757ab3f7206 603 }
bwang 1:24fd07a24094 604 wait(.005);
dicarloj 0:7757ab3f7206 605 }
dicarloj 0:7757ab3f7206 606
dicarloj 0:7757ab3f7206 607 for(uint16_t h = X_MIN; h < X_MAX; h++)
dicarloj 0:7757ab3f7206 608 {
dicarloj 0:7757ab3f7206 609 for(uint16_t v = Y_MIN; v < Y_MAX+15; v++)
dicarloj 0:7757ab3f7206 610 {
dicarloj 0:7757ab3f7206 611 im_line_va[v*H_RES + h] = 0;
dicarloj 0:7757ab3f7206 612 }
bwang 1:24fd07a24094 613 wait(.005);
dicarloj 0:7757ab3f7206 614 }
dicarloj 0:7757ab3f7206 615
dicarloj 0:7757ab3f7206 616 for(int v = Y_MIN; v < Y_MAX+15; v++)
dicarloj 0:7757ab3f7206 617 {
dicarloj 0:7757ab3f7206 618 for(uint16_t h = X_MIN; h < X_MAX; h++)
dicarloj 0:7757ab3f7206 619 {
dicarloj 0:7757ab3f7206 620 im_line_va[v*H_RES+h] = 0;
dicarloj 0:7757ab3f7206 621 }
dicarloj 0:7757ab3f7206 622 }
dicarloj 0:7757ab3f7206 623 }
dicarloj 0:7757ab3f7206 624
dicarloj 0:7757ab3f7206 625 void draw_cube_spin(int kkkk)
dicarloj 0:7757ab3f7206 626 {
dicarloj 0:7757ab3f7206 627 draw_line_inv = kkkk;
dicarloj 0:7757ab3f7206 628 //blank
dicarloj 0:7757ab3f7206 629 for(uint16_t h = X_MIN; h < X_MAX; h++)
dicarloj 0:7757ab3f7206 630 {
dicarloj 0:7757ab3f7206 631 for(uint16_t v = Y_MIN; v < Y_MAX; v++)
dicarloj 0:7757ab3f7206 632 {
dicarloj 0:7757ab3f7206 633 if( (h > 22) && (h < 76+18))
dicarloj 0:7757ab3f7206 634 im_line_va[v*H_RES + h] = kkkk;
dicarloj 0:7757ab3f7206 635 }
dicarloj 0:7757ab3f7206 636 }
dicarloj 0:7757ab3f7206 637 apply_xf_rot(cube_a,y_rot);
dicarloj 0:7757ab3f7206 638 apply_xf_rot(cube_a,y_rot);
dicarloj 0:7757ab3f7206 639 apply_rot(cube_pts,x_rot);
dicarloj 0:7757ab3f7206 640 apply_rot(cube_pts,x_rot);
dicarloj 0:7757ab3f7206 641 apply_rot(cube_pts,y_rot);
dicarloj 0:7757ab3f7206 642 apply_rot(cube_pts,y_rot);
dicarloj 0:7757ab3f7206 643 apply_rot(cube_pts,z_rot);
dicarloj 0:7757ab3f7206 644 //draw ball
dicarloj 0:7757ab3f7206 645 im_line_va[(py/10)*H_RES + (px/10)] = 1;
dicarloj 0:7757ab3f7206 646 draw_line(X_0,Y_0,(px/10),(py/10));
dicarloj 0:7757ab3f7206 647 draw_cube(cube_pts);
dicarloj 0:7757ab3f7206 648
dicarloj 0:7757ab3f7206 649 //update position/check for bounces
dicarloj 0:7757ab3f7206 650 px += vx;
dicarloj 0:7757ab3f7206 651 py += vy;
dicarloj 0:7757ab3f7206 652 px2 += vx2;
dicarloj 0:7757ab3f7206 653 py2 += vy2;
dicarloj 0:7757ab3f7206 654 if(px/10 > (X_MAX-2) || px/10 < (X_MIN+1)) vx = -vx;
dicarloj 0:7757ab3f7206 655 if(py/10 > (Y_MAX-2) || py/10 < (Y_MIN+1)) vy = -vy;
dicarloj 0:7757ab3f7206 656 if(px2/10 > (X_MAX-2) || px2/10 < (X_MIN+1)) vx2 = -vx2;
dicarloj 0:7757ab3f7206 657 if(py2/10 > (Y_MAX-2) || py2/10 < (Y_MIN+1)) vy2 = -vy2;
dicarloj 0:7757ab3f7206 658 if(k%(8000*50)) return;
dicarloj 0:7757ab3f7206 659
dicarloj 0:7757ab3f7206 660 jjj = !jjj;
dicarloj 0:7757ab3f7206 661 int bmi = 0;
dicarloj 0:7757ab3f7206 662 for(int y = BY_0; y < BY_0 + BY; y++)
dicarloj 0:7757ab3f7206 663 {
dicarloj 0:7757ab3f7206 664 for(int x = BX_0; x < BX_0 + BX; x++)
dicarloj 0:7757ab3f7206 665 {
dicarloj 0:7757ab3f7206 666 im_line_va[H_RES*y + x] = kkkk^(miters[bmi]*jjj + (!jjj)*tv[bmi]);
dicarloj 0:7757ab3f7206 667 bmi++;
dicarloj 0:7757ab3f7206 668 }
dicarloj 0:7757ab3f7206 669 }
dicarloj 0:7757ab3f7206 670 }
dicarloj 0:7757ab3f7206 671
bwang 3:d9edc0575aa3 672 int flappy_pong() {
bwang 3:d9edc0575aa3 673
bwang 3:d9edc0575aa3 674 //clear frame
bwang 3:d9edc0575aa3 675 for(int y = 0; y < PADDLE_LEN; y++) {
bwang 3:d9edc0575aa3 676 im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 0;
bwang 3:d9edc0575aa3 677 im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 0;
bwang 3:d9edc0575aa3 678 }
bwang 3:d9edc0575aa3 679 im_line_va[H_RES*(int)by+(int)bx] = 0;
bwang 3:d9edc0575aa3 680 //read inputs
bwang 3:d9edc0575aa3 681 int cmd1 = p1_in.read();
bwang 3:d9edc0575aa3 682 int cmd2 = p2_in.read();
bwang 3:d9edc0575aa3 683 if (cmd1 == 0) p1v = 0.1; else p1v = -0.1f;
bwang 3:d9edc0575aa3 684 if (cmd2 == 0) p2v = 0.1; else p2v = -0.1f;
bwang 3:d9edc0575aa3 685
bwang 3:d9edc0575aa3 686 p1 += p1v;
bwang 3:d9edc0575aa3 687 p2 += p2v;
bwang 3:d9edc0575aa3 688 bx += bxv;
bwang 3:d9edc0575aa3 689 by += byv;
bwang 3:d9edc0575aa3 690
bwang 3:d9edc0575aa3 691 if (p1 < SY_MIN) p1 = SY_MIN;
bwang 3:d9edc0575aa3 692 if (p1 > SY_MAX-PADDLE_LEN) p1 = SY_MAX-PADDLE_LEN;
bwang 3:d9edc0575aa3 693 if (p2 < SY_MIN) p2 = SY_MIN;
bwang 3:d9edc0575aa3 694 if (p2 > SY_MAX-PADDLE_LEN) p2 = SY_MAX-PADDLE_LEN;
bwang 3:d9edc0575aa3 695
bwang 3:d9edc0575aa3 696 if (bx < SX_MIN) {
bwang 3:d9edc0575aa3 697 bxv = -bxv;
bwang 3:d9edc0575aa3 698 bx = SX_MIN;
bwang 3:d9edc0575aa3 699 if (by < p1 - 3 || by > p1 + PADDLE_LEN + 3) {
bwang 3:d9edc0575aa3 700 im_line_va[H_RES*(SY_MIN-2)+2*s1+SX_MIN] = 1;
bwang 3:d9edc0575aa3 701 bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2;
bwang 3:d9edc0575aa3 702 s1++;
bwang 3:d9edc0575aa3 703 if (s1>14) return 0;
bwang 3:d9edc0575aa3 704 }
bwang 3:d9edc0575aa3 705 }
bwang 3:d9edc0575aa3 706 if (bx > SX_MAX) {
bwang 3:d9edc0575aa3 707 bxv = -bxv;
bwang 3:d9edc0575aa3 708 bx = SX_MAX;
bwang 3:d9edc0575aa3 709 if (by < p2 - 3 || by > p2 + PADDLE_LEN + 3) {
bwang 3:d9edc0575aa3 710 im_line_va[H_RES*(SY_MAX+2)+2*s2+SX_MIN] = 1;
bwang 3:d9edc0575aa3 711 bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2;
bwang 3:d9edc0575aa3 712 s2++;
bwang 3:d9edc0575aa3 713 if (s2>14) return 0;
bwang 3:d9edc0575aa3 714 }
bwang 3:d9edc0575aa3 715 }
bwang 3:d9edc0575aa3 716 if (by < SY_MIN) {byv = -byv; by = SY_MIN;}
bwang 3:d9edc0575aa3 717 if (by > SY_MAX) {byv = -byv; by = SY_MAX;}
bwang 3:d9edc0575aa3 718
bwang 1:24fd07a24094 719 for(int y = 0; y < PADDLE_LEN; y++) {
bwang 1:24fd07a24094 720 im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1;
bwang 1:24fd07a24094 721 im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1;
bwang 1:24fd07a24094 722 }
bwang 1:24fd07a24094 723 im_line_va[H_RES*(int)by+(int)bx] = 1;
bwang 3:d9edc0575aa3 724
bwang 3:d9edc0575aa3 725 wait(1/1200.0f);
bwang 3:d9edc0575aa3 726 return 1;
bwang 3:d9edc0575aa3 727 }
bwang 3:d9edc0575aa3 728
bwang 3:d9edc0575aa3 729 int fishy() {
bwang 3:d9edc0575aa3 730 uint16_t xstart, ystart, xend, yend;
bwang 3:d9edc0575aa3 731 float s = sinf(ftheta);
bwang 3:d9edc0575aa3 732 float c = cosf(ftheta);
bwang 3:d9edc0575aa3 733
bwang 3:d9edc0575aa3 734 xstart = (uint16_t) fx;
bwang 3:d9edc0575aa3 735 ystart = (uint16_t) fy;
bwang 3:d9edc0575aa3 736
bwang 3:d9edc0575aa3 737
bwang 3:d9edc0575aa3 738 for(int x = xstart-5; x < xstart + 5; x++) {
bwang 3:d9edc0575aa3 739 for (int y = ystart - 5; y < ystart + 5; y++) {
bwang 3:d9edc0575aa3 740 im_line_va[H_RES*y+x] = 0;
bwang 3:d9edc0575aa3 741 }
bwang 3:d9edc0575aa3 742 }
bwang 3:d9edc0575aa3 743 for (int i = 0; i < 8; i++) {
bwang 3:d9edc0575aa3 744 int index = H_RES*(int)uy[i]+(int)ux[i];
bwang 3:d9edc0575aa3 745 im_line_va[index] = 0;
bwang 3:d9edc0575aa3 746 }
bwang 3:d9edc0575aa3 747
bwang 3:d9edc0575aa3 748 float fx_old = fx, fy_old = fy;
bwang 3:d9edc0575aa3 749 fx += fv * s;
bwang 3:d9edc0575aa3 750 fy += fv * c;
bwang 3:d9edc0575aa3 751 int cmd = p1_in.read();
bwang 3:d9edc0575aa3 752 if (cmd) ftheta += fa; else ftheta -= fa;
bwang 3:d9edc0575aa3 753 if (ftheta >= 2 * 3.1415926) ftheta -= 2 * 3.1415926;
bwang 3:d9edc0575aa3 754 if (ftheta < 0) ftheta += 2 * 3.1415926;
bwang 3:d9edc0575aa3 755
bwang 3:d9edc0575aa3 756 s = sinf(ftheta);
bwang 3:d9edc0575aa3 757 c = cosf(ftheta);
bwang 3:d9edc0575aa3 758
bwang 3:d9edc0575aa3 759 xstart = (uint16_t)fx;
bwang 3:d9edc0575aa3 760 ystart = (uint16_t)fy;
bwang 3:d9edc0575aa3 761 xend = (uint16_t)(fx+s*4);
bwang 3:d9edc0575aa3 762 yend = (uint16_t)(fy+c*4);
bwang 3:d9edc0575aa3 763
bwang 3:d9edc0575aa3 764 if (xstart < SX_MIN || xstart > SX_MAX ||
bwang 3:d9edc0575aa3 765 ystart < SY_MIN || ystart > SY_MAX ||
bwang 3:d9edc0575aa3 766 xend < SX_MIN || xend > SX_MAX ||
bwang 3:d9edc0575aa3 767 yend < SY_MIN || yend > SY_MAX) {
bwang 3:d9edc0575aa3 768 fx = fx_old;
bwang 3:d9edc0575aa3 769 fy = fy_old;
bwang 3:d9edc0575aa3 770 xstart = (uint16_t)fx;
bwang 3:d9edc0575aa3 771 ystart = (uint16_t)fy;
bwang 3:d9edc0575aa3 772 xend = (uint16_t)(fx+s*4);
bwang 3:d9edc0575aa3 773 yend = (uint16_t)(fy+c*4);
bwang 3:d9edc0575aa3 774 }
bwang 3:d9edc0575aa3 775
bwang 3:d9edc0575aa3 776 draw_line(xstart, ystart, xend, yend);
bwang 3:d9edc0575aa3 777 for (int i = 0; i < 8; i++) {
bwang 3:d9edc0575aa3 778 if (!ulive[i]) continue;
bwang 3:d9edc0575aa3 779 if (xstart == (int)ux[i] && ystart == (int)uy[i]) {
bwang 3:d9edc0575aa3 780 fdeath_ticker = FDEATH_RESET;
bwang 3:d9edc0575aa3 781 fs+=1;
bwang 3:d9edc0575aa3 782 ulive[i] = 0;
bwang 3:d9edc0575aa3 783 }
bwang 3:d9edc0575aa3 784 ux[i]+= uv*uvx[i];
bwang 3:d9edc0575aa3 785 uy[i]+= uv*uvy[i];
bwang 3:d9edc0575aa3 786 if (ux[i] < SX_MIN) {ux[i] = SX_MIN; uvx[i] = -uvx[i];}
bwang 3:d9edc0575aa3 787 if (ux[i] > SX_MAX) {ux[i] = SX_MAX; uvx[i] = -uvx[i];}
bwang 3:d9edc0575aa3 788 if (uy[i] < SY_MIN) {uy[i] = SY_MIN; uvy[i] = -uvy[i];}
bwang 3:d9edc0575aa3 789 if (uy[i] > SY_MAX) {uy[i] = SY_MAX; uvy[i] = -uvy[i];}
bwang 3:d9edc0575aa3 790
bwang 3:d9edc0575aa3 791 int index = H_RES*(int)uy[i]+(int)ux[i];
bwang 3:d9edc0575aa3 792 im_line_va[index] = 1;
bwang 3:d9edc0575aa3 793 }
bwang 3:d9edc0575aa3 794 for (int i = 0; i < 8; i++) {
bwang 3:d9edc0575aa3 795 im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 0;
bwang 3:d9edc0575aa3 796 }
bwang 3:d9edc0575aa3 797 for (int i = 0; i < fs; i++) {
bwang 3:d9edc0575aa3 798 im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 1;
bwang 3:d9edc0575aa3 799 }
bwang 3:d9edc0575aa3 800 fdeath_ticker--;
bwang 3:d9edc0575aa3 801 if (fdeath_ticker < 0) fs -= 0.0001f;
bwang 3:d9edc0575aa3 802 if (fs < 0) fs = 0;
bwang 3:d9edc0575aa3 803
bwang 3:d9edc0575aa3 804 return 1;
bwang 3:d9edc0575aa3 805 }
bwang 3:d9edc0575aa3 806
bwang 3:d9edc0575aa3 807 void dispchr(int x0, int y0, uint8_t* chr) {
bwang 3:d9edc0575aa3 808 int bmi = 0;
bwang 3:d9edc0575aa3 809 for(int y = SY_MIN + y0; y < SY_MIN + y0 + 7; y++)
bwang 1:24fd07a24094 810 {
bwang 3:d9edc0575aa3 811 for(int x = SX_MIN + x0; x < SX_MIN + x0 + 6; x++)
bwang 3:d9edc0575aa3 812 {
bwang 3:d9edc0575aa3 813 im_line_va[H_RES*y + x] = chr[bmi];
bwang 3:d9edc0575aa3 814 bmi++;
bwang 1:24fd07a24094 815 }
bwang 3:d9edc0575aa3 816 }
bwang 3:d9edc0575aa3 817 }
bwang 3:d9edc0575aa3 818
bwang 4:02e3ae7a3aea 819 void dispsprite(int x0, int y0, uint8_t* chr) {
bwang 4:02e3ae7a3aea 820 int bmi = 0;
bwang 4:02e3ae7a3aea 821 for(int y = SY_MIN + y0; y < SY_MIN + y0 + 8; y++)
bwang 4:02e3ae7a3aea 822 {
bwang 4:02e3ae7a3aea 823 for(int x = SX_MIN + x0; x < SX_MIN + x0 + 7; x++)
bwang 4:02e3ae7a3aea 824 {
bwang 5:2859a892497f 825 if (chr[bmi]) im_line_va[H_RES*y + x] = chr[bmi];
bwang 4:02e3ae7a3aea 826 bmi++;
bwang 4:02e3ae7a3aea 827 }
bwang 4:02e3ae7a3aea 828 }
bwang 4:02e3ae7a3aea 829 }
bwang 4:02e3ae7a3aea 830
bwang 4:02e3ae7a3aea 831 void disp_tunnel() {
bwang 4:02e3ae7a3aea 832 for (int y = SY_MIN; y < SY_MAX; y++) {
bwang 4:02e3ae7a3aea 833 int tunw = 30 * (y) / TUN_LEN;
bwang 4:02e3ae7a3aea 834 int yy = SY_MAX-(SY_MAX-y)*3/4;
bwang 5:2859a892497f 835 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 836 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 837 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 838 }
bwang 4:02e3ae7a3aea 839 }
bwang 4:02e3ae7a3aea 840
bwang 4:02e3ae7a3aea 841 void init_tunnel() {
bwang 4:02e3ae7a3aea 842 for (int i = 0; i < TUN_LEN; i++) tunnel[i] = 20;
bwang 4:02e3ae7a3aea 843 disp_tunnel();
bwang 4:02e3ae7a3aea 844
bwang 4:02e3ae7a3aea 845 int bmi = 0;
bwang 4:02e3ae7a3aea 846
bwang 4:02e3ae7a3aea 847 for(int y = SY_MIN; y < SY_MIN + BY; y++)
bwang 4:02e3ae7a3aea 848 {
bwang 4:02e3ae7a3aea 849 for(int x = SX_MIN; x < SX_MIN + BX; x++)
bwang 4:02e3ae7a3aea 850 {
bwang 4:02e3ae7a3aea 851 im_line_va[H_RES*y + x + 10] = tv[bmi];
bwang 4:02e3ae7a3aea 852 bmi++;
bwang 4:02e3ae7a3aea 853 }
bwang 4:02e3ae7a3aea 854 }
bwang 4:02e3ae7a3aea 855 dispsprite(1,2,sprite_tree);
bwang 4:02e3ae7a3aea 856 dispsprite(50,2,sprite_tree);
bwang 4:02e3ae7a3aea 857 dispsprite(11,2,sprite_tree);
bwang 4:02e3ae7a3aea 858 }
bwang 4:02e3ae7a3aea 859
bwang 4:02e3ae7a3aea 860 void update_tunnel() {
bwang 4:02e3ae7a3aea 861 for (int j = TUN_LEN-1; j > 0; j--) tunnel[j] = tunnel[j-1];
bwang 4:02e3ae7a3aea 862
bwang 5:2859a892497f 863 int x = rand() % 48;
bwang 4:02e3ae7a3aea 864 if (x == 0) tundir = -tundir;
bwang 5:2859a892497f 865 if (x > 24) tunnel[0] = tunnel[0]+tundir;
bwang 4:02e3ae7a3aea 866
bwang 4:02e3ae7a3aea 867 if (tunnel[0] < 1) {
bwang 4:02e3ae7a3aea 868 tunnel[0] = 1;
bwang 4:02e3ae7a3aea 869 tundir = 1;
bwang 4:02e3ae7a3aea 870 }
bwang 4:02e3ae7a3aea 871 if (SX_MIN + tunnel[0] + 30 + 1 > SX_MAX) {
bwang 4:02e3ae7a3aea 872 tunnel[0] = SX_MAX-SX_MIN-30-1;
bwang 4:02e3ae7a3aea 873 tundir = -1;
bwang 4:02e3ae7a3aea 874 }
bwang 4:02e3ae7a3aea 875
bwang 4:02e3ae7a3aea 876 disp_tunnel();
bwang 4:02e3ae7a3aea 877
bwang 4:02e3ae7a3aea 878 int cmd1 = p1_in.read();
bwang 4:02e3ae7a3aea 879 int cmd2 = p2_in.read();
bwang 5:2859a892497f 880 if (cmd1) tunnp+=1.0f;
bwang 5:2859a892497f 881 if (cmd2) tunnp-=1.0f;
bwang 5:2859a892497f 882 if (tunnp<SX_MIN+8) tunnp = SX_MIN+8;
bwang 5:2859a892497f 883 if (tunnp>SX_MAX-8) tunnp = SX_MAX-8;
bwang 6:0a34891a82c7 884 leg_ctr++;
bwang 6:0a34891a82c7 885 if (leg_ctr == 50) leg_ctr = 0;
bwang 6:0a34891a82c7 886 if (leg_ctr < 25) dispsprite((int)(tunnp-SX_MIN), 31, sprite_manl);
bwang 6:0a34891a82c7 887 else dispsprite((int)(tunnp-SX_MIN), 31, sprite_manr);
bwang 4:02e3ae7a3aea 888
bwang 5:2859a892497f 889 wait(0.01);
bwang 4:02e3ae7a3aea 890 }
bwang 6:0a34891a82c7 891
bwang 6:0a34891a82c7 892 void update_rc() {
bwang 6:0a34891a82c7 893 int cmd1 = p1_in.read();
bwang 6:0a34891a82c7 894 int cmd2 = p2_in.read();
bwang 6:0a34891a82c7 895 if (!cmd1) {
bwang 6:0a34891a82c7 896 float oldDirX = dirX;
bwang 6:0a34891a82c7 897 dirX = dirX * rc_cos - dirY * rc_sin;
bwang 6:0a34891a82c7 898 dirY = oldDirX * rc_sin + dirY * rc_cos;
bwang 6:0a34891a82c7 899 float oldPlaneX = planeX;
bwang 6:0a34891a82c7 900 planeX = planeX * rc_cos - planeY * rc_sin;
bwang 6:0a34891a82c7 901 planeY = oldPlaneX * rc_sin + planeY * rc_cos;
bwang 6:0a34891a82c7 902 }
bwang 6:0a34891a82c7 903 if (!cmd2) {
bwang 6:0a34891a82c7 904 float oldDirX = dirX;
bwang 6:0a34891a82c7 905 dirX = dirX * rc_cos + dirY * rc_sin;
bwang 6:0a34891a82c7 906 dirY = -oldDirX * rc_sin + dirY * rc_cos;
bwang 6:0a34891a82c7 907 float oldPlaneX = planeX;
bwang 6:0a34891a82c7 908 planeX = planeX * rc_cos + planeY * rc_sin;
bwang 6:0a34891a82c7 909 planeY = -oldPlaneX * rc_sin + planeY * rc_cos;
bwang 6:0a34891a82c7 910 }
bwang 6:0a34891a82c7 911 if(worldMap[int(posX + dirX * 0.01f)][int(posY)] == false) posX += dirX * 0.01f;
bwang 6:0a34891a82c7 912 if(worldMap[int(posX)][int(posY + dirY * 0.01f)] == false) posY += dirY * 0.01f;
bwang 6:0a34891a82c7 913
bwang 6:0a34891a82c7 914 int w = SX_MAX-SX_MIN;
bwang 6:0a34891a82c7 915 int h = SY_MAX-SY_MIN;
bwang 6:0a34891a82c7 916 for (int x = 0; x < SX_MAX - SX_MIN; x++) {
bwang 6:0a34891a82c7 917 float cameraX = 2 * x / float(w) - 1; //x-coordinate in camera space
bwang 6:0a34891a82c7 918 float rayPosX = posX;
bwang 6:0a34891a82c7 919 float rayPosY = posY;
bwang 6:0a34891a82c7 920 float rayDirX = dirX + planeX * cameraX;
bwang 6:0a34891a82c7 921 float rayDirY = dirY + planeY * cameraX;
bwang 6:0a34891a82c7 922
bwang 6:0a34891a82c7 923 int mapX = int(rayPosX);
bwang 6:0a34891a82c7 924 int mapY = int(rayPosY);
bwang 6:0a34891a82c7 925
bwang 6:0a34891a82c7 926 float sideDistX, sideDistY;
bwang 6:0a34891a82c7 927
bwang 6:0a34891a82c7 928 float deltaDistX = sqrtf(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
bwang 6:0a34891a82c7 929 float deltaDistY = sqrtf(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
bwang 6:0a34891a82c7 930 float perpWallDist;
bwang 6:0a34891a82c7 931
bwang 6:0a34891a82c7 932 int stepX, stepY;
bwang 6:0a34891a82c7 933 int hit = 0, side;
bwang 6:0a34891a82c7 934 if (rayDirX < 0) {
bwang 6:0a34891a82c7 935 stepX = -1;
bwang 6:0a34891a82c7 936 sideDistX = (rayPosX - mapX) * deltaDistX;
bwang 6:0a34891a82c7 937 } else {
bwang 6:0a34891a82c7 938 stepX = 1;
bwang 6:0a34891a82c7 939 sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX;
bwang 6:0a34891a82c7 940 }
bwang 6:0a34891a82c7 941 if (rayDirY < 0) {
bwang 6:0a34891a82c7 942 stepY = -1;
bwang 6:0a34891a82c7 943 sideDistY = (rayPosY - mapY) * deltaDistY;
bwang 6:0a34891a82c7 944 } else {
bwang 6:0a34891a82c7 945 stepY = 1;
bwang 6:0a34891a82c7 946 sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY;
bwang 6:0a34891a82c7 947 }
bwang 6:0a34891a82c7 948
bwang 6:0a34891a82c7 949 while (hit == 0)
bwang 6:0a34891a82c7 950 {
bwang 6:0a34891a82c7 951 //jump to next map square, OR in x-direction, OR in y-direction
bwang 6:0a34891a82c7 952 if (sideDistX < sideDistY)
bwang 6:0a34891a82c7 953 {
bwang 6:0a34891a82c7 954 sideDistX += deltaDistX;
bwang 6:0a34891a82c7 955 mapX += stepX;
bwang 6:0a34891a82c7 956 side = 0;
bwang 6:0a34891a82c7 957 }
bwang 6:0a34891a82c7 958 else
bwang 6:0a34891a82c7 959 {
bwang 6:0a34891a82c7 960 sideDistY += deltaDistY;
bwang 6:0a34891a82c7 961 mapY += stepY;
bwang 6:0a34891a82c7 962 side = 1;
bwang 6:0a34891a82c7 963 }
bwang 6:0a34891a82c7 964 //Check if ray has hit a wall
bwang 6:0a34891a82c7 965 if (worldMap[mapX][mapY] > 0) hit = 1;
bwang 6:0a34891a82c7 966 }
bwang 6:0a34891a82c7 967 //Calculate distance projected on camera direction (oblique distance will give fisheye effect!)
bwang 6:0a34891a82c7 968 if (side == 0) perpWallDist = (mapX - rayPosX + (1 - stepX) / 2) / rayDirX;
bwang 6:0a34891a82c7 969 else perpWallDist = (mapY - rayPosY + (1 - stepY) / 2) / rayDirY;
bwang 6:0a34891a82c7 970
bwang 6:0a34891a82c7 971 //Calculate height of line to draw on screen
bwang 6:0a34891a82c7 972 int drawStart,drawEnd;
bwang 6:0a34891a82c7 973 int lineHeight = (int)(h / perpWallDist);
bwang 6:0a34891a82c7 974 if (lineHeight > h) {
bwang 6:0a34891a82c7 975 drawStart = 0;
bwang 6:0a34891a82c7 976 drawEnd = h;
bwang 6:0a34891a82c7 977 } else {
bwang 6:0a34891a82c7 978 drawStart = -lineHeight / 2 + h / 2;
bwang 6:0a34891a82c7 979 drawEnd = lineHeight / 2 + h / 2;
bwang 6:0a34891a82c7 980 }
bwang 6:0a34891a82c7 981 if (side == 0) {
bwang 6:0a34891a82c7 982 for(int y = 0; y < drawStart; y++) {
bwang 6:0a34891a82c7 983 im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0;
bwang 6:0a34891a82c7 984 }
bwang 6:0a34891a82c7 985 for(int y = drawStart;y < drawEnd;y++) {
bwang 6:0a34891a82c7 986 im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 1;
bwang 6:0a34891a82c7 987 }
bwang 6:0a34891a82c7 988 for(int y = drawEnd; y < h; y++) {
bwang 6:0a34891a82c7 989 im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0;
bwang 6:0a34891a82c7 990 }
bwang 6:0a34891a82c7 991 } else {
bwang 6:0a34891a82c7 992 for(int y = 0; y < h; y++) im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0;
bwang 6:0a34891a82c7 993 im_line_va[H_RES*(drawStart+SY_MIN)+x+SX_MIN] = 1;
bwang 6:0a34891a82c7 994 im_line_va[H_RES*(drawEnd-1+SY_MIN)+x+SX_MIN] = 1;
bwang 6:0a34891a82c7 995 }
bwang 6:0a34891a82c7 996 }
bwang 6:0a34891a82c7 997 }
bwang 6:0a34891a82c7 998
bwang 3:d9edc0575aa3 999 int main() {
bwang 3:d9edc0575aa3 1000 potato:
bwang 3:d9edc0575aa3 1001 init_buffers();
bwang 3:d9edc0575aa3 1002 t.attach_us(&isr,63);
bwang 6:0a34891a82c7 1003
bwang 3:d9edc0575aa3 1004 int bmi = 0;
bwang 3:d9edc0575aa3 1005
bwang 4:02e3ae7a3aea 1006 for(int y = SY_MIN; y < SY_MIN + BY2; y++)
bwang 3:d9edc0575aa3 1007 {
bwang 3:d9edc0575aa3 1008 for(int x = SX_MIN; x < SX_MIN + BX; x++)
bwang 3:d9edc0575aa3 1009 {
bwang 3:d9edc0575aa3 1010 im_line_va[H_RES*y + x] = miters[bmi];
bwang 3:d9edc0575aa3 1011 bmi++;
bwang 3:d9edc0575aa3 1012 }
bwang 3:d9edc0575aa3 1013 }
bwang 3:d9edc0575aa3 1014
bwang 6:0a34891a82c7 1015 /*
bwang 4:02e3ae7a3aea 1016 dispchr(4, BY2+1, chr_P);
bwang 4:02e3ae7a3aea 1017 dispchr(11, BY2+1, chr_A);
bwang 4:02e3ae7a3aea 1018 dispchr(18, BY2+1, chr_N);
bwang 4:02e3ae7a3aea 1019 dispchr(25, BY2+1, chr_G);
bwang 4:02e3ae7a3aea 1020
bwang 4:02e3ae7a3aea 1021 dispchr(4, BY2+9, chr_F);
bwang 4:02e3ae7a3aea 1022 dispchr(11, BY2+9, chr_A);
bwang 4:02e3ae7a3aea 1023 dispchr(18, BY2+9, chr_S);
bwang 4:02e3ae7a3aea 1024 dispchr(25, BY2+9, chr_H);
bwang 3:d9edc0575aa3 1025
bwang 4:02e3ae7a3aea 1026 dispchr(4, BY2+17, chr_D);
bwang 4:02e3ae7a3aea 1027 dispchr(11, BY2+17, chr_A);
bwang 4:02e3ae7a3aea 1028 dispchr(18, BY2+17, chr_M);
bwang 4:02e3ae7a3aea 1029 dispchr(25, BY2+17, chr_O);
bwang 3:d9edc0575aa3 1030
bwang 4:02e3ae7a3aea 1031 dispchr(4, BY2+25, chr_D);
bwang 4:02e3ae7a3aea 1032 dispchr(11, BY2+25, chr_R);
bwang 4:02e3ae7a3aea 1033 dispchr(18, BY2+25, chr_A);
bwang 4:02e3ae7a3aea 1034 dispchr(25, BY2+25, chr_V);
bwang 6:0a34891a82c7 1035 */
bwang 3:d9edc0575aa3 1036 int cursor_pos = 0;
bwang 6:0a34891a82c7 1037 int menu_offs = 0;
bwang 3:d9edc0575aa3 1038
bwang 3:d9edc0575aa3 1039 for (;;) {
bwang 1:24fd07a24094 1040 int cmd1 = p1_in.read();
bwang 1:24fd07a24094 1041 int cmd2 = p2_in.read();
bwang 3:d9edc0575aa3 1042
bwang 3:d9edc0575aa3 1043 int cursor_x = SX_MIN;
bwang 4:02e3ae7a3aea 1044 int cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5;
bwang 1:24fd07a24094 1045
bwang 3:d9edc0575aa3 1046 if (cmd1 || cmd2) im_line_va[H_RES*cursor_y+cursor_x] = 0;
bwang 1:24fd07a24094 1047
bwang 3:d9edc0575aa3 1048 if (!cmd1) cursor_pos++;
bwang 3:d9edc0575aa3 1049 if (!cmd2) cursor_pos--;
bwang 3:d9edc0575aa3 1050 if (!cmd1 && !cmd2) break;
bwang 1:24fd07a24094 1051
bwang 3:d9edc0575aa3 1052 if (cursor_pos < 0) cursor_pos = 0;
bwang 6:0a34891a82c7 1053 if (cursor_pos > 4) cursor_pos = 4;
bwang 6:0a34891a82c7 1054 if (cursor_pos > 3) menu_offs = cursor_pos - 3; else menu_offs = 0;
bwang 1:24fd07a24094 1055
bwang 3:d9edc0575aa3 1056 cursor_x = SX_MIN;
bwang 6:0a34891a82c7 1057 if (cursor_pos < 4) cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5;
bwang 6:0a34891a82c7 1058 else cursor_y = SY_MIN + 8*3 + BY2 + 5;
bwang 6:0a34891a82c7 1059
bwang 6:0a34891a82c7 1060 for(int y = 0; y < 4; y++) {
bwang 6:0a34891a82c7 1061 for(int x = 0; x < 4; x++) {
bwang 6:0a34891a82c7 1062 dispchr(4+7*x,BY2+1+8*y,menu[4*(y+menu_offs)+x]);
bwang 6:0a34891a82c7 1063 }
bwang 6:0a34891a82c7 1064 }
bwang 1:24fd07a24094 1065
bwang 3:d9edc0575aa3 1066 im_line_va[H_RES*cursor_y+cursor_x] = 1;
bwang 3:d9edc0575aa3 1067
bwang 3:d9edc0575aa3 1068 wait(0.1);
bwang 1:24fd07a24094 1069 }
bwang 1:24fd07a24094 1070
bwang 3:d9edc0575aa3 1071 init_buffers();
bwang 2:1d16e99f334b 1072
bwang 3:d9edc0575aa3 1073 if (cursor_pos == 0) {
bwang 3:d9edc0575aa3 1074 for (;;) {
bwang 3:d9edc0575aa3 1075 if (!flappy_pong()) break;
bwang 3:d9edc0575aa3 1076 }
bwang 3:d9edc0575aa3 1077 } else if (cursor_pos == 1) {
bwang 3:d9edc0575aa3 1078 for (;;) fishy();
bwang 4:02e3ae7a3aea 1079 } else if (cursor_pos == 2) {
bwang 4:02e3ae7a3aea 1080 for (;;) update_image();
bwang 6:0a34891a82c7 1081 } else if (cursor_pos == 3) {
bwang 4:02e3ae7a3aea 1082 init_tunnel();
bwang 4:02e3ae7a3aea 1083 for (;;)
bwang 4:02e3ae7a3aea 1084 {
bwang 4:02e3ae7a3aea 1085 update_tunnel();
bwang 4:02e3ae7a3aea 1086 }
bwang 6:0a34891a82c7 1087 } else if (cursor_pos == 4) {
bwang 6:0a34891a82c7 1088 for (;;) {
bwang 6:0a34891a82c7 1089 update_rc();
bwang 6:0a34891a82c7 1090 }
dicarloj 0:7757ab3f7206 1091 }
bwang 3:d9edc0575aa3 1092 goto potato;
dicarloj 0:7757ab3f7206 1093 }