19ba4781b5d7690488d8b573ad84158ac0aba6e7.svn-base (12876B)
1 #ifndef ACTOR_H 2 #define ACTOR_H 3 4 #include "Utils.h" 5 #include "Console.h" 6 #include "Animation.h" 7 #include "AnimationGraph.h" 8 #include "Physics.h" 9 #include "Terrain.h" 10 #include "ActorHandle.h" 11 12 //Actor State Defines 13 #define IDLE 10 14 #define RUN 20 15 #define IDLE_BEGIN 30 16 #define JUMP 40 17 #define WANDER 50 18 #define PURSUE 60 19 20 #define ALIVE 70 21 #define DEAD 80 22 23 #define SPLASH 90 24 25 #define RUN_LEFT 0x1 26 #define RUN_RIGHT 0x02 27 #define RUN_DOWN 0x003 28 #define RUN_UP 0x0004 29 // 30 31 struct Trajectory 32 { 33 float slope; 34 int dir; 35 }; 36 37 class Actor : public EventReceiver 38 { 39 public: 40 41 Actor() : mOpacity(255) {} 42 43 Actor(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib); 44 45 virtual bool UpdateAnimation() = 0; 46 47 virtual bool ActorUpdate() = 0; 48 49 int GetX() 50 { 51 return mPosData.x; 52 } 53 54 int GetY() 55 { 56 return mPosData.y; 57 } 58 59 int GetHeight() 60 { 61 return mPosData.h; 62 } 63 64 int GetWidth() 65 { 66 return mPosData.w; 67 } 68 69 int GetDrawX() 70 { 71 return mDrawPos.x; 72 } 73 74 int GetDrawY() 75 { 76 return mDrawPos.y; 77 } 78 79 int GetDrawHeight() 80 { 81 return mDrawPos.h; 82 } 83 84 int GetDrawWidth() 85 { 86 return mDrawPos.w; 87 } 88 89 SDL_Rect* GetPosition() 90 { 91 return &mPosData; 92 } 93 94 SDL_Rect* GetDrawPosition() 95 { 96 return &mDrawPos; 97 } 98 99 SDL_Rect CalcDrawRect() 100 { 101 if (mDir == RIGHT) 102 { 103 mDrawPos.x = mOff_x; 104 } 105 else //mDir = LEFT 106 { 107 mDrawPos.x = -(mDrawPos.w + (mOff_x - mPosData.w) ); 108 } 109 return mDrawPos; 110 } 111 112 int GetOpacity() 113 { 114 return mOpacity; 115 } 116 117 int SetOpacity(int i) 118 { 119 return mOpacity = i; 120 } 121 122 Frame* GetFrame() 123 { 124 return mFrame; 125 } 126 127 int GetState() 128 { 129 return mState; 130 } 131 132 int GetDir() 133 { 134 return mDir; 135 } 136 137 std::vector<Actor*> GetHats() 138 { 139 return mHats; 140 } 141 142 int AttachHat(Actor* hat) 143 { 144 mHats.push_back(hat); 145 return ((int)mHats.size() - 1); 146 } 147 148 int SetHandle(int i) 149 { 150 return mHandle = i; 151 } 152 153 int GetHandle() 154 { 155 return mHandle; 156 } 157 158 int SetSpatID(int i) 159 { 160 return mSpatID = i; 161 } 162 163 int GetSpatID() 164 { 165 return mSpatID; 166 } 167 168 AnimGraph* GetAnimGraph() 169 { 170 return mAnimGraph; 171 } 172 173 void PassAnimGraphState() 174 { 175 mAnimGraph->GiveActorState(&mAnimID); 176 } 177 178 int GetAnimID() 179 { 180 return mAnimID; 181 } 182 183 int GetChannel() 184 { 185 return mSoundChannel; 186 } 187 188 bool IsBlocking() 189 { 190 return mBlocking; 191 } 192 193 EventFeed mFeed; 194 195 protected: 196 197 AnimGraph* mAnimGraph; 198 Frame* mFrame; 199 int mOpacity; 200 201 int mState; 202 int mDir; 203 int mAnimID; 204 205 SDL_Rect mPosData; //Where the actors collision box is 206 SDL_Rect mDrawPos; //Where the actor is drawn relative to its physical position (mPosData) 207 208 int mOff_x; 209 int mOff_y; 210 211 std::vector<Actor*> mHats; 212 213 ActorHandleManager* mAHM; 214 int mHandle; 215 216 EventReceiver* mSpat; //SpatialMonitor deals with actor collision and other region checking (like LoS) 217 int mSpatID; //!This should become the same as mHandle! Used by mSpat to ID this actor 218 219 EventReceiver* mParticleLib; //Deal with the spawning of particles 220 221 EventReceiver* mSoundLib; //Deals with sounds and the spawning or point sounds 222 int mSoundChannel; //used to play sounds directly from the actor 223 224 bool mBlocking; 225 }; 226 227 class Winch : public Actor 228 { 229 public: 230 Winch(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib, Actor* gate, int dir) : Actor(AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib), mGate(gate) 231 { 232 mState = IDLE; 233 mDir = dir; 234 } 235 236 bool EventProcess(Event eve); 237 238 bool UpdateAnimation(); 239 240 bool ActorUpdate(); 241 242 protected: 243 244 Actor* mGate; 245 }; 246 247 class Blocker : public Actor 248 { 249 public: 250 Blocker(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib); 251 252 protected: 253 }; 254 255 class Test_Blocker : public Blocker 256 { 257 public: 258 Test_Blocker(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib); 259 260 bool EventProcess(Event eve); 261 262 bool UpdateAnimation(); 263 264 bool ActorUpdate(); 265 protected: 266 }; 267 268 class Gate : public Blocker 269 { 270 public: 271 Gate(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib, int dir); 272 273 bool EventProcess(Event eve); 274 275 bool UpdateAnimation(); 276 277 bool ActorUpdate(); 278 protected: 279 }; 280 281 class Interactable : public Actor 282 { 283 public: 284 285 Interactable(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib); 286 287 protected: 288 }; 289 290 class Talker : public Interactable 291 { 292 public: 293 Talker(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib, char* str) : Interactable(AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib), mStr(str) 294 {} 295 296 bool EventProcess(Event eve); 297 298 bool UpdateAnimation(); 299 300 bool ActorUpdate(); 301 302 protected: 303 304 char* mStr; 305 }; 306 307 class Gateman : public Talker 308 { 309 public: 310 311 //Gateman(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib, char* str, EventReceiver* gate) : Talker(AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib, str), mGate(gate) 312 Gateman(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib, char* str, int gate) : Talker(AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib, str), mGateH(gate) 313 { 314 mLOS = Pos; 315 mLOS.w = 250; 316 mLOS.x = mLOS.x - 125 - (int)((float)mPosData.w / 2);//(mLOS.x - (30 - (mPosData.w) / 2)); 317 mLOS.h = 70; 318 319 mTalked = false; 320 mState = GATE_DOWN; 321 } 322 323 bool EventProcess(Event eve); 324 325 bool UpdateAnimation(); 326 327 bool ActorUpdate(); 328 329 protected: 330 331 SDL_Rect mLOS; 332 //EventReceiver* mGate; 333 int mGateH; 334 335 bool mTalked; 336 }; 337 338 class Door : public Interactable 339 { 340 public: 341 342 Door(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib, int x_off, int y_off) : Interactable(AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib) 343 { 344 mTele_Pos = mPosData; 345 mTele_Pos.x += x_off; 346 mTele_Pos.y += y_off; 347 } 348 349 SDL_Rect* GetTelePos() 350 { 351 return &mTele_Pos; 352 } 353 354 void SetTeleDest(SDL_Rect* dest) 355 { 356 mTele_Dest = dest; 357 } 358 359 bool EventProcess(Event eve); 360 361 bool UpdateAnimation(); 362 363 bool ActorUpdate(); 364 365 protected: 366 367 SDL_Rect mTele_Pos; 368 SDL_Rect* mTele_Dest; 369 }; 370 371 class Mobile : public Actor 372 { 373 public: 374 375 Mobile() : mXspd(0), mYspd(0) {} 376 377 Mobile(AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib); 378 379 void SetPosition(SDL_Rect* Dest); 380 381 bool ModifyActorPosition(int x, int y); 382 383 SDL_Rect MoveActor(int xspd, int yspd); 384 385 int MoveActorDirect(float xspd, float yspd); 386 387 protected: 388 float mXspd; 389 float mYspd; 390 int mXmove; 391 int mYmove; 392 }; 393 394 class Hat : public Mobile 395 { 396 public: 397 Hat(AnimGraph* AnimData, Actor* tar, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : mTarget(tar), Mobile(AnimData, *tar->GetPosition(), *tar->GetDrawPosition(), AHM, spat, prtLib, SoundLib) 398 { 399 mEnabled = true; 400 } 401 402 bool IsEnabled() 403 { 404 return mEnabled; 405 } 406 407 void ToggleHat(bool state) 408 { 409 mEnabled = state; 410 } 411 412 bool EventProcess(Event eve) 413 { 414 return true; 415 } 416 417 bool ActorUpdate(); 418 419 protected: 420 421 Actor* mTarget; 422 bool mEnabled; 423 }; 424 425 class bad_hat : public Hat 426 { 427 public: 428 429 bad_hat(AnimGraph* AnimData, Actor* tar, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : Hat(AnimData, tar, AHM, spat, prtLib, SoundLib) 430 { 431 } 432 433 bool UpdateAnimation() 434 { 435 switch (mState) 436 { 437 case RUN: 438 default: 439 mAnimID = IDLE; 440 break; 441 } 442 mFrame = mAnimGraph->UpdateAnimation(); 443 return false; 444 } 445 protected: 446 }; 447 448 class sword : public Hat 449 { 450 public: 451 452 sword(AnimGraph* AnimData, Actor* tar, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : Hat(AnimData, tar, AHM, spat, prtLib, SoundLib) 453 { 454 mEnabled = false; 455 } 456 457 bool UpdateAnimation() 458 { 459 mAnimID = mTarget->GetAnimID(); 460 mFrame = mAnimGraph->UpdateAnimation(); 461 return false; 462 } 463 protected: 464 }; 465 466 class Character : public Mobile 467 { 468 public: 469 470 Character() {} 471 472 Character(SDL_Surface* ter, AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib); 473 474 bool DetectFalling() 475 { 476 SDL_Rect GroundDetector = mPosData; 477 GroundDetector.y = (mPosData.y + mPosData.h); 478 GroundDetector.h = 1; 479 if (mColMan.DetectFalling() == true && (mSpat->EventProcess(Event(CHECK_BLOCKERS, Touch, &GroundDetector, mSpatID)) == false)) 480 { 481 return true; 482 } 483 else 484 { 485 return false; 486 } 487 } 488 489 bool UpdatePhysics(); 490 491 bool UpdateFireables(); 492 493 Trajectory GetTrajectory(SDL_Rect Dest, SDL_Rect Init); 494 495 SDL_Rect RefinePosition(SDL_Rect* Dest, Trajectory trj, float destx, float desty, int RecursionCount = 0); 496 497 bool HandleDirectionalCollisions(SDL_Rect& Destination); 498 499 bool UpdatePosition(); 500 501 TerrainCollisionManager* getColMan() 502 { 503 return &mColMan; 504 } 505 506 protected: 507 508 SDL_Rect mDestData; 509 colman_Character mColMan; 510 PhysicsManager mPhysMan; 511 }; 512 513 class Player : public Character 514 { 515 public: 516 Player() {} 517 518 Player(SDL_Surface* ter, AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : mWielded(false), mTalker(NULL), mHP(100), mHPmax(100), mRecover(0), mTouch(Pos), Character(ter, AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib) 519 { 520 mTouch.h = Pos.h; 521 mTouch.w = 18; 522 } 523 524 bool EventProcess(Event eve); 525 526 bool UpdateAnimation(); 527 528 bool ActorUpdate(); 529 530 int* GetHP() 531 { 532 return &mHP; 533 } 534 535 int* GetMaxHP() 536 { 537 return &mHPmax; 538 } 539 540 void SetSword(int index) 541 { 542 mHatIndex_Sword = index; 543 } 544 545 protected: 546 547 // bool mTalking; 548 EventReceiver* mTalker; 549 550 bool mWielded; 551 int mHatIndex_Sword; 552 553 int mHP; 554 int mHPmax; 555 556 int mRecover; //Timer to force recovery pause between jumps 557 558 SDL_Rect mTouch; //Rect that deterimes what can be interacted with 559 }; 560 561 class Loyal_Bug : public Character 562 { 563 public: 564 Loyal_Bug(SDL_Surface* ter, AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : mMounted(false), Character(ter, AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib) 565 { 566 } 567 568 bool EventProcess(Event eve); 569 570 bool UpdateAnimation(); 571 572 bool ActorUpdate(); 573 574 protected: 575 576 bool mMounted; 577 }; 578 579 class Bug : public Character 580 { 581 public: 582 Bug(SDL_Surface* ter, AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : Character(ter, AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib) 583 { 584 } 585 586 protected: 587 588 int mTimer; 589 590 }; 591 592 class Wanderer : public Character 593 { 594 public: 595 596 Wanderer() : mWaitLimit(0), mWaitTimer(0), mWanderLimit(0), mWanderTimer(0) {} 597 598 Wanderer(SDL_Surface* ter, AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : Character(ter, AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib), mWanderTimer(0), mWanderLimit(0), mWaitTimer(0), mWaitLimit(0) 599 { 600 } 601 602 bool Wander(); 603 604 bool WaitRandom(); 605 606 bool EventProcess(Event eve); 607 608 virtual bool UpdateAnimation(); 609 610 bool ActorUpdate(); 611 612 protected: 613 614 int mWanderTimer; 615 int mWanderLimit; 616 int mWaitLimit; 617 int mWaitTimer; 618 }; 619 620 class Pursuer : public Character 621 { 622 public: 623 Pursuer() {} 624 625 Pursuer(SDL_Surface* ter, AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : Character(ter, AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib), mRestTimer(0) 626 { 627 mState = IDLE; 628 mLOS = mPosData; 629 mLOS.x -= (170 - mLOS.w) / 2; 630 mLOS.w = 170; 631 } 632 633 bool Pursue(); 634 635 bool rest(int t); 636 637 bool EventProcess(Event eve); 638 639 virtual bool UpdateAnimation(); 640 641 bool ActorUpdate(); 642 643 protected: 644 645 Actor* mTarget; 646 int mRestTimer; 647 SDL_Rect mLOS; 648 }; 649 650 class Rabbit : public Character 651 { 652 public: 653 Rabbit() {} 654 655 Rabbit(SDL_Surface* ter, AnimGraph* AnimData, SDL_Rect Pos, SDL_Rect DrawPos, ActorHandleManager* AHM, EventReceiver* spat, EventReceiver* prtLib, EventReceiver* SoundLib) : Character(ter, AnimData, Pos, DrawPos, AHM, spat, prtLib, SoundLib), mWaitLimit(0), mWaitTimer(0), mWanderLimit(0), mWanderTimer(0) 656 { 657 } 658 659 bool Hop(); 660 661 bool Wander(); 662 663 bool Behave(); 664 665 bool WaitRandom(); 666 667 bool EventProcess(Event eve); 668 669 virtual bool UpdateAnimation(); 670 671 bool ActorUpdate(); 672 673 protected: 674 675 int mWanderTimer; 676 int mWanderLimit; 677 int mWaitLimit; 678 int mWaitTimer; 679 }; 680 681 #endif