]> git.lizzy.rs Git - dragonfireclient.git/blob - src/player.h
grass edges workin'
[dragonfireclient.git] / src / player.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 /*
21 (c) 2010 Perttu Ahola <celeron55@gmail.com>
22 */
23
24 #ifndef PLAYER_HEADER
25 #define PLAYER_HEADER
26
27 #include "common_irrlicht.h"
28 #include "inventory.h"
29
30 #define PLAYERNAME_SIZE 20
31
32 class Map;
33
34 class Player
35 {
36 public:
37         Player();
38         virtual ~Player();
39
40         void move(f32 dtime, Map &map);
41
42         v3f getSpeed()
43         {
44                 return m_speed;
45         }
46
47         void setSpeed(v3f speed)
48         {
49                 m_speed = speed;
50         }
51         
52         // Y direction is ignored
53         void accelerate(v3f target_speed, f32 max_increase);
54
55         v3f getPosition()
56         {
57                 return m_position;
58         }
59
60         virtual void setPosition(v3f position)
61         {
62                 m_position = position;
63         }
64
65         void setPitch(f32 pitch)
66         {
67                 m_pitch = pitch;
68         }
69
70         virtual void setYaw(f32 yaw)
71         {
72                 m_yaw = yaw;
73         }
74
75         f32 getPitch()
76         {
77                 return m_pitch;
78         }
79
80         f32 getYaw()
81         {
82                 return m_yaw;
83         }
84
85         virtual void updateName(const char *name)
86         {
87                 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
88         }
89
90         const char * getName()
91         {
92                 return m_name;
93         }
94
95         virtual bool isLocal() const = 0;
96
97         bool touching_ground;
98         bool in_water;
99         
100         Inventory inventory;
101
102         u16 peer_id;
103
104 protected:
105         char m_name[PLAYERNAME_SIZE];
106         f32 m_pitch;
107         f32 m_yaw;
108         v3f m_speed;
109         v3f m_position;
110 };
111
112 class RemotePlayer : public Player, public scene::ISceneNode
113 {
114 public:
115         RemotePlayer(
116                 scene::ISceneNode* parent=NULL,
117                 IrrlichtDevice *device=NULL,
118                 s32 id=0);
119         
120         virtual ~RemotePlayer();
121
122         /*
123                 ISceneNode methods
124         */
125
126         virtual void OnRegisterSceneNode()
127         {
128                 if (IsVisible)
129                         SceneManager->registerNodeForRendering(this);
130
131                 ISceneNode::OnRegisterSceneNode();
132         }
133
134         virtual void render()
135         {
136                 // Do nothing
137         }
138         
139         virtual const core::aabbox3d<f32>& getBoundingBox() const
140         {
141                 return m_box;
142         }
143
144         void setPosition(v3f position)
145         {
146                 Player::setPosition(position);
147                 ISceneNode::setPosition(position);
148         }
149
150         virtual void setYaw(f32 yaw)
151         {
152                 Player::setYaw(yaw);
153                 ISceneNode::setRotation(v3f(0, -yaw, 0));
154         }
155
156         bool isLocal() const
157         {
158                 return false;
159         }
160
161         void updateName(const char *name);
162
163 private:
164         scene::ITextSceneNode* m_text;
165         core::aabbox3d<f32> m_box;
166 };
167
168 struct PlayerControl
169 {
170         PlayerControl()
171         {
172                 up = false;
173                 down = false;
174                 left = false;
175                 right = false;
176                 jump = false;
177                 superspeed = false;
178                 pitch = 0;
179                 yaw = 0;
180         }
181         PlayerControl(
182                 bool a_up,
183                 bool a_down,
184                 bool a_left,
185                 bool a_right,
186                 bool a_jump,
187                 bool a_superspeed,
188                 float a_pitch,
189                 float a_yaw
190         )
191         {
192                 up = a_up;
193                 down = a_down;
194                 left = a_left;
195                 right = a_right;
196                 jump = a_jump;
197                 superspeed = a_superspeed;
198                 pitch = a_pitch;
199                 yaw = a_yaw;
200         }
201         bool up;
202         bool down;
203         bool left;
204         bool right;
205         bool jump;
206         bool superspeed;
207         float pitch;
208         float yaw;
209 };
210
211 class LocalPlayer : public Player
212 {
213 public:
214         LocalPlayer();
215         virtual ~LocalPlayer();
216
217         bool isLocal() const
218         {
219                 return true;
220         }
221
222         void applyControl(float dtime);
223         
224         PlayerControl control;
225
226 private:
227 };
228
229 #endif
230