1 /* 2 * Holotz's Castle 3 * Copyright (C) 2004 Juan Carlos Seijo P�rez 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License as published by the Free 7 * Software Foundation; either version 2 of the License, or (at your option) 8 * any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 59 17 * Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Juan Carlos Seijo P�rez 20 * jacob@mainreactor.net 21 */ 22 23 /** Level timer for holotz's castle. 24 * @file HCTimer.h 25 * @author Juan Carlos Seijo P�rez 26 * @date 04/10/2004 27 * @version 0.0.1 - 4/10/2004 - First version. 28 */ 29 30 #ifndef _HCTIMER_INCLUDED 31 #define _HCTIMER_INCLUDED 32 33 #include <JLib/Util/JTimer.h> 34 #include <JLib/Graphics/JImage.h> 35 #include <JLib/Graphics/JFont.h> 36 37 /** Tracks the time elapsed within the level and updates the marker. 38 */ 39 class HCTimer : public JDrawable, public JTimer 40 { 41 protected: 42 JImage *img; /**< Image to draw the time remaining to. */ 43 s32 maxTime; /**< Maximum time. */ 44 JFont *font; /**< Font to use. */ 45 46 /** Build the given time's image. 47 * @param t Seconds to show. 48 * @return <b>true</b> if succedded, <b>false</b> otherwise. 49 */ 50 bool Build(u16 t, u8 r, u8 g, u8 b); 51 52 public: 53 /** Creates an empty timer. 54 */ HCTimer()55 HCTimer() : img(0), maxTime(0), font(0) 56 {} 57 58 /** Initializes the timer. 59 * @param t Seconds to count. 60 * @param f Font to use to render the text. 61 * @return <b>true</b> if succedded, <b>false</b> otherwise. 62 */ 63 bool Init(u16 t, JFont *f); 64 65 /** Checks whether the time has elapsed or not. 66 * @return Milliseconds remaining to end (note: <= 0 if finished). 67 */ TimeRemaining()68 s32 TimeRemaining() {return maxTime - TotalLap();} 69 70 /** Draws the timer. 71 */ 72 virtual void Draw(); 73 74 /** Updates the timer. 75 * @return 0 if not finished, -1 if so. 76 */ 77 virtual s32 Update(); 78 79 /** Destroys the associated image. 80 */ Destroy()81 void Destroy() {JDELETE(img);} 82 83 /** Destroys the object. 84 */ ~HCTimer()85 virtual ~HCTimer() {Destroy();} 86 }; 87 88 #endif // _HCTIMER_INCLUDED 89