DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
True Drop Box
FTP/SFTP Hosting
Group Account
Team Anywhere
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Cloud-to-Cloud Backup
|
DVR/Camera Backup
FTP, Email & Web Service
FTP/SFTP Hosting
|
Email Hosting
|
Web Hosting
|
Webcam Hosting
Other Products & Services
Team Anywhere
|
Connect to Remote PC
|
Cloud Surveillance
|
Virtual CCTV NVR
Quick Links
Security and Privacy
Customer Support
Service Manual
Use Cases
Group Account
Online Help
Support Forum
Contact Us
About DriveHQ
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
Other Features
Team Anywhere (Remote Desktop Service)
CameraFTP Cloud Surveillance
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Team Anywhere for Windows (Beta)
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
#pragma once //#include "DXUT.h" #include "DarkPuzzle.h" #include "Character.h" #include "GameLevel.h" #include "GameEngine.h" namespace DarkBattle{ #define FUNC_FRAMEMOVE "FrameMove" //#define FUNC_MOVE_WAYPOINT "MoveWayPoint" #define CHARACTER_NAME "Character" extern FILE* fdebug; //extern GameLevel* theGameLevel; const char* Character::characterNames[] = {"Hamster","DarkWizzard"}; Character* Character::theHero = NULL; MyHashTable
Character::pool; float Character::FireRange = 60; float Character::FireHeight = 8; int Character::EvaluateRange = 6; int Character::WayPointQueueLength = 10; void Character::ThinkStep(){ ScriptEngine::GetInstance()->ExecuteOneParamFunction("ThinkStep",(void*)this,CHARACTER_NAME); } void Character::FireToHero(){ if ((Character::GetHero()->GetPos()-GetPos()).Length() < Character::FireRange){ if ( GameLevel::RayCast(GetPos()+Vec3(0,0,Character::FireHeight), Character::GetHero()->GetPos()+Vec3(0,0,Character::FireHeight),NULL,NULL) ){ }else{ GameLevel::DrawDebugLine(GetPos()+Vec3(0,0,Character::FireHeight), Character::GetHero()->GetPos()+Vec3(0,0,Character::FireHeight),Vec3(0,0,1)); } } } Character::Character(Game3DObject* pObjectResource, btRigidBody* pRigidBody, const char* Name): Game3DInstance(pObjectResource,pRigidBody), closeList(GameLevel::GetInstance()->GetMap()->SizeX(), GameLevel::GetInstance()->GetMap()->SizeY()), distanceMap(GameLevel::GetInstance()->GetMap()->SizeX(), GameLevel::GetInstance()->GetMap()->SizeY()), isCovered(GameLevel::GetInstance()->GetMap()->SizeX(), GameLevel::GetInstance()->GetMap()->SizeY()) { this->forceStop = false; this->isMoving = false; this->openList.Clean(); this->hitPoint = 10; this->light = NULL; CLONE_STR(this->name,Name); type = identifyCharacterType(name); assert(type!=CHARACTER_NOTCHARACTER); //if (type==CHARACTER_HERO){ // GameLevel::GetInstance()->controllableCharacter = this; // Character::theHero = this; //} this->light = Light::CreateLight(this,Light::LightTypesConst::LightEye); pool.Put(name,this); } Character* Character::Add(char* modelName, const char* name){ Game3DObject* pObjResorce; btRigidBody* pRidBody; Game3DInstance::GetReference(modelName,&pObjResorce,&pRidBody); GameLevel::GetInstance()->AddRigidBody(pRidBody); return new Character(pObjResorce,pRidBody,name); } Character* Character::Get(char* name){ return pool.Get(name); } int Character::identifyCharacterType(const char* name){ for (int i=0;i
applyImpulse(impulse,btVector3(0,0,0)); pRigidBody->activate(); pRigidBody->setLinearVelocity(impulse); } void Character::MoveTo(Vec3 pos){ isMoving = true; pRigidBody->activate(); btVector3 impulse = btVector3(pos.x,pos.y,0); impulse = impulse - pRigidBody->getCenterOfMassPosition(); impulse.setZ(0); impulse.normalize(); float angle; if (impulse.getX()==0){ if (impulse.getY()>0) angle = 3.14159/2; else angle = -3.14159/2; }else{ angle = atanf(impulse.getY()/impulse.getX()); if (impulse.getX()<0) angle+=3.14159; } angle+=3.14159/2;//to make this angle identical to character angle //if (angle>3.14159/2*3) angle = -(3.14159*2-angle);//make the negative part float curAngle = this->GetAngle(); if (curAngle<0) curAngle+=3.14159*2;//make no negative part //impulse*=GameEngine::RunVelocity; //pRigidBody->setLinearVelocity(impulse); btVector3 vel = impulse*GameEngine::RunVelocity; //impulse*=GameEngine::RunAcceleration; //if ((pRigidBody->getLinearVelocity()-vel).length()>GameEngine::RunVelocityEpsilon){ // pRigidBody->applyImpulse(impulse,btVector3(0,0,0)); //}else{ pRigidBody->setLinearVelocity(vel); //} //DEBUG_OUTPUT("%f -- %f\n",curAngle/3.14159*180,angle/3.14159*180); float distPlus,distMinus,dist; if (angle>curAngle){ distPlus = abs(angle-curAngle); distMinus = abs(3.14159*2-angle+curAngle); if (distPlus
3.14159/180*2) pRigidBody->setAngularVelocity(btVector3(0,0,dist)); //if (curAngle<0 && angle > 3.14159) dist = curAngle - (-3.14159*2+angle);//must >0 //else if (curAngle>3.14159 && angle <0) dist = -3.14159*2+curAngle - angle;//must <0 //else dist = curAngle - angle; //if (dist>3.14159/180*2){ // pRigidBody->setAngularVelocity(btVector3(0,0,-dist/1.3)); //}else if (dist<-3.14159/180*2) // pRigidBody->setAngularVelocity(btVector3(0,0,+dist/1.3)); } void Character::Jump(){ pRigidBody->activate(); //pRigidBody->setLinearVelocity(btVector3(0,0,20)); pRigidBody->applyImpulse(btVector3(0,0,40),btVector3(0,0,10)); } void Character::SetPos(Vec3 pos){ btTransform trans = btTransform(); trans.setIdentity(); trans.setOrigin(btVector3(pos.x,pos.y,pos.z)); pRigidBody->activate(); pRigidBody->setLinearVelocity(btVector3(0,0,0)); pRigidBody->setWorldTransform(trans); } Vec3 Character::GetPos(){ //float ret[3]; btVector3 pos = pRigidBody->getWorldTransform().getOrigin(); return Vec3( pos.getX(),pos.getY(),pos.getZ()); //return ret; } bool Character::IsAt(Vec3 pos){ return GetPos().IsAt(pos); } void Character::Stop(){ isMoving = false; btVector3 curLinearVel = pRigidBody->getLinearVelocity(); pRigidBody->setLinearVelocity(btVector3(0,0,curLinearVel.z())); pRigidBody->setAngularVelocity(btVector3(0,0,0)); } bool Character::CheckNameBelongToThisClass(const char* name){ return (identifyCharacterType(name)!=CHARACTER_NOTCHARACTER); } void Character::FrameMove(float elapsedTime){ //perform per frame action in Lua evaluatedThisFrame = false; ScriptEngine::GetInstance()->ExecuteOneParamFunction(FUNC_FRAMEMOVE,(void*)this,CHARACTER_NAME); } void Character::InitComputeDistanceMap(){ Vec3 from = GetPos(); Map::GetInstance()->InitPathFindingParameters(NULL,NULL,&distanceMap,&from,&openList,&closeList ,NULL,NULL); } void Character::InitComputeDistanceMapBreath(){ Vec3 from = GetPos(); Map::GetInstance()->InitPathFindingParameters(NULL,NULL,&distanceMap,&from,&openList,&closeList ,&visitedPos,&isCovered); } bool Character::ComputeDistanceMapStep(Vec3 to){ return Map::GetInstance()->ComputeDistanceMapStep(to,distanceMap,openList,closeList); } bool Character::ComputeDistanceMapBreathStep(){ return Map::GetInstance()->ComputeDistanceMapStep(GetPos(),Character::EvaluateRange,distanceMap, openList,closeList,visitedPos,isCovered); } void Character::InitMakePath(Vec3 to){ Stop(); Map::GetInstance()->GetCell(to,curPathPos.x,curPathPos.y); Map::GetInstance()->InitPathFindingParameters(&wayPoints,&smoothWP,NULL,NULL,NULL,NULL ,NULL,NULL); } bool Character::MakePathStep(){ return Map::GetInstance()->MakePathStep(GetPos(),curPathPos,distanceMap,wayPoints); } void Character::InitMakeSmoothPath(Vec3 to){ Map::GetInstance()->InitMakeSmoothPath(GetPos(),smoothRefPos,smoothPrePos); } bool Character::MakeSmoothPathStep(Vec3 to){ return Map::GetInstance()->MakeSmoothPathStep(smoothRefPos,smoothPrePos,to,wayPoints,smoothWP); } bool Character::IsCovered(const Vec3 &from, const Vec3 &to){ return ((from-to).Length()>Character::FireRange) || GameLevel::RayCast(from + Vec3(0,0,Character::FireHeight), to + Vec3(0,0,Character::FireHeight),NULL,NULL); } bool Character::InitEvaluateEvadeStep(){ if (evaluatedThisFrame) return false; if (isMoving) return false; if (IsCovered(Character::GetHero()->GetPos(),GetPos())) return false; Map::GetInstance()->GetCell(GetPos(),bestSoFar.x,bestSoFar.y); bestCovered = false; bestDistance = 0; found = false; return true; } #define EVADE_STEPS 10 bool Character::EvaluateEvadeStep(){ evaluatedThisFrame = true; //ComputeDistanceMap(); Vec2 pos; int processedStep = 0; while (!visitedPos.IsEmpty()){ pos = visitedPos.Pop(); if (!bestCovered){ if (isCovered.get(pos.x,pos.y)){ bestCovered = true; bestSoFar = pos; bestDistance = distanceMap.get(pos.x,pos.y); found =true; } }else{ if (isCovered.get(pos.x,pos.y)){ if (distanceMap.get(pos.x,pos.y)
EVADE_STEPS) return false; } if (found){ //smoothWP.Clean(); //smoothWP.PushBack(Map::GetInstance()->GetPosition(bestSoFar.x,bestSoFar.y)); evaluatedPos = Map::GetInstance()->GetPosition(bestSoFar.x,bestSoFar.y); } return true; //if (found) // MoveWayPointTo(Map::GetInstance()->GetPosition(bestSoFar.x,bestSoFar.y)); } void Character::MakePath(Vec3 to){ ScriptEngine::GetInstance()->ExecuteTwoParamFunction("MakePath", (void*)this,CHARACTER_NAME,(void*)&to,"Vec3"); } void Character::MakeSmoothPath(Vec3 to){ //MakePathStep(to); ScriptEngine::GetInstance()->ExecuteTwoParamFunction("MakeSmoothPath", (void*)this,CHARACTER_NAME,(void*)&to,"Vec3"); } Character* Character::GetHero(){ assert(Character::theHero!=NULL); return Character::theHero; } void Character::SetHero(Character* hero){ assert(hero!=NULL); theHero = hero; GameLevel::GetInstance()->controllableCharacter = theHero; }; btVector3 Character::GetCenter(){ D3DXMATRIX ret = this->GetTransformMatrix(); return btVector3(ret._41,ret._42,ret._43); } }
Character.cpp
Page URL
File URL
Prev 1/65
Next
Download
( 10 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.