-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.cpp
More file actions
80 lines (71 loc) · 1.74 KB
/
Player.cpp
File metadata and controls
80 lines (71 loc) · 1.74 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
#include "Player.h"
void Player::Reset()
{
switch (_playerNumber)
{
case 1:
_xPos = -PlayerInitialXPosition;
break;
case 2:
_xPos = +PlayerInitialXPosition;
break;
}
_yPos = PlayerInitialYPosition;
_zPos = 0;
_playerJumpState = playerJumpState::GROUND;
}
void Player::drawPlayer()
{
//iscrtavanje celog igraca
glPushMatrix();
glTranslatef(_xPos, _yPos, _zPos);
drawHead();
drawBody();
glPopMatrix();
}
void Player::drawBody()
{
glPushMatrix();
if(_playerNumber == 1)
glColor3f(1, 0, 0);
if (_playerNumber == 2)
glColor3f(0, 0, 1);
glTranslatef(0, -100.0, 0); //telo je za -100 ispod glave po y osi
glutSolidCube(90);
glPopMatrix();
}
void Player::drawHead()
{
glPushMatrix();
glColor3f(255, 255, 0);
glColor3f(255, 255, 0);
glutSolidSphere(PlayerHeadSize, 50, 50);
glPopMatrix();
}
void Player::PlayerJumpUpdate()
{
//ako ne skace izlazimo
if(_playerJumpState == playerJumpState::GROUND)
return;
//ako je u skoku ka gore a jos nije dostigao max
if(_playerJumpState == playerJumpState::UP)
{
_yPos+=10;
}
//ako je dostigao max i krenuo ka dole
if(_playerJumpState == playerJumpState::DOWN)
{
_yPos-=15;
}
//dostigao max
if(_yPos >= PlayerMaxJumpYHeight)
{
_playerJumpState = playerJumpState::DOWN;
}
//zavrsio skok
if(_yPos < PlayerInitialYPosition)
{
_playerJumpState = playerJumpState::GROUND;
_yPos = PlayerInitialYPosition;
}
}