Bullet is the name of the game I'm making, but the code is being spo annoying. I can't figure out what's wrong. Help please:
Code:
Help fix it. PLEASE!
Code:
#include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.h"
#include "PictureData.h"
#include "stdlib.h"
void CopySprite(const void* datar, int x, int y, int width, int height) {
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
*(VRAM++) = *(data++);
}
VRAM += LCD_WIDTH_PX-width;
}
}
void CopySpriteMasked(const void*datar, int x, int y, int width, int height, int maskcolor) {
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
if (*(data) != maskcolor) {
*(VRAM++) = *(data++);
} else { VRAM++; data++; }
}
VRAM += LCD_WIDTH_PX-width;
}
}
int PRGM_GetKey(){
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
struct Coord {
int x;
int y;
};
int keydown(int basic_keycode)
{
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (keyboard_register[word] & 1<<bit));
}
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_LEFT) && cursor->x>45) cursor->x-=8;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<302) cursor->x+=8;
}
int main() {
int y = 129;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
CopySprite(BulletMenu, 0, 0, 384, 216);
CopySpriteMasked(BulletMenuSelector, 7, y, 18, 16, COLOR_RED);
if(keydown(KEY_PRGM_UP) && y>129)
y-=16;
if(keydown(KEY_PRGM_DOWN) && y<145)
y+=16;
if(keydown(KEY_PRGM_SHIFT) && y == 129) {
while(1) {
struct Coord cur;
cur.x = 128;
int w = rand()%(340-45+1) + 45;
int b = rand()%(340-45+1) + 45;
int j = 0;
int s = 0;
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BulletBackground, 0, 0, 384, 216);
CopySpriteMasked(SpenBullet, cur.x, 159, 38, 43, COLOR_RED);
CopySpriteMasked(Banana, w, j, 75, 80, COLOR_RED);
CopySpriteMasked(LSDOMG, b, j, 34, 34, COLOR_RED);
if(w == cur.x && j == 159)
break;
if(b == cur.x && j == 159)
s++;
j+=8;
if(j >= 216) {
j = 0;
w = rand()%(340-45+1) + 45;
b = rand()%(340-45+1) + 45;
}
if(keydown(KEY_PRGM_EXIT))
break;
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
} }
if(keydown(KEY_PRGM_SHIFT) && y == 145) {
while(1) {
CopySprite(Instructions, 0, 0, 384, 216);
if(keydown(KEY_PRGM_EXIT))
break;
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
return 0;
}
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
return 0;
}
Help fix it. PLEASE!