void TextView::draw(GraphicContext& gc) { if (1) gc.fill_rect(Rect(0, 0, get_rect().get_width(), get_rect().get_height()), Color(64, 64, 64)); // FIXME: move font handling in GraphicContext TTY_Blit(tty, gc.get_surface(), get_rect().left, get_rect().top); }
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); } }