/* * Send a 2-bit frame by settings Num Lock to bit 0 and Caps Lock to bit 1. * Toggling Scroll Lock acts as a clock signal. */ void send_frame(const uint8_t frame) { set_lock(NUM, (frame & 0x01) == 0x01); set_lock(CAPS, (frame & 0x02) == 0x02); set_lock(SCROLL, 1); printf("sending frame 0x%02x...", frame); printf("got 0x%02x from getchar\n", getchar()); toggle_key(SCROLL); }
void alpha_down(const uint8_t code, const uint8_t action) { switch(action & KEY_ACTION_MASK) { case ACTION_NORMAL: case ACTION_LOCKABLE: case ACTION_TAPKEY: case ACTION_RAPIDFIRE: enqueue_key(code); break; case ACTION_TOGGLE: toggle_key(code); break; default: break; } }
void game_manager::init(int w, int h) { WINDOW_WIDTH = w; WINDOW_HEIGHT = h; last_time_ = glutGet(GLUT_ELAPSED_TIME); auto frog_ = std::make_shared<frog>(); frog_->position() = vector3(0.0, FROG_LEVEL, 1.95); frog_->scale(0.1); game_objects_.push_back(frog_); collision_manager::instance().register_object(frog_); auto car1_ = std::make_shared<car>(); car1_->position() = vector3(-1.2, ROAD_LEVEL, LINE_4); car1_->scale(0.1); car1_->speed().x() = 1.0; game_objects_.push_back(car1_); collision_manager::instance().register_object(car1_); for (int i = 0; i < 3; i++) { auto truck_ = std::make_shared<truck>(); truck_->position() = vector3(-1.5 + i * 1.5, ROAD_LEVEL, LINE_3); truck_->scale(0.1); truck_->speed().x() = 0.5; game_objects_.push_back(truck_); collision_manager::instance().register_object(truck_); } auto bus1_ = std::make_shared<bus>(); bus1_->position() = vector3(0.9, ROAD_LEVEL, LINE_5); bus1_->scale(0.1); bus1_->speed().x() = 1.5; game_objects_.push_back(bus1_); collision_manager::instance().register_object(bus1_); auto bus2_ = std::make_shared<bus>(); bus2_->position() = vector3(-0.1, ROAD_LEVEL, LINE_4); bus2_->scale(0.1); bus2_->speed().x() = 1.0; game_objects_.push_back(bus2_); collision_manager::instance().register_object(bus2_); for (int i = 0; i < 2; i++) { auto log_ = std::make_shared<timberlog>(); log_->position() = vector3(-0.6 + i * 2.0, RIVER_LEVEL, LINE_1); log_->scale(0.1); log_->speed().x() = 0.5; game_objects_.push_back(log_); collision_manager::instance().register_object(log_); auto log1_ = std::make_shared<timberlog>(); log1_->position() = vector3(-1.1 + i * 1.9, RIVER_LEVEL, LINE_2); log1_->scale(0.1); log1_->speed().x() = 0.75; game_objects_.push_back(log1_); collision_manager::instance().register_object(log1_); } for (int i = 0; i < 4; i++) { auto turtle_ = std::make_shared<turtle>(); turtle_->position() = vector3(-2.5 + i * 1.3, RIVER_LEVEL + 0.05, LINE_6); turtle_->scale(0.1); turtle_->speed().x() = 0.75; game_objects_.push_back(turtle_); collision_manager::instance().register_object(turtle_); } auto river_ = std::make_shared<river>(); river_->position() = vector3(0.0, 0.0, LINE_1); game_objects_.push_back(river_); collision_manager::instance().register_object(river_); auto tunnel_ = std::make_shared<tunnel>(); tunnel_->position() = vector3(0.0, 0.0, LINE_1); game_objects_.push_back(tunnel_); auto road_ = std::make_shared<road>(); road_->position() = vector3(0.0, 0.0, LINE_4); game_objects_.push_back(road_); // INVALID CAMERAS: they will be set correctly on reshape // Camera 0: top view orthogonal camera cameras_.push_back(std::make_shared<orthogonal_camera>()); cameras_.back()->eye().set(0.0, 0.0, 0.0); cameras_.back()->at().set(0.0, -1.0, 0.0); cameras_.back()->up().set(0.0, 0.0, -1.0); // Camera 1: top view perspective camera cameras_.push_back(std::make_shared<perspective_camera>()); cameras_.back()->eye().set(0.0, 3.0, 2.0); cameras_.back()->at().set(0.0, 0.0, 0.0); cameras_.back()->up().set(0.0, 0.0, -1.0); // Camera 2: frog perspective camera cameras_.push_back(frog_->cam()); light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT0)); light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT1)); light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT2)); light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT3)); light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT4)); light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT5)); light_sources_.push_back(std::make_shared<light_source>(GL_LIGHT6)); light_sources_.push_back(frog_->headlight()); auto light = light_sources_[0]; light->ambient().set(0.2, 0.2, 0.2, 1.0); light->diffuse().set(0.3, 0.3, 0.3, 1.0); light->position().set(0.0, 5.0, 0.0, 1.0); light->turn_on(); light->toggle_key() = 'n'; for (size_t i : {1, 2, 3, 4, 5, 6}) { light = light_sources_[i]; light->toggle_key() = 'c'; light->diffuse().set(0.23, 0.23, 0.23, 1.0); light->turn_off(); light->position().x() = i % 2 == 0 ? 2.0 : -2.0; light->direction().x() = -light->position().x() / 2; light->position().y() = 1.5; light->direction().y() = -light->position().y(); light->position().z() = -2.0 + 2.0 * ((i - 1) / 2); light->direction().z() = -light->position().z() / 2; // make positional light light->position().w() = 1; light->cutoff() = 30; light->exponent() = 15; } }
void set_lock(const BYTE key, const uint8_t state) { while (GetKeyState(key) != state) { toggle_key(key); } }