-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
119 lines (94 loc) · 2.92 KB
/
Copy pathPlayer.cpp
File metadata and controls
119 lines (94 loc) · 2.92 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "Player.h"
#include "Definitions.h"
Player::Player() {
health = 500;
score = 0;
/* Inicial position for the square */
x = (WIDTH/2-50.0);
y = (HEIGHT/2-50.0);
moving = false;
}
int Player::getHealth() {
return health;
}
double Player::getX() {
return x;
}
double Player::getY() {
return y;
}
void Player::setX(double number) {
x = number;
}
void Player::setY(double number) {
y = number;
}
GLuint * Player::getVertexBuffer() {
return &vertexBuffer;
}
GLuint * Player::getTextureBuffer() {
return &textureBuffer;
}
void Player::setMoving(int dir, int act) {
moving = true;
direction = dir;
action = act;
}
int Player::getScore() {
return score;
}
void Player::setHealth(int number) {
health += number;
}
void Player::setScore(int number) {
score += number;
}
void Player::draw() {
ILuint image;
ILboolean success;
/* Rendering the square with dynamic values that change with the user's input */
Vertex square[] = {
{{0.0f + x, 0.0f + y, 0.0f}, {1.0f, 1.0f}},
{{SQUARE_SIZE + x, 0.0f + y, 0.0f}, {0.0f, 1.0f}},
{{SQUARE_SIZE + x, SQUARE_SIZE + y, 0.0f}, {0.0f, 0.0f}},
{{0.0f + x, SQUARE_SIZE + y, 0.0f}, {1.0f, 0.0f}}
};
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(square), square, GL_DYNAMIC_DRAW);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (GLvoid *) offsetof(Vertex, coords));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (GLvoid *) offsetof(Vertex, text));
ilGenImages(1, &image);
ilBindImage(image);
if(action == GLFW_RELEASE) {
moving = false;
}
if(moving) {
if(direction == GLFW_KEY_LEFT) {
ilLoadImage("Images/adventurer_right_1.png");
} else if(direction == GLFW_KEY_RIGHT) {
ilLoadImage("Images/adventurer_left_1.png");
} else if(direction == GLFW_KEY_UP) {
ilLoadImage("Images/adventurer_up_1.png");
} else if(direction == GLFW_KEY_DOWN) {
ilLoadImage("Images/adventurer_down_1.png");
}
} else {
ilLoadImage("Images/adventurer_idle.png");
}
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glGenTextures(1, &textureBuffer);
glBindTexture(GL_TEXTURE_2D, textureBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
glDrawArrays(GL_QUADS, 0, 4);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}