NXEngine v1.0.0.6
[NXEngine.git] / pause / objects.cpp
blob981239c042f789b1899c86c1a52599653e6c772b
2 // A miniature implementation of the object manager.
3 // It runs the little "mascots" that come on the screen after a while in the options menu.
4 #include "../nx.h"
5 #include "../common/llist.h"
6 #include "options.h"
7 #include "objects.fdh"
8 using namespace Options;
10 Object *firstobj, *lastobj;
12 #define OC_CONTROLLER 0
13 #define OC_QUOTE 1
14 #define OC_IKACHAN 2
16 void Options::init_objects()
18 firstobj = NULL;
19 lastobj = NULL;
20 create_object(0, 0, OC_CONTROLLER);
23 void Options::close_objects()
25 Object *o = firstobj;
26 while(o)
28 Object *next = o->next;
29 delete o;
30 o = next;
33 firstobj = lastobj = NULL;
36 void Options::run_and_draw_objects(void)
38 void (*ai_routine[])(Object *) = {
39 ai_oc_controller,
40 ai_oc_quote,
41 ai_oc_ikachan
44 // draw character
45 Object *o = firstobj;
46 while(o)
48 (*ai_routine[o->type])(o);
49 Object *next = o->next;
51 // cull deleted
52 if (o->deleted)
54 LL_REMOVE(o, prev, next, firstobj, lastobj);
55 delete o;
57 else if (o->sprite != SPR_NULL)
59 o->x += o->xinertia;
60 o->y += o->yinertia;
62 draw_sprite(o->x >> CSF, o->y >> CSF, o->sprite, o->frame, o->dir);
65 o = next;
69 Object *Options::create_object(int x, int y, int type)
71 static Object ZERO;
73 Object *o = new Object;
74 *o = ZERO;
76 o->x = x;
77 o->y = y;
78 o->type = type;
79 LL_ADD_END(o, prev, next, firstobj, lastobj);
81 return o;
86 void c------------------------------() {}
89 static void ai_oc_controller(Object *o)
91 //AIDEBUG;
93 switch(o->state)
95 case 0: // init
97 o->timer = 400;
98 o->state = 1;
100 break;
101 case 1: // delay before next event
103 if (--o->timer <= 0)
105 o->state = (++o->timer2 * 10);
106 o->timer = 0;
108 if (o->timer2 >= 2)
109 o->timer2 = 0;
112 break;
114 case 10: // quote
116 create_object(0, 0, OC_QUOTE);
117 o->timer = 1100;
118 o->state = 1;
120 break;
122 case 20: // ikachans
124 o->timer++;
126 // current
127 /*if (o->timer < 175)
129 if ((o->timer % 6) == 1)
130 create_object(-16<<CSF, random(-16, SCREEN_HEIGHT) << CSF, OC_CURRENT);
133 if (o->timer <= 150)
135 if ((o->timer % 10) == 1)
136 create_object(-16<<CSF, random(-16, SCREEN_HEIGHT) << CSF, OC_IKACHAN);
139 if (o->timer > 300)
140 o->state = 0;
142 break;
147 static void ai_oc_quote(Object *o)
149 //AIDEBUG;
151 switch(o->state)
153 case 0:
155 o->xmark = (SCREEN_WIDTH - 50) << CSF;
156 o->xmark2 = (SCREEN_WIDTH + 10) << CSF;
158 o->x = o->xmark2;
159 o->y = (SCREEN_HEIGHT - sprites[o->sprite].h - 8) << CSF;
160 o->dir = LEFT;
162 o->sprite = SPR_OC_QUOTE;
163 o->state = 20;
165 break;
167 case 20:
169 o->dir = LEFT;
170 o->timer = 0;
171 o->animtimer = 2;
172 o->state = 21;
174 case 21:
176 if (o->x > o->xmark)
178 ANIMATE(8, 0, 3);
179 XMOVE(0x100);
181 else
183 o->frame = 0;
184 o->xinertia = 0;
186 if (++o->timer > 20)
188 o->state = 22;
189 o->timer = 0;
190 o->frame = 4;
194 break;
195 case 22:
197 o->timer++;
198 if (o->timer == 100) o->frame = 0;
199 if (o->timer > 130)
201 o->state = 30;
202 o->timer = 0;
203 o->dir = RIGHT;
206 break;
208 case 30:
210 ANIMATE(8, 0, 3);
211 XMOVE(0x100);
213 if (o->x > o->xmark2)
214 o->deleted = true;
216 break;
221 static void ai_oc_ikachan(Object *o)
223 switch(o->state)
225 case 0:
227 o->state = 1;
228 o->timer = random(3, 20);
229 o->sprite = SPR_IKACHAN;
231 case 1: // he pushes ahead
233 if (--o->timer <= 0)
235 o->state = 2;
236 o->timer = random(10, 50);
237 o->frame = 1;
238 o->xinertia = 0x600;
241 break;
243 case 2: // after a short time his tentacles look less whooshed-back
245 if (--o->timer <= 0)
247 o->state = 3;
248 o->timer = random(40, 50);
249 o->frame = 2;
250 o->yinertia = random(-0x100, 0x100);
253 break;
255 case 3: // gliding
257 if (--o->timer <= 0)
259 o->state = 1;
260 o->timer = 0;
261 o->frame = 0;
264 o->xinertia -= 0x10;
266 break;
269 if (o->x > SCREEN_WIDTH<<CSF)
270 o->deleted = true;
274 static void ai_oc_current(Object *o)
276 o->sprite = SPR_WATER_DROPLET;
277 o->frame = random(0, 4);
279 o->xinertia = 0x400;
281 if (o->x > SCREEN_WIDTH<<CSF)
282 o->deleted = true;