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 bool touching_ground;
108 char m_name[PLAYERNAME_SIZE];
115 class ServerRemotePlayer : public Player
121 virtual ~ServerRemotePlayer()
130 void move(f32 dtime, Map &map)
139 class RemotePlayer : public Player, public scene::ISceneNode
143 scene::ISceneNode* parent=NULL,
144 IrrlichtDevice *device=NULL,
147 virtual ~RemotePlayer();
153 virtual void OnRegisterSceneNode()
156 SceneManager->registerNodeForRendering(this);
158 ISceneNode::OnRegisterSceneNode();
161 virtual void render()
166 virtual const core::aabbox3d<f32>& getBoundingBox() const
171 void setPosition(v3f position)
173 m_oldpos = m_showpos;
175 if(m_pos_animation_time < 0.001 || m_pos_animation_time > 1.0)
176 m_pos_animation_time = m_pos_animation_time_counter;
178 m_pos_animation_time = m_pos_animation_time * 0.9
179 + m_pos_animation_time_counter * 0.1;
180 m_pos_animation_time_counter = 0;
181 m_pos_animation_counter = 0;
183 Player::setPosition(position);
184 //ISceneNode::setPosition(position);
187 virtual void setYaw(f32 yaw)
190 ISceneNode::setRotation(v3f(0, -yaw, 0));
198 void updateName(const char *name);
200 virtual void updateLight(u8 light_at_pos)
205 u8 li = decode_light(light_at_pos);
206 video::SColor color(255,li,li,li);
208 scene::IMesh *mesh = m_node->getMesh();
210 u16 mc = mesh->getMeshBufferCount();
211 for(u16 j=0; j<mc; j++)
213 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
214 video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
215 u16 vc = buf->getVertexCount();
216 for(u16 i=0; i<vc; i++)
218 vertices[i].Color = color;
223 void move(f32 dtime, Map &map);
226 scene::IMeshSceneNode *m_node;
227 scene::ITextSceneNode* m_text;
228 core::aabbox3d<f32> m_box;
231 f32 m_pos_animation_counter;
232 f32 m_pos_animation_time;
233 f32 m_pos_animation_time_counter;
269 superspeed = a_superspeed;
283 class LocalPlayer : public Player
287 virtual ~LocalPlayer();
294 void move(f32 dtime, Map &map);
296 void applyControl(float dtime);
298 PlayerControl control;