3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
21 (c) 2010 Perttu Ahola <celeron55@gmail.com>
27 #include "common_irrlicht.h"
28 #include "inventory.h"
30 #define PLAYERNAME_SIZE 20
40 //void move(f32 dtime, Map &map);
41 virtual void move(f32 dtime, Map &map) = 0;
48 void setSpeed(v3f speed)
53 // Y direction is ignored
54 void accelerate(v3f target_speed, f32 max_increase);
61 virtual void setPosition(v3f position)
63 m_position = position;
66 void setPitch(f32 pitch)
71 virtual void setYaw(f32 yaw)
86 virtual void updateName(const char *name)
88 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
91 const char * getName()
96 virtual bool isLocal() const = 0;
98 virtual void updateLight(u8 light_at_pos) {};
100 virtual bool isClientConnected() { return false; }
101 virtual void setClientConnected(bool) {}
103 bool touching_ground;
111 char m_name[PLAYERNAME_SIZE];
118 class ServerRemotePlayer : public Player
121 ServerRemotePlayer(bool client_connected):
122 m_client_connected(client_connected)
125 virtual ~ServerRemotePlayer()
129 virtual bool isLocal() const
134 virtual void move(f32 dtime, Map &map)
138 virtual bool isClientConnected()
140 return m_client_connected;
142 virtual void setClientConnected(bool client_connected)
144 m_client_connected = client_connected;
148 bool m_client_connected;
155 class RemotePlayer : public Player, public scene::ISceneNode
159 scene::ISceneNode* parent=NULL,
160 IrrlichtDevice *device=NULL,
163 virtual ~RemotePlayer();
169 virtual void OnRegisterSceneNode()
172 SceneManager->registerNodeForRendering(this);
174 ISceneNode::OnRegisterSceneNode();
177 virtual void render()
182 virtual const core::aabbox3d<f32>& getBoundingBox() const
187 void setPosition(v3f position)
189 m_oldpos = m_showpos;
191 if(m_pos_animation_time < 0.001 || m_pos_animation_time > 1.0)
192 m_pos_animation_time = m_pos_animation_time_counter;
194 m_pos_animation_time = m_pos_animation_time * 0.9
195 + m_pos_animation_time_counter * 0.1;
196 m_pos_animation_time_counter = 0;
197 m_pos_animation_counter = 0;
199 Player::setPosition(position);
200 //ISceneNode::setPosition(position);
203 virtual void setYaw(f32 yaw)
206 ISceneNode::setRotation(v3f(0, -yaw, 0));
214 void updateName(const char *name);
216 virtual void updateLight(u8 light_at_pos)
221 u8 li = decode_light(light_at_pos);
222 video::SColor color(255,li,li,li);
224 scene::IMesh *mesh = m_node->getMesh();
226 u16 mc = mesh->getMeshBufferCount();
227 for(u16 j=0; j<mc; j++)
229 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
230 video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
231 u16 vc = buf->getVertexCount();
232 for(u16 i=0; i<vc; i++)
234 vertices[i].Color = color;
239 void move(f32 dtime, Map &map);
242 scene::IMeshSceneNode *m_node;
243 scene::ITextSceneNode* m_text;
244 core::aabbox3d<f32> m_box;
247 f32 m_pos_animation_counter;
248 f32 m_pos_animation_time;
249 f32 m_pos_animation_time_counter;
285 superspeed = a_superspeed;
299 class LocalPlayer : public Player
303 virtual ~LocalPlayer();
310 void move(f32 dtime, Map &map);
312 void applyControl(float dtime);
314 PlayerControl control;