coderx04

Members
  • Content count

    43
  • Joined

  • Last visited

Community Reputation

122 Neutral

About coderx04

  • Rank
    Member
  1. Thank you very much eville, its really help. Its working fine now. I will rate you *_*
  2. Unity

    ooww thank you, Im giving funny question yeah? :P.. Thankss..
  3. Unity

    How to check if there is any key being pressed??
  4. ok cool , thanks for the help...
  5. void CSprite::clearBG() { if(mDrawn==1) { SDL_Rect dest; dest.x = mOldX; dest.y = mOldY; dest.w = mSpriteBase->mW; dest.h = mSpriteBase->mH; SDL_BlitSurface(mBackreplacement, NULL, mScreen, &dest); } } void CSprite::updateBG() { SDL_Rect srcrect; srcrect.w = mSpriteBase->mW; srcrect.h = mSpriteBase->mH; srcrect.x = mX; srcrect.y = mY; mOldX=mX;mOldY=mY; SDL_BlitSurface(mScreen, &srcrect, mBackreplacement, NULL); } Where is wrong with that? And actually Im not quite understand how to - Erase all the Image in the screen? - when to use the SDL_FLIP? - Whats wrong with the transparant image?
  6. Soory I dont understand what you mean by dirty rectangle method? Is it because I flip the whole screen? I have to flip every rectangle sprite or what? Please help ... And what is Antiliasing ? how to solve this? please..
  7. The one with yellow circle is what im complain about..
  8. void DrawScene() { sun.clearBG(); Swords.clearBG(); sun.updateBG(); Swords.updateBG(); sun.draw(); Swords.draw(); SDL_Flip(screen); } SDL_Surface * ImageLoad(char *file) { SDL_Surface *temp1, *temp2; temp1 = SDL_LoadBMP(file); temp2 = SDL_DisplayFormat(temp1); SDL_FreeSurface(temp1); return temp2; } int InitImages() { back = ImageLoad("back.bmp"); image = ImageLoad("map1.bmp"); return 0; } //--------------------------------------------- void DrawBG(SDL_Surface *bg) { //Slock(screen); SDL_FillRect(screen, NULL, 0); DrawIMG(bg, 0, 0); } //--------------------------------------------- int main(int argc, char *argv[]) { Uint8* keys; my_timer_id = SDL_AddTimer((33/10)*10, my_callbackfunc, my_callback_param); if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) <0 ) { printf("Unable to init SDL: %s\n", SDL_GetError()); return 1; } atexit(SDL_Quit); if(Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0) { printf("Warning: Couldn't set 44100 Hz 16-bit audio\n - Reason: %s\n", SDL_GetError()); } screen=SDL_SetVideoMode(SCREENWIDTH,SCREENHEIGHT,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_HWPALETTE); if ( screen == NULL ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); exit(1); } //load the music music = Mix_LoadMUS("data/sound/(sblu)moon6.xm"); //play the music if(!Mix_PlayingMusic()) { // then start playing it. Mix_PlayMusic(music, 0); } Swordsbase.init("data/testC/down"); sunbase.init("data/sun"); sun.init(&sunbase,screen); sun.set(480,50); sun.setSpeed(1); Swords.init(&Swordsbase,screen); Swords.set(150,300); Swords.setSpeed(2); SDL_ShowCursor(0); font = initFont("data/font"); InitImages(); //DrawBG(back); while (game_state!=GAME_EXIT) { SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) { game_state=GAME_EXIT;} if ( event.type == SDL_KEYDOWN ) { if ( event.key.keysym.sym == SDLK_ESCAPE ) { game_state=GAME_EXIT; } } } keys = SDL_GetKeyState(NULL); if ( keys[SDLK_UP] ) { Swords.yadd(-1); } if ( keys[SDLK_DOWN] ) { Swords.yadd(1); } if ( keys[SDLK_LEFT] ) { Swords.xadd(-1); } if ( keys[SDLK_RIGHT] ) { Swords.xadd(1); } if ( keys[SDLK_s] ) { if(game_state!=GAME_RUN||game_state!=GAME_STARTING) { SDL_FillRect(screen,0,0); sun.clearBG(); Swords.clearBG(); game_state = GAME_STARTING; } //SDL_FillRect(screen,0,0); //DrawIMG(image, 0, 0); //SDL_Flip(screen); } if(game_state == GAME_INIT) DrawBG(back); if(game_state == GAME_STARTING) { SDL_FillRect(screen, NULL, 0); DrawBG(image); //SDL_Flip(screen); //game_state++; } DrawScene(); } return 0; } I have problem, when the character move down, it have some red colour on the screen.. And when I change the background image, it still have a square colour from the previous background image... Ill show you the picture how to upload a picture in here?
  9. ok thanks.. One Question, I can just basically use SDL_DELAY(100) for 10 millisecond rite?.. thankss..
  10. Quote:Original post by coderx04 Or make the movement time based, so instead of saying move 1 unit per frame, you can say more X units per second. how to move X units per second actually? using the SDL_DELAY?
  11. [quote]Or make the movement time based, so instead of saying move 1 unit per frame, you can say more X units per second. [\quote] how to move X units per second actually? using the SDL_DELAY?
  12. How to get the correct time in SDL? is there any example of using SDL_TIMER?
  13. Why not hard Code it? Is there any other way to force change the resolution when the game start. because, I dont want to have the game be different if the use change the display settings. And thanks, After I include windows.h before include winuser.h It did compile, but still no different.
  14. Quote: void ChangeRes() { // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_7gz7.asp // #include <winuser.h> // get the current devices display settings DEVMODE lpDevMode; ZeroMemory(&lpDevMode, sizeof(DEVMODE)); lpDevMode.dmSize = sizeof(DEVMODE); lpDevMode.dmDriverExtra = 0; if (!EnumDisplaySettings(NULL/* current device */,ENUM_CURRENT_SETTINGS, &lpDevMode)) ExitProcess(1); if (lpDevMode.dmPelsWidth == 800 && lpDevMode.dmPelsHeight == 600) return; // no need to change // set settings lpDevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; lpDevMode.dmPelsWidth = 800; lpDevMode.dmPelsHeight = 600; lpDevMode.dmDisplayFrequency = 85; // change settings long status; do { status = ChangeDisplaySettings(&lpDevMode, CDS_FULLSCREEN /* temporary, till program exits*/); lpDevMode.dmDisplayFrequency -= 5; } while (status != DISP_CHANGE_SUCCESSFUL && lpDevMode.dmDisplayFrequency >= 60); if (status != DISP_CHANGE_SUCCESSFUL) { lpDevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT ; status = ChangeDisplaySettings(&lpDevMode, CDS_FULLSCREEN /* temporary, till program exits*/); if (status != DISP_CHANGE_SUCCESSFUL) ExitProcess(1); } } I got this code from my tutor for borland C++ builder, But When I use it in Visual C++ win32 application. and use SDL library, its not working, Can you tell me whats wrong with that..? This is the error when im compiling it : c:\program files\microsoft visual studio\vc98\include\winuser.h(39) : error C2146: syntax error : missing ';' before identifier 'HDWP' c:\program files\microsoft visual studio\vc98\include\winuser.h(39) : fatal error C1004: unexpected end of file found Error executing cl.exe.