#38835 - christosterone - Fri Apr 01, 2005 5:54 am
im a total noob to this; i just got the compliler.
my game keeps flickering;
heres the code:
my game keeps flickering;
heres the code:
Code: |
#include "gba.h" #include "screenmodes.h" #include "keypad.h" u16* theVideoBuffer = (u16*)VideoBuffer; u16* theBackBuffer = (u16*)BackBuffer; #define RGB(r,g,b) (r+(g<<5)+(b<<10)) //Macro to build a color from its parts int x = 50; int y = 50; int canMove() { int returnval=0; if( x>=0 && x<240 && y>=0 && y<160 ) returnval=1; return returnval; } void clrscreen() { for( int i=0; i<(160*240); i++ ) { theVideoBuffer[ i ] = RGB( 256, 0, 0 ); } } void WaitForVsync() { while((volatile u16)REG_VCOUNT != 160){} } void flip() { if (REG_DISPCNT & BACKBUFFER) { REG_DISPCNT &= ~BACKBUFFER; theVideoBuffer = theBackBuffer; } else { REG_DISPCNT |= BACKBUFFER; theVideoBuffer = theBackBuffer; } } void repaint() { clrscreen(); WaitForVsync(); theBackBuffer[ x + (y * 240) ] = RGB( 31, 31, 31 ); flip(); } int main() { SetMode( SCREENMODE3 | BG2ENABLE ); //Set screen mode repaint(); while(1) { if( KEY_DOWN(KEYUP) ) { y--; if( canMove()==0 ) y++; repaint(); } else if( KEY_DOWN(KEYDOWN) ) { y++; if( canMove()==0 ) y--; repaint(); } else if( KEY_DOWN(KEYRIGHT) ) { x++; if( canMove()==0 ) x--; repaint(); } else if( KEY_DOWN(KEYLEFT) ) { x--; if( canMove()==0 ) x++; repaint(); } } return 0; } |