File: animate.h

package info (click to toggle)
exult 1.2-4
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 9,040 kB
  • ctags: 10,543
  • sloc: cpp: 99,373; sh: 8,333; ansic: 4,659; makefile: 988; yacc: 769; lex: 313; xml: 19
file content (192 lines) | stat: -rw-r--r-- 5,227 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
 **	Animate.h - Animated game objects.
 **
 **	Written: 7/27/2000 - JSF
 **/

/*
Copyright (C) 2000  Jeffrey S. Freedman

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef INCL_ANIMATE
#define INCL_ANIMATE	1

#include "iregobjs.h"

/*
 *	An animator:
 */
class Animator : public Time_sensitive, public Game_singletons
	{
protected:
	Game_object *obj;		// Object we're controlling.
	unsigned char deltax, deltay;	// If wiggling, deltas from
					//   original position.
	bool animating;			// 1 if animation turned on.
	int sfxnum;			// Sound effects #, or -1 if none.
	void start_animation();
public:
	Animator(Game_object *o, int snum = -1) 
		: obj(o), deltax(0), deltay(0), animating(false), sfxnum(snum)
		{  }
	static Animator *create(Game_object *ob);
	~Animator();
	void want_animation()		// Want animation on.
		{
		if (!animating)
			start_animation();
		}
	int get_deltax()
		{ return deltax; }
	int get_deltay()
		{ return deltay; }
	virtual int get_framenum();
	};

/*
 *	Animate by going through frames.
 */
class Frame_animator : public Animator
	{
	unsigned char first_frame;	// First frame of animation.
	unsigned char frames;		// # of frames.
	unsigned int created;		// Time created
	unsigned int delay;		// Rate of animation
	unsigned short last_shape;	// To check if we need to re init
	unsigned short last_frame;	// To check if we need to re init
	enum				// Type of animation
	{
		FA_LOOPING = 0,
		FA_SUNDIAL = 1,
		FA_ENERGY_FIELD = 2
	} type;
	void Initialize();
public:
	Frame_animator(Game_object *o);
	virtual int get_framenum();
					// For Time_sensitive:
	virtual void handle_event(unsigned long time, long udata);
	};

/*
 *	Just play SFX.
 */
class Sfx_animator : public Animator
	{
public:
	Sfx_animator(Game_object *o);
					// For Time_sensitive:
	virtual void handle_event(unsigned long time, long udata);
	};

/*
 *	Animate by going through frames, but only do the lower frames once.
 */
class Field_frame_animator : public Animator
	{
	unsigned char frames;		// # of frames.
	unsigned char recycle;		// # of frame to recycle at.
	bool activated;			// Time to check for damage.
public:
	friend class Field_object;
	Field_frame_animator(Game_object *o, int rcy);
					// For Time_sensitive:
	virtual void handle_event(unsigned long time, long udata);
	};

/*
 *	Animate by wiggling.
 */
class Wiggle_animator : public Animator
	{
public:
	Wiggle_animator(Game_object *o) : Animator(o)
		{  }
					// For Time_sensitive:
	virtual void handle_event(unsigned long time, long udata);
	};

/*
 *	An object that cycles through its frames, or wiggles if just one
 *	frame.  The base class is for those in U7chunks.
 */
class Animated_object : public Terrain_game_object
	{
	Animator *animator;		// Controls animation.
public:
	Animated_object(int shapenum, int framenum, unsigned int tilex, 
	       unsigned int tiley, unsigned int lft = 0);
	virtual ~Animated_object();
					// Render.
	virtual void paint();
					// +++++Needed on this one:
					// Get coord. where this was placed.
	virtual Tile_coord get_original_tile_coord() const
		{ return get_tile() + 
			Tile_coord(-animator->get_deltax(), 
				   -animator->get_deltay(), 0); }
	};

/*
 *	An object that cycles through its frames, or wiggles if just one
 *	frame.  This is the IREG version.
 */
class Animated_ireg_object : public Ireg_game_object
	{
	Animator *animator;		// Controls animation.
public:
	Animated_ireg_object(int shapenum, int framenum, unsigned int tilex, 
	       unsigned int tiley, unsigned int lft = 0);
	virtual ~Animated_ireg_object();
					// Render.
	virtual void paint();
					// Get coord. where this was placed.
	virtual Tile_coord get_original_tile_coord() const
		{ return get_tile() + 
			Tile_coord(-animator->get_deltax(), 
				   -animator->get_deltay(), 0); }

				// Write out to IREG file.
	virtual void write_ireg(DataSource* out);
	};

/*
 *	An object that cycles through its frames, or wiggles if just one
 *	frame.  This is the IFIX version.
 */
class Animated_ifix_object : public Ifix_game_object
	{
	Animator *animator;		// Controls animation.
public:
	Animated_ifix_object(unsigned char *ifix);
	Animated_ifix_object(int shapenum, int framenum, unsigned int tilex, 
	       unsigned int tiley, unsigned int lft = 0);
	virtual ~Animated_ifix_object();
					// Render.
	virtual void paint();
					// Get coord. where this was placed.
	virtual Tile_coord get_original_tile_coord() const
		{ return get_tile() + 
			Tile_coord(-animator->get_deltax(), 
				   -animator->get_deltay(), 0); }

	virtual void write_ifix(DataSource* ifix);

	};
#endif