void MonsterController::update_position(GameState* gs, EnemyInst* e) { CollisionAvoidance& coll_avoid = gs->collision_avoidance(); simul_id simid = e->collision_simulation_id(); PosF pos = coll_avoid.get_position(simid); PosF new_xy = e->attempt_move_to_position(gs, PosF(round(pos.x), round(pos.y))); coll_avoid.set_position(simid, new_xy.x, new_xy.y); coll_avoid.set_maxspeed(simid, e->effective_stats().movespeed); }
// // D3DSkyNode11::VOnRestore - Chapter 16, page 556 // HRESULT D3DSkyNode11::VOnRestore(Scene *pScene) { HRESULT hr; V_RETURN(SceneNode::VOnRestore(pScene)); m_camera = pScene->GetCamera(); V_RETURN (m_D3D11VertexShader.OnRestore(pScene)); V_RETURN (m_D3D11PixelShader.OnRestore(pScene)); // Create the vertex buffer m_numVerts = 24; m_sides = 5; // Fill the vertex buffer. We are setting the tu and tv texture // coordinates, which range from 0.0 to 1.0 D3D11VertexPosTexture *m_Vertices = AC_NEW D3D11VertexPosTexture[m_numVerts]; AC_ASSERT(m_Vertices && "Out of memory in D3DSkyNode11::VOnRestore()"); if (!m_Vertices) return E_FAIL; float dim = 50.0f; // create Pos vectors centered Vec3 PosA(-dim/2.0f, dim/2.0f, -dim/2.0f); Vec3 PosB(dim/2.0f, dim/2.0f, -dim/2.0f); Vec3 PosC(-dim/2.0f, -dim/2.0f, -dim/2.0f); Vec3 PosD(dim/2.0f, -dim/2.0f, -dim/2.0f); Vec3 PosE(dim/2.0f, dim/2.0f, dim/2.0f); Vec3 PosF(-dim/2.0f, dim/2.0f, dim/2.0f); Vec3 PosG(dim/2.0f,-dim/2.0f, dim/2.0f); Vec3 PosH(-dim/2.0f, -dim/2.0f, dim/2.0f); // create Texture vectors Vec2 UvA(0.0f, 1.0f); Vec2 UvB(1.0f, 1.0f); Vec2 UvC(0.0f, 0.0f); Vec2 UvD(1.0f, 0.0f); // N m_Vertices[0] = D3D11VertexPosTexture(PosH, UvA); m_Vertices[1] = D3D11VertexPosTexture(PosG, UvB); m_Vertices[2] = D3D11VertexPosTexture(PosF, UvC); m_Vertices[3] = D3D11VertexPosTexture(PosE, UvD); // E m_Vertices[4] = D3D11VertexPosTexture(PosE, UvC); m_Vertices[5] = D3D11VertexPosTexture(PosG, UvA); m_Vertices[6] = D3D11VertexPosTexture(PosB, UvD); m_Vertices[7] = D3D11VertexPosTexture(PosD, UvB); // S m_Vertices[8] = D3D11VertexPosTexture(PosA, UvD); m_Vertices[9] = D3D11VertexPosTexture(PosB, UvC); m_Vertices[10] = D3D11VertexPosTexture(PosC, UvB); m_Vertices[11] = D3D11VertexPosTexture(PosD, UvA); // W m_Vertices[12] = D3D11VertexPosTexture(PosH, UvB); m_Vertices[13] = D3D11VertexPosTexture(PosF, UvD); m_Vertices[14] = D3D11VertexPosTexture(PosC, UvA); m_Vertices[15] = D3D11VertexPosTexture(PosA, UvC); // U m_Vertices[16] = D3D11VertexPosTexture(PosC, UvA); m_Vertices[17] = D3D11VertexPosTexture(PosD, UvB); m_Vertices[18] = D3D11VertexPosTexture(PosH, UvC); m_Vertices[19] = D3D11VertexPosTexture(PosG, UvD); // D m_Vertices[20] = D3D11VertexPosTexture(PosF, UvA); m_Vertices[21] = D3D11VertexPosTexture(PosE, UvB); m_Vertices[22] = D3D11VertexPosTexture(PosA, UvC); m_Vertices[23] = D3D11VertexPosTexture(PosB, UvD); WORD *m_Indices = AC_NEW WORD[m_sides * 6]; m_Indices[0] = 2; m_Indices[1] = 1; m_Indices[2] = 0; m_Indices[3] = 2; m_Indices[4] = 3; m_Indices[5] = 1; m_Indices[6] = 6; m_Indices[7] = 5; m_Indices[8] = 4; m_Indices[9] = 6; m_Indices[10] = 7; m_Indices[11] = 5; m_Indices[12] = 10; m_Indices[13] = 9; m_Indices[14] = 8; m_Indices[15] = 10; m_Indices[16] = 11; m_Indices[17] = 9; m_Indices[18] = 14; m_Indices[19] = 13; m_Indices[20] = 12; m_Indices[21] = 14; m_Indices[22] = 15; m_Indices[23] = 13; m_Indices[24] = 22; m_Indices[25] = 21; m_Indices[26] = 20; m_Indices[27] = 22; m_Indices[28] = 23; m_Indices[29] = 21; //m_Indices[30] = 18; //m_Indices[31] = 17; //m_Indices[32] = 16; //m_Indices[33] = 18; //m_Indices[34] = 19; //m_Indices[35] = 17; V_RETURN (m_D3D11VertexBuffer.OnRestore(m_Vertices, m_numVerts, m_Indices, m_sides * 2)); SAFE_DELETE_ARRAY(m_Vertices); SAFE_DELETE_ARRAY(m_Indices); return S_OK; }
PosF on_screen(GameState* gs, const PosF& p) { GameView& view = gs->view(); return PosF(p.x - view.x, p.y - view.y); }