//update the game void GameWindow::Update() { //if in game if(m_bInGame){ //Spawn Enemies Spawn(); //check for damage Damage(); //run enemy ai for(int i = 0; i < 7; i++){ if(m_eAllEnemies[i].m_bOnScreen){ m_eAllEnemies[i].AI(m_pPlatformList, m_PlatformCount, m_wPlayer); } } //move all entities Movement(); //check players displayed image m_wPlayer.SwapImage(); m_wPlayer.Tick(); //apply gravity to all entities Gravity(); //reset player velocity m_wPlayer.m_xVelocity = 0; } //handle key input HandleInput(); //draw all images and sprites Draw(); //check if game over EndGame(); }
int Ground(int stgnum, Agent_status *agent, node_t *trees,int auto_or_mamual,Girl *Girl_status){ int count = 0; if(agent->END_FLAG == 0) { Gravity(stgnum,agent,trees,auto_or_mamual,Girl_status); agent->Jumpflag = 0; control(stgnum,agent,trees,auto_or_mamual,Girl_status); if(count > 10) { resistance(agent); count = 0; } count++; /* if((agent->X >= Girl_status->X)) { END(1,stgnum,trees,auto_or_mamual,agent); return 0; } */ // if (agent->END_FLAG != 1) // { // usleep(20000); Ground(stgnum,agent,trees,auto_or_mamual,Girl_status); // } } return 0; }
void Fall_Block::NotStoped() { Gravity(); Move(); Jump(); Stop(); }
vec3 Phyengine::World(vec3 tempCamera, vec3 cameraEyes, bool flying, bool birth) { vec3 camera = cameraEyes; detect detector = Collide(tempCamera); if (!detector.collide) { camera = tempCamera; if (camera.y < detector.y) { float temp = SmoothClimb(camera.y); if (temp < detector.y) { camera.y = temp; } else { camera.y = detector.y; climbv = 0; } gv = 0; } else if (camera.y >= detector.y && !flying) { float temp = Gravity(camera.y); if (temp > detector.y) { camera.y = temp; } else { camera.y = detector.y; gv = 0; } } } else { gv = 0; } return camera; }
//重力 int Gravity(int stgnum,Agent_status *agent, node_t *trees,int auto_or_mamual,Girl *Girl_status){ //慣性を監視 // mvprintw(0,0,"intertia = %d",agent->INTERTIA); if (agent->END_FLAG != 1) { if (agent->X >= Girl_status->X) { END(1,stgnum,trees,auto_or_mamual,agent); return 0; } else if (agent->Y > Girl_status->Y+8) { END(0,stgnum,trees,auto_or_mamual,agent); return 0; } printBoy(agent,stgnum); if(mvinch(agent->Y+1,agent->X) != 'I') { agent->Y += 1; control(stgnum,agent,trees,auto_or_mamual,Girl_status); // usleep(80000); moveRoL(agent); Gravity(stgnum,agent,trees,auto_or_mamual,Girl_status); } } return 0; }
pEntity phy_AdjustGravity(pEntity Ent) { float factor; factor = gravity.value * 0.0001f; Ent = Gravity(Ent, factor); return Ent; }
void Action_update() { TurnLft( ACTIONS[ACTION_TURNLFT] ); TurnRgt( ACTIONS[ACTION_TURNRGT] ); MoveFwd( ACTIONS[ACTION_MOVEFWD] ); AutoDie( ACTIONS[ACTION_AUTODIE] ); Gravity( ACTIONS[ACTION_GRAVITY] ); Collide( ACTIONS[ACTION_COLLIDE] ); ShootIt( ACTIONS[ACTION_SHOOTIT] ); Animate( ACTIONS[ACTION_ANIMATE] ); }
void Player::Update() { mouse_pos = env.mousePosition(); Throw(); Gravity(); Move(); if (env.isPushButton(Mouse::RIGHT)) { Reset(); } }
Level::Level() { b2Vec2 Gravity(0.f, 9.8f); World = new b2World(Gravity); createGround(400.f, 500.f); QTimer* timer = new QTimer(this); timer->setInterval(60); connect(timer, SIGNAL(timeout()), this, SLOT(step())); timer->start(); //boxScene = new QGraphicsScene(); }
//static void DyWorld::Create() { // Setup default memory usage. btDefaultCollisionConstructionInfo DefaultCollisionConstructionInfo; DefaultCollisionConstructionInfo.m_stackAlloc = NULL; DefaultCollisionConstructionInfo.m_persistentManifoldPool = (0); DefaultCollisionConstructionInfo.m_collisionAlgorithmPool = (0); DefaultCollisionConstructionInfo.m_defaultMaxPersistentManifoldPoolSize = 1000; DefaultCollisionConstructionInfo.m_defaultMaxCollisionAlgorithmPoolSize = 1000; DefaultCollisionConstructionInfo.m_defaultStackAllocatorSize = 1000; // Create the default collision configuration m_pCollisionConfiguration = new btDefaultCollisionConfiguration( DefaultCollisionConstructionInfo ); // Default collision dispatcher m_pCollisionDispatcher = new btCollisionDispatcher( m_pCollisionConfiguration ); // Register GIMPACT btGImpactCollisionAlgorithm::registerAlgorithm( m_pCollisionDispatcher ); // Create the broad phase interface m_pBroadphaseInterface = new btAxisSweep3( gWorldAabbMin, gWorldAabbMax, gMaxHandles ); // Create the constraint solver m_pConstraintSolver = new btSequentialImpulseConstraintSolver(); // Create the dynamics world // m_pDynamicsWorld = new btDiscreteDynamicsWorld( m_pCollisionDispatcher, m_pBroadphaseInterface, m_pConstraintSolver, m_pCollisionConfiguration ); m_pDynamicsWorld = new btSoftRigidDynamicsWorld(m_pCollisionDispatcher, m_pBroadphaseInterface, m_pConstraintSolver, m_pCollisionConfiguration); Gravity( MtVector3( 0, 0, 0) ); if( ApConfig::GetDevice() == ApDevice_WIN ) { m_tick = 1.0f / 60.0f; } else { m_tick = 1.0f / 30.0f; } m_speed = 1.0f; m_subSteps = 3.0f; }
void CPHWorld::Create() { dWorldID phWorld=0; if (psDeviceFlags.test(mtPhysics)) Device.seqFrameMT.Add (this,REG_PRIORITY_HIGH); else Device.seqFrame.Add (this,REG_PRIORITY_LOW); m_commander =xr_new<CPHCommander>(); //dVector3 extensions={2048,256,2048}; /* Fbox level_box = Level().ObjectSpace.GetBoundingVolume(); Fvector level_size,level_center; level_box . getsize (level_size); level_box . getcenter (level_center); dVector3 extensions = { level_size.x ,256.f,level_size.z}; dVector3 center = {level_center.x,0.f,level_center.z}; */ #ifdef ODE_SLOW_SOLVER #else dWorldSetAutoEnableDepthSF1(phWorld, 100000000); ///dWorldSetContactSurfaceLayer(phWorld,0.f); //phWorld->contactp.min_depth =0.f; #endif ContactGroup = dJointGroupCreate(0); dWorldSetGravity (phWorld, 0,-Gravity(), 0);//-2.f*9.81f Mesh.Create (0,phWorld); #ifdef PH_PLAIN plane=dCreatePlane(Space,0,1,0,0.3f); #endif //const dReal k_p=2400000.f;//550000.f;///1000000.f; //const dReal k_d=200000.f; dWorldSetERP(phWorld, ERP(world_spring,world_damping) ); dWorldSetCFM(phWorld, CFM(world_spring,world_damping)); //dWorldSetERP(phWorld, 0.2f); //dWorldSetCFM(phWorld, 0.000001f); disable_count=0; m_motion_ray=dCreateRayMotions(0); phBoundaries.set(Level().ObjectSpace.GetBoundingVolume()); phBoundaries.y1-=30.f; CPHCollideValidator::Init(); b_exist=true; }
//---------------------------------------------------------------------- System::System(RTPSSettings* set, CL* c) { dout<<"settings "<<set<<endl; settings = set; cli = c; acquiredGL=false; max_num = settings->GetSettingAs<unsigned int>("max_num_particles"); num = settings->GetSettingAs<unsigned int>("num_particles"); maxGravSources=settings->GetSettingAs<unsigned int>("max_gravity_sources"); activeParticle = 0; // I should be able to not specify this, but GPU restrictions ... //seed random srand ( time(NULL) ); grid = Domain(settings->GetSettingAs<float4>("domain_min"),settings->GetSettingAs<float4>("domain_max")); setupTimers(); //*** end Initialization #ifdef CPU dout<<"RUNNING ON THE CPU"<<endl; #endif #ifdef GPU dout<<"RUNNING ON THE GPU"<<endl; prepareSorted(); //dout<<"Here"<<endl; //should be more cross platform string common_source_dir = settings->GetSettingAs<string>("rtps_path") + "/" + std::string(COMMON_CL_SOURCE_DIR); cli->addIncludeDir(common_source_dir); //dout<<common_source_dir.c_str()<<endl; hash = Hash(common_source_dir, cli, timers["hash_gpu"]); gravity = Gravity(common_source_dir, cli); bitonic = Bitonic<unsigned int>(common_source_dir, cli ); //radix = Radix<unsigned int>(common_source_dir, cli, max_num, 128); cellindices = CellIndices(common_source_dir, cli, timers["ci_gpu"] ); permute = Permute( common_source_dir, cli, timers["perm_gpu"] ); m2p = MeshToParticles(common_source_dir, cli, timers["meshtoparticles_gpu"]); marchingcubes = MarchingCubes(common_source_dir, cli, timers["marchingcubes_gpu"],settings->GetSettingAs<unsigned int>("color_field_res","2")); #endif }
void Movement::MovementRunner(double dt, Camera5 &camera, Mesh ** meshList, int Start, int End) { int speed = 70; float offset = 2; if (camera.position.x + camera.view.Normalized().x * dt * speed + 1 < 498 && camera.position.x + camera.view.Normalized().x * dt * speed - 1 > -498) { bool move = false; for (int i = Start; i < End; i++) { if (meshList[i]->min != nullptr && meshList[i]->max != nullptr) { if (camera.position.z < meshList[i]->min->z + meshList[i]->position.z - offset || //Check min and max for z axis. If bigger than min, smaller than max, walk = false camera.position.z > meshList[i]->max->z + meshList[i]->position.z + offset || //Check max for z axis. If bigger than min, smaller than max, walk = false camera.position.x + camera.view.Normalized().x * dt * speed < meshList[i]->min->x + meshList[i]->position.x - offset || //Check min for x axis. If bigger than min, smaller than max, walk = false camera.position.x + camera.view.Normalized().x * dt * speed > meshList[i]->max->x + meshList[i]->position.x + offset || //Check max for x axis. If bigger than min, smaller than max, walk = false camera.position.y < meshList[i]->min->y + meshList[i]->position.y - offset || camera.position.y - 5 + offset >= meshList[i]->max->y + meshList[i]->position.y + offset) { move = true; } else { move = false; break; } } else { move = true; } } if (move) camera.position.x += camera.view.Normalized().x * dt * speed; } if (camera.position.z + camera.view.Normalized().z * dt * speed + 1 < 498 && camera.position.z + camera.view.Normalized().z * dt * speed - 1 > -498) { bool move = false; for (int i = Start; i < End; i++) { if (meshList[i]->min != nullptr && meshList[i]->max != nullptr) { if (camera.position.x < meshList[i]->min->x + meshList[i]->position.x - offset || camera.position.x > meshList[i]->max->x + meshList[i]->position.x + offset || camera.position.z + camera.view.Normalized().z * dt * speed > meshList[i]->max->z + meshList[i]->position.z + offset || camera.position.z + camera.view.Normalized().z * dt * speed < meshList[i]->min->z + meshList[i]->position.z - offset || camera.position.y < meshList[i]->min->y + meshList[i]->position.y - offset || camera.position.y - 5 + offset > meshList[i]->max->y + meshList[i]->position.y + offset) move = true; else { move = false; break; } } else { move = true; } } if (move) camera.position.z += camera.view.Normalized().z * dt * speed; } if (Application::IsKeyPressed('A')) { if (camera.position.x - camera.right.Normalized().x * dt * speed + 1 < 498 && camera.position.x - camera.right.Normalized().x * dt * speed - 1 > -498) { bool move = false; for (int i = Start; i < End; i++) { if (meshList[i]->min != nullptr && meshList[i]->max != nullptr) { if (camera.position.z < meshList[i]->min->z + meshList[i]->position.z - offset || camera.position.z > meshList[i]->max->z + meshList[i]->position.z + offset || camera.position.x - camera.right.Normalized().x * dt * speed < meshList[i]->min->x + meshList[i]->position.x - offset || camera.position.x - camera.right.Normalized().x * dt * speed > meshList[i]->max->x + meshList[i]->position.x + offset || camera.position.y < meshList[i]->min->y + meshList[i]->position.y - offset || camera.position.y - 5 + offset > meshList[i]->max->y + meshList[i]->position.y + offset) move = true; else { move = false; break; } } else { move = true; } } if (move) camera.position.x -= camera.right.Normalized().x * dt * speed; } if (camera.position.z - camera.right.Normalized().z * dt * speed + 1 < 498 && camera.position.z - camera.right.Normalized().z * dt * speed - 1 > -498) { bool move = false; for (int i = Start; i < End; i++) { if (meshList[i]->min != nullptr && meshList[i]->max != nullptr) { if (camera.position.x < meshList[i]->min->x + meshList[i]->position.x - offset || camera.position.x > meshList[i]->max->x + meshList[i]->position.x + offset || camera.position.z - camera.right.Normalized().z * dt * speed > meshList[i]->max->z + meshList[i]->position.z + offset || camera.position.z - camera.right.Normalized().z * dt * speed < meshList[i]->min->z + meshList[i]->position.z - offset || camera.position.y < meshList[i]->min->y + meshList[i]->position.y - offset || camera.position.y - 5 + offset> meshList[i]->max->y + meshList[i]->position.y + offset) move = true; else { move = false; break; } } else { move = true; } } if (move) camera.position.z -= camera.right.Normalized().z * dt * speed; } } if (Application::IsKeyPressed('D')) { if (camera.position.x + camera.right.Normalized().x * dt * speed + 1 < 498 && camera.position.x + camera.right.Normalized().x * dt * speed - 1 > -498) { bool move = false; for (int i = Start; i < End; i++) { if (meshList[i]->min != nullptr && meshList[i]->max != nullptr) { if (camera.position.z < meshList[i]->min->z + meshList[i]->position.z - offset || camera.position.z > meshList[i]->max->z + meshList[i]->position.z + offset || camera.position.x + camera.right.Normalized().x * dt * speed < meshList[i]->min->x + meshList[i]->position.x - offset || camera.position.x + camera.right.Normalized().x * dt * speed > meshList[i]->max->x + meshList[i]->position.x + offset || camera.position.y < meshList[i]->min->y + meshList[i]->position.y - offset || camera.position.y - 5 + offset > meshList[i]->max->y + meshList[i]->position.y + offset) move = true; else { move = false; break; } } else { move = true; } } if (move) camera.position.x += camera.right.Normalized().x * dt * speed; } if (camera.position.z + camera.right.Normalized().z * dt * speed + 1 < 498 && camera.position.z + camera.right.Normalized().z * dt * speed - 1 > -498) { bool move = false; for (int i = Start; i < End; i++) { if (meshList[i]->min != nullptr && meshList[i]->max != nullptr) { if (camera.position.x < meshList[i]->min->x + meshList[i]->position.x - offset || camera.position.x > meshList[i]->max->x + meshList[i]->position.x + offset || camera.position.z + camera.right.Normalized().z * dt * speed > meshList[i]->max->z + meshList[i]->position.z + offset || camera.position.z + camera.right.Normalized().z * dt * speed < meshList[i]->min->z + meshList[i]->position.z - offset || camera.position.y < meshList[i]->min->y + meshList[i]->position.y - offset || camera.position.y - 5 + offset > meshList[i]->max->y + meshList[i]->position.y + offset) move = true; else { move = false; break; } } else { move = true; } } if (move) camera.position.z += camera.right.Normalized().z * dt * speed; } } Gravity(dt, camera, meshList, Start, End); }
double MOCFluid::TranPressToH(double dPress) { return dPress/Density()/Gravity(); }
double MOCFluid::TranPressToHGL(double dPress) { return (dPress-m_dAtmosphericPressure)/Density()/Gravity(); }
double MOCFluid::TranHToPress(double dH) { return Density()*Gravity()*dH; }
void Tutorial(int& scene, Font& font) { //画像呼び込み Texture floor_image("res/image/floor.png"); Texture dog_image("res/image/dog.png"); Texture skeleton_image("res/image/skeleton.png"); //背景画像 Random rand; rand.setSeed(std::time(nullptr)); int bg_count = rand(0, 5); Texture bg; Texture bg2; Vec2f bg_pos = Vec2f(-WIDTH / 2, -HEIGHT / 2); Vec2f bg2_pos = Vec2f(WIDTH * 3 / 2, -HEIGHT / 2); switch (bg_count) { case 0: bg = Texture("res/image/gm_bg.png"); bg2 = Texture("res/image/gm_bg.png"); break; case 1: bg = Texture("res/image/gm_bg2.png"); bg2 = Texture("res/image/gm_bg2.png"); break; case 2: bg = Texture("res/image/gm_bg3.png"); bg2 = Texture("res/image/gm_bg3.png"); break; case 3: bg = Texture("res/image/gm_bg4.png"); bg2 = Texture("res/image/gm_bg4.png"); break; case 4: bg = Texture("res/image/gm_bg5.png"); bg2 = Texture("res/image/gm_bg5.png"); break; case 5: bg = Texture("res/image/gm_bg6.png"); bg2 = Texture("res/image/gm_bg6.png"); break; } //サウンド Media skeletonjump("res/sound/skeletonjump.wav"); Media dogjump("res/sound/dogjump.wav"); Media dogdash("res/sound/dogdash.wav"); Media skeletondash("res/sound/skeletondash.wav"); //決定音 Media decision("res/sound/decision.wav"); //ポーズ Color color1 = Color::red; Color color2 = Color::white; int count = 0; //for文で使う int i; int k; //アニメーション int index = 4; int index2 = 0; int animation_count = 0; //プレイヤー Player skeleton, dog; //プレイヤー (ガイコツ) skeleton.pos.x() = 0.0f; skeleton.pos.y() = -160.0f; skeleton.size.x() = 64.0f; skeleton.size.y() = 80.0f; skeleton.vector.x() = 15.0f; skeleton.vector.y() = 0.0f; skeleton.jumpflag = false; skeleton.speedupflag = false; //プレイヤー (犬) dog.pos.x() = -700.0f; dog.pos.y() = -160.0; dog.size.x() = 128.0f; dog.size.y() = 64.0f; dog.vector.x() = 14.0f; dog.vector.y() = 0.0f; dog.jumpflag = false; dog.speedupflag = false; //床 Object floor; //ステータス Status status; status.camera = 0.0f; status.scroll = 20.0; status.gravity = 0.2f; status.pose = false; //床 int mapchip[Geography::HEIGHTNUM][Geography::WIDTHNUM] = { //20 //50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; float mapchip_pos_x[Geography::HEIGHTNUM][Geography::WIDTHNUM]; float mapchip_pos_y[Geography::HEIGHTNUM][Geography::WIDTHNUM]; float map_pos_x = -2048.0f; float map_pos_y = 352.0f; float map_size_xy = 128.0f; for (i = 0; i < Geography::HEIGHTNUM; ++i) { for (k = 0; k < Geography::WIDTHNUM; ++k) { mapchip_pos_x[i][k] = map_pos_x; mapchip_pos_y[i][k] = map_pos_y; map_pos_x += map_size_xy; } map_pos_x = -2048.0f; map_pos_y -= map_size_xy; } ///////////////////////////////////////////////////////////////////////////////////////////// //チュートリアルスタート前 Vec2f size = Vec2f(2048.0f, 512.0f); while (size.y() != 0.0f) { if (!env.isOpen()){ exit(0); } size.y() -= 8.0f; env.begin(); drawTextureBox(-WIDTH / 2, -HEIGHT / 2, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, bg); //地形 for (i = 0; i < Geography::HEIGHTNUM; ++i) { for (k = 0; k < Geography::WIDTHNUM; ++k) { if (mapchip[i][k] == FLOOR) { if (mapchip_pos_x[i][k] + map_size_xy - status.camera >= -(WIDTH / 2) && mapchip_pos_x[i][k] - status.camera < WIDTH / 2) { drawTextureBox(mapchip_pos_x[i][k] - status.camera, mapchip_pos_y[i][k], map_size_xy, map_size_xy, 0, 0, 64, 64, floor_image); } } if (mapchip[i][k] == FACE) { drawTextureBox(mapchip_pos_x[i][k] - status.camera, mapchip_pos_y[i][k], map_size_xy, map_size_xy, 0, 0, 192, 64, floor_image); } } } //犬 drawTextureBox(dog.pos.x() - status.camera, dog.pos.y(), dog.size.x(), dog.size.y(), 128 * index, 0, 100, 50, dog_image); //ガイコツ drawTextureBox(skeleton.pos.x() - status.camera, skeleton.pos.y(), skeleton.size.x(), skeleton.size.y(), 128 * index2 + 30, 0, 98, 230, skeleton_image); drawFillBox(-WIDTH / 2, -HEIGHT / 2, size.x(), size.y(), Color::black); drawFillBox(-WIDTH / 2, HEIGHT / 2, size.x(), -size.y(), Color::black); env.end(); } ///////////////////////////////////////////////////////////////////////////////////////////// //チュートリアル while (scene == TUTORIAL || decision.isPlaying()) { if (!env.isOpen()){ exit(0); } env.begin(); //重力 Gravity(skeleton, dog, status); //速度、ジャンプ Move(skeletonjump, dogjump, dogdash, skeletondash, dog, skeleton, status); //当たり判定 for (i = 0; i < Geography::HEIGHTNUM; ++i) { for (k = 0; k < Geography::WIDTHNUM; ++k) { if (mapchip[i][k] == Geography::FLOOR) { floor.pos = Vec2f(mapchip_pos_x[i][k], mapchip_pos_y[i][k]); floor.size = Vec2f(map_size_xy, map_size_xy); HitFlag(skeleton, floor, status, mapchip[i - 1][k], mapchip[i - 1][k + 1], mapchip[i][k + 1], mapchip[i + 1][k], i, k); HitFlag(dog, floor, status, mapchip[i - 1][k], mapchip[i - 1][k + 1], mapchip[i][k + 1], mapchip[i + 1][k], i, k); } } } //リスタート Restart(dog, skeleton, status); //無限生成 Repeat(skeleton, dog, status, mapchip_pos_x[0][314], bg_pos, bg2_pos); ///////////////////////////////////////////////////////////////////////// //ポーズ Pose(font, scene, status, skeleton, dog, color1, color2, count, decision); ///////////////////////////////////////////////////////////////////////// //アニメーション Animation(index, index2, animation_count); //////////////////////////////////////////////////////////////////////// //背景ループ //////////////////////////////////////////////////////////////////////// Bg(bg_pos, bg2_pos, status); /////////////////////////////////////////////////////////////////////// //表示処理 drawTextureBox(bg_pos.x() - status.camera, bg_pos.y(), WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, bg); drawTextureBox(bg2_pos.x() - status.camera, bg2_pos.y(), -WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, bg2); //地形 for (i = 0; i < Geography::HEIGHTNUM; ++i) { for (k = 0; k < Geography::WIDTHNUM; ++k) { if (mapchip[i][k] == FLOOR) { if (mapchip_pos_x[i][k] + map_size_xy - status.camera >= -(WIDTH / 2) && mapchip_pos_x[i][k] - status.camera < WIDTH / 2) { drawTextureBox(mapchip_pos_x[i][k] - status.camera, mapchip_pos_y[i][k], map_size_xy, map_size_xy, 0, 0, 64, 64, floor_image); } } if (mapchip[i][k] == FACE) { drawTextureBox(mapchip_pos_x[i][k] - status.camera, mapchip_pos_y[i][k], map_size_xy, map_size_xy, 0, 0, 192, 64, floor_image); } } } //犬 font.draw("A / ダッシュ", Vec2f(dog.pos.x() + dog.size.x() / 2 - font.drawSize("A / ダッシュ").x() / 2 - status.camera, dog.pos.y() + dog.size.y() + font.drawSize("A / ダッシュ").y() * 2), Color::lime); font.draw("S / ジャンプ", Vec2f(dog.pos.x() + dog.size.x() / 2 - font.drawSize("A / ダッシュ").x() / 2 - status.camera, dog.pos.y() + dog.size.y() + font.drawSize("A / ダッシュ").y()), Color::lime); drawTextureBox(dog.pos.x() - status.camera, dog.pos.y(), dog.size.x(), dog.size.y(), 128 * index, 0, 100, 50, dog_image); //ガイコツ font.draw("K / ダッシュ", Vec2f(skeleton.pos.x() + skeleton.size.x() / 2 - font.drawSize("K / ダッシュ").x() / 2 - status.camera, skeleton.pos.y() + skeleton.size.y() + font.drawSize("K / ダッシュ").y() * 2), Color::red); font.draw("L / ジャンプ", Vec2f(skeleton.pos.x() + skeleton.size.x() / 2 - font.drawSize("L / ジャンプ").x() / 2 - status.camera, skeleton.pos.y() + skeleton.size.y() + font.drawSize("L / ジャンプ").y()), Color::red); font.draw("SPACE / ポーズ", Vec2f(WIDTH / 2 - font.drawSize("SPACE / ポーズ").x(), -HEIGHT / 2), Color::yellow); drawTextureBox(skeleton.pos.x() - status.camera, skeleton.pos.y(), skeleton.size.x(), skeleton.size.y(), 128 * index2 + 30, 0, 98, 230, skeleton_image); //ポーズ if (status.pose == true) { drawFillBox(-WIDTH / 2, -HEIGHT / 2, WIDTH, HEIGHT, Color(0.0f, 0.0f, 0.0f, 0.7f)); font.draw("タイトル", Vec2f(0, 80) - font.drawSize("タイトル") / 2, color1); font.draw("再開", Vec2f(0, -80) - font.drawSize("再開") / 2, color2); } env.end(); } env.flushInput(); }
void FWiimoteInputDevice::handle_event(struct wiimote_t* wm, int id) { UE_LOG(LogWiimote, Log, TEXT("\n\n--- EVENT [id %i] ---"), wm->unid); CurrentStates[0] = IS_PRESSED(wm, WIIMOTE_BUTTON_A) || IS_HELD(wm, WIIMOTE_BUTTON_A); CurrentStates[1] = IS_PRESSED(wm, WIIMOTE_BUTTON_B) || IS_HELD(wm, WIIMOTE_BUTTON_B); CurrentStates[2] = IS_PRESSED(wm, WIIMOTE_BUTTON_ONE) || IS_HELD(wm, WIIMOTE_BUTTON_ONE); CurrentStates[3] = IS_PRESSED(wm, WIIMOTE_BUTTON_TWO) || IS_HELD(wm, WIIMOTE_BUTTON_TWO); CurrentStates[4] = IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS) || IS_HELD(wm, WIIMOTE_BUTTON_PLUS); CurrentStates[5] = IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS) || IS_HELD(wm, WIIMOTE_BUTTON_MINUS); CurrentStates[6] = IS_PRESSED(wm, WIIMOTE_BUTTON_UP) || IS_HELD(wm, WIIMOTE_BUTTON_UP); CurrentStates[7] = IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN) || IS_HELD(wm, WIIMOTE_BUTTON_DOWN); CurrentStates[8] = IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT) || IS_HELD(wm, WIIMOTE_BUTTON_LEFT); CurrentStates[9] = IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT) || IS_HELD(wm, WIIMOTE_BUTTON_RIGHT); if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) { UE_LOG(LogWiimote, Log, TEXT("HOME pressed")); } /* show events specific to supported expansions */ if (wm->exp.type == EXP_NUNCHUK || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { /* nunchuk */ struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; const float DEADZONE = 0.6f; CurrentStates[10] = IS_PRESSED(nc, NUNCHUK_BUTTON_C) || IS_HELD(wm, NUNCHUK_BUTTON_C); CurrentStates[11] = IS_PRESSED(nc, NUNCHUK_BUTTON_Z) || IS_HELD(wm, NUNCHUK_BUTTON_Z); CurrentStates[12] = nc->js.y > DEADZONE; CurrentStates[13] = nc->js.y < -DEADZONE; CurrentStates[14] = nc->js.x < -DEADZONE; CurrentStates[15] = nc->js.x > DEADZONE; UE_LOG(LogWiimote, Log, TEXT("nunchuk roll = %f"), nc->orient.roll); UE_LOG(LogWiimote, Log, TEXT("nunchuk pitch = %f"), nc->orient.pitch); UE_LOG(LogWiimote, Log, TEXT("nunchuk yaw = %f"), nc->orient.yaw); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick angle: %f"), nc->js.ang); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick magnitude: %f"), nc->js.mag); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick vals: %f, %f"), nc->js.x, nc->js.y); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick calibration (min, center, max): x: %i, %i, %i y: %i, %i, %i"), nc->js.min.x, nc->js.center.x, nc->js.max.x, nc->js.min.y, nc->js.center.y, nc->js.max.y); } /* * If IR tracking is enabled then print the coordinates * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wm)) { /* go through each of the 4 possible IR sources */ for (int i = 0; i < 4; ++i) { /* check if the source is visible */ if (wm->ir.dot[i].visible) { UE_LOG(LogWiimote, Log, TEXT("IR source %i: (%u, %u)"), i, wm->ir.dot[i].x, wm->ir.dot[i].y); } } UE_LOG(LogWiimote, Log, TEXT("IR cursor: (%u, %u)"), wm->ir.x, wm->ir.y); UE_LOG(LogWiimote, Log, TEXT("IR z distance: %f"), wm->ir.z); } // Update motion controls. FVector Tilt(0, 0, 0); FVector RotationRate(0, 0, 0); FVector Gravity(0, 0, 0); FVector Acceleration(0, 0, 0); /* if the accelerometer is turned on then print angles */ if (WIIUSE_USING_ACC(wm)) { Tilt.X = -wm->orient.pitch; Tilt.Y = wm->orient.yaw; Tilt.Z = wm->orient.roll; Acceleration.X = wm->accel.x; Acceleration.Y = wm->accel.y; Acceleration.Z = wm->accel.z; } if (wm->exp.type == EXP_MOTION_PLUS || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { RotationRate.X = -wm->exp.mp.angle_rate_gyro.pitch; RotationRate.Y = wm->exp.mp.angle_rate_gyro.yaw; RotationRate.Z = wm->exp.mp.angle_rate_gyro.roll; } Gravity.X = wm->gforce.x; Gravity.Y = wm->gforce.y; Gravity.Z = wm->gforce.z; MessageHandler->OnMotionDetected(Tilt, RotationRate, Gravity, Acceleration, id); }
int main(int argc, char *argv[]) { b2Vec2 Gravity(0.f, 9.8f); b2World world(Gravity); LevelManager lvlMngr(&world); ContactListener contact = ContactListener(&lvlMngr); world.SetContactListener(&contact); Uint32 lastFrameTime = 0; Uint32 frameDelay = 0; SDL_Event e; bool quit = false; AudioManager::GetInstance()->Init(); AudioManager::GetInstance()->LoadMedia(); while (!quit) { // Update loop // gets the deltaTime between frames, pass 'frameDelay' to updates Uint32 currentFrameTime = SDL_GetTicks(); if (currentFrameTime > lastFrameTime) { frameDelay = currentFrameTime - lastFrameTime; lastFrameTime = currentFrameTime; } Render::GetInstance()->Update(); //move the simulation forward float32 timeStep = 1.0f / 60.0f; int32 velocityIterations = 6; int32 positionIterations = 2; world.Step(timeStep, velocityIterations, positionIterations); lvlMngr.Update(); //Handle events on queue while (SDL_PollEvent(&e) != 0) { InputManager::GetInstance()->UpdatePolledEvents(e); //User requests quit if (e.type == SDL_QUIT) //user presses close button on window { quit = true; } //User presses a key else if (e.type == SDL_KEYDOWN) { switch (e.key.keysym.sym) { case SDLK_ESCAPE: quit = true; break; default: break; } } }//End Poll Events InputManager::GetInstance()->UpdateKeyboardState(); }//End Game loop SDL_Quit(); return 0; } //End Main
int main(int, char**) { //initialise SDL system and the video subsystem if (SDL_Init(SDL_INIT_VIDEO) != 0) { QuitWithError("SDL_Init Error: "); } //Create a Window SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (win == nullptr) { QuitWithError("SDL_CreateWindow Error: "); } //SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN); Mix_Music *music = NULL; Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1; std::string basepath(SDL_GetBasePath()); music = Mix_LoadMUS((basepath + "background.wav").c_str()); Mix_PlayMusic(music, -1); Render* renderer = new Render(win); //Main loop flag bool quit = false; b2Vec2 Gravity(0.f, 0.0098f); b2World World(Gravity); string bgPath = basepath + "background22.bmp"; SDL_Surface* back = SDL_LoadBMP(bgPath.c_str()); SDL_Rect* backGroundRect = renderer->AddSurfaceToRenderer(back, 0, -600, 1.0f); Button button = Button(-200, -50, World, renderer); Door door = Door(600, -100, renderer); Level level = Level(World, renderer); Player player = Player(100, 500, World, renderer); vector<Cannon*> cannons; cannons.push_back(new Cannon(170, 350, World, renderer, 1)); cannons.push_back(new Cannon(1010, 50, World, renderer, 2)); cannons.push_back(new Cannon(170, 450, World, renderer, 1)); cannons.push_back(new Cannon(1010, 150, World, renderer, 2)); cannons.push_back(new Cannon(170, 550, World, renderer, 1)); cannons.push_back(new Cannon(1010, 250, World, renderer, 2)); MenuScene* menu = new MenuScene(1200, 100, renderer); SDL_Event e; //thread t1(&Process::run, Process((*(game)))); //Passing references //t1.detach(); //detaches from SDL mainline float prevTicks = SDL_GetTicks(); float currentTicks = SDL_GetTicks(); float FPS = 0; int fpsTimer = 0; SDL_Init(0); //game loop while (!quit) { World.Step(1 / 60.f, 6, 2); while (SDL_PollEvent(&e) != 0) { if (inputHandler.CheckInput(SDLK_ESCAPE, e)) { quit = true; } } if (menu->playBool == false && menu->quitBool == false) { renderer->DrawMenuScene(); menu->Update(renderer); } if (menu->playBool == true) { //PLAY GAME STATE int dir = player.Move(inputHandler, e); for (int i = 0; i < cannons.size(); i++) { cannons.at(i)->Update(); } SDL_Rect rec(player.spriteRect); rec.y = player.GetY(); for (int j = 0; j < cannons.size(); j++) { for (int i = 0; i < cannons.at(j)->fireballs.size(); i++) { if (cannons.at(j)->fireballs.at(i)->CheckCollision(&rec) == true) { std::cout << "Collision Detected!" << std::endl; player.Respawn(); button.setOnce(false); button.buttonBody->SetTransform(b2Vec2(880 / SCALE, 39 / SCALE), 0); door.spriteRect->x = -1000; door.spriteRect->y = -1000; player.prevPosX.clear(); player.prevPosY.clear(); player.count = 0; } } } button.Update(); if (button.CheckCollision(&rec) == true) { std::cout << "Collision Detected!" << std::endl; button.collision = true; button.spriteRect->x = -2000; button.spriteRect->y = -2000; button.buttonBody->SetTransform(b2Vec2(-2000, -2000), 0); //door.Draw(renderer); } if (door.CheckCollision(&rec) == true) { button.buttonBody->SetTransform(b2Vec2(880 / SCALE, 39/ SCALE), 0); std::cout << "Collision Detected!" << std::endl; player.Respawn(); button.setOnce(false); door.spriteRect->x = -1000; door.spriteRect->y = -1000; player.prevPosX.clear(); player.prevPosY.clear(); player.count = 0; player.Respawn(); menu->playBool = false; menu->quitBool = false; menu->backGroundRect->x = 0; menu->current = 0; button.collision = false; } if (button.collision == false) { door.DrawCage(renderer); } if (button.collision == true) { door.DrawNoCage(renderer); } int ticks = SDL_GetTicks(); int seconds = ticks / 50; int sprite = seconds % 8; renderer->Update(player.srcRect, player.dstRect, *player.LeftTexture, *player.RightTexture, *player.StandTexture, sprite, dir, player.moving, player.GetY()); player.dstRect.w = player.spriteRect.w; player.dstRect.h = player.spriteRect.h; player.dstRect.x = player.spriteRect.x; player.dstRect.y = player.spriteRect.y + 5; } if (menu->quitBool == true) { quit = true; } fpsthink(); if (fpsTimer == 60) { printf("%f\n", framespersecond); fpsTimer = 0; } fpsTimer++; } SDL_DestroyRenderer(renderer->ren); SDL_DestroyWindow(win); SDL_DestroyMutex(mutex); SDL_Quit(); return 0; }