int main( int argc, char* argv[] ) { OBJSC model; load_objsc("./Models/Dress.objsc", &model); /* Information about the current video settings. */ const SDL_VideoInfo* info = NULL; /* Dimensions of our window. */ int width = 0; int height = 0; /* Color depth in bits of our window. */ int bpp = 0; /* Flags we will pass into SDL_SetVideoMode. */ int flags = 0; /* First, initialize SDL's video subsystem. */ if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { /* Failed, exit. */ fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) ); quit_tutorial( 1 ); } /* Let's get some video information. */ info = SDL_GetVideoInfo( ); if( !info ) { /* This should probably never happen. */ fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) ); quit_tutorial( 1 ); } /* * Set our width/height to 640/480 (you would * of course let the user decide this in a normal * app). We get the bpp we will request from * the display. On X11, VidMode can't change * resolution, so this is probably being overly * safe. Under Win32, ChangeDisplaySettings * can change the bpp. */ width = 640; height = 480; bpp = info->vfmt->BitsPerPixel; /* * Now, we want to setup our requested * window attributes for our OpenGL window. * We want *at least* 5 bits of red, green * and blue. We also want at least a 16-bit * depth buffer. * * The last thing we do is request a double * buffered window. '1' turns on double * buffering, '0' turns it off. * * Note that we do not use SDL_DOUBLEBUF in * the flags to SDL_SetVideoMode. That does * not affect the GL attribute state, only * the standard 2D blitting setup. */ SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); /* * We want to request that SDL provide us * with an OpenGL window, in a fullscreen * video mode. * * EXERCISE: * Make starting windowed an option, and * handle the resize events properly with * glViewport. */ flags = SDL_OPENGL; /* * Set the video mode */ if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) { /* * This could happen for a variety of reasons, * including DISPLAY not being set, the specified * resolution not being available, etc. */ fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); quit_tutorial( 1 ); } /* * At this point, we should have a properly setup * double-buffered window for use with OpenGL. */ setup_opengl( width, height ); /* * Now we want to begin our normal app process-- * an event loop with a lot of redrawing. */ while( 1 ) { /* Process incoming events. */ process_events( ); /* Draw the screen. */ draw_screen( &model ); SDL_PumpEvents(); uint8_t * keys = SDL_GetKeyState(NULL); game_time += 0.4; float friction = (speed < 0.4) ? (speed < 0.2) ? 0.5 : 0.85 : 0.98; speed *= friction; if(keys[SDLK_w]){ speed += 0.13*(1-speed) + 0.1*speed; } if(keys[SDLK_a]){ angle += .1; speed += 0.13*(1-speed) - 0.1*speed; } if(keys[SDLK_d]){ angle -= .1; speed += 0.13*(1-speed) - 0.1*speed; } if(speed > 1) speed = 1; } /* * EXERCISE: * Record timings using SDL_GetTicks() and * and print out frames per second at program * end. */ /* Never reached. */ return 0; }
void Player::getInput() { key = SDL_GetKeyState(NULL); //Primary Attack if ( key[SDLK_DOWN] ) { Power = 1; Attacking = true; Clip.x = 64; frame = 2; } //Special Attack else if ( key[SDLK_RCTRL] ) { Power = 5; Attacking = true; Clip.x = 64; frame = 2; Special -= 1.5; } else { Attacking = false; Clip.x = 0; } if ( Special <= 0 ) { Power = 1; } //Movement if ( key[SDLK_RIGHT] ) { Pos.x += Speed; Direction = 3; Clip.y = 48; frame += 1; } if ( key[SDLK_LEFT] ) { Pos.x -= Speed; Direction = 2; Clip.y = 0; frame += 1; } //Boost if ( key[SDLK_UP] ) { Speed = 10; Boost -= 0.05; } else { Speed = 5; } if ( Boost <= 0 ) { Speed = 5; } //Sheild if ( key[SDLK_RSHIFT] ) { IsEnabledShield = true; } else { IsEnabledShield = false; } //Updating frame and direction if ( frame > 1 && Attacking == false ) { frame = 0; } Clip.x = frame * 32; //Wrap player to other side of screen if ( Pos.x < 0 ) Pos.x = 640; if ( Pos.x > 640 ) Pos.x = 0; }
EventInput::EventInput() { keystate = SDL_GetKeyState(NULL); }
//Check for any window messages (keypress, paint, mousemove, etc) void CheckMessages() { SDL_Event ev; bool quit = false; if(HandleDPad()) { return; } lastchar_is_mouse = false; while(SDL_PollEvent(&ev)) { switch(ev.type) { case SDL_KEYDOWN: { int lc = 0; //hide mouse cursor on keyboard input if(OPTIONS["HIDE_CURSOR"] != "show" && SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_DISABLE); } Uint8 *keystate = SDL_GetKeyState(NULL); // manually handle Alt+F4 for older SDL lib, no big deal if( ev.key.keysym.sym == SDLK_F4 && (keystate[SDLK_RALT] || keystate[SDLK_LALT]) ) { quit = true; break; } else if( ev.key.keysym.sym == SDLK_RSHIFT || ev.key.keysym.sym == SDLK_LSHIFT || ev.key.keysym.sym == SDLK_RCTRL || ev.key.keysym.sym == SDLK_LCTRL || ev.key.keysym.sym == SDLK_RALT ) { break; // temporary fix for unwanted keys } else if( ev.key.keysym.sym == SDLK_LALT ) { begin_alt_code(); break; } else if( ev.key.keysym.unicode != 0 ) { lc = ev.key.keysym.unicode; switch (lc){ case 13: //Reroute ENTER key for compatilbity purposes lc=10; break; case 8: //Reroute BACKSPACE key for compatilbity purposes lc=127; break; } } if( ev.key.keysym.sym == SDLK_LEFT ) { lc = KEY_LEFT; } else if( ev.key.keysym.sym == SDLK_RIGHT ) { lc = KEY_RIGHT; } else if( ev.key.keysym.sym == SDLK_UP ) { lc = KEY_UP; } else if( ev.key.keysym.sym == SDLK_DOWN ) { lc = KEY_DOWN; } else if( ev.key.keysym.sym == SDLK_PAGEUP ) { lc = KEY_PPAGE; } else if( ev.key.keysym.sym == SDLK_PAGEDOWN ) { lc = KEY_NPAGE; } if( !lc ) { break; } if( alt_down ) { add_alt_code( lc ); } else { lastchar = lc; } lastchar_isbutton = false; } break; case SDL_KEYUP: { if( ev.key.keysym.sym == SDLK_LALT ) { int code = end_alt_code(); if( code ) { lastchar = code; } } } break; case SDL_JOYBUTTONDOWN: lastchar = ev.jbutton.button; lastchar_isbutton = true; break; case SDL_JOYAXISMOTION: // on gamepads, the axes are the analog sticks // TODO: somehow get the "digipad" values from the axes break; case SDL_MOUSEMOTION: if( (OPTIONS["HIDE_CURSOR"] == "show" || OPTIONS["HIDE_CURSOR"] == "hidekb") && !SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_ENABLE); } break; case SDL_MOUSEBUTTONUP: if (ev.button.button == SDL_BUTTON_LEFT) { lastchar_is_mouse = true; lastchar = MOUSE_BUTTON_LEFT; } else if (ev.button.button == SDL_BUTTON_RIGHT) { lastchar_is_mouse = true; lastchar = MOUSE_BUTTON_RIGHT; } else if (ev.button.button == SDL_BUTTON_WHEELUP) { // Mouse wheel emulates '<' and '>' // FIXME This should really find current key from 'keymap', in case it's remapped, but // that's in action.h. When that's available at a different abstraction level, // this can be improved. lastchar = '<'; } else if (ev.button.button == SDL_BUTTON_WHEELDOWN) { lastchar = '>'; } break; case SDL_QUIT: quit = true; break; } } #ifdef SDLTILES if (needupdate) { try_update(); } #endif if(quit) { endwin(); exit(0); } }
void keyInput(void) { // 传入NULL参数将返回所有已按的按键的一个指针数组、迩可以 // 遍历这个数组然后检测迩想检测的按键是否已经按下去了 keys = SDL_GetKeyState(NULL); if(Gamepad->Button_Start) { showMenu(); } /* if(keys[SDLK_f]) { delete [] cheatcode; cheatcode = new char[10]; strcpy(cheatcode,"f"); keys[SDLK_f] = 0; } if(keys[SDLK_i]) { if(strlen(cheatcode)<10) strcat(cheatcode,"i"); keys[SDLK_i] = 0; } if(keys[SDLK_r]) { if(strlen(cheatcode)<10) strcat(cheatcode,"r"); keys[SDLK_r] = 0; } */ // 1、 假如输入fir再输入e、那么会掉一个花出来奖励给玩家、如果再按 // 会再出现、最多只能出现5朵花 // 2、假如输入了di再输入e、那么会自杀 // e就是执行的意思 if(keys[SDLK_8]) { if(cheats_enabled) //if(!strcmp(cheatcode,"fir")) { keys[SDLK_8] = 0; for(int i=0;i<5;i++) // 同一时刻只准在屏幕中出现最多5个奖励物品 if(!BONUS_DYNAMIC[i]->online) { cheater = 1; BONUS_DYNAMIC[i]->init(PLAYER->x/40,(PLAYER->y-80)/40,1); break; } } //if(!strcmp(cheatcode,"di")) //PLAYER->die(); } if(keys[SDLK_0]) { if(cheats_enabled) //if(!strcmp(cheatcode,"fir")) { keys[SDLK_0] = 0; for(int i=0;i<5;i++) // 同一时刻只准在屏幕中出现最多5个奖励物品 if(!BONUS_DYNAMIC[i]->online) { cheater = 1; BONUS_DYNAMIC[i]->init(PLAYER->x/40,(PLAYER->y-80)/40,2); break; } } //if(!strcmp(cheatcode,"di")) //PLAYER->die(); } /* else if(keys[SDLK_b]) { delete [] cheatcode; cheatcode = new char[10]; strcpy(cheatcode,"b"); keys[SDLK_b] = 0; } */ // 如果输入了bi再输入g、就长出蘑菇、和前面长出花是一样道理的 if(keys[SDLK_9]) { if(cheats_enabled) //if(!strcmp(cheatcode,"bi")) { keys[SDLK_9] = 0; for(int i=0;i<5;i++) if(!BONUS_DYNAMIC[i]->online) { cheater = 1; BONUS_DYNAMIC[i]->init(PLAYER->x/40,(PLAYER->y-80)/40,0); break; } } } /* else if(keys[SDLK_d]) { delete [] cheatcode; cheatcode = new char[10]; strcpy(cheatcode,"d"); keys[SDLK_d] = 0; } else if(keys[SDLK_s]) { delete [] cheatcode; cheatcode = new char[10]; strcpy(cheatcode,"s"); keys[SDLK_s] = 0; } */ // 先输入s再输入l可以实现超级跳 if(keys[SDLK_l]) { if(cheats_enabled) //if(!strcmp(cheatcode,"s")) PLAYER->changeStat(0); } if(keys[SDLK_p]) { PLAYSOUND0(S_PAUSE); showTip(" Game Paused"," "," "," The journey goes on"," "," "," "); } // 如果同时输入5和1、MARIO会飞 if(cheats_enabled) if(keys[SDLK_i]) { cheater = 1; PLAYER->y_speed = -5; } }
void inpUpdate() { int event = 0; int x, y; int key; // while( SDL_PollEvent( &event ) ) SDL_PollEvent( event ); // { // switch( event.type ) // if (event & SDL_KEYDOWN) { //switch( event.key.keysym.sym ) key = SDL_GetKeyState(NULL); if (key & SDLK_SPACE) _Inp.keyC = BNX_TRUE; if(key & SDLK_RETURN) _Inp.keyA = BNX_TRUE; if(key & SDLK_ESCAPE) _Inp.keyB = BNX_TRUE; if(key & SDLK_UP) _Inp.keyUp = BNX_TRUE; if(key & SDLK_DOWN) _Inp.keyDown = BNX_TRUE; if(key & SDLK_LEFT) _Inp.keyLeft = BNX_TRUE; if(key & SDLK_RIGHT) _Inp.keyRight = BNX_TRUE; if(key & SDLK_w) _Inp.keyAltUp = BNX_TRUE; if(key & SDLK_s) _Inp.keyAltDown = BNX_TRUE; if(key & SDLK_a) _Inp.keyAltLeft = BNX_TRUE; if(key & SDLK_d) _Inp.keyAltRight= BNX_TRUE; if(key & SDLK_DELETE) _Inp.keyDel = BNX_TRUE; if(key & SDLK_PAGEUP) _Inp.keyPageUp = BNX_TRUE; if(key & SDLK_PAGEDOWN) _Inp.keyPageDown= BNX_TRUE; if (key & SDL_MOUSEBUTTONDOWN) { _Inp.mousePress = BNX_TRUE; } if (!aptMainLoop()) { // if (event & SDL_QUIT) { // case SDL_QUIT: SDL_Quit(); exit(0); // break; } // } SDL_GetMouseState( &x, &y ); _Inp.mouseX = x; _Inp.mouseY = y; }
//Check for any window messages (keypress, paint, mousemove, etc) void CheckMessages() { SDL_Event ev; bool quit = false; while(SDL_PollEvent(&ev)) { switch(ev.type) { case SDL_KEYDOWN: { int lc = 0; if(OPTIONS["HIDE_CURSOR"] != "Always" && SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_DISABLE); //hide mouse cursor on keyboard input } Uint8 *keystate = SDL_GetKeyState(NULL); // manually handle Alt+F4 for older SDL lib, no big deal if(ev.key.keysym.sym==SDLK_F4 && (keystate[SDLK_RALT] || keystate[SDLK_LALT]) ) { quit = true; break; } else if(ev.key.keysym.sym==SDLK_RSHIFT || ev.key.keysym.sym==SDLK_LSHIFT || ev.key.keysym.sym==SDLK_RCTRL || ev.key.keysym.sym==SDLK_LCTRL || ev.key.keysym.sym==SDLK_RALT ) { break; // temporary fix for unwanted keys } else if(ev.key.keysym.sym==SDLK_LALT) { begin_alt_code(); break; } else if (ev.key.keysym.unicode != 0) { lc = ev.key.keysym.unicode; switch (lc){ case 13: //Reroute ENTER key for compatilbity purposes lc=10; break; case 8: //Reroute BACKSPACE key for compatilbity purposes lc=127; break; } } if(ev.key.keysym.sym==SDLK_LEFT) { lc = KEY_LEFT; } else if(ev.key.keysym.sym==SDLK_RIGHT) { lc = KEY_RIGHT; } else if(ev.key.keysym.sym==SDLK_UP) { lc = KEY_UP; } else if(ev.key.keysym.sym==SDLK_DOWN) { lc = KEY_DOWN; } else if(ev.key.keysym.sym==SDLK_PAGEUP) { lc = KEY_PPAGE; } else if(ev.key.keysym.sym==SDLK_PAGEDOWN) { lc = KEY_NPAGE; } if(!lc) break; if(alt_down) { add_alt_code(lc); }else { lastchar = lc; } } break; case SDL_KEYUP: { if(ev.key.keysym.sym==SDLK_LALT) { int code = end_alt_code(); if(code) lastchar = code; } } break; case SDL_MOUSEMOTION: if((OPTIONS["HIDE_CURSOR"] == "Always" || OPTIONS["HIDE_CURSOR"] == "HiddenKB") && !SDL_ShowCursor(-1)) SDL_ShowCursor(SDL_ENABLE); break; case SDL_QUIT: quit = true; break; } } if(quit) { endwin(); exit(0); } }
bool CWinEventsSDL::MessagePump() { SDL_Event event; bool ret = false; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: if (!g_application.m_bStop) CApplicationMessenger::Get().Quit(); break; #ifdef HAS_SDL_JOYSTICK case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: case SDL_JOYAXISMOTION: case SDL_JOYBALLMOTION: case SDL_JOYHATMOTION: g_Joystick.Update(event); ret = true; break; #endif case SDL_ACTIVEEVENT: //If the window was inconified or restored if( event.active.state & SDL_APPACTIVE ) { g_application.m_AppActive = event.active.gain != 0; g_Windowing.NotifyAppActiveChange(g_application.m_AppActive); } else if (event.active.state & SDL_APPINPUTFOCUS) { g_application.m_AppFocused = event.active.gain != 0; g_Windowing.NotifyAppFocusChange(g_application.m_AppFocused); } break; case SDL_KEYDOWN: { // process any platform specific shortcuts before handing off to XBMC #ifdef __APPLE__ if (ProcessOSXShortcuts(event)) { ret = true; break; } #endif XBMC_Event newEvent; newEvent.type = XBMC_KEYDOWN; newEvent.key.keysym.scancode = event.key.keysym.scancode; newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym; newEvent.key.keysym.unicode = event.key.keysym.unicode; newEvent.key.state = event.key.state; newEvent.key.type = event.key.type; newEvent.key.which = event.key.which; // Check if the Windows keys are down because SDL doesn't flag this. uint16_t mod = event.key.keysym.mod; uint8_t* keystate = SDL_GetKeyState(NULL); if (keystate[SDLK_LSUPER] || keystate[SDLK_RSUPER]) mod |= XBMCKMOD_LSUPER; newEvent.key.keysym.mod = (XBMCMod) mod; #if defined(_LINUX) && !defined(__APPLE__) // If the keysym.sym is zero try to get it from the scan code if (newEvent.key.keysym.sym == 0) newEvent.key.keysym.sym = (XBMCKey) SymFromScancode(newEvent.key.keysym.scancode); #endif // don't handle any more messages in the queue until we've handled keydown, // if a keyup is in the queue it will reset the keypress before it is handled. ret |= g_application.OnEvent(newEvent); break; } case SDL_KEYUP: { XBMC_Event newEvent; newEvent.type = XBMC_KEYUP; newEvent.key.keysym.scancode = event.key.keysym.scancode; newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym; newEvent.key.keysym.mod =(XBMCMod) event.key.keysym.mod; newEvent.key.keysym.unicode = event.key.keysym.unicode; newEvent.key.state = event.key.state; newEvent.key.type = event.key.type; newEvent.key.which = event.key.which; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEBUTTONDOWN: { XBMC_Event newEvent; newEvent.type = XBMC_MOUSEBUTTONDOWN; newEvent.button.button = event.button.button; newEvent.button.state = event.button.state; newEvent.button.type = event.button.type; newEvent.button.which = event.button.which; newEvent.button.x = event.button.x; newEvent.button.y = event.button.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEBUTTONUP: { XBMC_Event newEvent; newEvent.type = XBMC_MOUSEBUTTONUP; newEvent.button.button = event.button.button; newEvent.button.state = event.button.state; newEvent.button.type = event.button.type; newEvent.button.which = event.button.which; newEvent.button.x = event.button.x; newEvent.button.y = event.button.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_MOUSEMOTION: { if (0 == (SDL_GetAppState() & SDL_APPMOUSEFOCUS)) { g_Mouse.SetActive(false); #if defined(__APPLE__) // See CApplication::ProcessSlow() for a description as to why we call Cocoa_HideMouse. // this is here to restore the pointer when toggling back to window mode from fullscreen. Cocoa_ShowMouse(); #endif break; } XBMC_Event newEvent; newEvent.type = XBMC_MOUSEMOTION; newEvent.motion.xrel = event.motion.xrel; newEvent.motion.yrel = event.motion.yrel; newEvent.motion.state = event.motion.state; newEvent.motion.type = event.motion.type; newEvent.motion.which = event.motion.which; newEvent.motion.x = event.motion.x; newEvent.motion.y = event.motion.y; ret |= g_application.OnEvent(newEvent); break; } case SDL_VIDEORESIZE: { XBMC_Event newEvent; newEvent.type = XBMC_VIDEORESIZE; newEvent.resize.w = event.resize.w; newEvent.resize.h = event.resize.h; ret |= g_application.OnEvent(newEvent); g_windowManager.MarkDirty(); break; } case SDL_USEREVENT: { XBMC_Event newEvent; newEvent.type = XBMC_USEREVENT; newEvent.user.code = event.user.code; ret |= g_application.OnEvent(newEvent); break; } case SDL_VIDEOEXPOSE: g_windowManager.MarkDirty(); break; } memset(&event, 0, sizeof(SDL_Event)); } return ret; }
bool Engine::IsKeyPressed(SDLKey k) { int numkeys = 0; uint8 *state = SDL_GetKeyState(&numkeys); return k < numkeys && state[k]; }
void Game::state_gameplay_running(SDL_Event* event) { int m_x, m_y; SDL_GetMouseState(&m_x, &m_y); Uint8* keystate = SDL_GetKeyState(NULL); if (keystate[SDLK_f]) FPS_MAX = 1000; else FPS_MAX = 60; if (event->type == SDL_KEYDOWN) { if (event->key.keysym.sym == SDLK_ESCAPE) { cancel_selection(); } else if (event->key.keysym.sym == SDLK_KP_PLUS) { if (game_speed < 2.f) { game_speed *= 2; std::string s("x"); s.append(ftos(game_speed)); speed_text->update_text(s); speed_text->set_center_x(585); game_speed == 1.f ? speed_text->hide() : speed_text->show(); } } else if (event->key.keysym.sym == SDLK_KP_MINUS) { if (game_speed > .5f) { game_speed /= 2; std::string s("x"); s.append(ftos(game_speed)); speed_text->update_text(s); speed_text->set_center_x(585); game_speed == 1.f ? speed_text->hide() : speed_text->show(); } } else if (game_started && event->key.keysym.sym == SDLK_n) { send_new_wave(); } if (buildmenu_selection == NULL) { buildmenu_selection_not_set(event); } else //Player has selected a tower to build { buildmenu_selection_set(event); } } else if (event->type == SDL_MOUSEBUTTONDOWN) { if (event->button.button == SDL_BUTTON_LEFT) { left_mousebutton(m_x, m_y); } //Mousebutton left else if (event->button.button == SDL_BUTTON_RIGHT) { if (buildmenu_selection == NULL && selection_sprite->overlaps(m_x, m_y)) { if (selection_sprite->is_visible()) { toggle_option_box(); } } else { if (option_box_visible) hide_option_box(); else cancel_selection(); } } } else if (event->type == SDL_MOUSEMOTION) { if (tile_selection == NULL && buildmenu_selection == NULL) { int m_x, m_y; SDL_GetMouseState(&m_x, &m_y); //Loop through build objects for (iter_build_obj = build_list.begin(); iter_build_obj != build_list.end(); iter_build_obj++) { if ((*iter_build_obj)->overlaps(m_x, m_y)) { hovered_build_item = (*iter_build_obj); return; } } } hovered_build_item = NULL; } }
int Draw_LoopIteration() { SDL_Event event; // Process Events #ifdef EMSCRIPTEN while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { Input_SetKey(InputKey_Exit, 1); } if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) { Input_SetKey(InputKey_Exit, 1); } } if (event.type == SDL_MOUSEMOTION) { Input_SetPointerPosition(event.motion.x / (float)_width, event.motion.y / (float)_height); } if (event.type == SDL_MOUSEBUTTONDOWN) { Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height); Input_SetPointerDown(1); } if (event.type == SDL_FINGERMOTION) { Input_SetPointerPosition(event.tfinger.x, event.tfinger.y); } if (event.type == SDL_FINGERDOWN) { Input_SetPointerPosition(event.tfinger.x, event.tfinger.y); Input_SetPointerDown(1); } if (event.type == SDL_TOUCHBUTTONDOWN) { Input_SetPointerPosition(event.tfinger.x, event.tfinger.y); Input_SetPointerDown(1); } if (event.type == SDL_MOUSEBUTTONUP) { Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height); Input_SetPointerDown(0); } if (event.type == SDL_FINGERUP) { Input_SetPointerPosition(event.tfinger.x, event.tfinger.y); Input_SetPointerDown(0); } if (event.type == SDL_TOUCHBUTTONUP) { Input_SetPointerPosition(event.tfinger.x, event.tfinger.y); Input_SetPointerDown(0); } } #else while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { Input_SetKey(InputKey_Exit, 1); if (!_draw_exitoverrided) { _draw_looping = 0; } } if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) { Input_SetKey(InputKey_Exit, 1); if (!_draw_exitoverrided) { _draw_looping = 0; } } } if (event.type == SDL_MOUSEMOTION) { Input_SetPointerPosition(event.motion.x / (float)_width, event.motion.y / (float)_height); } if (event.type == SDL_MOUSEBUTTONDOWN) { Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height); Input_SetPointerDown(1); } if (event.type == SDL_MOUSEBUTTONUP) { Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height); Input_SetPointerDown(0); } } #endif #ifndef EMSCRIPTEN // Process keys for Draw Uint8 *keys; keys = (Uint8 *)SDL_GetKeyState(NULL); if (keys[SDLK_F12]) { // Screenshot key char strFile[255]; int idx = -1; do { idx++; snprintf(strFile, 255, "shot-%04d.png", idx); } while (access(strFile, F_OK) != -1); Draw_SaveScreenshoot(strFile); } #endif // Process if (_proc_func) { if (_accTime > 100000) { _accTime = 100000; } while (_accTime >= proc_t_frame && _draw_looping) { Input_Frame(); _proc_func(_data); _accTime -= proc_t_frame; Input_PostFrame(); } } // Sound Frame Audio_Frame(); // Draw SDL_GL_SwapBuffers(); if (_draw_func) { _draw_func(_data, (float)_accTime / (float)proc_t_frame); Draw_Flush(); } return _draw_looping; }
bool ChooseAnImage(int sx,int sy, char *incoming_dir, int slot, char **filename, bool *isdir, int *index_file) { /* Parameters: sx, sy - window size, incoming_dir - in what dir find files, slot - in what slot should an image go (common: #6 for 5.25' 140Kb floppy disks, and #7 for hard-disks). slot #5 - for 800Kb floppy disks, but we do not use them in Apple][? (They are as a rule with .2mg extension) index_file - from which file we should start cursor (should be static and 0 when changing dir) Out: filename - chosen file name (or dir name) isdir - if chosen name is a directory */ /* Surface: */ SDL_Surface *my_screen; // for background if(font_sfc == NULL) if(!fonts_initialization()) return false; //if we don't have a fonts, we just can do none List<char> files; // our files List<char> sizes; // and their sizes (or 'dir' for directories) int act_file; // current file int first_file; // from which we output files printf("Disckchoose! We are here: %s\n",incoming_dir); // files.Delete(); // sizes.Delete(); #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ DIR *dp; struct dirent *ep; dp = opendir (incoming_dir); // open and read incoming directory char *tmp; int i,j, B, N; // for cycles, beginning and end of list // build prev dir if(strcmp(incoming_dir, "/")) { tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs if (dp != NULL) { while (ep = readdir (dp)) // first looking for directories { int what = getstat(incoming_dir, ep->d_name, NULL); if (strlen(ep->d_name) > 0 && /*strcmp(ep->d_name,".")*/// omit "." (cur dir) ep->d_name[0] != '.'/*strcmp(ep->d_name,"..")*/ && what == 1) // is directory! { tmp = new char[strlen(ep->d_name)+1]; // add entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } /* if */ } } #else /* Windows specific functions of reading directory structure */ /* Find subdirs: */ if(strcmp(incoming_dir, "/")) { // we are not in upper direcory tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } } /* while */ } /* if */ #endif // sort directories. Please, don't laugh at my bubble sorting - it the simplest thing I've ever seen --bb if(files.Length() > 2) { N = files.Length() - 1; // B = 1;`- defined above for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } B = files.Length(); // start for files #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ (void) rewinddir (dp); // to the start // now get all regular files while (ep = readdir (dp)) { int fsize; if (strlen(ep->d_name) > 4 && ep->d_name[0] != '.' && (getstat(incoming_dir, ep->d_name, &fsize) == 2)) // is normal file! { tmp = new char[strlen(ep->d_name)+1]; // add this entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", fsize); sizes.Add(tmp); // add this size to list } /* if */ } (void) closedir (dp); #else /* Windows specific functions of reading directory structure */ /* Find files: */ h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { // char *tmp; - must be defined in previous section, when searching subdirs if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } } /* while */ } /* if */ #endif // do sorting for files if(files.Length() > 2 && B < files.Length()) { N = files.Length() - 1; // B = 1; for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } // Count out cursor position and file number output act_file = *index_file; if(act_file >= files.Length()) act_file = 0; // cannot be more than files in list first_file = act_file - (FILES_IN_SCREEN / 2); if (first_file < 0) first_file = 0; // cannot be negativ... // Show all directories (first) and files then // char *tmp; char *siz; // int i; // prepare screen double facx = double(g_ScreenWidth) / double(SCREEN_WIDTH); double facy = double(g_ScreenHeight) / double(SCREEN_HEIGHT); SDL_Surface *tempSurface = NULL; if(!g_WindowResized) { if(g_nAppMode == MODE_LOGO) tempSurface = g_hLogoBitmap; // use logobitmap else tempSurface = g_hDeviceBitmap; } else tempSurface = g_origscreen; if(tempSurface == NULL) tempSurface = screen; // use screen, if none available my_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, tempSurface->format->BitsPerPixel, 0, 0, 0, 0); if(tempSurface->format->palette && my_screen->format->palette) SDL_SetColors(my_screen, tempSurface->format->palette->colors, 0, tempSurface->format->palette->ncolors); surface_fader(my_screen, 0.2F, 0.2F, 0.2F, -1, 0); // fade it out to 20% of normal SDL_BlitSurface(tempSurface, NULL, my_screen, NULL); while(true) { SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background font_print_centered(sx/2 ,5*facy , incoming_dir, screen, 1.5*facx, 1.3*facy); if (slot == 6) font_print_centered(sx/2,20*facy,"Choose image for floppy 140KB drive", screen, 1*facx, 1*facy); else if (slot == 7) font_print_centered(sx/2,20*facy,"Choose image for Hard Disk", screen, 1*facx, 1*facy); else if (slot == 5) font_print_centered(sx/2,20*facy,"Choose image for floppy 800KB drive", screen, 1*facx, 1*facy); else if (slot == 1) font_print_centered(sx/2,20*facy,"Select file name for saving snapshot", screen, 1*facx, 1*facy); else if (slot == 0) font_print_centered(sx/2,20*facy,"Select snapshot file name for loading", screen, 1*facx, 1*facy); font_print_centered(sx/2,30*facy, "Press ENTER to choose, or ESC to cancel",screen, 1.4*facx, 1.1*facy); files.Rewind(); // from start sizes.Rewind(); i = 0; // printf("We've printed some messages, go to file list!\n"); // show all fetched dirs and files // topX of first fiel visible int TOPX = int(45*facy); while(files.Iterate(tmp)) { sizes.Iterate(siz); // also fetch size string if (i >= first_file && i < first_file + FILES_IN_SCREEN) { // FILES_IN_SCREEN items on screen // char tmp2[80],tmp3[256]; if (i == act_file) { // show item under cursor (in inverse mode) SDL_Rect r; r.x= 2; r.y= TOPX + (i-first_file) * 15 * facy - 1; if(strlen(tmp) > 46) r.w = 46 * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; else r.w= strlen(tmp) * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; // 6- FONT_SIZE_X r.h= 9 * 1.5 * facy; SDL_FillRect(screen, &r, SDL_MapRGB(screen->format,255,0,0));// in RED } /* if */ // print file name with enlarged font char ch; ch = 0; if(strlen(tmp) > 46) { ch = tmp[46]; tmp[46] = 0;} //cut-off too long string font_print(4, TOPX + (i - first_file) * 15 * facy, tmp, screen, 1.7*facx, 1.5*facy); // show name font_print(sx - 70 * facx, TOPX + (i - first_file) * 15 * facy, siz, screen, 1.7*facx, 1.5*facy);// show info (dir or size) if(ch) tmp[46] = ch; //restore cut-off char } /* if */ i++; // next item } /* while */ ///////////////////////////////////////////////////////////////////////////////////////////// // draw rectangles rectangle(screen, 0, TOPX - 5, sx, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 480*facx, TOPX - 5, 0, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(10); SDL_PollEvent(&event); } // control cursor keyboard = SDL_GetKeyState(NULL); // get current state of pressed (and not pressed) keys if (keyboard[SDLK_UP] || keyboard[SDLK_LEFT]) { if (act_file>0) act_file--; // up one position if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_DOWN] || keyboard[SDLK_RIGHT]) { if (act_file < (files.Length() - 1)) act_file++; if (act_file >= (first_file + FILES_IN_SCREEN)) first_file=act_file - FILES_IN_SCREEN + 1; } /* if */ if (keyboard[SDLK_PAGEUP]) { act_file-=FILES_IN_SCREEN; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN]) { act_file+=FILES_IN_SCREEN; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+FILES_IN_SCREEN)) first_file=act_file-FILES_IN_SCREEN + 1; } /* if */ // choose an item? if (keyboard[SDLK_RETURN]) { // dup string from selected file name *filename = strdup(files[act_file]); // printf("files[act_file]=%s, *filename=%s\n\n", files[act_file], *filename); if(!strcmp(sizes[act_file], "<DIR>") || !strcmp(sizes[act_file], "<UP>")) *isdir = true; else *isdir = false; // this is directory (catalog in Apple][ terminology) *index_file = act_file; // remember current index files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return true; } /* if */ if (keyboard[SDLK_ESCAPE]) { files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return false; // ESC has been pressed } /* if */ if (keyboard[SDLK_HOME]) { // HOME? act_file=0; first_file=0; } /* if */ if (keyboard[SDLK_END]) { // END? act_file=files.Length() - 1; // go to the last possible file in list first_file=act_file - FILES_IN_SCREEN + 1; if(first_file < 0) first_file = 0; } /* if */ } } /* ChooseAnImage */
void run() { bool quit = false; SDL_Event event; Uint32 last_tick = 0; Player player; while(!quit) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: quit = true; break; } } Uint8 *keystates = SDL_GetKeyState( NULL ); if (keystates[SDLK_LEFT]) player.left(); else if (keystates[SDLK_RIGHT]) player.right(); else player.stop(); if (keystates[SDLK_SPACE]) player.jump = true; else player.jump = false; if (player.on_ground()) { if (keystates[SDLK_DOWN]) player.duck = true; else player.duck = false; } for(int y = 0; y < 16; ++y) for(int x = 0; x < 20; ++x) { if (level[y][x] == ' ') { draw_rect(x*32, y*32 - 16, 32, 32, 50, 50, 50, true); } else if (level[y][x] == '#') { draw_rect(x*32, y*32 - 16, 32, 32, 200, 200, 200); } } Uint32 tick = SDL_GetTicks(); float delta = (tick - last_tick)/1000.0f; last_tick = tick; while (delta > 0.0f) { player.update(0.01f); delta -= 0.01f; } player.draw(); TTY_Blit(tty, screen, 0, 0); SDL_Flip(screen); } }
int main(int argc, char *argv[]) { #ifdef RPI bcm_host_init(); #endif putenv((char*)"SDL_VIDEO_CENTERED=1"); std::string app_name; std::string app_name_nice; bool landscape; NativeGetAppInfo(&app_name, &app_name_nice, &landscape); net::Init(); #ifdef __APPLE__ // Make sure to request a somewhat modern GL context at least - the // latest supported by MacOSX (really, really sad...) // Requires SDL 2.0 // We really should upgrade to SDL 2.0 soon. //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); #endif if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } #ifdef USING_EGL if (EGL_Open()) return 1; #endif // Get the video info before doing anything else, so we don't get skewed resolution results. const SDL_VideoInfo* desktopVideoInfo = SDL_GetVideoInfo(); g_DesktopWidth = desktopVideoInfo->current_w; g_DesktopHeight = desktopVideoInfo->current_h; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); int mode; #ifdef USING_GLES2 mode = SDL_SWSURFACE | SDL_FULLSCREEN; #else mode = SDL_OPENGL | SDL_RESIZABLE; #endif int set_xres = -1; int set_yres = -1; bool portrait = false; bool set_ipad = false; float set_dpi = 1.0f; float set_scale = 1.0f; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i],"--fullscreen")) mode |= SDL_FULLSCREEN; if (set_xres == -2) { set_xres = parseInt(argv[i]); } else if (set_yres == -2) { set_yres = parseInt(argv[i]); } if (set_dpi == -2) set_dpi = parseFloat(argv[i]); if (set_scale == -2) set_scale = parseFloat(argv[i]); if (!strcmp(argv[i],"--xres")) set_xres = -2; if (!strcmp(argv[i],"--yres")) set_yres = -2; if (!strcmp(argv[i],"--dpi")) set_dpi = -2; if (!strcmp(argv[i],"--scale")) set_scale = -2; if (!strcmp(argv[i],"--ipad")) set_ipad = true; if (!strcmp(argv[i],"--portrait")) portrait = true; } if (mode & SDL_FULLSCREEN) { const SDL_VideoInfo* info = SDL_GetVideoInfo(); pixel_xres = info->current_w; pixel_yres = info->current_h; #ifdef PPSSPP g_Config.bFullScreen = true; #endif } else { // set a sensible default resolution (2x) pixel_xres = 480 * 2 * set_scale; pixel_yres = 272 * 2 * set_scale; if (portrait) { std::swap(pixel_xres, pixel_yres); } #ifdef PPSSPP g_Config.bFullScreen = false; #endif } set_dpi = 1.0f / set_dpi; if (set_ipad) { pixel_xres = 1024; pixel_yres = 768; } if (!landscape) { std::swap(pixel_xres, pixel_yres); } if (set_xres > 0) { pixel_xres = set_xres; } if (set_yres > 0) { pixel_yres = set_yres; } float dpi_scale = 1.0f; if (set_dpi > 0) { dpi_scale = set_dpi; } dp_xres = (float)pixel_xres * dpi_scale; dp_yres = (float)pixel_yres * dpi_scale; g_Screen = SDL_SetVideoMode(pixel_xres, pixel_yres, 0, mode); if (g_Screen == NULL) { fprintf(stderr, "SDL SetVideoMode failed: Unable to create OpenGL screen: %s\n", SDL_GetError()); SDL_Quit(); return 2; } #ifdef USING_EGL EGL_Init(); #endif #ifdef PPSSPP SDL_WM_SetCaption((app_name_nice + " " + PPSSPP_GIT_VERSION).c_str(), NULL); #endif #ifdef MOBILE_DEVICE SDL_ShowCursor(SDL_DISABLE); #endif #ifndef USING_GLES2 if (GLEW_OK != glewInit()) { printf("Failed to initialize glew!\n"); return 1; } if (GLEW_VERSION_2_0) { printf("OpenGL 2.0 or higher.\n"); } else { printf("Sorry, this program requires OpenGL 2.0.\n"); return 1; } #endif #ifdef _MSC_VER // VFSRegister("temp/", new DirectoryAssetReader("E:\\Temp\\")); TCHAR path[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path); PathAppend(path, (app_name + "\\").c_str()); #else // Mac / Linux char path[512]; const char *the_path = getenv("HOME"); if (!the_path) { struct passwd* pwd = getpwuid(getuid()); if (pwd) the_path = pwd->pw_dir; } strcpy(path, the_path); if (path[strlen(path)-1] != '/') strcat(path, "/"); #endif #ifdef _WIN32 NativeInit(argc, (const char **)argv, path, "D:\\", "BADCOFFEE"); #else NativeInit(argc, (const char **)argv, path, "/tmp", "BADCOFFEE"); #endif pixel_in_dps = (float)pixel_xres / dp_xres; g_dpi_scale = dp_xres / (float)pixel_xres; printf("Pixels: %i x %i\n", pixel_xres, pixel_yres); printf("Virtual pixels: %i x %i\n", dp_xres, dp_yres); NativeInitGraphics(); NativeResized(); SDL_AudioSpec fmt, ret_fmt; memset(&fmt, 0, sizeof(fmt)); fmt.freq = 44100; fmt.format = AUDIO_S16; fmt.channels = 2; fmt.samples = 2048; fmt.callback = &mixaudio; fmt.userdata = (void *)0; if (SDL_OpenAudio(&fmt, &ret_fmt) < 0) { ELOG("Failed to open audio: %s", SDL_GetError()); } else { if (ret_fmt.samples != fmt.samples) // Notify, but still use it ELOG("Output audio samples: %d (requested: %d)", ret_fmt.samples, fmt.samples); if (ret_fmt.freq != fmt.freq || ret_fmt.format != fmt.format || ret_fmt.channels != fmt.channels) { ELOG("Sound buffer format does not match requested format."); ELOG("Output audio freq: %d (requested: %d)", ret_fmt.freq, fmt.freq); ELOG("Output audio format: %d (requested: %d)", ret_fmt.format, fmt.format); ELOG("Output audio channels: %d (requested: %d)", ret_fmt.channels, fmt.channels); ELOG("Provided output format does not match requirement, turning audio off"); SDL_CloseAudio(); } } // Audio must be unpaused _after_ NativeInit() SDL_PauseAudio(0); #ifndef _WIN32 joystick = new SDLJoystick(); #endif EnableFZ(); int framecount = 0; float t = 0; float lastT = 0; uint32_t pad_buttons = 0; // legacy pad buttons while (true) { input_state.accelerometer_valid = false; input_state.mouse_valid = true; SDL_Event event; while (SDL_PollEvent(&event)) { float mx = event.motion.x * g_dpi_scale; float my = event.motion.y * g_dpi_scale; switch (event.type) { case SDL_QUIT: g_QuitRequested = 1; break; #if !defined(MOBILE_DEVICE) case SDL_VIDEORESIZE: { g_Screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_OPENGL | SDL_RESIZABLE); if (g_Screen == NULL) { fprintf(stderr, "SDL SetVideoMode failed: Unable to create OpenGL screen: %s\n", SDL_GetError()); SDL_Quit(); return 2; } pixel_xres = event.resize.w; pixel_yres = event.resize.h; dp_xres = (float)pixel_xres * dpi_scale; dp_yres = (float)pixel_yres * dpi_scale; NativeResized(); break; } #endif case SDL_KEYDOWN: { int k = event.key.keysym.sym; KeyInput key; key.flags = KEY_DOWN; key.keyCode = KeyMapRawSDLtoNative.find(k)->second; key.deviceId = DEVICE_ID_KEYBOARD; NativeKey(key); for (int i = 0; i < ARRAY_SIZE(legacyKeyMap); i++) { if (legacyKeyMap[i] == key.keyCode) pad_buttons |= 1 << i; } break; } case SDL_KEYUP: { int k = event.key.keysym.sym; KeyInput key; key.flags = KEY_UP; key.keyCode = KeyMapRawSDLtoNative.find(k)->second; key.deviceId = DEVICE_ID_KEYBOARD; NativeKey(key); for (int i = 0; i < ARRAY_SIZE(legacyKeyMap); i++) { if (legacyKeyMap[i] == key.keyCode) pad_buttons &= ~(1 << i); } break; } case SDL_MOUSEBUTTONDOWN: switch (event.button.button) { case SDL_BUTTON_LEFT: { input_state.pointer_x[0] = mx; input_state.pointer_y[0] = my; input_state.pointer_down[0] = true; input_state.mouse_valid = true; TouchInput input; input.x = mx; input.y = my; input.flags = TOUCH_DOWN; input.id = 0; NativeTouch(input); KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_DOWN); NativeKey(key); } break; case SDL_BUTTON_RIGHT: { KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_DOWN); NativeKey(key); } break; case SDL_BUTTON_WHEELUP: { KeyInput key; key.deviceId = DEVICE_ID_MOUSE; key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; key.flags = KEY_DOWN; NativeKey(key); } break; case SDL_BUTTON_WHEELDOWN: { KeyInput key; key.deviceId = DEVICE_ID_MOUSE; key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; key.flags = KEY_DOWN; NativeKey(key); } break; } break; case SDL_MOUSEMOTION: if (input_state.pointer_down[0]) { input_state.pointer_x[0] = mx; input_state.pointer_y[0] = my; input_state.mouse_valid = true; TouchInput input; input.x = mx; input.y = my; input.flags = TOUCH_MOVE; input.id = 0; NativeTouch(input); } break; case SDL_MOUSEBUTTONUP: switch (event.button.button) { case SDL_BUTTON_LEFT: { input_state.pointer_x[0] = mx; input_state.pointer_y[0] = my; input_state.pointer_down[0] = false; input_state.mouse_valid = true; //input_state.mouse_buttons_up = 1; TouchInput input; input.x = mx; input.y = my; input.flags = TOUCH_UP; input.id = 0; NativeTouch(input); KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_UP); NativeKey(key); } break; case SDL_BUTTON_RIGHT: { KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_UP); NativeKey(key); } break; case SDL_BUTTON_WHEELUP: { KeyInput key; key.deviceId = DEVICE_ID_DEFAULT; key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; key.flags = KEY_UP; NativeKey(key); } break; case SDL_BUTTON_WHEELDOWN: { KeyInput key; key.deviceId = DEVICE_ID_DEFAULT; key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; key.flags = KEY_UP; NativeKey(key); } break; } break; default: #ifndef _WIN32 joystick->ProcessInput(event); #endif break; } } if (g_QuitRequested) break; const uint8 *keys = (const uint8 *)SDL_GetKeyState(NULL); SimulateGamepad(keys, &input_state); input_state.pad_buttons = pad_buttons; UpdateInputState(&input_state, true); UpdateRunLoop(); if (g_QuitRequested) break; #if defined(PPSSPP) && !defined(MOBILE_DEVICE) if (lastUIState != GetUIState()) { lastUIState = GetUIState(); if (lastUIState == UISTATE_INGAME && g_Config.bFullScreen && !g_Config.bShowTouchControls) SDL_ShowCursor(SDL_DISABLE); if (lastUIState != UISTATE_INGAME && g_Config.bFullScreen) SDL_ShowCursor(SDL_ENABLE); } #endif if (framecount % 60 == 0) { // glsl_refresh(); // auto-reloads modified GLSL shaders once per second. } #ifdef USING_EGL eglSwapBuffers(g_eglDisplay, g_eglSurface); #else if (!keys[SDLK_TAB] || t - lastT >= 1.0/60.0) { SDL_GL_SwapBuffers(); lastT = t; } #endif ToggleFullScreenIfFlagSet(); time_update(); t = time_now(); framecount++; } #ifndef _WIN32 delete joystick; #endif // Faster exit, thanks to the OS. Remove this if you want to debug shutdown // The speed difference is only really noticable on Linux. On Windows you do notice it though #ifndef MOBILE_DEVICE exit(0); #endif NativeShutdownGraphics(); SDL_PauseAudio(1); SDL_CloseAudio(); NativeShutdown(); #ifdef USING_EGL EGL_Close(); #endif SDL_Quit(); net::Shutdown(); #ifdef RPI bcm_host_deinit(); #endif exit(0); return 0; }
static void PlayGame() { Uint8 *keystate; int quit = 0; int turn; int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */ /* framerate counter variables */ int start_time, end_time; int frames_drawn = 0; prev_ticks = SDL_GetTicks(); start_time = time(NULL); while (quit == 0) { /* Determine how many milliseconds have passed since the last frame, and update our motion scaling. */ prev_ticks = cur_ticks; cur_ticks = SDL_GetTicks(); time_scale = (double)(cur_ticks-prev_ticks)/30.0; /* Update SDL's internal input state information. */ SDL_PumpEvents(); /* Grab a snapshot of the keyboard. */ keystate = SDL_GetKeyState(NULL); /* Respond to input. */ if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1; /* Left and right arrow keys control turning. */ turn = 0; if (keystate[SDLK_LEFT]) turn += 15; if (keystate[SDLK_RIGHT]) turn -= 15; /* Forward and back arrow keys activate thrusters. */ player.accel = 0; if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST; if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST; /* Spacebar slows the ship down. */ if (keystate[SDLK_SPACE]) { player.velocity *= 0.8; } /* Just an amusing way to test the particle system. */ if (keystate[SDLK_e]) { CreateParticleExplosion( player.world_x, player.world_y, 255, 255, 255, 10, 300); CreateParticleExplosion( player.world_x, player.world_y, 255, 0, 0, 5, 100); CreateParticleExplosion( player.world_x, player.world_y, 255, 255, 0, 2, 50); } /* Allow a turn of four degrees per frame. */ player.angle += turn * time_scale; if (player.angle < 0) player.angle += 360; if (player.angle >= 360) player.angle -= 360; /* If this is a player vs. computer game, give the computer a chance. */ if (opponent_type == OPP_COMPUTER) { if (RunGameScript() != 0) { fprintf(stderr, "Ending game due to script error.\n"); quit = 1; } } /* Update the player's position. */ UpdatePlayer(&player); UpdatePlayer(&opponent); /* Make the camera follow the player (but impose limits). */ camera_x = player.world_x - SCREEN_WIDTH/2; camera_y = player.world_y - SCREEN_HEIGHT/2; if (camera_x < 0) camera_x = 0; if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH) camera_x = WORLD_WIDTH-SCREEN_WIDTH-1; if (camera_y < 0) camera_y = 0; if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT) camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1; /* Update the particle system. */ UpdateParticles(); /* Redraw everything. */ DrawBackground(screen, camera_x, camera_y); DrawParallax(screen, camera_x, camera_y); DrawParticles(screen, camera_x, camera_y); DrawPlayer(&player); DrawPlayer(&opponent); /* Flip the page. */ SDL_Flip(screen); frames_drawn++; } end_time = time(NULL); if (start_time == end_time) end_time++; /* Display the average framerate. */ printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n", frames_drawn, end_time-start_time, (float)frames_drawn/(float)(end_time-start_time)); }
bool Visualization::update() { if (!m_initialized) { printf("Visualization has not been yet initialized."); return false; } // Compute the time since last update (in seconds). Uint32 time = SDL_GetTicks(); float dt = (time - m_lastTickCount) / 1000.0f; m_lastTickCount = time; bool singleSimulationStep = false; bool scrollForward = false; bool scrollBackward = false; int mscroll = 0; SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: // Handle any key presses here. if (event.key.keysym.sym == SDLK_ESCAPE) //Escape. { m_stopRequested = true; } else if (event.key.keysym.sym == SDLK_SPACE) { m_paused = !m_paused; } else if (event.key.keysym.sym == SDLK_TAB) { singleSimulationStep = true; } else if (event.key.keysym.sym == SDLK_r) { float pos[3] = {-15, 0, 15}; m_crowd->pushAgentPosition(0, pos); } else if (event.key.keysym.sym == SDLK_KP7) { float pos[3] = {-19, 0, -19}; dtVnormalize(pos); dtVscale(pos, pos, 2.f); dtCrowdAgent ag; m_crowd->fetchAgent(ag, 0); dtVcopy(ag.velocity, pos); m_crowd->pushAgent(ag); } else if (event.key.keysym.sym == SDLK_KP9) { float pos[] = {19, 0, -19}; dtVnormalize(pos); dtVscale(pos, pos, 2.f); dtCrowdAgent ag; m_crowd->fetchAgent(ag, 0); dtVcopy(ag.velocity, pos); m_crowd->pushAgent(ag); } else if (event.key.keysym.sym == SDLK_KP3) { float pos[3] = {19, 0, 19}; dtVnormalize(pos); dtVscale(pos, pos, 2.f); dtCrowdAgent ag; m_crowd->fetchAgent(ag, 0); dtVcopy(ag.velocity, pos); m_crowd->pushAgent(ag); } else if (event.key.keysym.sym == SDLK_KP1) { float pos[3] = {-19, 0, 19}; dtVnormalize(pos); dtVscale(pos, pos, 2.f); dtCrowdAgent ag; m_crowd->fetchAgent(ag, 0); dtVcopy(ag.velocity, pos); m_crowd->pushAgent(ag); } else if (event.key.keysym.sym == SDLK_KP5) { float pos[3] = {0, 0, 0}; dtVnormalize(pos); dtVscale(pos, pos, 2.f); dtCrowdAgent ag; m_crowd->fetchAgent(ag, 0); dtVcopy(ag.velocity, pos); m_crowd->pushAgent(ag); } break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_RIGHT) { // Rotate view m_rotating = true; m_initialMousePosition[0] = m_mousePosition[0]; m_initialMousePosition[1] = m_mousePosition[1]; m_intialCameraOrientation[0] = m_cameraOrientation[0]; m_intialCameraOrientation[1] = m_cameraOrientation[1]; m_intialCameraOrientation[2] = m_cameraOrientation[2]; } else if (event.button.button == SDL_BUTTON_WHEELUP) { scrollForward = true; } else if (event.button.button == SDL_BUTTON_WHEELDOWN) { scrollBackward = true; } break; case SDL_MOUSEBUTTONUP: if (event.button.button == SDL_BUTTON_RIGHT) { m_rotating = false; } else if (event.button.button == SDL_BUTTON_LEFT) { float pickedPosition[3]; int index = 0; pick(pickedPosition, &index); } break; case SDL_MOUSEMOTION: m_mousePosition[0] = event.motion.x; m_mousePosition[1] = m_winHeight-1 - event.motion.y; if (m_rotating) { int dx = m_mousePosition[0] - m_initialMousePosition[0]; int dy = m_mousePosition[1] - m_initialMousePosition[1]; m_cameraOrientation[0] = m_intialCameraOrientation[0] - dy*0.25f; m_cameraOrientation[1] = m_intialCameraOrientation[1] + dx*0.25f; } break; case SDL_QUIT: m_stopRequested = true; break; default: break; } } unsigned char mbut = 0; if (SDL_GetMouseState(0,0) & SDL_BUTTON_LMASK) mbut |= IMGUI_MBUT_LEFT; if (SDL_GetMouseState(0,0) & SDL_BUTTON_RMASK) mbut |= IMGUI_MBUT_RIGHT; // Update the camera velocity from keyboard state. Uint8* keystate = SDL_GetKeyState(NULL); #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4800) #endif updateCameraVelocity( dt, keystate[SDLK_w] || keystate[SDLK_UP] || scrollForward, keystate[SDLK_s] || keystate[SDLK_DOWN] || scrollBackward, keystate[SDLK_a] || keystate[SDLK_LEFT], keystate[SDLK_d] || keystate[SDLK_RIGHT], SDL_GetModState() & KMOD_SHIFT); #ifdef _MSC_VER #pragma warning(pop) #endif //Update the camera position updateCameraPosition(dt); //Update the crowd if (m_crowd) { if (singleSimulationStep) { m_paused = true; m_debugInfo->startUpdate(); m_crowd->update(m_crowdDt); m_debugInfo->endUpdate(m_crowdDt); m_crowdAvailableDt = 0.f; } else if (!m_paused) { m_crowdAvailableDt += dt; while(m_crowdAvailableDt > m_crowdDt) { m_debugInfo->startUpdate(); m_crowd->update(m_crowdDt); m_debugInfo->endUpdate(m_crowdDt); m_crowdAvailableDt -= m_crowdDt; } } else { m_crowdAvailableDt = 0.f; } } // Set rendering context glViewport(0, 0, m_winWidth, m_winHeight); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); // Render 3D glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50.0f, (float)m_winWidth/(float)m_winHeight, m_zNear, m_zFar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(m_cameraOrientation[0],1,0,0); glRotatef(m_cameraOrientation[1],0,1,0); glRotatef(m_cameraOrientation[2],0,0,1); glTranslatef(-m_cameraPosition[0], -m_cameraPosition[1], -m_cameraPosition[2]); // Extract OpenGL view properties glGetDoublev(GL_PROJECTION_MATRIX, m_projection); glGetDoublev(GL_MODELVIEW_MATRIX, m_modelView); glGetIntegerv(GL_VIEWPORT, m_viewport); renderScene(); renderCrowd(); // Render 2D Overlay glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, m_winWidth, 0, m_winHeight); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); imguiBeginFrame(m_mousePosition[0], m_mousePosition[1], mbut,mscroll); renderDebugInfoOverlay(); imguiEndFrame(); imguiRenderGLDraw(); glEnable(GL_DEPTH_TEST); SDL_GL_SwapBuffers(); return true; }
void menu(SDL_Surface *ecran, Sprites &sprites, Boutons &boutons, int &modeMenu, int &modeJeu, SourisEvent &sourisEvent, Time &time, Message msgs[], Partie &partie, Chien &chien) { bool sortir = false; int lastKeyPressed; int lastKeyPressedBis; int lastMenu = 1; bool keyPressed = false; bool keyPressedBis = false; bool defilTouche = false; for (int i=0; i<LONGUEUR_MAX_PSEUDO; i++) { partie.pseudoT[i] = 0; } getScore("scoresClassic", partie.highScore); int carActif = 0; Uint8 *keystate = SDL_GetKeyState(NULL); time.currentTime = SDL_GetTicks(); time.timeMenu = time.currentTime; time.timeKey = time.currentTime; time.timeDefKey = time.currentTime; while (!sortir && modeMenu!=0) { if (getEvents(sourisEvent, 1)) { modeMenu = 0; modeJeu = 0; } time.currentTime = SDL_GetTicks(); switch (modeMenu) { case 0: sortir = true; break; case 1 : boutons.bouton[BOUTON_PLAY].position.x = (LARGEUR - boutons.lecture[0].w) / 2; boutons.bouton[BOUTON_PLAY].position.y = 100; boutons.bouton[BOUTON_SCORE].position.x = (LARGEUR - boutons.lecture[0].w) / 2; boutons.bouton[BOUTON_SCORE].position.y = 250; boutons.bouton[BOUTON_OPTIONS].position.x = (LARGEUR - boutons.lecture[0].w) / 2; boutons.bouton[BOUTON_OPTIONS].position.y = 400; boutons.bouton[BOUTON_QUIT].position.x = (LARGEUR - boutons.lecture[0].w) / 2; boutons.bouton[BOUTON_QUIT].position.y = 550; if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_QUIT], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 0; modeJeu = 0; } else if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_PLAY], boutons.lecture[0]))&&sourisEvent.clicGauche) { time.currentTime = SDL_GetTicks(); time.timeMenu = time.currentTime; modeJeu = 1; modeMenu = 6; initChien(chien); sprites.canardActifs = 2; for (int i = 0 ; i < sprites.canardActifs ; i++) { sprites.canard[i].type = alea(0, 3); initCanard(sprites.canard[i], partie); } partie.niveau = 0; partie.score = 0; initPartie(partie, sprites.canardActifs); initTableau(partie.tableauChasse, sprites); } else if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_SCORE], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 7; } else if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_OPTIONS], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 2; } break; case 2: boutons.bouton[BOUTON_RETOUR].position.x = (LARGEUR/2) - (boutons.lecture[0].w/2); boutons.bouton[BOUTON_RETOUR].position.y = 600; boutons.bouton[BOUTON_THEME_CLASSIQUE].position.x = ((LARGEUR/2) - (boutons.lecture[0].w/2))/2; boutons.bouton[BOUTON_THEME_CLASSIQUE].position.y = 200; boutons.bouton[BOUTON_THEME_ISLAND].position.x = (((LARGEUR/2) - (boutons.lecture[0].w/2))/2)+((LARGEUR/2) - (boutons.lecture[0].w/2)); boutons.bouton[BOUTON_THEME_ISLAND].position.y = 200; if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_RETOUR], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = lastMenu; } else if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_THEME_CLASSIQUE], boutons.lecture[0]))&&sourisEvent.clicGauche) { boutons.bouton[BOUTON_THEME_CLASSIQUE].actif = true; boutons.bouton[BOUTON_THEME_ISLAND].actif = false; libererImages(sprites, chien, boutons); chargerImages(sprites, chien, boutons, "classique"); } else if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_THEME_ISLAND], boutons.lecture[0]))&&sourisEvent.clicGauche) { boutons.bouton[BOUTON_THEME_CLASSIQUE].actif = false; boutons.bouton[BOUTON_THEME_ISLAND].actif = true; libererImages(sprites, chien, boutons); chargerImages(sprites, chien, boutons, "island"); } break; case 5 : boutons.bouton[BOUTON_REPRENDRE].position.x = (LARGEUR/2) - (boutons.lecture[0].w/2); boutons.bouton[BOUTON_REPRENDRE].position.y = 200; boutons.bouton[BOUTON_OPTIONS].position.x = (LARGEUR/2) - (boutons.lecture[0].w/2); boutons.bouton[BOUTON_OPTIONS].position.y = 400; boutons.bouton[BOUTON_QUIT].position.x = (LARGEUR/2) - (boutons.lecture[0].w/2); boutons.bouton[BOUTON_QUIT].position.y = 600; if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_QUIT], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 1; lastMenu = 1; } else if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_REPRENDRE], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 0; } else if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_OPTIONS], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 2; lastMenu = 5; } break; case 6: if (time.currentTime >= time.menuTime + time.timeMenu) { modeMenu = 0; time.timeMenu = time.currentTime; } break; case 7: boutons.bouton[BOUTON_RETOUR].position.x = (LARGEUR/2) - (boutons.lecture[0].w/2); boutons.bouton[BOUTON_RETOUR].position.y = 600; if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_RETOUR], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 1; } break; case 8: boutons.bouton[BOUTON_OK].position.x = (LARGEUR/2) - (boutons.lecture[0].w/2); boutons.bouton[BOUTON_OK].position.y = 600; lastKeyPressedBis = lastKeyPressed; keyPressedBis = keyPressed; keyPressed = false; if (carActif < LONGUEUR_MAX_PSEUDO-1) { for (int i=97; i<123; i++) { if (keystate[i]) { lastKeyPressed = i; keyPressed = true; } } } if ((carActif > 0)&&keystate[SDLK_BACKSPACE]) { lastKeyPressed = -1; keyPressed = true; } if ((lastKeyPressedBis !=lastKeyPressed)||(defilTouche&&(time.currentTime >= time.timeDefKey + time.defKeyTime))||(keyPressedBis!=keyPressed)) { if (keyPressedBis!=keyPressed) { defilTouche = false; } if (carActif < LONGUEUR_MAX_PSEUDO-1) { for (int i=97; i<123; i++) { if (keystate[i]) { partie.pseudoT[carActif]=(i-32); carActif++; time.timeKey = time.currentTime; } } } if ((carActif > 0)&&keystate[SDLK_BACKSPACE]) { partie.pseudoT[carActif-1]=0; carActif--; time.timeKey = time.currentTime; } if (defilTouche) { time.timeDefKey = time.currentTime; } } else { if ((time.currentTime >= time.timeKey + time.keyTime)&&keyPressed) { defilTouche = true; } } partie.pseudo = std::string(partie.pseudoT); if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_OK], boutons.lecture[0]))&&sourisEvent.clicGauche) { addScore("scoresClassic", partie.pseudo, partie.score, partie.highScore); modeMenu = 7; } break; case 9: boutons.bouton[BOUTON_RETOUR].position.x = (LARGEUR/2) - (boutons.lecture[0].w/2); boutons.bouton[BOUTON_RETOUR].position.y = 600; if ((testHoverBouton(sourisEvent.sx, sourisEvent.sy, boutons.bouton[BOUTON_RETOUR], boutons.lecture[0]))&&sourisEvent.clicGauche) { modeMenu = 1; } break; default: break; } if (time.currentTime >= time.timeFps + time.fpsTime) { showMenu(ecran, sprites, boutons, modeMenu, msgs, partie, sourisEvent.sx, sourisEvent.sy); time.timeFps = time.currentTime; } SDL_Flip(ecran); } }
void frame(FUNCTION_PARAMS) { int numkeys ; int _mouse=globalptr("mouse"); SDL_Rect srcrect,dstrect; SDL_Surface* mapamouse; SDL_PumpEvents(); keys = SDL_GetKeyState(&numkeys ) ; /* MOUSE */ mbuttons = SDL_GetMouseState(&fp->mem[_mouse],&fp->mem[_mouse+1]); /* Ponemos los 5 botones a 0 */ memset(&fp->mem[_mouse+9],0,5*4); if(mbuttons&SDL_BUTTON(1)) fp->mem[_mouse+9]=1; if(mbuttons&SDL_BUTTON(2)) fp->mem[_mouse+10]=1; if(mbuttons&SDL_BUTTON(3)) fp->mem[_mouse+11]=1; if(mbuttons&SDL_BUTTON(4)) /* podria no funcionar ¿necesario sdl_event? */ fp->mem[_mouse+12]=1; if(mbuttons&SDL_BUTTON(5)) /* podria no funcionar ¿necesario sdl_event? */ fp->mem[_mouse+13]=1; /* si mouse.graph!=0 */ if(fp->mem[_mouse+2]!=0) { mapamouse=fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].Surface; srcrect.x=0; srcrect.y=0; srcrect.w=mapamouse->w; srcrect.h=mapamouse->h; dstrect.x=fp->mem[_mouse]/*-fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].cpoint[0].x*/; dstrect.y=fp->mem[_mouse+1]/*-fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].cpoint[0].y*/; dstrect.w=mapamouse->w; dstrect.h=mapamouse->h; /* * TODO: añadir chequeo de error si no existe file o mapa */ fp->Dibuja(mapamouse,dstrect.x,dstrect.y,fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].cpoint[0].x,fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].cpoint[0].y,fp->mem[_mouse+8],fp->mem[_mouse+4],fp->mem[_mouse+7],(fp->mem[_mouse+7]&4)?128:255,fp->mem[_mouse+6],fp->mem[_mouse+5]); } /* FIN DE MOUSE */ /* FILE* fichero ; */ /* fichero = fopen( "input.txt" , "w+" ) ; */ /* for ( i = 0 ; i < 256 ; i++ ) */ /* keys[i] = 0 ; */ /* for ( i = 0 ; i < 256 ; i++ ) { if ( event[i].type == SDL_KEYDOWN ) { keys[ SDLtoDIV[ event[i].key.keysym.sym ] ] = 1 ; } if ( event[i].type == SDL_KEYUP ) { keys[ SDLtoDIV[ event[i].key.keysym.sym ] ] = 0 ; } }*/ /* while(SDL_PollEvent(&tecla)) { if(tecla.type == SDL_KEYDOWN) { if ( keys[tecla.key.keysym.sym] = 1 ; //i=(int)tecla.key.keysym.sym; } } */ /* for ( i = 0 ; i < 256 ; i++ ) { fprintf( fichero , "%i " , keys[i] ) ; } fprintf( fichero , "\n" ) ; */ //fclose( fichero ) ; }
int main (int argc, char *argv[]) { SDL_Surface *screen; printf ("Initializing SDL.\n"); /* Initializes Audio and the CDROM, add SDL_INIT_VIDEO for Video */ if (SDL_Init(SDL_INIT_VIDEO)< 0) { printf("Could not initialize SDL:%s\n", SDL_GetError()); SDL_Quit(); return 1; } if(TTF_Init() != 0) { printf("Could not initialize TTF:%s\n", SDL_GetError()); return 1; } printf("Video initialized correctly\n"); atexit( SDL_Quit ); printf("SCREENW : %d, SCREENH : %d\n", SCREENW, SCREENW); screen = SDL_SetVideoMode( SCREENW, SCREENH, 16, SDL_HWSURFACE ); SDL_WM_SetCaption( "421", 0 ); if( screen == NULL ) { printf( "Can't set video mode: %s\n", SDL_GetError( ) ); return EXIT_FAILURE; } // Part of the bitmap that we want to draw SDL_Rect bgsource; bgsource.x = 0; bgsource.y = 0; bgsource.w = 1000; bgsource.h = 903; // Part of the screen we want to draw the sprite to SDL_Rect bgdestination; bgdestination.x = 0; bgdestination.y = 0; bgdestination.w = 1000; bgdestination.h = 903; SDL_Surface *background; background = (SDL_Surface*) IMG_Load("pixs/background.png"); background = SDL_DisplayFormat(background); SDL_BlitSurface(background, &bgsource, screen, &bgdestination); SDL_Flip(screen); // Part of the bitmap that we want to draw SDL_Rect d1source; d1source.x = 0; d1source.y = 0; d1source.w = 189; d1source.h = 199; // Part of the screen we want to draw the sprite to SDL_Rect d1destination; d1destination.x = 0; d1destination.y = 0; d1destination.w = 189; d1destination.h = 199; SDL_Surface *dice; dice = (SDL_Surface*) IMG_Load("pixs/dices.png"); dice = SDL_DisplayFormat(dice); Uint32 colorkey = SDL_MapRGB(dice->format, 0, 255, 0); SDL_SetColorKey(dice, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey ); bool quit = false; SDL_Event event; struct dice *d1, *d2, *d3; d1 = NULL; d2 = NULL; d3 = NULL; hands *ah; ah = hands_new(); ah = hands_init(ah); hands_print(ah); while(quit == false) { while( SDL_PollEvent( &event ) ) { int x = 0; int y = 0; if(event.type == SDL_MOUSEBUTTONDOWN) { x = event.motion.x; y = event.motion.y; printf("Down (%d, %d)!!!! \n", x, y); //board_click(bd, x/24, y/24); d1 = dice_new(490, 240); d2 = dice_new(340, 340); d3 = dice_new(650, 440); if(!d1->rolling) d1 = dice_roll(d1); if(!d2->rolling) d2 = dice_roll(d2); if(!d3->rolling) d3 = dice_roll(d3); } // User press key if( event.type == SDL_KEYDOWN ) { Uint8 *keystates = SDL_GetKeyState( NULL ); // User press ESCAPE if( keystates[ SDLK_ESCAPE ] ) { quit = true; } } // User press X if( event.type == SDL_QUIT ) { quit = true; } } if(d1 && d2 && d3) if(d1->rolling || d2->rolling || d3->rolling) { SDL_BlitSurface(background, &bgsource, screen, &bgdestination); d1 = dice_check_dices_collisions(d1, d2, d3); d2 = dice_check_dices_collisions(d2, d3, d1); d3 = dice_check_dices_collisions(d3, d1, d2); } if(d1) { if(d1->rolling) d1 = dice_update(d1); d1source.x = d1->imgoffset; d1destination.x = d1->position->x; d1destination.y = d1->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } if(d2) { if(d2->rolling) d2 = dice_update(d2); d1source.x = d2->imgoffset; d1destination.x = d2->position->x; d1destination.y = d2->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } if(d3) { if(d3->rolling) d3 = dice_update(d3); d1source.x = d3->imgoffset; d1destination.x = d3->position->x; d1destination.y = d3->position->y; SDL_BlitSurface(dice, &d1source, screen, &d1destination); } SDL_Flip(screen); } return 0; }
int fs_ml_event_loop(void) { // printf("fs_ml_event_loop\n"); int result = 0; SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: fs_log("intercepted SDL_QUIT\n"); fs_ml_quit(); #ifdef FS_EMU_DRIVERS printf("returning 1 from fs_ml_event_loop\n"); result = 1; #endif continue; #ifdef USE_SDL2 case SDL_WINDOWEVENT: // printf("SDL_WINDOWEVENT...\n"); if (event.window.event == SDL_WINDOWEVENT_RESIZED) { on_resize(event.window.data1, event.window.data2); } else if (event.window.event == SDL_WINDOWEVENT_CLOSE) { event.type = SDL_QUIT; SDL_PushEvent(&event); } continue; #else case SDL_VIDEORESIZE: on_resize(event.resize.w, event.resize.h); continue; case SDL_ACTIVEEVENT: //fs_log("got active event %d %d %d %d\n", event.active.state, // SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, SDL_APPACTIVE); if ((event.active.state & SDL_APPINPUTFOCUS)) { if (event.active.gain) { fs_log("got keyboard focus\n"); // just got keyboard focus -- clearing modifier states fs_ml_clear_keyboard_modifier_state(); if (g_fs_ml_had_input_grab) { fs_log("- had input grab, re-acquiring\n"); fs_ml_grab_input(1, 1); g_fs_ml_had_input_grab = 0; } if (g_fs_ml_was_fullscreen) { if (!g_fs_emu_video_fullscreen) { fs_log("- was in fullsreen mode before (switching)\n"); fs_ml_toggle_fullscreen(); } g_fs_ml_was_fullscreen = 0; } } else { fs_log("lost keyboard focus\n"); if (fs_ml_has_input_grab()) { fs_log("- releasing input grab\n"); fs_ml_grab_input(0, 1); g_fs_ml_had_input_grab = 1; } else { fs_log("- did not have input grab\n"); //g_fs_ml_had_input_grab = 0; } } } continue; #endif case SDL_KEYDOWN: case SDL_KEYUP: if (g_debug_input) { fs_log("SDL key sym %d mod %d scancode %d state %d\n", event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.scancode, event.key.state); } if (event.key.keysym.sym == 0 && event.key.keysym.scancode == 0) { // ignore "ghost key" seen on OS X which without this // specific check will cause the A key to be mysteriously // pressed. if (g_debug_input) { fs_log("- ignored key with keysym 0 and scancode 0\n"); } continue; } /* if (event.key.keysym.sym == SDLK_F12) { g_f12_state = event.key.state ? FS_ML_KEY_MOD_F12 : 0; printf("-- g_f12_state is %d\n", g_f12_state); } else if (event.key.keysym.sym == SDLK_F11) { g_f11_state = event.key.state ? FS_ML_KEY_MOD_F11 : 0; } */ const Uint8* key_state; int num_keys; #ifdef USE_SDL2 key_state = SDL_GetKeyboardState(&num_keys); g_f11_state = key_state[SDL_SCANCODE_F11] ? FS_ML_KEY_MOD_F11 : 0; g_f12_state = key_state[SDL_SCANCODE_F12] ? FS_ML_KEY_MOD_F12 : 0; // printf("%d %d\n", g_f11_state, g_f12_state); #else key_state = SDL_GetKeyState(&num_keys); g_f11_state = key_state[SDLK_F11] ? FS_ML_KEY_MOD_F11 : 0; g_f12_state = key_state[SDLK_F12] ? FS_ML_KEY_MOD_F12 : 0; #endif int key = -1; #ifdef USE_SDL2 if (event.key.keysym.scancode <= LAST_SDL2_SCANCODE) { key = g_sdl2_keys[event.key.keysym.scancode]; } #else if (0) { } #endif #if defined(MACOSX) #ifdef USE_SDL2 #else else if (event.key.keysym.sym == SDLK_LSHIFT) { key = SDLK_LSHIFT; } else if (event.key.keysym.sym == SDLK_LCTRL) { key = SDLK_LCTRL; } else if (event.key.keysym.sym == SDLK_LALT) { key = SDLK_LALT; } else if (event.key.keysym.sym == SDLK_LMETA) { key = SDLK_LSUPER; } else if (event.key.keysym.sym == SDLK_RMETA) { key = SDLK_RSUPER; } else if (event.key.keysym.sym == SDLK_RALT) { key = SDLK_RALT; } else if (event.key.keysym.sym == SDLK_RCTRL) { key = SDLK_RCTRL; } else if (event.key.keysym.sym == SDLK_RSHIFT) { key = SDLK_RSHIFT; } else if (event.key.keysym.sym == SDLK_CAPSLOCK) { key = SDLK_CAPSLOCK; } #endif #elif defined(WINDOWS) #else else if (event.key.keysym.sym == SDLK_MODE) { key = SDLK_RALT; } #endif else { key = fs_ml_scancode_to_key(event.key.keysym.scancode); } #ifdef USE_SDL2 if (0) { // the below trick does not currently work for SDL2, as // there is no mapping yet for translated keys } #else if (g_f12_state || g_f11_state) { // leave translated key code in keysym } #endif else if (key >= 0) { if (g_debug_input) { fs_log("- key code set to %d (was %d) based on " "scancode %d\n", key, event.key.keysym.sym, event.key.keysym.scancode); } event.key.keysym.sym = key; } int mod = event.key.keysym.mod; if (mod & KMOD_LSHIFT || mod & KMOD_RSHIFT) { event.key.keysym.mod |= KMOD_SHIFT; } if (mod & KMOD_LALT || mod & KMOD_RALT) { //mod & ~(KMOD_LALT | KMOD_RALT); event.key.keysym.mod |= KMOD_ALT; } if (mod & KMOD_LCTRL || mod & KMOD_RCTRL) { event.key.keysym.mod |= KMOD_CTRL; } if (mod & KMOD_LMETA || mod & KMOD_RMETA) { event.key.keysym.mod |= KMOD_META; } // filter out other modidifers event.key.keysym.mod &= (KMOD_SHIFT | KMOD_ALT | KMOD_CTRL | KMOD_META); // add F11/F12 state event.key.keysym.mod |= g_f11_state | g_f12_state; //printf("%d %d %d %d\n", event.key.keysym.mod, // KMOD_ALT, KMOD_LALT, KMOD_RALT); break; //case SDL_MOUSEBUTTONDOWN: // printf("--- mousebutton down ---\n"); } fs_ml_event *new_event = NULL; #if !defined(USE_SDL2) fs_ml_event *new_event_2 = NULL; #endif if (event.type == SDL_KEYDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_KEYDOWN; new_event->key.keysym.sym = event.key.keysym.sym; new_event->key.keysym.mod = event.key.keysym.mod; #ifdef USE_SDL2 // SDL2 sends its own text input events #else if (event.key.keysym.unicode && event.key.keysym.unicode < 128) { // FIXME: only supporting ASCII for now.. new_event_2 = fs_ml_alloc_event(); new_event_2->type = FS_ML_TEXTINPUT; new_event_2->text.text[0] = event.key.keysym.unicode; new_event_2->text.text[1] = '\0'; } #endif new_event->key.state = event.key.state; } else if (event.type == SDL_KEYUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_KEYUP; new_event->key.keysym.sym = event.key.keysym.sym; new_event->key.keysym.mod = event.key.keysym.mod; new_event->key.state = event.key.state; } else if (event.type == SDL_JOYBUTTONDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYBUTTONDOWN; new_event->jbutton.which = g_fs_ml_first_joystick_index + \ event.jbutton.which; new_event->jbutton.button = event.jbutton.button; new_event->jbutton.state = event.jbutton.state; } else if (event.type == SDL_JOYBUTTONUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYBUTTONUP; new_event->jbutton.which = g_fs_ml_first_joystick_index + \ event.jbutton.which; new_event->jbutton.button = event.jbutton.button; new_event->jbutton.state = event.jbutton.state; } else if (event.type == SDL_JOYAXISMOTION) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYAXISMOTION; new_event->jaxis.which = g_fs_ml_first_joystick_index + \ event.jaxis.which; new_event->jaxis.axis = event.jaxis.axis; new_event->jaxis.value = event.jaxis.value; } else if (event.type == SDL_JOYHATMOTION) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYHATMOTION; new_event->jhat.which = g_fs_ml_first_joystick_index + \ event.jhat.which; new_event->jhat.hat = event.jhat.hat; new_event->jhat.value = event.jhat.value; } else if (event.type == SDL_MOUSEMOTION) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEMOTION; new_event->motion.device = g_fs_ml_first_mouse_index; new_event->motion.xrel = event.motion.xrel; new_event->motion.yrel = event.motion.yrel; /* Absolute window coordinates */ new_event->motion.x = event.motion.x; new_event->motion.y = event.motion.y; //printf("ISREL %d\n", SDL_GetRelativeMouseMode()); if (g_debug_input) { fs_log("SDL mouse event x: %4d y: %4d xrel: %4d yrel: %4d\n", event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); } } else if (event.type == SDL_MOUSEBUTTONDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONDOWN; new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.button = event.button.button; #ifdef MACOSX if (new_event->button.button == 1) { int mod = SDL_GetModState(); if (mod & KMOD_ALT) { new_event->button.button = 2; } else if (mod & KMOD_CTRL) { new_event->button.button = 3; } } #endif new_event->button.state = event.button.state; } else if (event.type == SDL_MOUSEBUTTONUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONUP; new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.button = event.button.button; #ifdef MACOSX if (new_event->button.button == 1) { int mod = SDL_GetModState(); if (mod & KMOD_ALT) { new_event->button.button = 2; } else if (mod & KMOD_CTRL) { new_event->button.button = 3; } } #endif new_event->button.state = event.button.state; } #ifdef USE_SDL2 else if (event.type == SDL_MOUSEWHEEL) { /* if (event.wheel.which == SDL_TOUCH_MOUSEID) { } */ if (event.wheel.y) { if (g_debug_input) { fs_log("SDL mouse event y-scroll: %4d\n", event.wheel.y); } new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONDOWN; if (event.wheel.y > 0) { new_event->button.button = FS_ML_BUTTON_WHEELUP; } else { new_event->button.button = FS_ML_BUTTON_WHEELDOWN; } new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.state = 1; } } else if (event.type == SDL_TEXTINPUT) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_TEXTINPUT; memcpy(&(new_event->text.text), &(event.text.text), MIN(TEXTINPUTEVENT_TEXT_SIZE, SDL_TEXTINPUTEVENT_TEXT_SIZE)); new_event->text.text[TEXTINPUTEVENT_TEXT_SIZE - 1] = 0; } #endif if (new_event) { fs_ml_post_event(new_event); } #if !defined(USE_SDL2) if (new_event_2) { fs_ml_post_event(new_event_2); } #endif } return result; }
int mainmenu_cycle(int width,int height) { int i; int retval=0; unsigned char *keyboard; SDL_PumpEvents(); keyboard = SDL_GetKeyState(NULL); switch(mainmenu_status) { case 0: mainmenu_substatus++; if (mainmenu_substatus>=40) { mainmenu_substatus=0; mainmenu_status=1; } /* if */ break; case 1: mainmenu_substatus++; if ((keyboard[fire_key] && !old_keyboard[fire_key]) || (keyboard[SDLK_1] && !old_keyboard[SDLK_1])) { mainmenu_status=4; mainmenu_substatus=0; } /* if */ if (keyboard[SDLK_2] && !old_keyboard[SDLK_2]) { mainmenu_status=6; mainmenu_substatus=0; } /* if */ if (keyboard[SDLK_3] && !old_keyboard[SDLK_3]) { mainmenu_status=2; mainmenu_substatus=0; } /* if */ if (keyboard[SDLK_4] && !old_keyboard[SDLK_4]) { /* Change the MAP: */ if (mapnames.EmptyP()) { /* Fill the mapnames list: */ #ifdef _WIN32 WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile("/usr/local/share/netherearth/maps/*.map",&finfo); if (h!=INVALID_HANDLE_VALUE) { if (strcmp(finfo.cFileName,".")!=0 && strcmp(finfo.cFileName,"..")!=0) { char *name; name=new char[strlen(finfo.cFileName)+1]; strcpy(name,finfo.cFileName); mapnames.Add(name); } /* if */ while(FindNextFile(h,&finfo)==TRUE) { if (strcmp(finfo.cFileName,".")!=0 && strcmp(finfo.cFileName,"..")!=0) { char *name; name=new char[strlen(finfo.cFileName)+1]; strcpy(name,finfo.cFileName); mapnames.Add(name); } /* if */ } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; dp = opendir ("/usr/local/share/netherearth/maps/"); if (dp != NULL) { while (ep = readdir (dp)) { if ((strstr(ep->d_name,".map") + 4) == ep->d_name + strlen(ep->d_name)) { char *name; name=new char[strlen(ep->d_name)+1]; strcpy(name,ep->d_name); mapnames.Add(name); } } (void) closedir (dp); } #endif /* Look for the actualmap: */ mapnames.Rewind(); while(!mapnames.EndP() && strcmp(mapnames.GetObj(),mapname)!=0) mapnames.Next(); } /* if */ if (!mapnames.EmptyP()) { mapnames.Next(); if (mapnames.EndP()) mapnames.Rewind(); strcpy(mapname,mapnames.GetObj()); } /* if */ save_configuration(); } /* if */ if (keyboard[SDLK_5] && !old_keyboard[SDLK_5]) { mainmenu_status=5; mainmenu_substatus=0; } /* if */ break; case 2: mainmenu_substatus++; if (mainmenu_substatus>=40) { mainmenu_substatus=0; mainmenu_status=3; } /* if */ break; case 3: if (keyboard[SDLK_1] && !old_keyboard[SDLK_1]) { switch(SCREEN_X) { case 320: SCREEN_X=400; SCREEN_Y=300; break; case 400: SCREEN_X=640; SCREEN_Y=480; break; case 640: SCREEN_X=800; SCREEN_Y=600; break; case 800: SCREEN_X=1024; SCREEN_Y=768; break; case 1024: SCREEN_X=320; SCREEN_Y=240; break; default: SCREEN_X=640; SCREEN_Y=480; } /* switch */ retval=3; save_configuration(); } /* if */ if (keyboard[SDLK_2] && !old_keyboard[SDLK_2]) { switch(COLOUR_DEPTH) { case 8:COLOUR_DEPTH=16; break; case 16:COLOUR_DEPTH=24; break; case 24:COLOUR_DEPTH=32; break; default: COLOUR_DEPTH=8; } /* switch */ retval=3; save_configuration(); } /* if */ if (keyboard[SDLK_3] && !old_keyboard[SDLK_3]) { if (fullscreen) fullscreen=false; else fullscreen=true; retval=3; save_configuration(); } /* if */ if (keyboard[SDLK_4] && !old_keyboard[SDLK_4]) { shadows++; if (shadows>=3) shadows=0; save_configuration(); } /* if */ if (keyboard[SDLK_5] && !old_keyboard[SDLK_5]) { detaillevel++; if (detaillevel>=5) detaillevel=0; save_configuration(); } /* if */ if (keyboard[SDLK_6] && !old_keyboard[SDLK_6]) { if (sound) sound=false; else sound=true; save_configuration(); } /* if */ if (keyboard[SDLK_7] && !old_keyboard[SDLK_7]) { level++; if (level>=4) level=0; save_configuration(); } /* if */ if (keyboard[SDLK_8] && !old_keyboard[SDLK_8]) { if (show_radar) show_radar=false; else show_radar=true; save_configuration(); } /* if */ if (keyboard[SDLK_9] && !old_keyboard[SDLK_9]) { mainmenu_status=0; mainmenu_substatus=0; } /* if */ break; case 4: mainmenu_substatus++; if (mainmenu_substatus>=40) { retval=1; } /* if */ break; case 5: mainmenu_substatus++; if (mainmenu_substatus>=40) { retval=2; } /* if */ break; case 6: mainmenu_substatus++; if (mainmenu_substatus>=40) { mainmenu_status=7; mainmenu_substatus=0; } /* if */ break; case 7: { int i; for(i=0;i<SDLK_LAST;i++) { if (keyboard[i] && !old_keyboard[i]) { switch(mainmenu_substatus) { case 0:up_key=i; break; case 1:down_key=i; break; case 2:left_key=i; break; case 3:right_key=i; break; case 4:fire_key=i; break; case 5:pause_key=i; break; } /* sritch */ mainmenu_substatus++; if (mainmenu_substatus==7) { mainmenu_status=0; mainmenu_substatus=0; save_configuration(); } /* if */ } /* if */ } /* for */ } break; } /* if */ for(i=0;i<SDLK_LAST;i++) old_keyboard[i]=keyboard[i]; return retval; } /* mainmenu_cycle */
void Manager::play() { SDL_Event event; SDLSound sound; bool done = false; bool keyCatch = false; int rnd ; //Fuel bar; unsigned prevTicks = 0; unsigned currTicks = SDL_GetTicks(); unsigned ticks = 0; clock.unpause(); while ( not done ) { if ( ( myPlayer->X() > ( Gamedata::getInstance().getXmlInt("worldWidth") - 200) ) || (livesRemaining<0) ) { io.printMessageAt("Game Over !!!", 800, 400); gameOver = true; clock.pause(); SDL_Flip(screen); SDL_Delay(1250); done = true; break; } //if(cacheEnemies.size()<=5) //{ if(level == 1) { rnd = rand()%200; } else if(level == 2) { rnd = rand()%100; } else { rnd = rand()%50; } if(rnd == 5) { //Enemy *newenemy = new Enemy("enemy"); Enemy *newenemy = new Enemy("enemy", *cachePlayer); newenemy->setPosition(Vector2f(cachePlayer->X() + (3*Gamedata::getInstance().getXmlInt("viewWidth")/4) , rand()%(2*Gamedata::getInstance().getXmlInt("worldHeight")/3)+60 ) ); cacheEnemies.push_back(newenemy); //insert into cache enemies.push_back(newenemy); //insert into enemies currently drawn enemyBlasts.push_back(new MultiSprite("blast")); //insert corresponding blast sprite enemyExploded.push_back(false); //on creation explosion is false } //} for(unsigned i=0; i<enemies.size(); ++i) { if(enemyExploded[i]) { //if ( static_cast<MultiSprite*>(enemies[i])->getCurrentFrame() == 0 ) //sound[1]; if ( static_cast<MultiSprite*>(enemies[i])->getCurrentFrame() == 6 ) { /* //enemyExploded[i] = false; cacheEnemies[i].erase; enemies[i].erase; enemyBlasts[i].erase; enemyExploded[i].erase; //enemies[i] = cacheEnemies[i] ; */ unsigned ctr =0; std::vector<Enemy*>::iterator ptr = cacheEnemies.begin(); while ( ctr < i ) { ctr++; ptr++; } cacheEnemies.erase(ptr); ctr =0; std::vector<MultiSprite*>::iterator ptr1 = enemyBlasts.begin(); while ( ctr < i ) { ctr++; ptr1++; } enemyBlasts.erase(ptr1); ctr =0; std::vector<Drawable*>::iterator ptr2 = enemies.begin(); while ( ctr < i ) { ctr++; ptr2++; } enemies.erase(ptr2); ctr =0; std::vector<bool>::iterator ptr3 = enemyExploded.begin(); while ( ctr < i ) { ctr++; ptr3++; } enemyExploded.erase(ptr3); } } } if(explosion) { if ( static_cast<MultiSprite*>(myPlayer)->getCurrentFrame() == 0 ) { sound[1]; } if ( static_cast<MultiSprite*>(myPlayer)->getCurrentFrame() == 6 ) { timeSinceLastExplosion = 0; explosion = false; myPlayer = cachePlayer ; } } SDL_PollEvent(&event); Uint8 *keystate = SDL_GetKeyState(NULL); if (event.type == SDL_QUIT) { done = true; break; } if(event.type == SDL_KEYUP) { //std::cout<<"******************8KEY_UP*****"; keyCatch = false; if (!keystate[SDLK_RIGHT] && !keystate[SDLK_LEFT]) static_cast<Player*>(myPlayer)->stopX(); if (!keystate[SDLK_UP] && !keystate[SDLK_DOWN]) static_cast<Player*>(myPlayer)->stopY(); if (keystate[SDLK_LEFT] && !keyCatch && !showHelp ) { if(bar.getcurrentLength()) { static_cast<Player*>(myPlayer)->goLeft(); //keyCatch = false; } else { static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } if (keystate[SDLK_RIGHT] && !showHelp) { //std::cout<<bar.getcurrentLength(); if(bar.getcurrentLength()>0) { // std::cout<<"Condition checked"; static_cast<Player*>(myPlayer)->goRight(); } else { //std::cout<<"Condition FALSE"; static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } if (keystate[SDLK_UP] && !showHelp && !explosion) { //std::cout<<bar.getcurrentLength(); if(bar.getcurrentLength()>0) { // std::cout<<"Condition checked"; static_cast<Player*>(myPlayer)->goUp(); } else { //std::cout<<"Condition FALSE"; static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } if (keystate[SDLK_DOWN] && !showHelp && !explosion ) { //std::cout<<bar.getcurrentLength(); if(bar.getcurrentLength()>0) { // std::cout<<"Condition checked"; static_cast<Player*>(myPlayer)->goDown(); } else { // std::cout<<"Condition FALSE"; static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } } if(event.type == SDL_KEYDOWN) { if (keystate[SDLK_ESCAPE] || keystate[SDLK_q]) { clock.pause(); done = true; break; } if (keystate[SDLK_SPACE] && !keyCatch) { keyCatch = true; //io.clearString(); sound.toggleMusic(); break; } if (keystate[SDLK_r] && !keyCatch && !explosion) { keyCatch = true; sound[0]; bullets.shoot( Vector2f(myPlayer->X(),myPlayer->Y() +40) , Vector2f(Gamedata::getInstance().getXmlInt("bulletSpeedX"),Gamedata::getInstance().getXmlInt("bulletSpeedY")) ); } if (keystate[SDLK_p] && !keyCatch && parachutes.size()<100) { keyCatch = true; Sprite *newparachute; int rnd = rand()%3; if(rnd==0) { newparachute= new Sprite("parachuteBig") ; //newparachute->setPosition( Vector2f(sprites[0]->X() + rand()%(Gamedata::getInstance().getXmlInt("viewWidth")/2) , rand()%100) ); newparachute->setVelocity( Vector2f(-100 , 100 )); } else if(rnd==1) { newparachute= new Sprite("parachuteMed") ; //newparachute->setPosition( Vector2f(sprites[0]->X() + rand()%(Gamedata::getInstance().getXmlInt("viewWidth")/2) , rand()%100) ); newparachute->setVelocity( Vector2f(-50 , 50 )); } else { newparachute= new Sprite("parachuteSmall") ; //newparachute->setPosition( Vector2f(sprites[0]->X() + rand()%(Gamedata::getInstance().getXmlInt("viewWidth")/2) , rand()%100) ); newparachute->setVelocity( Vector2f(-25 , 25 )); } newparachute->setPosition( Vector2f(sprites[0]->X() + rand()%(Gamedata::getInstance().getXmlInt("viewWidth")/2) , rand()%100) ); parachutes.push_back(newparachute); std::sort(parachutes.begin(), parachutes.end(), ParachuteCompare()); } /* if (keystate[SDLK_t] && !keyCatch) { keyCatch = true; // currentSprite = (currentSprite+1) % sprites.size(); currentSprite = (currentSprite+1) % 2; viewport.setObjectToTrack(sprites[currentSprite]); }*//* if (keystate[SDLK_F1] && !keyCatch) { keyCatch = true; if(showHelp==true) { showHelp=false; //viewport.setObjectToTrack(sprites[currentSprite]); viewport.setObjectToTrack(myPlayer); } else { //viewport.setObjectToTrack(sprites[2]); viewport.setObjectToTrack(sprites[1]); showHelp=true; } }*/ if (keystate[SDLK_h]&& !keyCatch) { keyCatch = true; if(showHUD==true) { showHUD=false; //viewport.setObjectToTrack(sprites[currentSprite]); } else { //viewport.setObjectToTrack(sprites[2]); showHUD=true; } } /* if (keystate[SDLK_s] && !keyCatch) { keyCatch = true; clock.toggleSloMo(); }*/ if (keystate[SDLK_LEFT] && !showHelp && !explosion ) { if(bar.getcurrentLength()) { static_cast<Player*>(myPlayer)->goLeft(); //keyCatch = false; } else { static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } if (keystate[SDLK_RIGHT] && !showHelp && !explosion ) { //std::cout<<bar.getcurrentLength(); if(bar.getcurrentLength()>0) { //std::cout<<"Condition checked"; static_cast<Player*>(myPlayer)->goRight(); } else { //std::cout<<"Condition FALSE"; static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } if (keystate[SDLK_UP] && !showHelp && !explosion) { //std::cout<<bar.getcurrentLength(); if(bar.getcurrentLength()>0) { //std::cout<<"Condition checked"; static_cast<Player*>(myPlayer)->goUp(); } else { // std::cout<<"Condition FALSE"; static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } if (keystate[SDLK_DOWN] && !showHelp && !explosion ) { //std::cout<<bar.getcurrentLength(); if(bar.getcurrentLength()>0) { // std::cout<<"Condition checked"; static_cast<Player*>(myPlayer)->goDown(); } else { //std::cout<<"Condition FALSE"; static_cast<Player*>(myPlayer)->stopX(); static_cast<Player*>(myPlayer)->stopY(); } } if (keystate[SDLK_f]&& !keyCatch ) { keyCatch = true; // std::cout<<" R PRESSED "; //keyCatch = false; //keystate[SDLK_RIGHT] = 1; bar.reset(); } if (keystate[SDLK_e]&& !keyCatch && explosion==false ) { sound[1]; //std::cout<<"E pressed"; keyCatch = true; explosion = true; blast->resetCurrentFrame(); blast->setPosition(Vector2f(myPlayer->X(),myPlayer->Y())); blast->setVelocity(Vector2f(0,0)); myPlayer = blast ; } /* if (keystate[SDLK_k]&& !keyCatch) { sound[1]; //std::cout<<"E pressed"; keyCatch = true; for(unsigned i=0; i<enemies.size(); i++) { enemyExploded[i] = true; enemyBlasts[i]->resetCurrentFrame(); enemyBlasts[i]->setPosition(Vector2f(enemies[i]->X(),enemies[i]->Y())); enemyBlasts[i]->setVelocity(Vector2f(0,0)); enemies[i] = enemyBlasts[i] ; } }*/ } //std::sort(parachutes.begin(), parachutes.end(), ParachuteCompare()); draw(); // **************** Draw Health Meter ******************** //io.printMessageCenteredAt("Press r to reset health meter", 10); currTicks = SDL_GetTicks(); // currTicks = clock.getElapsedTicks(); ticks = currTicks-prevTicks; prevTicks = currTicks; if(showHUD) { bar.draw(); io.printMessageValueAt("FPS: ", clock.getAvgFps(), 10, 20); //string message = "Tracking: "+ sprites[currentSprite]->getName(); //io.printMessageAt(message, 80, 20); //io.printMessageAt("F1: Help", 230, 20); io.printMessageAt("Fuel : ", 1290, 20); io.printMessageValueAt("Level: ", level, 250, 20); io.printMessageValueAt("Score: ", score, 600, 20); //io.printMessageValueAt("timeSinceLastExplosion: ", timeSinceLastExplosion, 500, 20); io.printMessageValueAt("Lives Remaining: ", livesRemaining, 900, 20); if(rand()%10<9 && bar.getcurrentLength()<150) io.printMessageAt("Re-Fuel!!", 1200, 20); } if(!showHelp) bar.update(ticks); SDL_Flip(screen); update(); } }
int main(int argc, char* argv[]) { //Quit Trigger bool quit = false; //fps stuff; int frame = 0; Timer fps; //Initiate SDL and such if(!init()) return 1; //Load background if(!load_background()) return 2; //Load in other images BulletController* bulletController = new BulletController(); EnemyController* enemyController = new EnemyController(bulletController); Player player(bulletController); OSD osd; //Put all image loading into one function? //Definitely Going to use sprite sheets //The loop :D while(!quit) { //start timing fps fps.start(); //Check for events if(SDL_PollEvent(&event)) { //Quit when X is pressed if(event.type == SDL_QUIT) quit = true; } //Get keystates Uint8 *keystates = SDL_GetKeyState( NULL ); if(keystates[SDLK_ESCAPE]){ quit = true; } if((keystates[SDLK_RALT] && keystates[SDLK_RETURN]) || keystates[SDLK_F11]){ if(isFullscreen) screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); else screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE|SDL_FULLSCREEN); isFullscreen = !isFullscreen; } //update player.update(keystates); //render apply_surface( 0, 0, background, screen); player.render(screen); bulletController->update(screen); enemyController->update(screen); osd.update(screen); //Refresh the SCREEN if(SDL_Flip(screen) == -1) return 9999; frame++; if( (CAP_FRAMES) && (fps.get_ticks() < 1000 / FRAMES_PER_SECOND)) { SDL_Delay((1000 / FRAMES_PER_SECOND) - fps.get_ticks()); } } return 0; }
//------------------------------------------------------------------------------------ // установка-получение статуса нажатых кнопок на клавиатуре //------------------------------------------------------------------------------------ bool vw_GetKeys(int Num) { Uint8 *keystate = SDL_GetKeyState(&MaxKeyCount); if (keystate[Num]) return true; return false; }
void passage_mainloop(int map,int map_x,int map_y,unsigned char *screen,int dx,int dy) { unsigned char *keyboard; SDL_PumpEvents(); keyboard = (unsigned char *)SDL_GetKeyState(NULL); /* Dibujar el marco: */ int i; for(i=0;i<32;i++) { tiles[143]-> draw(GAME_VIEW_X+i*TILE_SIZE_X,GAME_VIEW_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[143]-> draw(GAME_VIEW_X+i*TILE_SIZE_X,GAME_VIEW_Y+18*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); } /* for */ for(i=0;i<19;i++) { tiles[143]-> draw(GAME_VIEW_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[143]-> draw(GAME_VIEW_X+TILE_SIZE_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[143]-> draw(GAME_VIEW_X+30*TILE_SIZE_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[143]-> draw(GAME_VIEW_X+31*TILE_SIZE_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); } /* for */ tiles[ladder_tile]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+19*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[character_tile[character]+7]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+16*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); /* Dibujar los bocadillos: */ tiles[151]-> draw(GAME_VIEW_X+4*TILE_SIZE_X,GAME_VIEW_Y+4*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[150]-> draw(GAME_VIEW_X+27*TILE_SIZE_X,GAME_VIEW_Y+4*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[149]-> draw(GAME_VIEW_X+27*TILE_SIZE_X,GAME_VIEW_Y+10*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[148]-> draw(GAME_VIEW_X+4*TILE_SIZE_X,GAME_VIEW_Y+10*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); for(i=5;i<27;i++) { tiles[146]-> draw(GAME_VIEW_X+i*TILE_SIZE_X,GAME_VIEW_Y+4*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[146]-> draw(GAME_VIEW_X+i*TILE_SIZE_X,GAME_VIEW_Y+10*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); } /* for */ for(i=5;i<10;i++) { tiles[147]-> draw(GAME_VIEW_X+4*TILE_SIZE_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[147]-> draw(GAME_VIEW_X+27*TILE_SIZE_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); } /* for */ tiles[145]-> draw(GAME_VIEW_X+11*TILE_SIZE_X,GAME_VIEW_Y+4*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[151]-> draw(GAME_VIEW_X+4*TILE_SIZE_X,GAME_VIEW_Y+11*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[150]-> draw(GAME_VIEW_X+27*TILE_SIZE_X,GAME_VIEW_Y+11*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[149]-> draw(GAME_VIEW_X+27*TILE_SIZE_X,GAME_VIEW_Y+15*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[148]-> draw(GAME_VIEW_X+4*TILE_SIZE_X,GAME_VIEW_Y+15*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); for(i=5;i<27;i++) { tiles[146]-> draw(GAME_VIEW_X+i*TILE_SIZE_X,GAME_VIEW_Y+11*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[146]-> draw(GAME_VIEW_X+i*TILE_SIZE_X,GAME_VIEW_Y+15*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); } /* for */ for(i=12;i<15;i++) { tiles[147]-> draw(GAME_VIEW_X+4*TILE_SIZE_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); tiles[147]-> draw(GAME_VIEW_X+27*TILE_SIZE_X,GAME_VIEW_Y+i*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); } /* for */ tiles[144]-> draw(GAME_VIEW_X+20*TILE_SIZE_X,GAME_VIEW_Y+15*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); if (map==0 && map_x==5 && map_y==9) { /* DEMETER */ tile_print("h F5 TO F9",TILE_SIZE_X*6,TILE_SIZE_Y*21,screen,dx,dy); tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); int slot=-1; /* Guardar el juego a disco: */ if (keyboard[SDLK_F5] && !old_keyboard[SDLK_F5]) slot=1; if (keyboard[SDLK_F6] && !old_keyboard[SDLK_F6]) slot=2; if (keyboard[SDLK_F7] && !old_keyboard[SDLK_F7]) slot=3; if (keyboard[SDLK_F8] && !old_keyboard[SDLK_F8]) slot=4; if (keyboard[SDLK_F9] && !old_keyboard[SDLK_F9]) slot=5; if (slot!=-1) { char passwd[48]; char tmp[80]; FILE *fp; generatepassword(passwd); sprintf(tmp,"sgame%.2i.txt",slot); fp=f1open(tmp,"w",USERDATA); if (fp!=0) { int i; for(i=0;i<48;i++) { fprintf(fp,"%c",passwd[i]); } /* for */ fclose(fp); Sound_play(S_select); } /* if */ } /* if */ if (passage_state==0) { tile_print("YOU WANT THE SECRET",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("CODE TO WAKEN",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("MY MEMORY KEEP THE",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("RECORDS ABOUT YOU?",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); tile_print(" YES NO",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { if (currently_selecting<1) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { if (currently_selecting==0) passage_state=2; if (currently_selecting==1) passage_state=1; keyboard[SWORD_KEY]=false; } /* if */ } /* if */ if (passage_state==1) { tile_print("RESCUE THE BABY AS ",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("SOON AS POSSIBLE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (passage_state==2) { char passwd[48]; char buf[20]; int k; for(k=0;k<20;k++) buf[k]=' '; generatepassword(passwd); buf[0]=passwd[0]; buf[1]=passwd[1]; buf[2]=passwd[2]; buf[3]=passwd[3]; buf[5]=passwd[4]; buf[6]=passwd[5]; buf[7]=passwd[6]; buf[8]=passwd[7]; buf[10]=passwd[8]; buf[11]=passwd[9]; buf[12]=passwd[10]; buf[13]=passwd[11]; buf[15]=passwd[12]; buf[16]=passwd[13]; buf[17]=passwd[14]; buf[18]=passwd[15]; buf[19]=0; tile_print(buf,TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); buf[0]=passwd[16]; buf[1]=passwd[17]; buf[2]=passwd[18]; buf[3]=passwd[19]; buf[5]=passwd[20]; buf[6]=passwd[21]; buf[7]=passwd[22]; buf[8]=passwd[23]; buf[10]=passwd[24]; buf[11]=passwd[25]; buf[12]=passwd[26]; buf[13]=passwd[27]; buf[15]=passwd[28]; buf[16]=passwd[29]; buf[17]=passwd[30]; buf[18]=passwd[31]; buf[19]=0; tile_print(buf,TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); buf[0]=passwd[32]; buf[1]=passwd[33]; buf[2]=passwd[34]; buf[3]=passwd[35]; buf[5]=passwd[36]; buf[6]=passwd[37]; buf[7]=passwd[38]; buf[8]=passwd[39]; buf[10]=passwd[40]; buf[11]=passwd[41]; buf[12]=passwd[42]; buf[13]=passwd[43]; buf[15]=passwd[44]; buf[16]=' '; buf[17]=' '; buf[18]=' '; buf[19]=0; tile_print(buf,TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("DID YOU GET THEM?",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); tile_print(" YES",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=3; } /* if */ } /* if */ if (passage_state==3) { tile_print("SEE YOU AGAIN",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); } /* if */ } /* if */ if (map==0 && map_x==8 && map_y==15) { int price[3]={20,30,20}; /* ARES */ tile_print("ARES",TILE_SIZE_X*18,TILE_SIZE_Y*5,screen,dx,dy); tiles[153]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[items_tile+30]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[armas_tile+4]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+8*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y,screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 20 30 20",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:n_arrows+=50; break; case 1:item[30]=true; item[31]=false; item[27]=false; break; case 2:item[36]=true; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==0 && map_y==13) { int price[3]={30,5,20}; /* HEPHAESTUS */ tile_print("HEPHAESTUS",TILE_SIZE_X*15,TILE_SIZE_Y*5,screen,dx,dy); tiles[153]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[armas_tile+5]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+8*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[arrow_tile+1]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 30 05 20",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:item[37]=true; break; case 1:n_keys+=2; break; case 2:n_arrows+=50; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==11 && map_y==10) { /* DEATH */ tile_print("DEATH",TILE_SIZE_X*18,TILE_SIZE_Y*5,screen,dx,dy); tiles[167]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if ((live_character[0] || !can_revive_character[0]) && (live_character[1] || !can_revive_character[1]) && passage_state==0) { tile_print("IF YOUR LOVER IS",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("KILLED,COME BACK",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("HERE WITH abc100,",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("dec100, AND fgc20.",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); } else { if (passage_state==0) { tile_print("GIVE ME abc100,",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("dec100 AND fgc20 IN",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("RETURN FOR REVIVING",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("YOUR LOVER.",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); tile_print(" YES NO",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+20 *TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { if (currently_selecting<1) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { if (currently_selecting==0 && n_arrows>=100 && n_coins>=100 && n_keys>=20) { n_arrows-=100; n_coins-=100; n_keys-=20; can_revive_character[1-character]=false; live_character[0]=live_character[1]=true; player_energy[1-character]=player_max[1-character]; passage_state=2; } /* if */ if (currently_selecting==1) passage_state=1; keyboard[SWORD_KEY]=false; } /* if */ } /* if */ if (passage_state==1) { tile_print("THEN,YOU MUST FIGHT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ALL BY YOURSELF",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("GO,RIGHT NOW.",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); } /* if */ if (passage_state==2) { tile_print("YOUR LOVER HAS",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("REVIVED, GO AND GET",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("BACK THE LITTLE BABY",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("TOGETHER. GO AHEAD!",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); } /* if */ } /* if */ } /* if */ if (map==0 && map_x==9 && map_y==7) { int price[3]={20,25,5}; /* HEPHAESTUS */ tile_print("HEPHAESTUS",TILE_SIZE_X*15,TILE_SIZE_Y*5,screen,dx,dy); tiles[153]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[items_tile+22]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[key_tile]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 20 25 05",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:n_arrows+=50; break; case 1:item[22]=true; break; case 2:n_keys+=2; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==12 && map_y==2) { int price[3]={20,50,5}; /* ARES */ tile_print("ARES",TILE_SIZE_X*18,TILE_SIZE_Y*5,screen,dx,dy); tiles[153]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[items_tile+12]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[key_tile]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 20 50 05",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:n_arrows+=50; break; case 1:item[12]=true; break; case 2:n_keys+=2; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==2 && map_y==2) { int price[3]={30,20,5}; /* HEPHAESTUS */ tile_print("HEPHAESTUS",TILE_SIZE_X*15,TILE_SIZE_Y*5,screen,dx,dy); tiles[153]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[items_tile+20]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[key_tile]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 30 20 05",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:item[20]=true; break; case 1:n_arrows+=50; break; case 2:n_keys+=2; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==2 && map_y==5) { int price[3]={20,25,5}; /* DETEMETER */ tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[items_tile]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[key_tile]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 20 25 05",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:n_arrows+=50; break; case 1:item[0]=true; break; case 2:n_keys+=2; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==12 && map_y==8) { int price[3]={20,40,5}; /* ARES */ tile_print("ARES",TILE_SIZE_X*18,TILE_SIZE_Y*5,screen,dx,dy); tiles[153]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[items_tile+31]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[key_tile]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 20 40 05",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:n_arrows+=50; break; case 1: item[27]=false; item[30]=false; item[31]=true; break; case 2:n_keys+=2; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==8 && map_y==1) { int price[3]={20,50,5}; /* ARES */ tile_print("ARES",TILE_SIZE_X*18,TILE_SIZE_Y*5,screen,dx,dy); tiles[153]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[arrow_tile]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[1]) { tiles[items_tile+27]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ if (shop_item[2]) { tiles[key_tile]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 20 50 05",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+9*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==1) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (currently_selecting==2) { tiles[152]-> draw(GAME_VIEW_X+21*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[RIGHT_KEY] && !old_keyboard[RIGHT_KEY]) { passage_state=0; if (currently_selecting<2) { currently_selecting++; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[LEFT_KEY] && !old_keyboard[LEFT_KEY]) { passage_state=0; if (currently_selecting>0) { currently_selecting--; Sound_play(S_select); } /* if */ } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; switch(currently_selecting) { case 0:n_arrows+=50; break; case 1: item[27]=true; item[30]=false; item[31]=false; break; case 2:n_keys+=2; break; } /* if */ Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==0 && map_x==7 && map_y==7) { /* ASCLEPIUS */ tile_print("ASCLEPIUS",TILE_SIZE_X*16,TILE_SIZE_Y*5,screen,dx,dy); tiles[178]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("SEE A FAIRY TO",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("RESTORE YOUR",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("VITALITY.",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); } /* if */ if (map==1) { /* DEMETER en el mundo 1 */ tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("TAKE A MINE WITH YOU",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("WHEN YOU GO TO",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("WORLD 4",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); } /* if */ if (map==2) { /* ATHENA en el mundo 2 */ tile_print("ATHENA",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[161]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("HIT THE WALL WITH",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("YOUR SWORD IF YOU",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("WANT TO GO TO THE",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("OPPOSITE SHORE.",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); } /* if */ if (map==3) { /* ATHENA en el mundo 3 */ tile_print("ATHENA",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[161]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("APHRODITE.DO NOT BE",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("AFRAID OF WATER.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (map==4) { /* DEMETER en el mundo 4 */ tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("THE PURE WATER IS",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("INSIDE THE WALL.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (map==5) { int price[1]={30}; /* DETEMETER */ tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[items_tile+3]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 30",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; item[3]=true; Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==6) { /* ATHENA en el mundo 6 */ tile_print("ATHENA",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[161]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("HIT THE WALL WHEN",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("YOU ARE HALFWAY OF",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("THE STAIRS.",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); } /* if */ if (map==7) { /* DEMETER en el mundo 7 */ tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("FIND THE SPELL",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("WRITTEN ON A STONE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("MONUMENT UNDER THE",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("WATER.",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); } /* if */ if (map==8) { int price[1]={30}; /* DETEMETER */ tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); if (passage_state==0) { tile_print("YOU CAN BUY SOME OF",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("MY TREASURE",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } else { tile_print("COINS ARE NOT",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("ENOUGH.",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); } /* if */ if (shop_item[0]) { tiles[items_tile+11]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+7*TILE_SIZE_Y, screen,col_buffer,dx,dy,dx); } /* if */ tile_print(" 30",TILE_SIZE_X*10,TILE_SIZE_Y*13,screen,dx,dy); if (currently_selecting==0) { tiles[152]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+12*TILE_SIZE_Y, TILE_SIZE_X,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); } /* if */ if (keyboard[SWORD_KEY] && !old_keyboard[SWORD_KEY]) { passage_state=0; if (n_coins>=price[currently_selecting] && shop_item[currently_selecting]) { /* Comprar objeto: */ n_coins-=price[currently_selecting]; shop_item[currently_selecting]=false; item[11]=true; Sound_play(S_item); } else { if (shop_item[currently_selecting] && n_coins<price[currently_selecting]) { Sound_play(S_nocoins); passage_state=1; } /* if */ } /* if */ } /* if */ } /* if */ if (map==9) { /* DEMETER en el mundo 9 */ tile_print("DEMETER",TILE_SIZE_X*17,TILE_SIZE_Y*5,screen,dx,dy); tiles[154]-> draw(GAME_VIEW_X+15*TILE_SIZE_X,GAME_VIEW_Y+2*TILE_SIZE_Y, TILE_SIZE_X*2,TILE_SIZE_Y*2,screen,col_buffer,dx,dy,dx); tile_print("A GATE WHICH LEADS",TILE_SIZE_X*10,TILE_SIZE_Y*9,screen,dx,dy); tile_print("TO GALIOUS WILL",TILE_SIZE_X*10,TILE_SIZE_Y*10,screen,dx,dy); tile_print("APPEAR SOMEWHERE IN",TILE_SIZE_X*10,TILE_SIZE_Y*11,screen,dx,dy); tile_print("THE CASTLE.",TILE_SIZE_X*10,TILE_SIZE_Y*12,screen,dx,dy); } /* if */ } /* passage_mainloop */
void vw_SetKeys(int Num, bool NewKeyStatus) { Uint8 *keystate = SDL_GetKeyState(&MaxKeyCount); keystate[Num] = NewKeyStatus; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; const Uint8* keystates; GPU_Camera camera; float dt; SDL_Surface* surface; GPU_Image* image; GPU_Image* image1; GPU_Image* image2; GPU_Image* image3; GPU_Image* image4; image = GPU_LoadImage("data/test.bmp"); //image = GPU_LoadImage("data/big_test.png"); if(image == NULL) return -1; // Copying the annoying way image1 = GPU_CreateImage(image->w, image->h, GPU_FORMAT_RGBA); GPU_LoadTarget(image1); GPU_Blit(image, NULL, image1->target, image1->target->w/2, image1->target->h/2); GPU_FreeTarget(image1->target); // Copying the normal way image2 = GPU_CopyImage(image); // Copying from a surface dump surface = GPU_CopySurfaceFromImage(image); //GPU_SaveSurface(surface, "save_surf1.bmp", GPU_FILE_AUTO); image3 = GPU_CopyImageFromSurface(surface); SDL_FreeSurface(surface); // A buffer for window capture image4 = NULL; keystates = SDL_GetKeyState(NULL); camera = GPU_GetDefaultCamera(); startTime = SDL_GetTicks(); frameCount = 0; dt = 0.010f; done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_SPACE) { // Take a window capture GPU_FreeImage(image4); image4 = GPU_CopyImageFromTarget(screen); } } } if(keystates[KEY_UP]) { camera.y -= 200*dt; } else if(keystates[KEY_DOWN]) { camera.y += 200*dt; } if(keystates[KEY_LEFT]) { camera.x -= 200*dt; } else if(keystates[KEY_RIGHT]) { camera.x += 200*dt; } if(keystates[KEY_MINUS]) { camera.zoom -= 1.0f*dt; } else if(keystates[KEY_EQUALS]) { camera.zoom += 1.0f*dt; } GPU_ClearRGBA(screen, 100, 100, 100, 255); GPU_SetCamera(screen, &camera); GPU_Blit(image, NULL, screen, 128, 128); GPU_Blit(image1, NULL, screen, 128 + 256, 128); GPU_Blit(image2, NULL, screen, 128 + 512, 128); GPU_Blit(image3, NULL, screen, 128, 128 + 256); if(image4 != NULL) GPU_BlitScale(image4, NULL, screen, 3*screen->w/4, 3*screen->h/4, 0.25f, 0.25f); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) GPU_LogError("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } GPU_LogError("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); GPU_FreeImage(image1); GPU_FreeImage(image2); GPU_FreeImage(image3); GPU_FreeImage(image4); } GPU_Quit(); return 0; }
uint32 parse_keymap(void) { uint32 flags = 0; if(get_keyboard_controller_status()) { Uint8 *key_map; if (Console::instance()->input_active()) { static Uint8 chat_input_mode_keymap[SDLK_LAST]; memset(&chat_input_mode_keymap, 0, sizeof(chat_input_mode_keymap)); key_map = chat_input_mode_keymap; } else { key_map = SDL_GetKeyState(NULL); } // ZZZ: let mouse code simulate keypresses mouse_buttons_become_keypresses(key_map); joystick_buttons_become_keypresses(key_map); // Parse the keymap key_definition *key = current_key_definitions; for (unsigned i=0; i<NUMBER_OF_STANDARD_KEY_DEFINITIONS; i++, key++) if (key_map[key->offset]) flags |= key->action_flag; // Post-process the keymap struct special_flag_data *special = special_flags; for (unsigned i=0; i<NUMBER_OF_SPECIAL_FLAGS; i++, special++) { if (flags & special->flag) { switch (special->type) { case _double_flag: // If this flag has a double-click flag and has been hit within // DOUBLE_CLICK_PERSISTENCE (but not at MAXIMUM_FLAG_PERSISTENCE), // mask on the double-click flag */ if (special->persistence < MAXIMUM_FLAG_PERSISTENCE && special->persistence > MAXIMUM_FLAG_PERSISTENCE - DOUBLE_CLICK_PERSISTENCE) flags |= special->alternate_flag; break; case _latched_flag: // If this flag is latched and still being held down, mask it out if (special->persistence == MAXIMUM_FLAG_PERSISTENCE) flags &= ~special->flag; break; default: assert(false); break; } special->persistence = MAXIMUM_FLAG_PERSISTENCE; } else special->persistence = FLOOR(special->persistence-1, 0); } bool do_interchange = (local_player->variables.flags & _HEAD_BELOW_MEDIA_BIT) ? (input_preferences->modifiers & _inputmod_interchange_swim_sink) != 0: (input_preferences->modifiers & _inputmod_interchange_run_walk) != 0; // Handle the selected input controller if (input_preferences->input_device != _keyboard_or_game_pad) { _fixed delta_yaw, delta_pitch, delta_velocity; test_mouse(input_preferences->input_device, &flags, &delta_yaw, &delta_pitch, &delta_velocity); flags = mask_in_absolute_positioning_information(flags, delta_yaw, delta_pitch, delta_velocity); if (do_interchange) flags ^= _run_dont_walk; } else { int joyflags = process_joystick_axes(flags, heartbeat_count); if (joyflags != flags) { flags = joyflags; } else { // Modify flags with run/walk and swim/sink if we're using the keyboard if (do_interchange) flags ^= _run_dont_walk; } } if (player_in_terminal_mode(local_player_index)) flags = build_terminal_action_flags((char *)key_map); } // if(get_keyboard_controller_status()) return flags; }
int main(int /*argc*/, char** /*argv*/) { // Init SDL if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { printf("Could not initialise SDL\n"); return -1; } // Init OpenGL SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); const SDL_VideoInfo* vi = SDL_GetVideoInfo(); const bool presentationMode = false; int width, height; SDL_Surface* screen = 0; if (presentationMode) { width = vi->current_w; height = vi->current_h; screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL|SDL_FULLSCREEN); } else { width = vi->current_w - 20; height = vi->current_h - 80; screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL); } if (!screen) { printf("Could not initialise SDL opengl\n"); return -1; } SDL_WM_SetCaption("Recast Demo", 0); if (!imguiRenderGLInit("DroidSans.ttf")) { printf("Could not init GUI renderer.\n"); SDL_Quit(); return -1; } float t = 0.0f; Uint32 lastTime = SDL_GetTicks(); int mx = 0, my = 0; float rx = 45; float ry = -45; float moveW = 0, moveS = 0, moveA = 0, moveD = 0; float camx = 0, camy = 0, camz = 0, camr = 1000; float origrx = 0, origry = 0; int origx = 0, origy = 0; float scrollZoom = 0; bool rotate = false; bool movedDuringRotate = false; float rays[3], raye[3]; bool mouseOverMenu = false; bool showMenu = !presentationMode; bool showLog = false; bool showDebugMode = true; bool showTools = true; bool showLevels = false; bool showSample = false; bool showTestCases = false; int propScroll = 0; int logScroll = 0; int toolsScroll = 0; int debugScroll = 0; char sampleName[64] = "Choose Sample..."; FileList files; char meshName[128] = "Choose Mesh..."; float mpos[3] = {0,0,0}; bool mposSet = false; SlideShow slideShow; slideShow.init("slides/"); InputGeom* geom = 0; Sample* sample = 0; TestCase* test = 0; rcLog log; log.clear(); rcSetLog(&log); glEnable(GL_CULL_FACE); float fogCol[4] = { 0.32f,0.25f,0.25f,1 }; glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, camr*0.2f); glFogf(GL_FOG_END, camr*1.25f); glFogfv(GL_FOG_COLOR, fogCol); glDepthFunc(GL_LEQUAL); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); bool done = false; while(!done) { // Handle input events. int mscroll = 0; bool processHitTest = false; bool processHitTestShift = false; SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: // Handle any key presses here. if (event.key.keysym.sym == SDLK_ESCAPE) { done = true; } else if (event.key.keysym.sym == SDLK_t) { showLevels = false; showSample = false; showTestCases = true; scanDirectory("Tests", ".txt", files); } else if (event.key.keysym.sym == SDLK_TAB) { showMenu = !showMenu; } else if (event.key.keysym.sym == SDLK_SPACE) { if (sample) sample->handleStep(); } else if (event.key.keysym.sym == SDLK_1) { if (geom) geom->save("geomset.txt"); } else if (event.key.keysym.sym == SDLK_2) { delete geom; geom = new InputGeom; if (!geom || !geom->load("geomset.txt")) { delete geom; geom = 0; showLog = true; logScroll = 0; printf("Geom load log %s:\n", meshName); for (int i = 0; i < log.getMessageCount(); ++i) printf("%s\n", log.getMessageText(i)); } if (sample && geom) { sample->handleMeshChanged(geom); } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.2f); glFogf(GL_FOG_END, camr*1.25f); } } else if (event.key.keysym.sym == SDLK_RIGHT) { slideShow.nextSlide(); } else if (event.key.keysym.sym == SDLK_LEFT) { slideShow.prevSlide(); } break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_RIGHT) { if (!mouseOverMenu) { // Rotate view rotate = true; movedDuringRotate = false; origx = mx; origy = my; origrx = rx; origry = ry; } } else if (event.button.button == SDL_BUTTON_WHEELUP) { if (mouseOverMenu) mscroll--; else scrollZoom -= 1.0f; } else if (event.button.button == SDL_BUTTON_WHEELDOWN) { if (mouseOverMenu) mscroll++; else scrollZoom += 1.0f; } break; case SDL_MOUSEBUTTONUP: // Handle mouse clicks here. if (event.button.button == SDL_BUTTON_RIGHT) { rotate = false; if (!mouseOverMenu) { if (!movedDuringRotate) { processHitTest = true; processHitTestShift = true; } } } else if (event.button.button == SDL_BUTTON_LEFT) { if (!mouseOverMenu) { processHitTest = true; processHitTestShift = (SDL_GetModState() & KMOD_SHIFT) ? true : false; } } break; case SDL_MOUSEMOTION: mx = event.motion.x; my = height-1 - event.motion.y; if (rotate) { int dx = mx - origx; int dy = my - origy; rx = origrx - dy*0.25f; ry = origry + dx*0.25f; if (dx*dx+dy*dy > 3*3) movedDuringRotate = true; } break; case SDL_QUIT: done = true; break; default: break; } } unsigned char mbut = 0; if (SDL_GetMouseState(0,0) & SDL_BUTTON_LMASK) mbut |= IMGUI_MBUT_LEFT; if (SDL_GetMouseState(0,0) & SDL_BUTTON_RMASK) mbut |= IMGUI_MBUT_RIGHT; Uint32 time = SDL_GetTicks(); float dt = (time - lastTime) / 1000.0f; lastTime = time; t += dt; // Hit test mesh. if (processHitTest && geom && sample) { float t; if (geom->raycastMesh(rays, raye, t)) { if (SDL_GetModState() & KMOD_CTRL) { // Marker mposSet = true; mpos[0] = rays[0] + (raye[0] - rays[0])*t; mpos[1] = rays[1] + (raye[1] - rays[1])*t; mpos[2] = rays[2] + (raye[2] - rays[2])*t; } else { float pos[3]; pos[0] = rays[0] + (raye[0] - rays[0])*t; pos[1] = rays[1] + (raye[1] - rays[1])*t; pos[2] = rays[2] + (raye[2] - rays[2])*t; sample->handleClick(pos, processHitTestShift); } } else { if (SDL_GetModState() & KMOD_CTRL) { // Marker mposSet = false; } } } // Update and render glViewport(0, 0, width, height); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); // Render 3d glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50.0f, (float)width/(float)height, 1.0f, camr); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(rx,1,0,0); glRotatef(ry,0,1,0); glTranslatef(-camx, -camy, -camz); // Get hit ray position and direction. GLdouble proj[16]; GLdouble model[16]; GLint view[4]; glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetIntegerv(GL_VIEWPORT, view); GLdouble x, y, z; gluUnProject(mx, my, 0.0f, model, proj, view, &x, &y, &z); rays[0] = (float)x; rays[1] = (float)y; rays[2] = (float)z; gluUnProject(mx, my, 1.0f, model, proj, view, &x, &y, &z); raye[0] = (float)x; raye[1] = (float)y; raye[2] = (float)z; // Handle keyboard movement. Uint8* keystate = SDL_GetKeyState(NULL); moveW = rcClamp(moveW + dt * 4 * (keystate[SDLK_w] ? 1 : -1), 0.0f, 1.0f); moveS = rcClamp(moveS + dt * 4 * (keystate[SDLK_s] ? 1 : -1), 0.0f, 1.0f); moveA = rcClamp(moveA + dt * 4 * (keystate[SDLK_a] ? 1 : -1), 0.0f, 1.0f); moveD = rcClamp(moveD + dt * 4 * (keystate[SDLK_d] ? 1 : -1), 0.0f, 1.0f); float keybSpeed = 22.0f; if (SDL_GetModState() & KMOD_SHIFT) keybSpeed *= 4.0f; float movex = (moveD - moveA) * keybSpeed * dt; float movey = (moveS - moveW) * keybSpeed * dt; movey += scrollZoom * 2.0f; scrollZoom = 0; camx += movex * (float)model[0]; camy += movex * (float)model[4]; camz += movex * (float)model[8]; camx += movey * (float)model[2]; camy += movey * (float)model[6]; camz += movey * (float)model[10]; glEnable(GL_FOG); if (sample) sample->handleRender(); if (test) test->handleRender(); glDisable(GL_FOG); // Render GUI glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, width, 0, height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); mouseOverMenu = false; imguiBeginFrame(mx,my,mbut,mscroll); if (sample) { sample->handleRenderOverlay((double*)proj, (double*)model, (int*)view); } if (test) { if (test->handleRenderOverlay((double*)proj, (double*)model, (int*)view)) mouseOverMenu = true; } // Help text. if (showMenu) { const char msg[] = "W/S/A/D: Move RMB: Rotate LMB+SHIFT: Place Start LMB: Place End"; imguiDrawText(width/2, height-20, IMGUI_ALIGN_CENTER, msg, imguiRGBA(255,255,255,128)); } if (showMenu) { int propDiv = showDebugMode ? (int)(height*0.6f) : height; if (imguiBeginScrollArea("Properties", width-250-10, 10+height-propDiv, 250, propDiv-20, &propScroll)) mouseOverMenu = true; if (imguiCheck("Show Log", showLog)) showLog = !showLog; if (imguiCheck("Show Tools", showTools)) showTools = !showTools; if (imguiCheck("Show Debug Mode", showDebugMode)) showDebugMode = !showDebugMode; imguiSeparator(); imguiLabel("Sample"); if (imguiButton(sampleName)) { if (showSample) { showSample = false; } else { showSample = true; showLevels = false; showTestCases = false; } } imguiSeparator(); imguiLabel("Input Mesh"); if (imguiButton(meshName)) { if (showLevels) { showLevels = false; } else { showSample = false; showTestCases = false; showLevels = true; scanDirectory("Meshes", ".obj", files); } } if (geom) { char text[64]; snprintf(text, 64, "Verts: %.1fk Tris: %.1fk", geom->getMesh()->getVertCount()/1000.0f, geom->getMesh()->getTriCount()/1000.0f); imguiValue(text); } imguiSeparator(); if (geom && sample) { sample->handleSettings(); if (imguiButton("Build")) { log.clear(); if (!sample->handleBuild()) { showLog = true; logScroll = 0; } printf("Build log %s:\n", meshName); for (int i = 0; i < log.getMessageCount(); ++i) printf("%s\n", log.getMessageText(i)); // Clear test. delete test; test = 0; } imguiSeparator(); } imguiEndScrollArea(); if (showDebugMode) { if (imguiBeginScrollArea("Debug Mode", width-250-10, 10, 250, height-propDiv-10, &debugScroll)) mouseOverMenu = true; if (sample) sample->handleDebugMode(); imguiEndScrollArea(); } } // Sample selection dialog. if (showSample) { static int levelScroll = 0; if (imguiBeginScrollArea("Choose Sample", width-10-250-10-200, height-10-250, 200, 250, &levelScroll)) mouseOverMenu = true; Sample* newSample = 0; for (int i = 0; i < g_nsamples; ++i) { if (imguiItem(g_samples[i].name)) { newSample = g_samples[i].create(); if (newSample) strcpy(sampleName, g_samples[i].name); } } if (newSample) { delete sample; sample = newSample; sample->setMeshName(meshName); if (geom && sample) { sample->handleMeshChanged(geom); } showSample = false; } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.2f); glFogf(GL_FOG_END, camr*1.25f); } imguiEndScrollArea(); } // Level selection dialog. if (showLevels) { static int levelScroll = 0; if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-450, 200, 450, &levelScroll)) mouseOverMenu = true; int levelToLoad = -1; for (int i = 0; i < files.size; ++i) { if (imguiItem(files.files[i])) levelToLoad = i; } if (levelToLoad != -1) { strncpy(meshName, files.files[levelToLoad], sizeof(meshName)); meshName[sizeof(meshName)-1] = '\0'; showLevels = false; delete geom; geom = 0; char path[256]; strcpy(path, "Meshes/"); strcat(path, meshName); geom = new InputGeom; if (!geom || !geom->loadMesh(path)) { delete geom; geom = 0; showLog = true; logScroll = 0; printf("Geom load log %s:\n", meshName); for (int i = 0; i < log.getMessageCount(); ++i) printf("%s\n", log.getMessageText(i)); } if (sample && geom) { sample->handleMeshChanged(geom); sample->setMeshName(meshName); } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.2f); glFogf(GL_FOG_END, camr*1.25f); } } imguiEndScrollArea(); } // Test cases if (showTestCases) { static int testScroll = 0; if (imguiBeginScrollArea("Choose Test To Run", width-10-250-10-200, height-10-450, 200, 450, &testScroll)) mouseOverMenu = true; int testToLoad = -1; for (int i = 0; i < files.size; ++i) { if (imguiItem(files.files[i])) testToLoad = i; } if (testToLoad != -1) { char path[256]; strcpy(path, "Tests/"); strcat(path, files.files[testToLoad]); test = new TestCase; if (test) { // Load the test. if (!test->load(path)) { delete test; test = 0; } // Create sample Sample* newSample = 0; for (int i = 0; i < g_nsamples; ++i) { if (strcmp(g_samples[i].name, test->getSampleName()) == 0) { newSample = g_samples[i].create(); if (newSample) strcpy(sampleName, g_samples[i].name); } } if (newSample) { delete sample; sample = newSample; showSample = false; } // Load geom. strcpy(meshName, test->getGeomFileName()); meshName[sizeof(meshName)-1] = '\0'; delete geom; geom = 0; strcpy(path, "Meshes/"); strcat(path, meshName); geom = new InputGeom; if (!geom || !geom->loadMesh(path)) { delete geom; geom = 0; showLog = true; logScroll = 0; printf("Geom load log %s:\n", meshName); for (int i = 0; i < log.getMessageCount(); ++i) printf("%s\n", log.getMessageText(i)); } if (sample && geom) { sample->handleMeshChanged(geom); } log.clear(); if (sample && !sample->handleBuild()) { printf("Build log %s:\n", meshName); for (int i = 0; i < log.getMessageCount(); ++i) printf("%s\n", log.getMessageText(i)); } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.2f); glFogf(GL_FOG_END, camr*1.25f); } // Do the tests. if (sample) test->doTests(sample->getNavMesh()); } } imguiEndScrollArea(); } // Log if (showLog && showMenu) { if (imguiBeginScrollArea("Log", 10, 10, width - 300, 200, &logScroll)) mouseOverMenu = true; for (int i = 0; i < log.getMessageCount(); ++i) imguiLabel(log.getMessageText(i)); imguiEndScrollArea(); } // Tools if (!showTestCases && showTools && showMenu && geom && sample) { if (imguiBeginScrollArea("Tools", 10, height - 10 - 350, 200, 350, &toolsScroll)) mouseOverMenu = true; sample->handleTools(); imguiEndScrollArea(); } slideShow.updateAndDraw(dt, (float)width, (float)height); // Marker if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2], model, proj, view, &x, &y, &z)) { // Draw marker circle glLineWidth(5.0f); glColor4ub(240,220,0,196); glBegin(GL_LINE_LOOP); const float r = 25.0f; for (int i = 0; i < 20; ++i) { const float a = (float)i / 20.0f * (float)M_PI*2; const float fx = (float)x + cosf(a)*r; const float fy = (float)y + sinf(a)*r; glVertex2f(fx,fy); } glEnd(); glLineWidth(1.0f); } imguiEndFrame(); imguiRenderGLDraw(); glEnable(GL_DEPTH_TEST); SDL_GL_SwapBuffers(); } imguiRenderGLDestroy(); SDL_Quit(); delete sample; delete geom; return 0; }
int main(int argc,char* args[]) { Uint8 *keys; /*variable para salir*/ int quit = 0; /*inicializamos la pantalla con la resolucion y la cantidad de colores*/ SE_screen_init(640,480,16); /*llamamos a la funcion cargarcosas()*/ cargarcosas(); /*posicion del jugador*/ int playerx = 0; int playery = 0; int tilex = 0; int tiley = 0; int valor = 0; while(quit == 0) { /*limpiamos la pantalla con un color*/ SE_screen_clear(0,0,0,0); SE_tilemap_draw(timap,tset,tilex,tiley,0); SE_sprite_draw_fx(sprchara,playerx,playery,0,64,64,1,1,0,0,0,1,1,1,1); /*flipamos el cuadro*/ SE_screen_flip(); keys=SDL_GetKeyState(NULL); if (keys[SDLK_UP]) { playery -= 1; if(SE_tilemap_collision(timap,sprchara->box,tilex,tiley,playerx,playery) > 0) playery +=1; } if (keys[SDLK_DOWN]) { playery += 1; if(SE_tilemap_collision(timap,sprchara->box,tilex,tiley,playerx,playery) > 0) playery -=1; } if (keys[SDLK_LEFT]) { playerx -= 1; if(SE_tilemap_collision(timap,sprchara->box,tilex,tiley,playerx,playery) > 0) playerx +=1; } if (keys[SDLK_RIGHT]) { playerx += 1; if(SE_tilemap_collision(timap,sprchara->box,tilex,tiley,playerx,playery) > 0) playerx -=1; } /*trocito de codigo de SDL que usamos para detectar si se cierra la ventana*/ while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = 1; } } } return 0; }