int PlayerObject::update(long elapsedTime) { if (isKeyDown(IM_W)) walkForward(); if (isKeyDown(IM_S)) walkBackward(); if (isKeyDown(IM_A)) walkLeft(); if (isKeyDown(IM_D)) walkRight(); //if (isKeyPressed(IM_SPACE)) jump(); if (isKeyDown(IM_SPACE)) jump(); if (isKeyPressed(IM_M1)) primaryClick(); if (isKeyReleased(IM_M1)) primaryRelease(); if (isKeyDown(IM_M1)) primaryDown(); if (isKeyUp(IM_M1)) primaryUp(); if (isKeyPressed(IM_M2)) secondaryClick(); if (isKeyReleased(IM_M2)) secondaryRelease(); if (isKeyDown(IM_M2)) secondaryDown(); if (isKeyUp(IM_M2)) secondaryUp(); if (isKeyPressed(IM_1)) changeSpell(0); if (isKeyPressed(IM_2)) changeSpell(1); if (isKeyPressed(IM_3)) changeSpell(2); if (isKeyPressed(IM_4)) changeSpell(3); if (isKeyPressed(IM_5)) changeSpell(4); if (getNetworkState() == NETWORK_STATE_OFFLINE) { if (isMouseScrollUp()) { PropObject * temp = new PropObject("sword.obj", "error.tga", "default.glsl", camera->getPos() + camera->getLookAtVector(), camera->getLookAtVector(), camera->getUpVector(), "sword.prop"); //RagdollObject * temp = new RagdollObject(box, t, s, camera->getPos(), camera->getLookAtVector(), camera->getUpVector()); temp->setVelocity(camera->getLookAtVector()*10.0f); temp->setRotation(camera->getLookAtVector(), camera->getUpVector()); } if (isMouseScrollDown()) { PropObject * temp = new PropObject("box.obj", "error.tga", "default.glsl", camera->getPos() + camera->getLookAtVector(), camera->getLookAtVector(), camera->getUpVector(), "box1x1.prop"); //RagdollObject * temp = new RagdollObject(box, t, s, camera->getPos(), camera->getLookAtVector(), camera->getUpVector()); temp->setVelocity(camera->getLookAtVector()*10.0f); temp->setRotation(camera->getLookAtVector(), camera->getUpVector()); } } POINT p = inputManager->getMouseMovement(); turn(p.x*0.05f, p.y*0.05f); int ret = CharacterObject::update(elapsedTime); //setDirection(camera->getLookAtVector()); camera->setPosition(btToGLM3(&getBTPosition()) + glm::vec3(0,1,0)); camera->setLookAtVector(getDirection()); //camera->update(elapsedTime); return ret; }
bool PathFindingApp::update(yam2d::ESContext* ctx, float deltaTime) { if (!m_appRunning) return false; if (deltaTime > 0.1f) deltaTime = 0.1f; #if defined(_WIN32) if( isKeyReleased(yam2d::KEY_SPACE) ) { quit(); } // Restart search if r pressed if (isKeyReleased(yam2d::KEY_R)) { m_textureStartCase = 0; m_texturePathFound = 0; } #endif if (m_textureStartCase == 0) { // Delete old and load new m_texturePathFound = 0; const char* const inFileName = "input.png"; char buf[100]; sprintf_s(buf, "Start finding path from input image: \"%s\"", inFileName); yam2d::esLogMessage(buf); m_text->setText(buf); m_textureStartCase = new yam2d::Texture(inFileName, true); // Copy input data to map. m_searchTimer = 0.0f; int width = m_textureStartCase->getWidth(); int height = m_textureStartCase->getHeight(); int bpp = m_textureStartCase->getBytesPerPixel(); yam2d::Ref<yam2d::StreamTexture> newTexture = new yam2d::StreamTexture(); newTexture->setData(m_textureStartCase->getData(), width, height, bpp); m_texturePathFound = newTexture; m_searchCompleted = false; } if (!m_searchCompleted) { // Find start and end int startX, startY, endX, endY; startX = startY = endX = endY = -1; for (int y = 0; y < m_textureStartCase->getHeight(); ++y) { for (int x = 0; x < m_textureStartCase->getWidth(); ++x) { unsigned char* p = m_textureStartCase->getPixel(x, y); if (isRed(p)) { // Red pixel startX = x; startY = y; } else if (isGreen(p)) { // Green pixel } else if (isBlue(p)) { // Blue pixel endX = x; endY = y; } } } // Update path find!! Set m_searchCompleted to true, when path found, so the texture data is updated. if (startX >= 0 && startY >= 0 && endX >= 0 && endY >= 0) { yam2d::ElapsedTimer timer; timer.reset(); m_searchCompleted = doPathfinding(startX, startY, endX, endY); m_searchTimer += timer.getTime(); // Update new data to the GPU m_texturePathFound->updateData(); } else { assert(0); } if (m_searchCompleted) { char buf[100]; sprintf_s(buf, "Path find done. Time spent %.3f seconds", m_searchTimer); yam2d::esLogMessage("%s\n",buf); m_text->setText(buf); } } // if (!m_searchCompleted) // Clear sprite before add new dynamic sprites. m_batch->clear(); // Add sprites. m_batch->addSprite(m_textureStartCase, m_spriteStartCase, yam2d::vec2(-256.0f - 20.0f, 0.0f), 0.0f, yam2d::vec2(512.0f, 512.0f)); m_batch->addSprite(m_texturePathFound, m_spritePathFound, yam2d::vec2(256.0f + 20.0f, 0.0f), 0.0f, yam2d::vec2(512.0f, 512.0f)); // Add text to position -400,300 m_batch->addText(m_fontTexture, m_text, yam2d::vec2(0, ((float)ctx->height) / 2.0f - 20.0f), 0.0f); return true; }