void World::mouseMotion(int x, int y) { double zxDeg = (width/2 - x) / 11.0; double xyDeg = (height/2 - y) / 11.0; if (trackMouse && (zxDeg != 0 || xyDeg != 0 )) { victor.rotateHorizontal(zxDeg); victor.rotateVertical(xyDeg); glutWarpPointer(width/2, height/2); movePerson(&victor, width, height); glutPostRedisplay(); } }
int main(int argc, const char * argv[]) { while (1) { system("clear"); // 1. 根据map数据打印出地图 showMap(); // 2. 接收输入小人的前进方向 char dir = enterDirection(); // 3. 根据小人前进的方向,来移动小人或者推箱子 if(dir == 'q'){ printf("Game Over ~ "); return 0; }else{ movePerson(dir); } } return 0; }
void World::init(int width, int height) { this->width = width; this->height = height; controls['w'] = std::make_pair(nullOperation, [] (double passed_time, int width, int height, Person *person) {person->moveForward(0.1); movePerson(person, width, height);}); controls['a'] = std::make_pair(nullOperation, [] (double passed_time, int width, int height, Person *person) {person->strafeRight(-0.1); movePerson(person, width, height);}); controls['s'] = std::make_pair(nullOperation, [] (double passed_time, int width, int height, Person *person) {person->moveForward(-0.1); movePerson(person, width, height);}); controls['d'] = std::make_pair(nullOperation, [] (double passed_time, int width, int height, Person *person) {person->strafeRight(0.1); movePerson(person, width, height);}); controls['q'] = std::make_pair(nullOperation, [] (double passed_time, int width, int height, Person *person) {person->ascend(0.1); movePerson(person, width, height);}); controls['e'] = std::make_pair(nullOperation, [] (double passed_time, int width, int height, Person *person) {person->ascend(-0.1); movePerson(person, width, height);}); trackMouse = false; lastClock = clock(); }
void World::reshape(int width, int height) { this->width = width; this->height = height; movePerson(&victor, width, height); }