-
Notifications
You must be signed in to change notification settings - Fork 1
/
fooditem.hh
119 lines (96 loc) · 2.26 KB
/
fooditem.hh
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
/**
TIE-02201 Ohjelmointi 2: Perusteet, K2019
Assignment 12.4: Matopelin paluu
3D Snake game made with OpenGL 2.1 immediate mode.
See 'instructions.txt' for further information.
fooditem.hh
Defines a class for 3D consumable objects on the
game board. Configurations are loaded from a
JSON file.
@author Joona Perasto, 272725, [email protected]
*/
#ifndef CONSUMABLE_HH
#define CONSUMABLE_HH
#include <QVector3D>
#include "gameobject.hh"
#include "foodeffect.hh"
const float ANIM_TIME = 0.45f;
const float FOOD_SCALE = 0.1f;
/*!
* \brief A class for 3D consumable objects on the game board.
*/
class FoodItem : public GameObject
{
public:
/*!
* \brief Constructs the FoodItem by looking up the itemName
* from a JSON table.
* \param scene
* \param itemName
*/
FoodItem(Scene* scene, const QString& itemName);
/*!
* \brief Animates the food and perform eating check.
* \param deltaTime
*/
void update(float deltaTime) override;
/*!
* \brief Renders the model.
* \param gl
*/
void render(QOpenGLFunctions *gl) override;
/*!
* \brief Tells the item to start disappearing.
*/
void consume();
/*!
* \brief canBeEaten
* \return true if yes, false if no
*/
bool canBeEaten() const;
/*!
* \brief Gets the position of the food.
* \return position
*/
QVector3D getPosition() const;
/*!
* \brief Gets the effect of the food.
* \return effect
*/
FoodEffect getEffect() const;
/*!
* \brief Sets the position of the food.
* \param position
*/
void setPosition(QVector3D position);
private:
/*!
* \brief Position of the food.
*/
QVector3D position_;
/*!
* \brief Effect that applies modifiers to snake when eaten.
*/
FoodEffect effect_;
/*!
* \brief Nesh to render.
*/
MeshData* mesh_;
/*!
* \brief Texture to bind to mesh when rendering.
*/
QOpenGLTexture* texture_;
/*!
* \brief isEaten_
*/
bool isEaten_;
/*!
* \brief timeEaten_
*/
float timeEaten_;
/*!
* \brief Variable for rotating and floating animation.
*/
float floatAngle_;
};
#endif // CONSUMABLE_HH