chip.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////
  19. // Blue Includes.
  20. //////////////////////////////////////////////////////////////////////
  21. #include "RSPiX.h"
  22. //////////////////////////////////////////////////////////////////////
  23. // Green Includes.
  24. //////////////////////////////////////////////////////////////////////
  25. //#include "BLiT/blit2d/blimage.h"
  26. //#include "cdt/slist.h"
  27. //////////////////////////////////////////////////////////////////////
  28. // Macros.
  29. //////////////////////////////////////////////////////////////////////
  30. //////////////////////////////////////////////////////////////////////
  31. // Typedefs.
  32. //////////////////////////////////////////////////////////////////////
  33. class CChip
  34. {
  35. public: // Con/Destruction.
  36. // Default constructor.
  37. CChip();
  38. // Destructor.
  39. ~CChip();
  40. public: // Methods.
  41. // Set an image for this chip.
  42. void SetChipImage(RImage* pim)
  43. { m_pimChip = pim; }
  44. // Set background BKD for all chips.
  45. static void SetBackground(RImage* pimbkd)
  46. { ms_pimView = pimbkd; }
  47. // Set stack image for all chips.
  48. static void SetStackImage(RImage* pim)
  49. { ms_pimStack = pim; }
  50. // Move this chip to the new location.
  51. void SetPosition(long lX, long lY, long lZ);
  52. // Slide this chip on update to the new location.
  53. // lRate is the magnitude of the vector directing the
  54. // chip.
  55. // Returns 0 if successfully started.
  56. short Slide(long lX, long lY, long lZ, long lRate);
  57. // Reset this chip. Stop sliding, if doing so.
  58. // Initialize/Release all members.
  59. void Reset(void);
  60. // Called to motivate this chip.
  61. // Returns 0 normally, 1 if chip destroyed.
  62. short Update(void);
  63. // Called to draw this chip.
  64. void Draw(void);
  65. // Called to motivate all chips.
  66. static void Critical(void);
  67. // Destroy all current chips.
  68. static void DeleteAll(void);
  69. // Stack chip if necessary.
  70. // Returns 0 normally, 1 if chip destroyed.
  71. short Stack(void);
  72. // Mark this chip as not stackable if sStack is FALSE.
  73. void SetStackable(short sStackable)
  74. { m_sStackable = sStackable; }
  75. // Add to this stack.
  76. // Returns 0 on success.
  77. short Add(CChip* pchip);
  78. // Remove sNum chips from this stack.
  79. // Returns chip/stack on success; NULL on error.
  80. CChip* Sub(short sNum);
  81. void SetSize(short sNum)
  82. { m_sNumChips = sNum; }
  83. public: // Querries.
  84. // Get the sprite for this chip.
  85. RImage* GetChipImage(void)
  86. { return m_pimChip; }
  87. // Returns pointer to background BKD for all chips.
  88. static RImage* GetBackground(void)
  89. { return ms_pimView; }
  90. // Returns pointer to stack image for all chips.
  91. static RImage* GetStackImage(void)
  92. { return ms_pimStack; }
  93. // TRUE if sliding, FALSE otherwise.
  94. short IsSliding(void)
  95. { return m_sSliding; }
  96. // Returns the first chip found to be colliding
  97. // with this chip. If sTop is TRUE, the lowest,
  98. // the one with the greatest Y, is found.
  99. CChip* IsColliding(short sTop = FALSE);
  100. // Returns size of this stack.
  101. short GetSize(void)
  102. { return m_sNumChips; }
  103. // Returns the first chip/stack in the given rectangle.
  104. // Returns NULL if none found.
  105. static CChip* GetChipIn(long lX, long lY, long lW, long lH);
  106. protected: // Internal.
  107. void Init(void);
  108. protected:
  109. RImage* m_pimChip; // Pointer to this image's sprite.
  110. float m_fX; // Current x coordinate.
  111. float m_fY; // Current y coordinate.
  112. float m_fZ; // Current z coordinate.
  113. short m_sDestX; // Destination x coordinate.
  114. short m_sDestY; // Destination y coordinate.
  115. short m_sDestZ; // Destination z coordinate.
  116. short m_sRate; // Rate to destination.
  117. short m_sSliding; // Sliding if TRUE.
  118. short m_sStackable; // Stackable if not FALSE.
  119. short m_sNumChips; // If greater than 1, this is
  120. // a stack.
  121. static RSList<CChip, float> ms_slistChips; // List of all
  122. // chips sorted by
  123. // each chip's Z
  124. // position.
  125. static RImage* ms_pimView; // Background for all chips.
  126. static RImage* ms_pimStack; // Stack for all chips.
  127. };
  128. //////////////////////////////////////////////////////////////////////
  129. // EOF
  130. //////////////////////////////////////////////////////////////////////