forked from Milez213/CityTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GamePointObject.cpp
99 lines (87 loc) · 2.57 KB
/
GamePointObject.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
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
//
// GamePointObject.cpp
//
//
// Created by Bryan Bell on 3/10/13.
//
//
#include "GamePointObject.h"
#define NUM_MATERIALS 6
float point_diff[NUM_MATERIALS * 3] = {
0.0, 1.0, 0.0,
1.0, 0.0, 0.0,
0.0, 0.0, 1.0,
1.0, 1.0, 0.0,
1.0, 0.0, 1.0,
0.0, 1.0, 1.0
};
float point_spec[NUM_MATERIALS * 3] = {
0.0, 1.0, 0.0,
1.0, 0.0, 0.0,
0.0, 0.0, 1.0,
1.0, 1.0, 0.0,
1.0, 0.0, 1.0,
0.0, 1.0, 1.0
};
GamePointObject::GamePointObject(int pointValue) : GameDrawableObject("models/squash.obj") {
points = pointValue;
state = STAND;
time = ((float)(rand() % 100) / 100.0f) * 3.0f;
int index = rand() % NUM_MATERIALS;
int index2 = rand() % NUM_MATERIALS;
for (unsigned int LoD = 0; LoD < meshStorage.size(); LoD++) {
for (int i = 0; i < meshStorage[LoD].numMeshes; i++) {
meshStorage[LoD].material[i].dColor = vec3(point_diff[index*3], point_diff[index*3+1],
point_diff[index*3+2]);
meshStorage[LoD].material[i].sColor = vec3(point_spec[index2*3], point_spec[index2*3+1],
point_spec[index2*3+2]);
}
}
}
void GamePointObject::onCollide(GameKartObject *other)
{
if (state == STAND) {
aim = other;
state = PICKUP;
vec3 movement = normalize(other->getVelocity());
pos = other->getPosition() + movement * other->getRadius() * 3.0f;
vel = movement * 20.0f;
vel.y = 5.0f;
vel.x *= 2.0f;
vel.z *= 1.5f;
time = 0.0;
}
}
void GamePointObject::update(float dt)
{
vec3 rotate = getRotation();
vec3 position = getPosition();
vec3 velocity = getVelocity();
time += dt;
if (state == STAND) {
rotate.y += 180.0f * dt;
if (rotate.y > 360.0f)
rotate.y -= 360.0f;
position.y = sin(time * 5.0) * 0.3 + 1.0 + basePosition.y;
} else if (state == PICKUP || state == CATCH) {
if (time > 0.5f)
state = CATCH;
vec3 newAim = normalize(aim->getPosition() - getPosition()) * time;
velocity += newAim;
if (time >= 1.0f)
velocity = newAim * (aim->getTopSpeed() + 1.0f);
if (position.y < 0.5f) {
position.y = 0.5f;
velocity.y = fabs(velocity.y * 0.5f);
}
if (time < 1.0f) {
setScale(vec3((5.0f-time * 2.0f)/10.0f, (5.0f-time*2.0f)/10.0f, (5.0f-time*2.0f)/10.0f));
} else {
setScale(vec3(3.0f/10.0f, 3.0f/10.0f, 3.0f/10.0f));
}
}
setRotation(rotate);
setPosition(position);
setVelocity(velocity);
GameObject::update(dt);
}