int main(int argc, char** argv) { // create main window sf::RenderWindow window(sf::VideoMode(800,600,32), "Hello World - SFML"); sf::Clock clock; TileMap tmap; tmap.init("map.txt"); Player player; player.init(); player.setTileMap(&tmap); while (window.isOpen()) { sf::Time dt = clock.restart(); sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } player.handleInput(); player.update(dt.asSeconds()); tmap.update(dt.asSeconds()); window.clear(); tmap.draw(window); player.draw(window); window.display(); } // Done. return 0; }
TileMap *create_bubble( std::vector<TileMap*> &landChunks ) { int ndx = ((float)rand() / (float)RAND_MAX) * landChunks.size(); TileMap *bub = new TileMap( landChunks[ndx]->m_size ); bub->bub_age = (float)rand() / (float)RAND_MAX; bub->paste( landChunks[ndx], 0, 0 ); int sz = bub->m_size * 12; BITMAP *tmpBmp = create_bitmap( sz, sz ); rectfill( tmpBmp, 0, 0, sz, sz, makecol( 0xff, 0x00, 0xff) ); bub->draw( tmpBmp, 0, 0, emptyObjs ); bub->bub_bmp = create_bitmap( 20, 20 ); stretch_blit( tmpBmp, bub->bub_bmp, 0, 0, tmpBmp->w, tmpBmp->h, 0, 0, bub->bub_bmp->w, bub->bub_bmp->h ); destroy_bitmap( tmpBmp ); circle( bub->bub_bmp, 10, 10, 9, makecol( 0x66, 0xee, 0xff ) ); circlefill( bub->bub_bmp, 6, 6, 2, makecol( 0xff, 0xff, 0xff ) ); hline( bub->bub_bmp, 2, 17, 18, makecol( 155, 193, 212 ) ); hline( bub->bub_bmp, 2, 18, 18, makecol( 0xff, 0x00, 0xff ) ); hline( bub->bub_bmp, 2, 19, 18, makecol( 0xff, 0x00, 0xff ) ); return bub; }
void R_draw(HDC hDC) { glGetUniformLocation(NULL,NULL); rt_back.Clear(0.2941f, 0.2941f, 0.2941f, 1.0f); rt_scene.Clear(0.3921f, 0.3921f, 0.3921f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBindFramebuffer(GL_FRAMEBUFFER, rt_scene.fbo); glViewport(0, 0, rt_scene.width, rt_scene.height); camera.setOrthoMatrix(); if(bdrawbglayer01) tilemap_back.draw(&camera); if(bdrawbglayer02) tilemap_front.draw(&camera); if(bdrawbglayer03 && tilemap_back.has_c_Map) DrawCollisionMap(); R_drawWorldDebug(); glViewport(0, 0, client_rect.w, client_rect.h); R_setScreenOrtho(); s_srcRect = ScreenRect(lmenuw/client_rect.w,0,1.0 - ((lmenuw + rmenuw)/client_rect.w),1); s_dstRect = ScreenRect(lmenuw, 0, client_rect.w - (lmenuw + rmenuw), client_rect.h); DrawQuadDS(rt_back, rt_scene,&s_dstRect,&s_srcRect, NULL); glViewport(0, 0, client_rect.w, client_rect.h); glBindFramebuffer(GL_FRAMEBUFFER, debug_rendertarget.fbo); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); R_setScreenOrtho(); DrawLeftPanel(); DrawRightPanel(); DrawClientBorder(); R_setPostProcessingOrtho(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); DrawFullscreenQuad(rt_back, debug_rendertarget, NULL); glFlush(); bdoublebuffer ? SwapBuffers( hDC ) : glDrawBuffer(GL_FRONT); }
int main(int argc, char **argv) { bool done = false; SDL_Event event; // init graphics gfx_init(WINDOW_X, WINDOW_Y, false); // get key state array keyStates = SDL_GetKeyState(NULL); #define SPRITE_CNT 1 Sprite *sprites[SPRITE_CNT+1]; sprites[0] = NULL; sprites[1] = new Sprite(); sprites[1]->init("1.bmp", false, 255, 255, 255); Sprite backGround; backGround.init("background.bmp", true); // load from file TileMap map; map.loadMap(MAPFILE_NAME); Player player(&map, "player.bmp", 0, 0, 0); Uint32 frameStart; while(!done) { frameStart = SDL_GetTicks(); // event processing while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: done = true; default: break; } } // player think player.think(); // draw backGround.draw(0, 0); map.draw((const Sprite **)sprites, NULL); player.draw(); // flip buffer SDL_Flip(screen); // Key to have smooth moving and jump animation while(SDL_GetTicks() - frameStart < FRAME_DURATION); } return 0; }
void Game::run() { quit = false; DisplayWindowDescription desc; desc.set_title("ClanLib TileMap Example"); desc.set_size(Size(640, 480), true); desc.set_allow_resize(false); DisplayWindow window(desc); Slot slot_quit = window.sig_window_close().connect(this, &Game::on_window_close); Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Game::on_input_up); Canvas canvas(window); clan::XMLResourceDocument xml_resource_document("resources.xml"); ResourceManager resources = clan::XMLResourceManager::create(xml_resource_document); TileMap map; map.load(canvas, "tavern", resources, xml_resource_document); // Run until someone presses escape, or closes the window while (!quit) { int x = window.get_ic().get_mouse().get_x() - canvas.get_width(); int y = window.get_ic().get_mouse().get_y() - canvas.get_height(); // ** Enable these 3 lines to display the example magnified ** //Mat4f matrix = Mat4f::scale( 2.0f, 2.0f, 1.0f); //x /= 2; y /= 2; //canvas.set_modelview(matrix); map.set_scroll(x, y); canvas.clear(Colorf::black); map.draw(canvas); // Flip the display, showing on the screen what we have drawed since last call to flip() window.flip(1); // This call processes user input and other events KeepAlive::process(0); } }