I already fixed it. Check the code:
Code: #include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.h"
#include "PortalPics.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_UP) && cursor->y>0) cursor->y-=16;
if( keydown(KEY_PRGM_DOWN) && cursor->y<LCD_HEIGHT_PX) cursor->y+=16;
if( keydown(KEY_PRGM_LEFT) && cursor->x>0) cursor->x-=16;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<LCD_WIDTH_PX) cursor->x+=16;
}
int main() {
struct Coord cur;
cur.x = 0;
cur.y = 0;
int a = 100;
int b = 100;
int c = 0;
int d = -33;
int e = 0;
int f = -33;
int h = 2;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(PortalBack, 0, 0, 384, 216);
CopySpriteMasked(BigCursor, cur.x, cur.y, 12, 21, COLOR_RED);
if(h == 1)
CopySpriteMasked(PortalPlayerBack, a, b, 18, 34, COLOR_RED);
if(h == 2)
CopySpriteMasked(PortalPlayerFront, a, b, 18, 34, COLOR_RED);
if(h == 3)
CopySpriteMasked(PortalPlayerLeft, a, b, 18, 34, COLOR_RED);
if(h == 4)
CopySpriteMasked(PortalPlayerRight, a, b, 18, 34, COLOR_RED);
if( keydown(KEY_PRGM_SHIFT)) {
c = cur.x;
d = cur.y; }
if( keydown(KEY_PRGM_ALPHA)) {
e = cur.x;
f = cur.y; }
if( keydown(KEY_PRGM_8) && b >= 0) {
b-=16;
h = 1;
CopySpriteMasked(PortalPlayerBack, a, b, 18, 34, COLOR_RED); }
if( keydown(KEY_PRGM_2) && b <= 189) {
b+=16;
h = 2;
CopySpriteMasked(PortalPlayerFront, a, b, 18, 34, COLOR_RED); }
if( keydown(KEY_PRGM_4) && a >= 4) {
a-=16;
h = 3;
CopySpriteMasked(PortalPlayerLeft, a, b, 18, 34, COLOR_RED); }
if( keydown(KEY_PRGM_6) && a <= 364) {
a+=16;
h = 4;
CopySpriteMasked(PortalPlayerRight, a, b, 18, 34, COLOR_RED); }
CopySpriteMasked(BluePortal, c, d, 24, 32, COLOR_RED);
CopySpriteMasked(OrangePortal, e, f, 24, 32, COLOR_RED);
if((a+9 >= c && a+9 <= c+24) && (b+17 >= d && b+17 <= d+32)) {
a = e-18;
b = f;}
if((a+9 >= e && a+9 <= e+24) && (b+17 >= f && b+17 <= f+32)) {
a = c-18;
b = d;}
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
return 0;
}
Thanks anyways!
Edit: So, I've Decided to make another Prizm game. Iknow I have other games to work on, but Bullet is almost done. I'm not sure what to call it, but it is going to be an RPG. Here is the main character:
Give opinions please.