JNR
laPlayer.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 #ifndef M_PLAYER_H
30 #define M_PLAYER_H
31 
33 
34 
40 
41 #define M_PLAYER_ATTACK_BASIC 0
42 #define M_PLAYER_ATTACK_QUICK 1
43 
44 // Player class
45 //
47 {
48  //Can be constructed from class name
49  CLASS_NAME(laPlayer);
50 
51  void _load_profile(char* strName);
52 protected:
53 
54  fxShutter shutterHit;
55  fxShutter shutterDeath;
56 
57  M_BOOL _bEnableBattleZoom;
58  M_BOOL _bBattleMode;
59 
60  double _dMonsterDistance;
61  laTimeTrig _ttBattleStance;
62 
63  rpgTrap *_pActiveTrap;
64 
65  // Level-up flags and triggers
66  //
67  fxParticleSystem _cbLevelUp;
68  fxParticleSystem _cbSkillUp;
69 
70  // Active NPC dialog
71  //
72  class laNPCDialog *_pNPCDialog;
73 
74  // Items inventory, Potions inventory
75  //
76  uiInventory _uiPotionsWindow;
77  uiInventory _uiInventoryWindow;
78  unsigned _nLastWeapon; //remember last active; used when switching to peaceful mode
79 
80  // GUI associated with the player
81  //
82  cuiProgressBar _IndicatorHP;
83  cuiProgressBar _IndicatorXP;
84 
85  laTexture _HBarTex;
86 
87  // Sounds
88  //
89  laSound* _pLevelupSound;
90 
91  laSound* _pStepSound;
92  laSound* _pLandSound;
93  laSound* _pJumpSound;
94 
95  laSound* _pCollectSound;
96  laSound* _pPotionSound;
97 
98 
99  //void _draw_potions_ui(laRenderer *r, laPoint3 ptBasePos);
100  void _draw_status_ui(laRenderer *r, laPoint3 ptBasePos);
101 
102  void _level_up();
103 
104  virtual unsigned _next_state( unsigned nCurrentState );
105 
106  laTimeTrig _ttPeacefulAction;
107 
108  rpgWeapon *_pwPeace;
109 
110 public:
111 
112  void saveProfile(FILE* f);
113 
114  uiInventory* getPotionsGUI() { return &_uiPotionsWindow; }
115  uiInventory* getItemsGUI() { return &_uiInventoryWindow; }
116 
117  // Constructor/destuctor
118  //
119  laPlayer(rpgSheet* pSheet = NULL);
120  ~laPlayer(void);
121 
122  // Respawn character
123  //
124  virtual void respawn();
125 
126  void enableBattleZoom(M_BOOL enable) {_bEnableBattleZoom = enable; }
127  void ctlBattleMode(){ _bBattleMode = M_TRUE;};
128  M_BOOL isInBattle(){return _bBattleMode; }
129 
130  double getMonsterDistance() { return _dMonsterDistance; }
131  void setMonsterDistance(double d) { _dMonsterDistance = d; }
132 
133  // Peaceful Mode
134  //
135  void modePeaceful(M_BOOL on)
136  {
137  rpgInventory* pInv = & ( ((rpgSheet_PlayableChar*)getSheet())->properties()->items );
138 
139  if( isPeaceful() == on ) return;
140 
141  if( on ){
142  //Remember weapon index and activate wo ( the "peaceful" weapon)
143  _nLastWeapon = pInv->activeIndex();
144  _uiInventoryWindow.select(0);
145  }
146  else{
147  //Retrun to last weapon
148  _uiInventoryWindow.select( _nLastWeapon );
149  }
150 
151  //_bPeacefulMode = on;
152  }
153 
154  M_BOOL isPeaceful() {
155  rpgInventory* pInv = & ( ((rpgSheet_PlayableChar*)getSheet())->properties()->items );
156  return pInv->activeIndex() ? M_FALSE : M_TRUE; /*_bPeacefulMode;*/
157  }
158 
159  M_BOOL isActionActive() { return !_ttPeacefulAction.isElapsed(); }
160  virtual void attackInitiate(M_BOOL bQuick = M_FALSE);
161 
162  virtual void hit( rpgAttack attack ); // hit me
163 
164  // Reflect trajectory (when touch damage is inflicted)
165  //
166  void reflect(/*M_BOOL bAffectX = M_TRUE*/ const laRect2 &rReference);
167 
168  // Special actions
169  // These methods can be invoced by collectable items
170  //
171  void heal( unsigned nHP );
172  void collect( unsigned nXP );
173  M_BOOL collect( rpgItem *item ); // true if a new entry in the inventory
174 
175  void skillUp( unsigned nSkill );
176 
177  // Potion actions
178  //
179  //unsigned potionDrink(laPotion* pPotion);
180  //void potionDiscardEffect(unsigned i);
181 
182  // Get info from the character sheet
183  //
184  unsigned getLevel() {return ((rpgSheet_PlayableChar*)_pSheet)->properties()->nLevel;}
185  unsigned getXP() {return ((rpgSheet_PlayableChar*)_pSheet)->properties()->nXP;}
186 
187 
188  // Draw the character and associated GUI
189  //
190  virtual void _draw_positioned_rotated(laRenderer *r);
191  virtual void _draw_positioned(laRenderer *r);
192  virtual void drawFx(laRenderer *r, laPoint3 ptBasePos);
193  virtual void _drawFx_positioned(laRenderer *r);
194  virtual void drawInterface(laRenderer *r, laPoint3 ptBasePos);
195 
196  // Animate the character
197  //
198  virtual void animate(laTimer &t);
199 
200  void animate_DeathMode(laTimer &t);
201  //void animate__level_up(laTimer &t);
202  void animate_TrapDamage(laTimer &t);
203  void animate_BattleZoom(laTimer &t);
204  void animate_Attack(laTimer &t);
205  void animate_Movement(laTimer &t);
206 
207  //This method is part of the laLoadableObj interface
208  //
209  virtual void load(class laFileParser *fp);
210 
211  // NPC dialog
212  //
213  void enableDialog(class laNPCDialog *pd) { _pNPCDialog = pd; }
214  M_BOOL isDialogActive() { return (_pNPCDialog!=NULL); }
215 
216 };
218 #endif //#ifndef M_PLAYER_H
Playable Character.
Definition: laPlayer.h:46
Item inventory.
Definition: uiInventory.h:49
Trap Properties.
Definition: rpgTrap.h:42
Dialog for interacting with non-player characters.
Definition: aiNPCDialog.h:40
Abstract RPG Properties Sheet.
Definition: rpgSheet.h:107
2D rectangle (used by the GUI and also as a simple tool for proximity testing)
Definition: laRect2.h:39
2D Texture
Definition: laTexture.h:45
Player RPG Properties.
Time-triggered events.
Definition: laTimeTrig.h:41
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
Attack RPG Properties.
Definition: rpgAttack.h:55
File Parser.
Definition: laFileParser.h:41
Sound Class.
Definition: laSound.h:40