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