Changeset 363d5ff in opengl-game


Ignore:
Timestamp:
Aug 8, 2017, 2:38:57 AM (7 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
4046b51
Parents:
eeece4e
Message:

Implement moving the paddle up and down the screen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pong.cpp

    reeece4e r363d5ff  
    9696
    9797   GLfloat points_paddle[] = {
    98       -1.0f,  1.0f,  0.0f,
    99       -1.0f,  0.7f,  0.0f,
    100       -0.9f,  0.7f,  0.0f,
    101       -1.0f,  1.0f,  0.0f,
    102       -0.9f,  0.7f,  0.0f,
    103       -0.9f,  1.0f,  0.0f,
     98      -1.0f,  0.15f,  0.0f,
     99      -1.0f, -0.15f,  0.0f,
     100      -0.9f, -0.15f,  0.0f,
     101      -1.0f,  0.15f,  0.0f,
     102      -0.9f, -0.15f,  0.0f,
     103      -0.9f,  0.15f,  0.0f,
    104104   };
    105105
     
    142142   float speed = 1.0f;
    143143   float last_position = 0.0f;
     144   float last_paddle_pos = 0.0f;
    144145
    145146   double previous_seconds = glfwGetTime();
     
    156157
    157158      model[12] = 0.0f;
     159      model[13] = last_paddle_pos;
    158160      glUniformMatrix4fv(location, 1, GL_FALSE, model);
    159161
     
    166168      model[12] = last_position + speed*elapsed_seconds;
    167169      last_position = model[12];
     170      model[13] = 0.0f;
    168171      glUniformMatrix4fv(location, 1, GL_FALSE, model);
    169172
     
    179182      if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE)) {
    180183         glfwSetWindowShouldClose(window, 1);
     184      }
     185      if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_UP)) {
     186         last_paddle_pos += 1.0f * elapsed_seconds;
     187         if (last_paddle_pos > 0.85f) {
     188            last_paddle_pos = 0.85f;
     189         }
     190      }
     191      if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_DOWN)) {
     192         last_paddle_pos -= 1.0f * elapsed_seconds;
     193         if (last_paddle_pos < -0.85f) {
     194            last_paddle_pos = -0.85f;
     195         }
    181196      }
    182197   }
Note: See TracChangeset for help on using the changeset viewer.