C言語を使用し、アセンブリを行うことでGBAで実行するためのコードで、Snake Gameを実現したいけどうまくできません。

C

12 while (1) {3 if ((((*key & right) == 0) || keyjudge == 1) && (getPixelColor(headx + 20, heady) != 0x7FE0)) {4 keyjudge = 1;5 delay(1000000);6 if(deletejudge == 2){7 bodypoint[0][1] = bodypoint[0][1] + 20;8 deletejudge = 1;9 }else if(deletejudge == 4){10 bodypoint[0][1] = bodypoint[0][1] - 20;11 deletejudge = 1;12 }13 DeleteSnake(bodypoint[0][0], bodypoint[0][1]);14 SnakeBody(headx, heady, snakecolor);15 headx = headx + 20;16 bodypoint[0][0] = bodypoint[0][0] + 20;17 SnakeHeadRight(headx, heady, snakecolor);18 if((*key & down) == 0){19 keyjudge = 2;20 }21 if((*key & up) == 0){22 keyjudge = 4;23 }24 } else if ((((*key & down) == 0) || keyjudge == 2) && (getPixelColor(headx, heady + 20) != 0x7FE0)) {25 keyjudge = 2;26 delay(1000000);27 if(deletejudge == 1){28 bodypoint[0][0] = bodypoint[0][0] + 20;29 deletejudge = 2;30 }else if(deletejudge == 3){31 bodypoint[0][0] = bodypoint[0][0] - 20;32 deletejudge = 2;33 }34 DeleteSnake(bodypoint[0][0], bodypoint[0][1]);35 SnakeBody(headx, heady, snakecolor);36 heady = heady + 20;37 bodypoint[0][1] = bodypoint[0][1] + 20;38 SnakeHeadDown(headx, heady, snakecolor);39 if((*key & right) == 0){40 keyjudge = 1;41 }42 if((*key & left) == 0){43 keyjudge = 3;44 }45 } else if ((((*key & left) == 0) || keyjudge == 3) && (getPixelColor(headx - 20, heady) != 0x7FE0)) {46 keyjudge = 3;47 delay(1000000);48 if(deletejudge == 2){49 bodypoint[0][1] = bodypoint[0][1] + 20;50 deletejudge = 3;51 }else if(deletejudge == 4){52 bodypoint[0][1] = bodypoint[0][1] - 20;53 deletejudge = 3;54 }55 DeleteSnake(bodypoint[0][0], bodypoint[0][1]);56 SnakeBody(headx, heady, snakecolor);57 headx = headx - 20;58 bodypoint[0][0] = bodypoint[0][0] - 20;59 SnakeHeadLeft(headx, heady, snakecolor);60 if((*key & down) == 0){61 keyjudge = 2;62 }63 if((*key & up) == 0){64 keyjudge = 4;65 }66 } else if ((((*key & up) == 0) || keyjudge == 4) && (getPixelColor(headx, heady - 20) != 0x7FE0)) {67 keyjudge = 4;68 delay(1000000);69 if(deletejudge == 1){70 bodypoint[0][0] = bodypoint[0][0] + 20;71 deletejudge = 4;72 }else if(deletejudge == 3){73 bodypoint[0][0] = bodypoint[0][0] - 20;74 deletejudge = 4;75 }76 DeleteSnake(bodypoint[0][0], bodypoint[0][1]);77 SnakeBody(headx, heady, snakecolor);78 heady = heady - 20;79 bodypoint[0][1] = bodypoint[0][1] - 20;80 SnakeHeadUp(headx, heady, snakecolor);81 if((*key & right) == 0){82 keyjudge = 1;83 }84 if((*key & left) == 0){85 keyjudge = 3;86 }87 } else if(getPixelColor(headx, heady) == 0x7FE0 || getPixelColor(headx, heady) == 0x7C00){88 while(1)89 return(0);90 }else{91 delay(1000000);92 SnakeBody(headx, heady, snakecolor);93 headx = headx + 20;94 SnakeHeadRight(headx, heady, snakecolor);95 }96 }97 return 0;98}99 100void SnakeHeadRight(hword startx, hword starty, hword color) {101 hword xa, ya, xb, yb;102 hword black = 0x0000;103 hword white = 0xFFFF;104 xa = startx - 8;105 ya = starty - 8;106 xb = startx + 10;107 yb = starty + 10;108 for (a = xa; a < xb; a++) {109 for (b = ya; b < yb; b++) {110 draw_point(a, b, color);111 if ((a > xb - 11 && a < xb - 2) && ((b > ya + 2 && b < ya + 8) || (b > yb - 8 && b < yb - 2))) {112 draw_point(a, b, white);113 }114 if ((a > xb - 7 && a < xb - 4) && ((b > ya + 3 && b < ya + 7) || (b > yb - 7 && b < yb - 3))) {115 draw_point(a, b, black);116 }117 }118 }119}120 121void SnakeHeadDown(hword startx, hword starty, hword color) {122 hword xa, ya, xb, yb;123 hword black = 0x0000;124 hword white = 0xFFFF;125 xa = startx - 8;126 ya = starty - 8;127 xb = startx + 10;128 yb = starty + 10;129 for (a = xa; a < xb; a++) {130 for (b = ya; b < yb; b++) {131 draw_point(a, b, color);132 if ((b > yb - 11 && b < yb - 2) && ((a > xa + 2 && a < xa + 8) || (a > xb - 8 && a < xb - 2))) {133 draw_point(a, b, white);134 }135 if ((b > yb - 7 && b < yb - 4) && ((a > xa + 3 && a < xa + 7) || (a > xb - 7 && a < xb - 3))) {136 draw_point(a, b, black);137 }138 }139 }140}141 142void SnakeHeadLeft(hword startx, hword starty, hword color) {143 hword xa, ya, xb, yb;144 hword black = 0x0000;145 hword white = 0xFFFF;146 xa = startx - 8;147 ya = starty - 8;148 xb = startx + 10;149 yb = starty + 10;150 for (a = xa; a < xb; a++) {151 for (b = ya; b < yb; b++) {152 draw_point(a, b, color);153 if ((a < xa + 11 && a > xa + 2) && ((b > ya + 2 && b < ya + 8) || (b > yb - 8 && b < yb - 2))) {154 draw_point(a, b, white);155 }156 if ((a < xa + 7 && a > xa + 4) && ((b > ya + 3 && b < ya + 7) || (b > yb - 7 && b < yb - 3))) {157 draw_point(a, b, black);158 }159 }160 }161}162 163void SnakeHeadUp(hword startx, hword starty, hword color) {164 hword xa, ya, xb, yb;165 hword black = 0x0000;166 hword white = 0xFFFF;167 xa = startx - 8;168 ya = starty - 8;169 xb = startx + 10;170 yb = starty + 10;171 for (a = xa; a < xb; a++) {172 for (b = ya; b < yb; b++) {173 draw_point(a, b, color);174 if ((b < ya + 11 && b > ya + 2) && ((a > xa + 2 && a < xa + 8) || (a > xb - 8 && a < xb - 2))) {175 draw_point(a, b, white);176 }177 if ((b < ya + 7 && b > ya + 4) && ((a > xa + 3 && a < xa + 7) || (a > xb - 7 && a < xb - 3))) {178 draw_point(a, b, black);179 }180 }181 }182}183 184void SnakeBody(hword startx, hword starty, hword color) {185 hword xa, ya, xb, yb;186 xa = startx - 8;187 ya = starty - 8;188 xb = startx + 10;189 yb = starty + 10;190 for (a = xa; a < xb; a++) {191 for (b = ya; b < yb; b++) {192 draw_point(a, b, color);193 }194 }195}196 197void DeleteSnake(hword talex, hword taley) {198 hword xa, ya, xb, yb;199 hword black = 0x0000; // 背景色を黒と仮定200 xa = talex - 8; // `startx` の代わりに `talex` を使用201 ya = taley - 8; // `starty` の代わりに `taley` を使用202 xb = talex + 10; // 同様に `talex` を使用203 yb = taley + 10; // 同様に `taley` を使用204 for (a = xa; a < xb; a++) {205 for (b = ya; b < yb; b++) {206 draw_point(a, b, black);207 }208 }209}210 211void draw_point(hword x, hword y, hword color) {212 hword *ptr;213 ptr = (hword*) VRAM;214 ptr += y * 240 + x;215 *ptr = color;216}217 218// 指定した座標のピクセルの色を取得する関数219hword getPixelColor(int x, int y) {220 hword *ptr;221 ptr = (hword*) VRAM;222 return ptr[y * 240 + x];223}224 225void delay(int count) {226 int i; // ここで変数を宣言227 for (i = 0; i < count; i++) {228 asm("nop");229 }230}231 232

コメントを投稿

0 コメント