void Player::act(void) { podeTeleportarVermelho = false; podeTeleportarAzul = false; if (!pulo) { if(position().y() > alturaMax) { alturaMax = position().y(); } } if(timer2 > 0) { timer2--; } if(timer3 > 0) { timer3--; } if(timer4 > 0) { timer4--; } if(timer5 > 0) { timer5--; } if(morto) { Text::writeCenter(screenWidth()/2,screenHeight()/2,"GAME OVER!"); } }
/******************************************************************************\ Clears the screen \******************************************************************************/ void clearScreen() { // clear the screen by printing spaces across it for ( int i = 0; i < screenHeight(); i++ ) for ( int j = 0; j < screenWidth(); j++ ) mvaddch( i, j, ' ' ); refresh(); }
void loadTextureFromScreen(textureT* tex) { int width = screenWidth(), height = screenHeight(); renderTargetT* old_rt = useRenderTarget(NULL); textureT* old_tex = useTexture(tex, 0); glCopyTexImage2D(texTarget(tex), 0, GL_RGBA8, 0, 0, width, height, 0); useTexture (old_tex, 0); useRenderTarget(old_rt); }
void drawCercle(float centre_x,float centre_y,float rayon) { unsigned int i; float pas_rad = 2.0*M_PI/128.; float r = screenWidth()/(float)screenHeight(); float pas_cour = 0.0; glBegin(GL_LINE_STRIP); for(i=0;i<=128;i++) { glVertex3f(centre_x+rayon*cos(pas_cour),centre_y+r*rayon*sin(pas_cour),0.0); pas_cour += pas_rad; } glEnd(); }
void SDLWindow::setPosition(int x, int y) { #ifdef G3D_WIN32 int W = screenWidth(); int H = screenHeight(); x = iClamp(x, 0, W); y = iClamp(y, 0, H); SetWindowPos(_Win32HWND, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); // Do not update settings-- wait for an event to notify us #endif #ifdef G3D_LINUX const int W = screenWidth(_X11Display); const int H = screenHeight(_X11Display); x = iClamp(x, 0, W); y = iClamp(y, 0, H); XMoveWindow(_X11Display, _X11WMWindow, x, y); #endif // TODO: OS X }
void SDLWindow::setDimensions(const Rect2D& dims) { #ifdef G3D_WIN32 int W = screenWidth(); int H = screenHeight(); int x = iClamp((int)dims.x0(), 0, W); int y = iClamp((int)dims.y0(), 0, H); int w = iClamp((int)dims.width(), 1, W); int h = iClamp((int)dims.height(), 1, H); SetWindowPos(_Win32HWND, NULL, x, y, w, h, SWP_NOZORDER); // Do not update settings-- wait for an event to notify us #endif #ifdef G3D_LINUX //TODO: Linux #endif // TODO: OS X }
void ScreenMx508::flushColorScreen(Qt::GlobalColor color) { QImage imageColor(screenWidth(),screenHeight(), QImage::Format_RGB32); imageColor.fill(color); flushImage(imageColor,QPoint(0,0)); }
void ShipBuildingArea::independentUpdate(float deltaTime) { setScreenWidth( IwGxGetScreenWidth() ); setScreenHeight( IwGxGetScreenHeight() ); int direction = 0; // Make the robot follow the alien if(!secondPass_) { robot()->followAlien(alien()->getX(), alien()->getY()); } // Update pointer system input()->update(); // Check for screen touches if (input()->getTouchCount() != 0) { // Create a touch pointer and let it point to the the current touch command Touch* touch = input()->getTouch(0); // If a touch was set correctly if (touch != NULL) { escapePodBuildingPuzzle_.touchUpdate(touch->x_, touch->y_); if( !escapePodBuildingPuzzle_.movingABuildPiece() && !secondPass_) { // If player is trying to move right while the alien is at the edge of its moving area if( alien()->getX() >= ( (int)((float)screenWidth() - (((float)screenWidth() / 100.0)*deadZone_))) && touch->x_ > ( (int)((float)screenWidth() - (((float)screenWidth() / 100.0)*deadZone_)) ) ) { if (playerStage_.isScrollingRight()) { alien()->setWalkingState(true); robot()->setWalking(); direction = -1; } } // If player is trying to move left while the alien is at the edge of its moving area else if( alien()->getX() <= ( (int)(((float)screenWidth() / 100.0)*deadZone_) ) && touch->x_ < ( (int)(((float)screenWidth() / 100.0)*deadZone_) ) ) { if (playerStage_.isScrollingLeft()) { alien()->setWalkingState(true); robot()->setWalking(); direction = 1; } } else { // If the touch is to the right of the alien if (touch->x_ > alien()->getX() ) { // Move the alien right alien()->moveRight(); alien()->setWalkingState(true); } // If the touch is the left of the alien if (touch->x_ < alien()->getX()) { // Move the alien left alien()->moveLeft(); alien()->setWalkingState(true); } } } } // end if (touch != NULL) // if multi-touch is available then ... if (input()->isMultiTouch()) { if (input()->getTouchCount() > 1) { touch = input()->getTouch(1); if (touch != NULL) { // Add update input effects here } } } } if (input()->getTouchCount() == 0 ) { escapePodBuildingPuzzle_.noTouchEventsActive(); // Set the alien walking to false as there are no touch events alien()->setWalkingState(false); } sky_.update(direction*deltaTime*SCROLL_SPEED*0.2); distantBackground_.update(direction*deltaTime*SCROLL_SPEED*0.4); closeBackground_.update(direction*deltaTime*SCROLL_SPEED*0.6); midground_.update(direction*deltaTime*SCROLL_SPEED*0.8); playerStage_.update(direction*deltaTime*SCROLL_SPEED); foreground_.update(direction*deltaTime*SCROLL_SPEED*1.8); escapePodBuildingPuzzle_.movePuzzle(direction*deltaTime*SCROLL_SPEED); // If the alien is beyond a set distance from the escape pod if( alien()->getX() >= ( escapePodBuildingPuzzle_.getCenterX() + offsetFromEscapePod) ) { // Move to the next level ambientSound_->stop(); robot()->stopAllSounds(); alien()->stopAllSounds(); Level::playerExitingLevel(); } if(escapePodBuildingPuzzle_.isComplete() && !endingPlayed_) { ambientSound_->stop(); ending_->play(); endingPlayed_ = true; } if(secondPass_) { alien()->setHoldingHose(true); } }
void drawScene(Scene *scene_) { // Draw Scene // Main if(scene_ == scene["main"]) { } // Main Exit else if(scene_ == scene["mainExit"]) { } // Saves else if(scene_ == scene["saves"]) { } // First game else if(scene_ == scene["savesNew"]) { } // Game else if(scene_ == scene["game"]) { // Draw saveSlot[selectedSaveSlot]->gMap.draw(Rect(Coord(gameRectX, gameRectY), gameRectWidth, gameRectHeight)); } // Pause else if(scene_ == scene["gamePause"]) { // Draw game (background) drawScene(scene["game"]); // Label "Pause" cls(0, 0, screenWidth(), screenHeight() / 3.0); cls(0, screenHeight() / 3.0 * 2.0, screenWidth(), screenHeight()); } // Exit Pause else if(scene_ == scene["gamePauseExit"]) { drawScene(scene["gamePause"]); } // Draw other scene if(scene_ == selectedScene) { scene_->draw(selectedButton, screen()); } }
int main(int argc, char *argv[]) { #ifdef DEBUG // Debugger QCoreApplication a(argc, argv); #endif // Init initAll(); // Shake Random srand(time(0)); #ifdef WINDOWS // Change lang PostMessage(GetForegroundWindow(), WM_INPUTLANGCHANGEREQUEST, 2, 0); #endif // Set time of out screensaver timerScreensaver = timer(5000); // Off deleting saves mode deleteSave = false; // Clear selectedGMap selectedSaveSlot = -1; // Read save loadSaves(); // Set Scene setScene(scene["screensaver"]); // Start Game cpu = clock(); do { // Enum CPU cpu = clock() - cpu; if(selectedScene == scene["screensaver"]) { if(clock() > timerScreensaver) { setScene(scene["main"]); } } // Set old Width / Height scrOldWidth = screenWidth(); scrOldHeight = screenHeight(); // Draw update(); // Set CPU cpu = clock(); // Get char keyStroke = getch(); keyChar = char(keyStroke); // Keys Commands if(selectedScene != scene["savesNew"]) { keysCommand(keyStroke); } else { if(keyStroke != -1) { if(keyBackspace(keyStroke)) { if(!selectedScene->label[1]->getText().empty()) { // Backspace string newText = selectedScene->label[1]->getText(); newText.pop_back(); selectedScene->label[1]->setText(newText); } } else if(keyEnter(keyStroke)) { // Create save saveSlot[selectedSaveSlot] = new SaveSlot(new GMapWorld(biome["forest"]), selectedScene->label[1]->getText()); saveSlot[selectedSaveSlot]->gMap.emptyGMapHome = new GMapHome(biome["home"]); // To game setScene(scene["game"]); } else { // Valid keyChar? if(selectedScene->label[1]->font->image.find(keyChar) != selectedScene->label[1]->font->image.end()) { // Add keyChar string newText = selectedScene->label[1]->getText(); newText.push_back(keyChar); selectedScene->label[1]->setText(newText); } } } } } while(true); endwin(); // Delete all // GMaps SAVE_DEL_MAS(saveSlot); // Messages SAVE_DEL_MAS(message); return 0; }
void drawText(const string* text, float x, float y, const string* font_name, int font_size) { text = (string*)wstrdup(text); HDC hdc = CreateCompatibleDC(0); string* font_face = wstrdup(font_name); int font_height = -MulDiv(font_size, GetDeviceCaps(hdc, LOGPIXELSY), 72); HFONT hfont = CreateFontW(font_height, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, font_face); free(font_face); SelectObject(hdc, hfont); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(255, 0, 0)); RECT rect = { 0 }; DrawTextW(hdc, text, -1, &rect, DT_CALCRECT | DT_NOCLIP); int width = rect.right - rect.left + 2, height = rect.bottom - rect.top + 2; rect.left++; rect.top++; void* bitmap_data = calloc(width*height, sizeof(uint32_t)); for (int i = 3; i < width*height*4; i+= 4) *((uint8_t*)bitmap_data+i) = 0xff; HBITMAP hbitmap = CreateBitmap(width, height, 1, 32, bitmap_data); SelectObject(hdc, hbitmap); DrawTextW(hdc, text, -1, &rect, DT_TOP | DT_LEFT); DeleteObject(hfont); free(text); GetBitmapBits(hbitmap, width*height*4, bitmap_data); DeleteObject(hbitmap); DeleteDC(hdc); for (int i = 0; i < width*height*4; i += 4) { *((uint8_t*)bitmap_data+i+3) = *((uint8_t*)bitmap_data+i+2); *((uint8_t*)bitmap_data+i ) = 0x10; *((uint8_t*)bitmap_data+i+1) = 0x10; *((uint8_t*)bitmap_data+i+2) = 0x10; } textureT* tex = createTexture(); textureT* old_tex = useTexture(tex, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, bitmap_data); free(bitmap_data); triMeshT* text_quad = createQuad(2.0f, 2.0f); if (!text_shader) initTextShader(); shaderT* old_shader = useShader(text_shader); setShaderParam("ScreenSize", &(vec2) { (float)screenWidth(), (float)screenHeight() }); setShaderParam("TextRect" , &(vec4) { (float)x, (float)y, (float)width, (float)height }); GLint depth_mask; glGetIntegerv(GL_DEPTH_WRITEMASK, &depth_mask); GLboolean cull_face, depth_test; glGetBooleanv(GL_CULL_FACE, &cull_face); glGetBooleanv(GL_DEPTH_TEST, &depth_test); glDepthMask(GL_FALSE); glDisable (GL_CULL_FACE); glDisable (GL_DEPTH_TEST); drawMesh(text_quad); glDepthMask(depth_mask); if (cull_face) glEnable(GL_CULL_FACE); if (depth_test) glEnable(GL_DEPTH_TEST); useTexture (old_tex, 0); useShader (old_shader); freeTexture(tex); freeMesh (text_quad); }
void Player::outro() { Text::writeCenter(screenWidth()/2,screenHeight()-screen,"PORTAL GAME"); Text::writeCenter(screenWidth()/2,(screenHeight())+300-screen,"DESENVOLVIDO POR:"); Text::writeCenter(screenWidth()/2,(screenHeight())+325-screen,"ANDRE FELIPE"); Text::writeCenter(screenWidth()/2,(screenHeight())+350-screen,"JONATAS BARBOSA"); Text::writeCenter(screenWidth()/2,(screenHeight())+550-screen,"PROFESSOR:"); Text::writeCenter(screenWidth()/2,(screenHeight())+575-screen,"RODRIGO TOLEDO"); Text::writeCenter(screenWidth()/2,(screenHeight())+775-screen,"MONITOR:"); Text::writeCenter(screenWidth()/2,(screenHeight())+800-screen,"MATHEUS LESSA"); Text::writeCenter(screenWidth()/2,(screenHeight())+1000-screen,"ENGINE:"); Text::writeCenter(screenWidth()/2,(screenHeight())+1025-screen,"URGE"); Text::writeCenter(screenWidth()/2,(screenHeight())+1225-screen,"MUSICA:"); Text::writeCenter(screenWidth()/2,(screenHeight())+1250-screen,"THE BUTTERFLY EFFECT - CRAVE"); if (timer5 == 0) { screen++; timer5 = 1; } }
SDLWindow::SDLWindow(const GWindow::Settings& settings) { #if defined(G3D_OSX) NSApplicationWrapper wrapper; // Hack to get our window/process to the front... ProcessSerialNumber psn = { 0, kCurrentProcess}; TransformProcessType (&psn, kProcessTransformToForegroundApplication); SetFrontProcess (&psn); _pool = new NSAutoreleasePoolWrapper(); #endif if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) { fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); debugPrintf("Unable to initialize SDL: %s\n", SDL_GetError()); Log::common()->printf("Unable to initialize SDL: %s\n", SDL_GetError()); exit(1); } // Set default icon if available if (settings.defaultIconFilename != "nodefault") { try { GImage defaultIcon; defaultIcon.load(settings.defaultIconFilename); setIcon(defaultIcon); } catch (const GImage::Error& e) { // Throw away default icon fprintf(stderr, "GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str()); debugPrintf("GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str()); Log::common()->printf("GWindow's default icon failed to load: %s (%s)", e.filename.c_str(), e.reason.c_str()); } } if (! settings.fullScreen) { // This doesn't really work very well due to SDL bugs so we fix up // the position after the window is created. if (settings.center) { System::setEnv("SDL_VIDEO_CENTERED", ""); } else { System::setEnv("SDL_VIDEO_WINDOW_POS", format("%d,%d", settings.x, settings.y)); } } _mouseVisible = true; _inputCapture = false; // Request various OpenGL parameters SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings.depthBits); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, settings.stencilBits); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, settings.rgbBits); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, settings.rgbBits); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, settings.rgbBits); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, settings.alphaBits); SDL_GL_SetAttribute(SDL_GL_STEREO, settings.stereo); #if SDL_FSAA if (settings.fsaaSamples > 1) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, settings.fsaaSamples); } #endif // Create a width x height OpenGL screen int flags = SDL_HWSURFACE | SDL_OPENGL | (settings.fullScreen ? SDL_FULLSCREEN : 0) | (settings.resizable ? SDL_RESIZABLE : 0) | (settings.framed ? 0 : SDL_NOFRAME); if (SDL_SetVideoMode(settings.width, settings.height, 0, flags) == NULL) { debugAssert(false); Log::common()->printf("Unable to create OpenGL screen: %s\n", SDL_GetError()); error("Critical Error", format("Unable to create OpenGL screen: %s\n", SDL_GetError()).c_str(), true); SDL_Quit(); exit(2); } // See what video mode we really got _settings = settings; int depthBits, stencilBits, redBits, greenBits, blueBits, alphaBits; glGetIntegerv(GL_DEPTH_BITS, &depthBits); glGetIntegerv(GL_STENCIL_BITS, &stencilBits); glGetIntegerv(GL_RED_BITS, &redBits); glGetIntegerv(GL_GREEN_BITS, &greenBits); glGetIntegerv(GL_BLUE_BITS, &blueBits); glGetIntegerv(GL_ALPHA_BITS, &alphaBits); int actualFSAABuffers = 0, actualFSAASamples = 0; #if SDL_FSAA SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &actualFSAABuffers); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actualFSAASamples); #else (void)actualFSAABuffers; (void)actualFSAASamples; #endif _settings.rgbBits = iMin(iMin(redBits, greenBits), blueBits); _settings.alphaBits = alphaBits; _settings.stencilBits = stencilBits; _settings.depthBits = depthBits; _settings.fsaaSamples = actualFSAASamples; SDL_version ver; SDL_VERSION(&ver); _version = format("%d,%0d.%0d", ver.major, ver.minor, ver.patch); SDL_EnableUNICODE(1); setCaption("G3D"); SDL_SysWMinfo info; SDL_VERSION(&info.version); SDL_GetWMInfo(&info); _glContext = glGetCurrentContext(); #if defined(G3D_WIN32) // Extract SDL HDC/HWND on Win32 _Win32HWND = info.window; _Win32HDC = wglGetCurrentDC(); #elif defined(G3D_LINUX) // Extract SDL's internal Display pointer on Linux _X11Display = info.info.x11.display; _X11Window = info.info.x11.window; _X11WMWindow = info.info.x11.wmwindow; if (glXGetCurrentDisplay != NULL) { G3D::_internal::x11Display = glXGetCurrentDisplay(); } else { G3D::_internal::x11Display = info.info.x11.display; } if (glXGetCurrentDrawable != NULL) { // A Drawable appears to be either a Window or a Pixmap G3D::_internal::x11Window = glXGetCurrentDrawable(); } else { G3D::_internal::x11Window = info.info.x11.window; } #endif // Adjust window position #ifdef G3D_WIN32 if (! settings.fullScreen) { int W = screenWidth(); int H = screenHeight(); int x = iClamp(settings.x, 0, W); int y = iClamp(settings.y, 0, H); if (settings.center) { x = (W - settings.width) / 2; y = (H - settings.height) / 2; } SetWindowPos(_Win32HWND, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } #endif #ifdef G3D_LINUX if (! settings.fullScreen) { int W = screenWidth(_X11Display); int H = screenHeight(_X11Display); int x = iClamp(settings.x, 0, W); int y = iClamp(settings.y, 0, H); if (settings.center) { x = (W - settings.width) / 2; y = (H - settings.height) / 2; } XMoveWindow(_X11Display, _X11WMWindow, x, y); } #endif // Check for joysticks int j = SDL_NumJoysticks(); if ((j < 0) || (j > 10)) { // If there is no joystick adapter on Win32, // SDL returns ridiculous numbers. j = 0; } if (j > 0) { SDL_JoystickEventState(SDL_ENABLE); // Turn on the joysticks joy.resize(j); for (int i = 0; i < j; ++i) { joy[i] = SDL_JoystickOpen(i); debugAssert(joy[i]); } } GLCaps::init(); // Register this window as the current window makeCurrent(); # if defined(G3D_LINUX) // If G3D is using the default assertion hooks, replace them with our own that use // SDL functions to release the mouse, since we've been unable to implement // a non-SDL way of releasing the mouse using the X11 handle directly. if (assertionHook() == _internal::_handleDebugAssert_) { setFailureHook(SDL_handleDebugAssert_); } if (failureHook() == _internal::_handleErrorCheck_) { setFailureHook(SDL_handleErrorCheck_); } # endif }