| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file jj1event.h |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created OpenJazz.h |
| 10 | * - 31st January 2006: Created level.h from parts of OpenJazz.h |
| 11 | * - 4th February 2009: Created events.h from parts of level.h |
| 12 | * - 11th February 2009: Created bullet.h from parts of events.h |
| 13 | * - 1st March 2009: Created bird.h from parts of events.h |
| 14 | * - 19th July 2009: Renamed events.h to event.h |
| 15 | * - 2nd March 2010: Created guardians.h from parts of event.h |
| 16 | * - 1st August 2012: Renamed event.h to jj1event.h |
| 17 | * |
| 18 | * @par Licence: |
| 19 | * Copyright (c) 2005-2012 AJ Thomson |
| 20 | * |
| 21 | * OpenJazz is distributed under the terms of |
| 22 | * the GNU General Public License, version 2.0 |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | #ifndef _EVENT_H |
| 28 | #define _EVENT_H |
| 29 | |
| 30 | |
| 31 | #include "../jj1level.h" |
| 32 | |
| 33 | #include "io/gfx/anim.h" |
| 34 | #include "level/movable.h" |
| 35 | #include "OpenJazz.h" |
| 36 | |
| 37 | |
| 38 | // Constants |
| 39 | |
| 40 | // Animations |
| 41 | #define E_LEFTANIM 0 |
| 42 | #define E_RIGHTANIM 1 |
| 43 | #define E_LFINISHANIM 2 |
| 44 | #define E_RFINISHANIM 3 |
| 45 | #define E_LSHOOTANIM 4 |
| 46 | #define E_RSHOOTANIM 5 |
| 47 | #define E_NOANIM 6 |
| 48 | |
| 49 | // Delays |
| 50 | #define T_FLASH 100 |
| 51 | |
| 52 | // Speed factors |
| 53 | #define ES_SLOW ITOF(80) |
| 54 | #define ES_FAST ITOF(240) |
| 55 | |
| 56 | |
| 57 | // Classes |
| 58 | |
| 59 | class Anim; |
| 60 | class JJ1LevelPlayer; |
| 61 | |
| 62 | /// JJ1 level event |
| 63 | class JJ1Event : public Movable { |
| 64 | |
| 65 | private: |
| 66 | void calcDimensions (); |
| 67 | |
| 68 | protected: |
| 69 | JJ1Event* next; ///< Next event |
| 70 | JJ1EventType* set; ///< Type |
| 71 | Anim* anim; ///< Current animation |
| 72 | fixed drawnX, drawnY; ///< Current drawing co-ordinates |
| 73 | fixed width, height; ///< Current dimensions |
| 74 | unsigned char gridX, gridY; ///< Grid position of the event |
| 75 | unsigned char animType; ///< Animation type (E_LEFTANIM, etc.) |
| 76 | unsigned int flashTime; ///< Time flash will end |
| 77 | bool noAnimOffset; |
| 78 | |
| 79 | JJ1Event (unsigned char gX, unsigned char gY); |
| 80 | |
| 81 | JJ1Event* remove (bool permanently); |
| 82 | void destroy (unsigned int ticks); |
| 83 | |
| 84 | void setAnimType (unsigned char type); |
| 85 | void setAnimFrame (int frame, bool looping); |
| 86 | |
| 87 | JJ1EventType* prepareStep (unsigned int ticks); |
| 88 | |
| 89 | public: |
| 90 | virtual ~JJ1Event (); |
| 91 | |
| 92 | JJ1Event* getNext (); |
| 93 | bool hit (JJ1LevelPlayer *source, int hits, unsigned int ticks); |
| 94 | bool isEnemy (); |
| 95 | bool isFrom (unsigned char gX, unsigned char gY); |
| 96 | bool overlap (fixed areaX, fixed areaY, fixed areaWidth, fixed areaHeight); |
| 97 | |
| 98 | virtual JJ1Event* step (unsigned int ticks) = 0; |
| 99 | virtual void draw (unsigned int ticks, int change) = 0; |
| 100 | void drawEnergy (unsigned int ticks); |
| 101 | |
| 102 | }; |
| 103 | |
| 104 | /// Standard JJ1 level event |
| 105 | class JJ1StandardEvent : public JJ1Event { |
| 106 | |
| 107 | private: |
| 108 | fixed node; ///< Current event path node |
| 109 | bool onlyLAnimOffset; |
| 110 | bool onlyRAnimOffset; |
| 111 | |
| 112 | void move (unsigned int ticks); |
| 113 | |
| 114 | public: |
| 115 | JJ1StandardEvent (JJ1EventType* event, unsigned char gX, unsigned char gY, fixed startX, fixed startY); |
| 116 | |
| 117 | JJ1Event* step (unsigned int ticks) override; |
| 118 | void draw (unsigned int ticks, int change) override; |
| 119 | |
| 120 | }; |
| 121 | |
| 122 | /// JJ1 level bridge |
| 123 | class JJ1Bridge : public JJ1Event { |
| 124 | |
| 125 | private: |
| 126 | fixed leftDipX; |
| 127 | fixed rightDipX; |
| 128 | |
| 129 | public: |
| 130 | JJ1Bridge (unsigned char gX, unsigned char gY); |
| 131 | |
| 132 | JJ1Event* step (unsigned int ticks) override; |
| 133 | void draw (unsigned int ticks, int change) override; |
| 134 | |
| 135 | }; |
| 136 | |
| 137 | #endif |
| 138 |