JNR
laTile.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 */
30 
31 
39 
40 #include "laloadableobj.h"
41 
42 class laTile : public laLoadableObj
43 {
44 protected:
45 
46  //Containing segment object and position
47  //
48  friend class laSegment;
49  class laSegment* _pSegment;
50  unsigned _nSegX;
51  unsigned _nSegY;
52 
53  //Tileset
54  laTileset* _pTileset;
55 
56  //Tile Element
57  //
58  laElement* _pTile;
59  unsigned _nTileIndex;
60  unsigned _nVaration;
61 
62  //Collision domain
63  laCollisionDomain _domain;
64 
65  // Trap
66  //
67  rpgTrap* _pTrap;
68  laTexture _texTrap;
69  laColor _rgbTrap;
70  fxParticleSystem *_pfxTrap;
71 
72 public:
73  laTile(void);
74  ~laTile(void);
75 
76  // Draw the tile
77  //
78  void drawGeometry(laRenderer *r); // geomety that can be cached
79  void drawDynamicGeometry(laRenderer *r); // animated geometry
80  void drawFx(laRenderer *r); // particle and other fx
81 
82  inline M_BOOL isStatic() {
83  return !(_pTrap);
84  }
85 
86  inline M_BOOL isEmpty() {
87  return !(_pTile->getModelCnt() || _pTile->getFxCnt());
88  }
89 
90  inline M_BOOL isWithoutFx() {
91  return !(_pTile->getFxCnt() || _pTrap);
92  }
93 
94  // Animate the tile
95  //
96  void animate(laTimer &t);
97 
98  // Load from level file
99  //
100  virtual void load(class laFileParser *fp);
101 
102  // Collision domain
103  //
104  // This information is extracted from the correspodning 3D models in the tileset
105  // and positioned at the appropriate location
106  //
107  unsigned bulidDomain(laPoint3 pos); // returns domain size
108 
109  inline laCollisionDomain* getDomain() {
110  return &_domain;
111  }
112 
113  // Retreive the offset and rotation of this tile as dictated by the ZOffset function;
114  // This information is precomputed for all level segmnets and creates terrain curviture.
115  //
116  double getOffset();
117  double getAngle();
118 
119  // Accessing varied data members
120  //
121  inline void setTS(laTileset* pTileset) {
122  _pTileset = pTileset;
123  };
124 
125  inline void setTSIndex( unsigned n ) {
126  ASSERT(_pTileset, "laTile::setTSIndex: NULL tile-set");
127  _nTileIndex = n;
128  _pTile = (laElement*)(_pTileset->getElement(_nTileIndex));
129  }
130 
131  inline laTileset* getTS() const{
132  ASSERT(_pTileset, "laTile::getTS: NULL tile-set");
133  return _pTileset;
134  };
135 
136  inline laElement* getTSObject() {
137  ASSERT(_pTile, "laTile::getTile: NULL tile");
138  return _pTile;
139  };
140 
141  inline unsigned getTSIndex() const{
142  return _nTileIndex;
143  }
144 };
Level Terrain Building-block.
Definition: laTile.h:42
Base Class for Tileset Elements.
Definition: laElement.h:48
Interface for loadable objects.
Definition: laLoadableObj.h:43
Trap Properties.
Definition: rpgTrap.h:42
Terrain Semgnet.
Definition: laSegment.h:48
2D Texture
Definition: laTexture.h:45
Collision Domain.
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
Tileset Class.
Definition: laTileset.h:46
File Parser.
Definition: laFileParser.h:41