game::game(const float3& position) : physics_player(position), action_handler_fct(this, &game::action_handler), gui_callback(this, &game::draw_interface), rendering_scene_callback(this, &game::draw_active_cube_hud) { old_tick = tick_push = SDL_GetTicks(); tick_diff = 0; death_tex = t->add_texture(e->data_path("death_screen.png"), TEXTURE_FILTERING::LINEAR, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); // fetch vis variables in order to speed up rendering process nvis_grab_color = conf::get<float4>("nvis_grab_color"); nvis_push_color = conf::get<float4>("nvis_push_color"); nvis_swap_color = conf::get<float4>("nvis_swap_color"); nvis_bg_selected = conf::get<float4>("nvis_bg_selected"); nvis_bg_selecting = conf::get<float4>("nvis_bg_selecting"); nvis_line_interval = conf::get<float2>("nvis_line_interval"); nvis_tex_interpolation = conf::get<float>("nvis_tex_interpolation"); nvis_time_denominator = conf::get<float>("nvis_time_denominator"); glGenBuffers(1, &laser_beam_vbo); // layout: // 0 // // 1 ---- 2 // // ... // // 3 const unsigned char laser_beam_indices[12] { 0,1,3, 0,2,3, 1,2,3, 0,1,2 }; glGenBuffers(1, &laser_beam_indices_vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, laser_beam_indices_vbo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12 * sizeof(unsigned char), &laser_beam_indices[0], GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); eevt->add_internal_event_handler(action_handler_fct, EVENT_TYPE::KEY_DOWN, EVENT_TYPE::KEY_UP, EVENT_TYPE::MOUSE_LEFT_DOWN, EVENT_TYPE::MOUSE_LEFT_UP, EVENT_TYPE::MOUSE_RIGHT_DOWN, EVENT_TYPE::MOUSE_RIGHT_UP, EVENT_TYPE::MOUSE_MIDDLE_DOWN, EVENT_TYPE::MOUSE_MIDDLE_UP); create_cube(cube_vbo[CUBE_VBO_INDEX_VERT], cube_vbo[CUBE_VBO_INDEX_INDEX]); create_cube_tex_n_bn_tn(cube_vbo[CUBE_VBO_INDEX_TEX], cube_vbo[CUBE_VBO_INDEX_NORMAL], cube_vbo[CUBE_VBO_INDEX_BINORMAL], cube_vbo[CUBE_VBO_INDEX_TANGENT]); // load permutation data into tex_permutation and enforce NEAREST filtering to avoid interpolated values glGenTextures(1, &tex_permutation); glBindTexture(GL_TEXTURE_2D, tex_permutation); char4* permutation_data = new char4[permutation_tex_size * permutation_tex_size]; for(size_t i = 0; i < permutation_tex_size; ++i) { for(size_t j = 0; j < permutation_tex_size; ++j) { char4* entry = permutation_data + (i * permutation_tex_size + j); unsigned char value = perm[(j + perm[i]) & permutation_tex_size]; *reinterpret_cast<char3*>(entry) = (grad3[value & 16] * permutation_tex_size_fourth + char3(permutation_tex_size_fourth, permutation_tex_size_fourth, permutation_tex_size_fourth)); entry->w = value; } } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, permutation_tex_size, permutation_tex_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, permutation_data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); delete [] permutation_data; // load gradient data into tex_gradient and enforce NEAREST filtering to avoid interpolated values glGenTextures(1, &tex_gradient); glBindTexture(GL_TEXTURE_2D, tex_gradient); permutation_data = new char4[permutation_tex_size * permutation_tex_size]; for(size_t i = 0; i < permutation_tex_size; ++i) { for(size_t j = 0; j < permutation_tex_size; ++j) { char4* entry = permutation_data + (i * permutation_tex_size + j); unsigned char value = perm[(j + perm[i]) & permutation_tex_size]; *entry = grad4[value & 16] * permutation_tex_size_fourth + char4(permutation_tex_size_fourth, permutation_tex_size_fourth, permutation_tex_size_fourth, permutation_tex_size_fourth); } } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, permutation_tex_size, permutation_tex_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, permutation_data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); delete [] permutation_data; }
StateMenu::StateMenu() { m_bDrawGorilla = false; m_konami = {sf::Keyboard::Up, sf::Keyboard::Up, sf::Keyboard::Down, sf::Keyboard::Down, sf::Keyboard::Left, sf::Keyboard::Right, sf::Keyboard::Left, sf::Keyboard::Right, sf::Keyboard::B, sf::Keyboard::A,}; m_TileSet.loadFromFile("Ressources/Texture/Vaisseaux.png"); m_CheatFont.loadFromFile("Ressources/fonts/Hanken-Book.ttf"); m_CheatText.setFont(m_CheatFont); m_CheatText.setString("Invincibility"); m_PlayButton.setTexture(m_TileSet); m_PlayButton.setTextureRect(sf::IntRect(0, 0, 78, 72)); m_PlayButton.setPosition(473, 450); const float beginX = 278; const float beginY = 50; std::shared_ptr<Enemie> char1(new EnemieL(m_TileSet)); char1->SetPos(beginX, beginY); m_EnemieList.push_back(char1); std::shared_ptr<Enemie> char2(new EnemieA(m_TileSet)); char2->SetPos(beginX + 78, beginY); m_EnemieList.push_back(char2); std::shared_ptr<Enemie> char3(new EnemieR(m_TileSet)); char3->SetPos(beginX + 78*2, beginY); m_EnemieList.push_back(char3); std::shared_ptr<Enemie> char4(new EnemieG(m_TileSet)); char4->SetPos(beginX + 78*3, beginY); m_EnemieList.push_back(char4); std::shared_ptr<Enemie> char5(new EnemieE(m_TileSet)); char5->SetPos(beginX + 78*4, beginY); m_EnemieList.push_back(char5); std::shared_ptr<Enemie> char6(new EnemieR(m_TileSet)); char6->SetPos(beginX + 78*5, beginY); m_EnemieList.push_back(char6); std::shared_ptr<Enemie> char7(new EnemieD(m_TileSet)); char7->SetPos(beginX - 78 * 0.5f - 78, beginY + 72); m_EnemieList.push_back(char7); std::shared_ptr<Enemie> char8(new EnemieI(m_TileSet)); char8->SetPos(beginX - 78 * 0.5f, beginY + 72); m_EnemieList.push_back(char8); std::shared_ptr<Enemie> char9(new EnemieM(m_TileSet)); char9->SetPos(beginX + 78 * 0.5f, beginY + 72); m_EnemieList.push_back(char9); std::shared_ptr<Enemie> char10(new EnemieE(m_TileSet)); char10->SetPos(beginX + 78 * 0.5f + 78, beginY + 72); m_EnemieList.push_back(char10); std::shared_ptr<Enemie> char11(new EnemieN(m_TileSet)); char11->SetPos(beginX + 78 * 0.5f + 78*2, beginY + 72); m_EnemieList.push_back(char11); std::shared_ptr<Enemie> char12(new EnemieS(m_TileSet)); char12->SetPos(beginX + 78 * 0.5f + 78*3, beginY + 72); m_EnemieList.push_back(char12); std::shared_ptr<Enemie> char13(new EnemieI(m_TileSet)); char13->SetPos(beginX + 78 * 0.5f + 78*4, beginY + 72); m_EnemieList.push_back(char13); std::shared_ptr<Enemie> char14(new EnemieO(m_TileSet)); char14->SetPos(beginX + 78 * 0.5f + 78*5, beginY + 72); m_EnemieList.push_back(char14); std::shared_ptr<Enemie> char15(new EnemieN(m_TileSet)); char15->SetPos(beginX + 78 * 0.5f + 78*6, beginY + 72); m_EnemieList.push_back(char15); std::shared_ptr<Enemie> char16(new Enemie3(m_TileSet)); char16->SetPos(beginX + 78*2, beginY + 144); m_EnemieList.push_back(char16); std::shared_ptr<Enemie> char17(new Enemie1(m_TileSet)); char17->SetPos(beginX + 78*3, beginY + 144); m_EnemieList.push_back(char17); }
// Ken Perlin's permutation and gradient tables // http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf static const unsigned char perm[permutation_tex_size] { 151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 }; static const char3 grad3[16] { char3(0,1,1),char3(0,1,-1),char3(0,-1,1),char3(0,-1,-1), char3(1,0,1),char3(1,0,-1),char3(-1,0,1),char3(-1,0,-1), char3(1,1,0),char3(1,-1,0),char3(-1,1,0),char3(-1,-1,0), char3(1,0,-1),char3(-1,0,-1),char3(0,-1,1),char3(0,1,1) }; // Stefan Gustavson's gradient table // http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf static char4 grad4[32] = { char4(0,1,1,1), char4(0,1,1,-1), char4(0,1,-1,1), char4(0,1,-1,-1), char4(0,-1,1,1), char4(0,-1,1,-1), char4(0,-1,-1,1), char4(0,-1,-1,-1), char4(1,0,1,1), char4(1,0,1,-1), char4(1,0,-1,1), char4(1,0,-1,-1), char4(-1,0,1,1), char4(-1,0,1,-1), char4(-1,0,-1,1), char4(-1,0,-1,-1), char4(1,1,0,1), char4(1,1,0,-1), char4(1,-1,0,1), char4(1,-1,0,-1), char4(-1,1,0,1), char4(-1,1,0,-1), char4(-1,-1,0,1), char4(-1,-1,0,-1), char4(1,1,1,0), char4(1,1,-1,0), char4(1,-1,1,0), char4(1,-1,-1,0), char4(-1,1,1,0), char4(-1,1,-1,0), char4(-1,-1,1,0), char4(-1,-1,-1,0)};