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 // NOTE: Use peer_id == 0 for disconnected
101 /*virtual bool isClientConnected() { return false; }
102 virtual void setClientConnected(bool) {}*/
104 bool touching_ground;
112 char m_name[PLAYERNAME_SIZE];
119 class ServerRemotePlayer : public Player
122 /*ServerRemotePlayer(bool client_connected):
123 m_client_connected(client_connected)*/
127 virtual ~ServerRemotePlayer()
131 virtual bool isLocal() const
136 virtual void move(f32 dtime, Map &map)
140 /*virtual bool isClientConnected()
142 return m_client_connected;
144 virtual void setClientConnected(bool client_connected)
146 m_client_connected = client_connected;
150 bool m_client_connected;*/
157 class RemotePlayer : public Player, public scene::ISceneNode
161 scene::ISceneNode* parent=NULL,
162 IrrlichtDevice *device=NULL,
165 virtual ~RemotePlayer();
171 virtual void OnRegisterSceneNode()
174 SceneManager->registerNodeForRendering(this);
176 ISceneNode::OnRegisterSceneNode();
179 virtual void render()
184 virtual const core::aabbox3d<f32>& getBoundingBox() const
189 void setPosition(v3f position)
191 m_oldpos = m_showpos;
193 if(m_pos_animation_time < 0.001 || m_pos_animation_time > 1.0)
194 m_pos_animation_time = m_pos_animation_time_counter;
196 m_pos_animation_time = m_pos_animation_time * 0.9
197 + m_pos_animation_time_counter * 0.1;
198 m_pos_animation_time_counter = 0;
199 m_pos_animation_counter = 0;
201 Player::setPosition(position);
202 //ISceneNode::setPosition(position);
205 virtual void setYaw(f32 yaw)
208 ISceneNode::setRotation(v3f(0, -yaw, 0));
216 void updateName(const char *name);
218 virtual void updateLight(u8 light_at_pos)
223 u8 li = decode_light(light_at_pos);
224 video::SColor color(255,li,li,li);
226 scene::IMesh *mesh = m_node->getMesh();
228 u16 mc = mesh->getMeshBufferCount();
229 for(u16 j=0; j<mc; j++)
231 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
232 video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
233 u16 vc = buf->getVertexCount();
234 for(u16 i=0; i<vc; i++)
236 vertices[i].Color = color;
241 void move(f32 dtime, Map &map);
244 scene::IMeshSceneNode *m_node;
245 scene::ITextSceneNode* m_text;
246 core::aabbox3d<f32> m_box;
249 f32 m_pos_animation_counter;
250 f32 m_pos_animation_time;
251 f32 m_pos_animation_time_counter;
287 superspeed = a_superspeed;
301 class LocalPlayer : public Player
305 virtual ~LocalPlayer();
312 void move(f32 dtime, Map &map);
314 void applyControl(float dtime);
316 PlayerControl control;