-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
31 lines (27 loc) · 875 Bytes
/
player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "player.h"
void Player::draw() {
glBegin(GL_POLYGON);
glVertex2f(m_pos.x(), m_pos.y());
glVertex2f(m_pos.x() + m_squareSideLen, m_pos.y());
glVertex2f(m_pos.x() + m_squareSideLen, m_pos.y() + m_squareSideLen);
glVertex2f(m_pos.x(), m_pos.y() + m_squareSideLen);
glEnd();
}
void Player::tick(double dt) {
LivingEntity::tick(dt);
// controls
Vector to = Entity::position();
if (glfwGetKey(g_window->getWindow(), GLFW_KEY_D) == GLFW_PRESS) {
to.add(Vector(1, 0));
}
if (glfwGetKey(g_window->getWindow(), GLFW_KEY_A) == GLFW_PRESS) {
to.subtract(Vector(1, 0));
}
if (m_isOnGround && glfwGetKey(g_window->getWindow(), GLFW_KEY_SPACE) == GLFW_PRESS) {
velocity(Vector(0, 180));
}
// only move if position has been changed
if (!m_pos.equals(to)) {
position(to);
}
}