void OnDrawFrame() { float dt=NowMs()-savedTime; gameState.flappyBird->update(dt); bool needResetLevel; for(List<Wall>::Node *node = gameState.wallsList.begin; node;) { Wall *wall = node->obj; wall->update(dt, needResetLevel); List<Wall>::Node *next_node = node->next; if(wall->x + wall->w < 0.0f) { delete wall; gameState.wallsList.remove(node); } node = next_node; } if(needResetLevel) gameState.resetLevel(); gameState.idleTime = gameState.idleTime - dt; if(gameState.idleTime <= 0) { gameState.idleTime = 2000.f + ((rand()%1000)*0.001f) * 1000.f; Wall *wall = new Wall; wall->x = gameState.screenWidth / gameState.scale; wall->y = 0.0f; wall->w = 40.0f + ((rand()%1000)*0.001f) * 20.0f; wall->h = 100.0f + ((rand()%1000)*0.001f) * 500.0f; if(gameState.side) { wall->y = 1000.f - wall->h; } gameState.side = !gameState.side; gameState.wallsList.add(wall); } savedTime=NowMs(); glClear(GL_COLOR_BUFFER_BIT); gameState.flappyBird->draw(); for(List<Wall>::Node *node = gameState.wallsList.begin; node; node = node->next) { Wall *wall = node->obj; wall->draw(); } }
//======================================= void draw() { glActiveTexture(GL_TEXTURE0); glPushMatrix(); myTerrain.drawTerrain(); glPopMatrix(); glPushMatrix(); wall.draw(SLOWDOWN); glPopMatrix(); //draw tank glPushMatrix(); myTank.draw(g_ViewMod); glPopMatrix(); glActiveTexture(GL_TEXTURE1); }
void MiParser::parse_mi (int length, uint8_t* data) { if (length == 0) { return; } current_data_read = 0; if (current_data_length) { //a previous transmission was incomplete, //hence append new data and try again uint8_t* new_data = new uint8_t[current_data_length + length]; memcpy(new_data, current_data, current_data_length); memcpy(new_data + current_data_length, data, length); delete current_data; current_data = new_data; current_data_length += length; } else { //first transmission or last one was completed current_data = data; current_data_length = length; } while (current_data_read < current_data_length) { read_reset_set(); READ_I32_OR_RESET(type_i) Mi type = (Mi)type_i; if (type == Mi::SET_RESOLUTION) { READ_I32_OR_RESET(w) READ_I32_OR_RESET(h) Jumpfree::Impl::set_resolution(w, h); } else if (type == Mi::FRAME_COMPLETED) { Jumpfree::Impl::frame_completed(); } else if (type == Mi::FILL_RECT) { READ_I32_OR_RESET(x) READ_I32_OR_RESET(y) READ_I32_OR_RESET(w) READ_I32_OR_RESET(h) READ_U8_OR_RESET(r) READ_U8_OR_RESET(g) READ_U8_OR_RESET(b) Jumpfree::Impl::fill_rect(x,y,w,h, r,g,b); } else if (type == Mi::SPRITE) { READ_I32_OR_RESET(id) READ_I32_OR_RESET(x) READ_I32_OR_RESET(y) Sprite* sprite = sprites[id]; if (sprite == NULL) sprite = (sprites[id] = new Sprite(id)); sprite->draw(x, y); } else if (type == Mi::WALL) { READ_I32_OR_RESET(id) READ_I32_OR_RESET(x) READ_I32_OR_RESET(y) READ_I32_OR_RESET(w) READ_I32_OR_RESET(h) READ_I32_OR_RESET(offset_x) READ_I32_OR_RESET(offset_y) Wall* wall = walls[id]; if (wall == NULL) wall = (walls[id] = new Wall(id)); wall->draw(x, y, w, h, offset_x, offset_y); } else if (type == Mi::BACKGROUND) { } else if (type == Mi::BACKGROUND_COLOR) { } else if (type == Mi::SOUND) { } else if (type == Mi::MUSIC) { } else { std::cout << "Unknown MI type " << (int)type << std::endl; break; } } //not returned, hence all current data has been read //or unknown MI type delete current_data; current_data_length = 0; }
void ColoredCubeApp::drawScene() { D3DApp::drawScene(); incrementedYMargin = 5; int lineHeight = 20; if(!startScreen && !endScreen) { // Restore default states, input layout and primitive topology // because mFont->DrawText changes them. Note that we can // restore the default states by passing null. md3dDevice->OMSetDepthStencilState(0, 0); float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f}; md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff); md3dDevice->IASetInputLayout(mVertexLayout); // set some variables for the shader int foo[1]; foo[0] = 0; // set the point to the shader technique D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc(&techDesc); //Set mVP to be view*projection, so we can pass that into GO::draw(..) mVP = mView*mProj; for (int i = 0; i < ragePickups.size(); i++) ragePickups[i].draw(mfxWVPVar, mTech, &mVP); //setting the color flip variable in the shader mfxFLIPVar->SetRawValue(&foo[0], 0, sizeof(int)); //draw the lines //drawLine(&xLine); //drawLine(&yLine); //drawLine(&zLine); /***************************************** Walls! *******************************************/ for(int i=0; i<gameNS::NUM_WALLS; i++)walls[i].draw(mfxWVPVar, mTech, &mVP); for(int i=0; i<gameNS::NUM_MONEY; i++) money[i].draw(mfxWVPVar, mTech, &mVP); ////draw the boxes //test.draw(mfxWVPVar, mTech, &mVP); floor.draw(mfxWVPVar, mTech, &mVP); player.draw(mfxWVPVar, mTech, &mVP); //pBullet.draw(mfxWVPVar, mTech, &mVP); //Player & bullet classes implemented //gravball.draw(mfxWVPVar, mTech, &mVP); //gameObject1.draw(mfxWVPVar, mTech, &mVP); /***************************************** Enemy Cameras *******************************************/ for(int i=0; i<gameNS::NUM_CAMS; i++){ enemyCam[i].draw(mfxWVPVar, mTech, &mVP); // enBullet[i].draw(mfxWVPVar, mTech, &mVP); for(int j=0; j<enBullets[i].size(); j++) { enBullets[i][j]->draw(mfxWVPVar, mTech, &mVP); } } // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {5, 5, 0, 0}; //mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK); for (int i = 0; i < debugText.getSize(); i++) { int xMargin = debugText.lines[i].x; int yMargin = debugText.lines[i].y; if (xMargin == -1) xMargin = 5; if (yMargin == -1) { yMargin = incrementedYMargin; incrementedYMargin += lineHeight; } } //RECT POS = {xMargin, yMargin, 0, 0}; RECT POS = {5, 5, 0, 0}; std::wostringstream outs; outs.precision(6); //outs << debugText.lines[i].s.c_str(); outs << L"Score: " << score; std::wstring sc = outs.str(); mFont->DrawText(0, sc.c_str(), -1, &POS, DT_NOCLIP, WHITE); } else if(startScreen) { for (int i = 0; i < sText.getSize(); i++) { int xMargin = sText.lines[i].x; int yMargin = sText.lines[i].y; if (xMargin == -1) xMargin = 5; if (yMargin == -1) { yMargin = incrementedYMargin; incrementedYMargin += lineHeight; } RECT POS = {xMargin, yMargin, 0, 0}; std::wostringstream outs; outs.precision(6); outs << sText.lines[i].s.c_str(); mFont->DrawText(0, outs.str().c_str(), -1, &POS, DT_NOCLIP, WHITE); } } else { for (int i = 0; i < eText.getSize(); i++) { int xMargin = eText.lines[i].x; int yMargin = eText.lines[i].y; if (xMargin == -1) xMargin = 5; if (yMargin == -1) { yMargin = incrementedYMargin; incrementedYMargin += lineHeight; } RECT POS = {xMargin, yMargin, 0, 0}; std::wostringstream outs; outs.precision(6); outs << eText.lines[i].s.c_str(); mFont->DrawText(0, outs.str().c_str(), -1, &POS, DT_NOCLIP, WHITE); } //RECT POS = {xMargin, yMargin, 0, 0}; RECT POS = {300, 350, 0, 0}; std::wostringstream outs; outs.precision(6); //outs << debugText.lines[i].s.c_str(); outs << L"Score: " << score; std::wstring sc = outs.str(); mFont->DrawText(0, sc.c_str(), -1, &POS, DT_NOCLIP, WHITE); } mSwapChain->Present(0, 0); }