Commits

Joseph Marshall committed 774cc9f Draft

Updated for latest version of sfml2

Comments (0)

Files changed (3)

src/fuzzycraft.cpp

 
 int main(int argc, char *argv[]) {
     sf::RenderWindow app(sf::VideoMode(1600, 900, 32), "fuzzycraft");
-    app.ShowMouseCursor(false);
+    app.setMouseCursorVisible(false);
     //app.SetFramerateLimit(60);
-    int hw = app.GetWidth()/2;
-    int hh = app.GetHeight()/2;
-    sf::Mouse::SetPosition(sf::Vector2i(hw, hh), app);
+    int hw = app.getSize().x/2;
+    int hh = app.getSize().y/2;
+    sf::Mouse::setPosition(sf::Vector2i(hw, hh), app);
 
     Game game;
 
     int last_x = hw;
     int last_y = hh;
 
-    clock.Reset();
-    while (app.IsOpened()) {
+    clock.restart();
+    while (app.isOpen()) {
         sf::Event event;
-        while (app.PollEvent(event)) {
-            if (event.Type == sf::Event::Closed) {
-                app.Close();
+        while (app.pollEvent(event)) {
+            if (event.type == sf::Event::Closed) {
+                app.close();
             }
-            else if ((event.Type == sf::Event::KeyPressed)){
-                if (event.Key.Code == sf::Keyboard::Escape)
-                    app.Close();
+            else if ((event.type == sf::Event::KeyPressed)){
+                if (event.key.code == sf::Keyboard::Escape)
+                    app.close();
 
-                if (event.Key.Code == sf::Keyboard::E){
+                if (event.key.code == sf::Keyboard::E){
                     if (game.player.control_lock)
                         game.player.control_lock = nullptr;
                     else if (game.player.resting_on != nullptr)
                         game.player.control_lock = game.player.resting_on;
                 }
 
-                if (event.Key.Code == sf::Keyboard::W)
+                if (event.key.code == sf::Keyboard::W)
                     game.player.move.y = 1;
-                else if (event.Key.Code == sf::Keyboard::S)
+                else if (event.key.code == sf::Keyboard::S)
                     game.player.move.y = -1;
-                else if (event.Key.Code == sf::Keyboard::A)
+                else if (event.key.code == sf::Keyboard::A)
                     game.player.move.x = -1;
-                else if (event.Key.Code == sf::Keyboard::D)
+                else if (event.key.code == sf::Keyboard::D)
                     game.player.move.x = 1;
-                else if (event.Key.Code == sf::Keyboard::Space)
+                else if (event.key.code == sf::Keyboard::Space)
                     game.player.move.z = 1;
-                else if (event.Key.Code == sf::Keyboard::LShift)
+                else if (event.key.code == sf::Keyboard::LShift)
                     game.player.slow = true;
             }
-            else if ((event.Type == sf::Event::KeyReleased)){
-                if (event.Key.Code == sf::Keyboard::W)
+            else if ((event.type == sf::Event::KeyReleased)){
+                if (event.key.code == sf::Keyboard::W)
                     game.player.move.y = 0;
-                else if (event.Key.Code == sf::Keyboard::S)
+                else if (event.key.code == sf::Keyboard::S)
                     game.player.move.y = 0;
-                else if (event.Key.Code == sf::Keyboard::A)
+                else if (event.key.code == sf::Keyboard::A)
                     game.player.move.x = 0;
-                else if (event.Key.Code == sf::Keyboard::D)
+                else if (event.key.code == sf::Keyboard::D)
                     game.player.move.x = 0;
-                else if (event.Key.Code == sf::Keyboard::Space)
+                else if (event.key.code == sf::Keyboard::Space)
                     game.player.move.z = 0;
-                else if (event.Key.Code == sf::Keyboard::LShift)
+                else if (event.key.code == sf::Keyboard::LShift)
                     game.player.slow = false;
             }
-            else if (event.Type == sf::Event::MouseMoved){
-                float dx = -(last_x - event.MouseMove.X)/1024.f*2;
-                float dy = (last_y - event.MouseMove.Y)/768.f*2;
+            else if (event.type == sf::Event::MouseMoved){
+                float dx = -(last_x - event.mouseMove.x)/1024.f*2;
+                float dy = (last_y - event.mouseMove.y)/768.f*2;
                 if (abs(dx) != 0 || abs(dy) != 0)
-                    sf::Mouse::SetPosition(sf::Vector2i(hw, hh), app);
+                    sf::Mouse::setPosition(sf::Vector2i(hw, hh), app);
                 last_x = hw;
                 last_y = hh;
                 dx = min(.05f, max(-.05f, dx));
                 game.player.rot.x += dx;
                 game.player.rot.y = max(-3.1f, min(3.1f,game.player.rot.y+dy));
             }
-            else if (event.Type == sf::Event::MouseButtonPressed){
+            else if (event.type == sf::Event::MouseButtonPressed){
                 game.add_block();
             }
         }
 
-        float dt = clock.GetElapsedTime()/1000.f;
-        clock.Reset();
+        float dt = clock.getElapsedTime().asSeconds();
+        clock.restart();
 
         if (dt > 0 && dt < .4){
             game.step(dt);
             game.draw();
-            app.Display();
+            app.display();
 
             /*count_time += dt;
             frame_count ++;

src/renderer/renderer.cpp

     h_shade = glGetAttribLocation(shader.id, "shade");
 
     sf::Image Image; 
-    if (!Image.LoadFromFile("res/tex/land.png")){
+    if (!Image.loadFromFile("res/tex/land.png")){
         printf("Failed to load texture");
     }
     glGenTextures(1, &tex);
     glBindTexture(GL_TEXTURE_2D, tex); 
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.GetWidth(),
-        Image.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
-        Image.GetPixelsPtr()); 
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.getSize().x,
+        Image.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+        Image.getPixelsPtr()); 
     glGenerateMipmap(GL_TEXTURE_2D);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,

src/renderer/water_display.cpp

 
 
     sf::Image Image; 
-    if (!Image.LoadFromFile("res/tex/water.png")){
+    if (!Image.loadFromFile("res/tex/water.png")){
         printf("Failed to load texture");
     }
     glGenTextures(1, &tex);
     glBindTexture(GL_TEXTURE_2D, tex); 
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.GetWidth(),
-        Image.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
-        Image.GetPixelsPtr()); 
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.getSize().x,
+        Image.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+        Image.getPixelsPtr()); 
     glGenerateMipmap(GL_TEXTURE_2D);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.