/src/NPC.cpp

https://bitbucket.org/brunobottazzini/olympia-game · C++ · 91 lines · 75 code · 12 blank · 4 comment · 9 complexity · 620d7f51d78ebe92ef27110d256d17b8 MD5 · raw file

  1. #include "NPC.h"
  2. NPC::NPC (IrrlichtDevice *device, IVideoDriver* driver, char caminhoModelo [], char caminhoTextura [], bool lightning)
  3. {
  4. this->smgr = device->getSceneManager();
  5. this->mesh = this->smgr->getMesh(caminhoModelo);
  6. this->node = this->smgr->addAnimatedMeshSceneNode( mesh );
  7. this->caminhotexture = caminhoTextura;
  8. this->driver = driver;
  9. this->speed = 2.0;
  10. this->lightning = lightning;
  11. if (node)
  12. {
  13. node->setMD2Animation(scene::EMAT_STAND);
  14. node->setMaterialFlag(EMF_LIGHTING, lightning);
  15. node->setMaterialTexture( 0, driver->getTexture(caminhoTextura) );
  16. if(lightning == true){
  17. this->node->addShadowVolumeSceneNode();
  18. smgr->setShadowColor(video::SColor(150,0,0,0));
  19. //this->node->setScale(core::vector3df(1,1,1));
  20. this->node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, lightning);
  21. }
  22. }
  23. this->LapFlag = 0;
  24. }
  25. void NPC::setMesh(char caminho_mesh[]){
  26. IAnimatedMesh* tempMesh = this->smgr->getMesh(caminho_mesh);
  27. this->node->setMesh(tempMesh);
  28. this->node->setMaterialTexture( 0, driver->getTexture(this->caminhotexture) );
  29. this->node->addShadowVolumeSceneNode();
  30. node->setMaterialFlag(EMF_LIGHTING, false);
  31. //smgr->setShadowColor(video::SColor(150,0,0,0));
  32. //this->node->setScale(core::vector3df(1,1,1));
  33. //this->node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, this->ligthning);
  34. }
  35. IAnimatedMesh* NPC::getMesh(){
  36. return this->mesh;
  37. }
  38. void NPC::setLapFlag(short flag){
  39. this->LapFlag = flag;
  40. }
  41. short NPC::getLapFlag(){
  42. return this->LapFlag;
  43. }
  44. IAnimatedMeshSceneNode* NPC::getNode(){
  45. return this->node;
  46. }
  47. void NPC::setPosition(float posX, float posY, float posZ)
  48. {
  49. core::vector3df playerPos;
  50. playerPos.X = posX;
  51. playerPos.Y = posY;
  52. playerPos.Z = posZ;
  53. this->node->setPosition(playerPos);
  54. }
  55. void NPC::setModelSpeed(float speed){
  56. this->speed = speed;
  57. if(speed >= 2.0 && speed <= 3.9){
  58. this->node->setAnimationSpeed(75);
  59. }else if (speed >= 4.0 && speed <= 5.9){
  60. this->node->setAnimationSpeed(95);
  61. }else if (speed >= 6.0 && speed <= 7.5){
  62. this->node->setAnimationSpeed(115);
  63. }
  64. }
  65. void NPC::setPosition(core::vector3df npcPos){
  66. this->node->setPosition(npcPos);
  67. }
  68. void NPC::rotateNPC(float x, float y, float z){
  69. this->node->setRotation(core::vector3df(x,y,z));
  70. }
  71. void NPC::setAnimationMD2(irr::scene::EMD2_ANIMATION_TYPE anim){
  72. this->node->setMD2Animation(anim);
  73. }
  74. void NPC::setAnimationMD2(char path[]){
  75. this->node->setMD2Animation(path);
  76. }
  77. vector3df NPC::getPosition(){
  78. return this->node->getPosition();
  79. }