#ifndef MODSYM_H #define MODSYM_H #include #include #include using namespace std; void StworzKolko(b2World* &mWorld, float32 x, float32 y, float32 rozmiar, int16 grupa, string userData) { b2Body* circle; b2CircleShape figura; figura.m_radius = rozmiar; b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(x, y); circle = mWorld->CreateBody(&bd); b2FixtureDef fixtureDef; fixtureDef.restitution = 0.2f; fixtureDef.friction = 0.3f; fixtureDef.density = 0.1f; fixtureDef.shape = &figura; fixtureDef.filter.groupIndex = grupa; circle->CreateFixture(&fixtureDef); circle->SetLinearVelocity(b2Vec2(0.0f, -5.0f)); } void StworzKwadrat(b2World* &mWorld, float32 x, float32 y, float32 rozmiar, int16 grupa, string userData) { /*Deklaracja typu i ustawienie rozmiaru kwadratu*/ b2Body* square; b2PolygonShape figura; figura.SetAsBox(rozmiar,0.5f*rozmiar); /*Deklaracja typu oraz położenia ciała*/ b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(x, y); /*Przekazanie ciała do metody tworzącej ją w świecie*/ square = mWorld->CreateBody(&bd); /*Zmiana */ b2FixtureDef fixtureDef; fixtureDef.restitution = 0.2f; fixtureDef.friction = 4.0f; fixtureDef.shape = &figura; fixtureDef.filter.groupIndex = grupa; square->CreateFixture(&fixtureDef); square->SetLinearVelocity(b2Vec2(0.0f, -5.0f)); } class ModSym : public Test { public: ModSym() { /*Tworzenie "pudełka"*/ { b2BodyDef bd; ground = m_world->CreateBody(&bd); b2EdgeShape groundShape; b2FixtureDef groundFixture; groundFixture.userData = "ground"; groundFixture.shape = &groundShape; groundShape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&groundFixture); rest = m_world->CreateBody(&bd); b2EdgeShape wallLeft; wallLeft.Set(b2Vec2(-40.0f, 40.0f), b2Vec2(-40.0f, 0.0f)); rest->CreateFixture(&wallLeft, 0.0f); b2EdgeShape wallRight; wallRight.Set(b2Vec2(40.0f, 40.0f), b2Vec2(40.0f, 0.0f)); rest->CreateFixture(&wallRight, 0.0f); b2EdgeShape ceiling; ceiling.Set(b2Vec2(-40.0f, 40.0f), b2Vec2(40.0f, 40.0f)); rest->CreateFixture(&ceiling, 0.0f); StworzKolko(m_world, -15.0f, 14.0f, 2.0f, 1, "lewy"); StworzKwadrat(m_world, 0.0f, 14.0f, 2.0f, 2, "srodek"); StworzKolko(m_world, 15.0f, 14.0f, 2.0f, 3, "prawy"); } } void Step(Settings* settings) { //run the default physics and rendering Test::Step(settings); wynik += 1; itoa(wynik, wynikStr, 10); g_debugDraw.DrawString(5, m_textLine - 20, "High Score:"); g_debugDraw.DrawString(5, m_textLine - 10, highScore); g_debugDraw.DrawString(5, m_textLine - 0, "Score:"); g_debugDraw.DrawString(5, m_textLine + 10, wynikStr); if (wynik == 500 || wynik == 1000) { StworzKolko(m_world, -15.0f, 30.0f, 2.0f, 1, "lewy"); } for (b2ContactEdge* ce = ground->GetContactList(); ce; ce = ce->next) { b2Contact* c = ce->contact; if (c) { if (wynik > high) { high = wynik; strncpy(highScore, wynikStr, 32); } wynik = 0; } } //if (contacting == true) g_debugDraw.DrawString(5, m_textLine, "Press 1-6 to drop stuff, m to change the mode"); //show some text in the main screen m_textLine += 15; } static Test* Create() { return new ModSym; } b2Body* ground; b2Body* rest; int wynik = 0, high = 0; char wynikStr[32]; char highScore[32]; }; #endif