blob: 70f7c1f3a1b54ef8c59834e2c407e4f057bcaf6c (
plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <wriggle/input.h>
#include <wriggle/gl.h>
#include <cmath>
#include "player.h"
#include "config.h"
Player::Player() {
x = 0.5;
y = 0.1;
move_factor = 0.005;
focus_factor = 0.5;
texture = new Texture("textures/player.png");
}
void Player::draw() {
glPointSize(32.0);
glColor4f(1, 1, 1, 1);
glEnable(GL_TEXTURE_2D);
texture->bind();
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void Player::update() {
Input input;
float factor = move_factor * (input.key_pressed(Key::LShift) ? focus_factor : 1);
float x_speed = factor * input.key_pressed(Key::Right) - factor * input.key_pressed(Key::Left);
float y_speed = factor * input.key_pressed(Key::Up) - factor * input.key_pressed(Key::Down);
if(x_speed && y_speed) {
x_speed /= sqrtf(2);
y_speed /= sqrtf(2);
}
x = fmaxf(fminf(x + x_speed, 1.0 - 0.018), 0.018);
y = fmaxf(fminf(y + y_speed, Config::viewport_aspect - 0.018), 0.018);
}
|