GameObjectFactory.java revision cfd74d65d832137e20e193c960802afba73b5d38
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.replica.replicaisland;
18
19import java.util.Comparator;
20
21import com.replica.replicaisland.AnimationComponent.PlayerAnimations;
22import com.replica.replicaisland.CollisionParameters.HitType;
23import com.replica.replicaisland.EnemyAnimationComponent.EnemyAnimations;
24import com.replica.replicaisland.GameObject.ActionType;
25import com.replica.replicaisland.GameObject.Team;
26
27/** A class for generating game objects at runtime.
28 * This should really be replaced with something that is data-driven, but it is hard to do data
29 * parsing quickly at runtime.  For the moment this class is full of large functions that just
30 * patch pointers between objects, but in the future those functions should either be
31 * a) generated from data at compile time, or b) described by data at runtime.
32 */
33public class GameObjectFactory extends BaseObject {
34    private final static int MAX_GAME_OBJECTS = 256;
35    private final static ComponentPoolComparator sComponentPoolComparator = new ComponentPoolComparator();
36    private FixedSizeArray<FixedSizeArray<BaseObject>> mStaticData;
37    private FixedSizeArray<GameComponentPool> mComponentPools;
38    private GameComponentPool mPoolSearchDummy;
39    private GameObjectPool mGameObjectPool;
40
41    private float mTightActivationRadius;
42    private float mNormalActivationRadius;
43    private float mWideActivationRadius;
44    private float mAlwaysActive;
45
46    private final static String sRedButtonChannel = "RED BUTTON";
47    private final static String sBlueButtonChannel = "BLUE BUTTON";
48    private final static String sGreenButtonChannel = "GREEN BUTTON";
49    private final static String sSurprisedNPCChannel = "SURPRISED";
50
51
52    // A list of game objects that can be spawned at runtime.  Note that the indicies of these
53    // objects must match the order of the object tileset in the level editor in order for the
54    // level content to make sense.
55    public enum GameObjectType {
56        INVALID(-1),
57
58        PLAYER (0),
59
60        // Collectables
61        COIN (1),
62        RUBY (2),
63        DIARY (3),
64
65        // Characters
66        WANDA (10),
67        KYLE (11),
68        KYLE_DEAD (12),
69        ANDOU_DEAD (13),
70        KABOCHA (26),
71        ROKUDOU_TERMINAL (27),
72        KABOCHA_TERMINAL (28),
73        EVIL_KABOCHA (29),
74        ROKUDOU (30),
75
76        // AI
77        BROBOT (16),
78        SNAILBOMB (17),
79        SHADOWSLIME (18),
80        MUDMAN (19),
81        SKELETON (20),
82        KARAGUIN (21),
83        PINK_NAMAZU (22),
84        TURRET (23),
85        TURRET_LEFT (24),
86        BAT (6),
87        STING(7),
88        ONION(8),
89
90        // Objects
91        DOOR_RED (32),
92        DOOR_BLUE (33),
93        DOOR_GREEN (34),
94        BUTTON_RED (35),
95        BUTTON_BLUE (36),
96        BUTTON_GREEN (37),
97        CANNON (38),
98        BROBOT_SPAWNER (39),
99        BROBOT_SPAWNER_LEFT (40),
100        BREAKABLE_BLOCK(41),
101        THE_SOURCE(42),
102
103        // Effects
104        DUST(48),
105        EXPLOSION_SMALL(49),
106        EXPLOSION_LARGE(50),
107        EXPLOSION_GIANT(51),
108
109
110        // Special Spawnable
111        DOOR_RED_NONBLOCKING (52),
112        DOOR_BLUE_NONBLOCKING (53),
113        DOOR_GREEN_NONBLOCKING (54),
114
115        GHOST_NPC(55),
116
117        CAMERA_BIAS(56),
118
119        SMOKE_BIG(57),
120        SMOKE_SMALL(58),
121
122        CRUSH_FLASH(59),
123        FLASH(60),
124
125        // Projectiles
126        ENERGY_BALL(68),
127        CANNON_BALL(65),
128        TURRET_BULLET(66),
129        BROBOT_BULLET(67),
130        BREAKABLE_BLOCK_PIECE(68),
131        BREAKABLE_BLOCK_PIECE_SPAWNER(69),
132        WANDA_SHOT(70),
133
134        // Special Objects -- Not spawnable normally
135        PLAYER_JETS(-1),
136        PLAYER_SPARKS(-1),
137        PLAYER_GLOW(-1),
138        ENEMY_SPARKS(-1),
139        GHOST(-1),
140        SMOKE_POOF(-1),
141        GEM_EFFECT(-1),
142        GEM_EFFECT_SPAWNER(-1),
143
144
145        // End
146        OBJECT_COUNT(-1);
147
148        private final int mIndex;
149        GameObjectType(int index) {
150            this.mIndex = index;
151        }
152
153        public int index() {
154            return mIndex;
155        }
156
157        // TODO: Is there any better way to do this?
158        public static GameObjectType indexToType(int index) {
159            final GameObjectType[] valuesArray = values();
160            GameObjectType foundType = INVALID;
161            for (int x = 0; x < valuesArray.length; x++) {
162                GameObjectType type = valuesArray[x];
163                if (type.mIndex == index) {
164                    foundType = type;
165                    break;
166                }
167            }
168            return foundType;
169        }
170
171    }
172
173    public GameObjectFactory() {
174        super();
175
176        mGameObjectPool = new GameObjectPool(MAX_GAME_OBJECTS);
177
178        final int objectTypeCount = GameObjectType.OBJECT_COUNT.ordinal();
179        mStaticData = new FixedSizeArray<FixedSizeArray<BaseObject>>(objectTypeCount);
180
181        for (int x = 0; x < objectTypeCount; x++) {
182            mStaticData.add(null);
183        }
184
185        final ContextParameters context = sSystemRegistry.contextParameters;
186        final float halfHeight2 = (context.gameHeight * 0.5f) * (context.gameHeight * 0.5f);
187        final float halfWidth2 = (context.gameWidth * 0.5f) * (context.gameWidth * 0.5f);
188        final float screenSizeRadius = (float)Math.sqrt(halfHeight2 + halfWidth2);
189        mTightActivationRadius = screenSizeRadius + 128.0f;
190        mNormalActivationRadius = screenSizeRadius * 1.25f;
191        mWideActivationRadius = screenSizeRadius * 2.0f;
192        mAlwaysActive = -1.0f;
193
194        // TODO: I wish there was a way to do this automatically, but the ClassLoader doesn't seem
195        // to provide access to the currently loaded class list.  There's some discussion of walking
196        // the actual class file objects and using forName() to instantiate them, but that sounds
197        // really heavy-weight.  For now I'll rely on (sucky) manual enumeration.
198        class ComponentClass {
199            public Class<?> type;
200            public int poolSize;
201            public ComponentClass(Class<?> classType, int size) {
202                type = classType;
203                poolSize = size;
204            }
205        }
206        ComponentClass[] componentTypes = {
207                new ComponentClass(AnimationComponent.class, 1),
208                new ComponentClass(AttackAtDistanceComponent.class, 16),
209                new ComponentClass(BackgroundCollisionComponent.class, 128),
210                new ComponentClass(ButtonAnimationComponent.class, 32),
211                new ComponentClass(CameraBiasComponent.class, 8),
212                new ComponentClass(ChangeComponentsComponent.class, 128),
213                new ComponentClass(DoorAnimationComponent.class, 256),  //!
214                new ComponentClass(DynamicCollisionComponent.class, 256),
215                new ComponentClass(EnemyAnimationComponent.class, 128),
216                new ComponentClass(FadeDrawableComponent.class, 32),
217                new ComponentClass(FixedAnimationComponent.class, 8),
218                new ComponentClass(GenericAnimationComponent.class, 32),
219                new ComponentClass(GhostComponent.class, 64),
220                new ComponentClass(GravityComponent.class, 128),
221                new ComponentClass(HitPlayerComponent.class, 256),
222                new ComponentClass(HitReactionComponent.class, 256),
223                new ComponentClass(InventoryComponent.class, 128),
224                new ComponentClass(LauncherComponent.class, 16),
225                new ComponentClass(LaunchProjectileComponent.class, 128),
226                new ComponentClass(LifetimeComponent.class, 256),
227                new ComponentClass(MotionBlurComponent.class, 1),
228                new ComponentClass(MovementComponent.class, 128),
229                new ComponentClass(NPCAnimationComponent.class, 8),
230                new ComponentClass(NPCComponent.class, 8),
231                new ComponentClass(OrbitalMagnetComponent.class, 1),
232                new ComponentClass(PatrolComponent.class, 128),
233                new ComponentClass(PhysicsComponent.class, 8),
234                new ComponentClass(PlayerComponent.class, 1),
235                new ComponentClass(PlaySingleSoundComponent.class, 32),
236                new ComponentClass(PopOutComponent.class, 32),
237                new ComponentClass(RenderComponent.class, 256),
238                new ComponentClass(ScrollerComponent.class, 8),
239                new ComponentClass(SelectDialogComponent.class, 8),
240                new ComponentClass(SimpleCollisionComponent.class, 32),
241                new ComponentClass(SimplePhysicsComponent.class, 128),
242                new ComponentClass(SleeperComponent.class, 32),
243                new ComponentClass(SolidSurfaceComponent.class, 16),
244                new ComponentClass(SpriteComponent.class, 256),
245                new ComponentClass(TheSourceComponent.class, 1),
246
247
248        };
249
250        mComponentPools = new FixedSizeArray<GameComponentPool>(componentTypes.length, sComponentPoolComparator);
251        for (int x = 0; x < componentTypes.length; x++) {
252            ComponentClass component = componentTypes[x];
253            mComponentPools.add(new GameComponentPool(component.type, component.poolSize));
254        }
255        mComponentPools.sort(true);
256
257        mPoolSearchDummy = new GameComponentPool(Object.class, 1);
258
259    }
260
261    @Override
262    public void reset() {
263
264    }
265
266    protected GameComponentPool getComponentPool(Class<?> componentType) {
267        GameComponentPool pool = null;
268        mPoolSearchDummy.objectClass = componentType;
269        final int index = mComponentPools.find(mPoolSearchDummy, false);
270        if (index != -1) {
271            pool = mComponentPools.get(index);
272        }
273        return pool;
274    }
275
276    protected GameComponent allocateComponent(Class<?> componentType) {
277        GameComponentPool pool = getComponentPool(componentType);
278        assert pool != null;
279        GameComponent component = null;
280        if (pool != null) {
281            component = pool.allocate();
282        }
283        return component;
284    }
285
286    protected void releaseComponent(GameComponent component) {
287        GameComponentPool pool = getComponentPool(component.getClass());
288        assert pool != null;
289        if (pool != null) {
290            component.reset();
291            component.shared = false;
292            pool.release(component);
293        }
294    }
295
296    public void preloadEffects() {
297        // These textures appear in every level, so they are long-term.
298        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
299        textureLibrary.allocateTexture(R.drawable.dust01);
300        textureLibrary.allocateTexture(R.drawable.dust02);
301        textureLibrary.allocateTexture(R.drawable.dust03);
302        textureLibrary.allocateTexture(R.drawable.dust04);
303        textureLibrary.allocateTexture(R.drawable.dust05);
304
305        textureLibrary.allocateTexture(R.drawable.effect_energyball01);
306        textureLibrary.allocateTexture(R.drawable.effect_energyball02);
307        textureLibrary.allocateTexture(R.drawable.effect_energyball03);
308        textureLibrary.allocateTexture(R.drawable.effect_energyball04);
309
310        textureLibrary.allocateTexture(R.drawable.effect_explosion_small01);
311        textureLibrary.allocateTexture(R.drawable.effect_explosion_small02);
312        textureLibrary.allocateTexture(R.drawable.effect_explosion_small03);
313        textureLibrary.allocateTexture(R.drawable.effect_explosion_small04);
314        textureLibrary.allocateTexture(R.drawable.effect_explosion_small05);
315        textureLibrary.allocateTexture(R.drawable.effect_explosion_small06);
316        textureLibrary.allocateTexture(R.drawable.effect_explosion_small07);
317
318        textureLibrary.allocateTexture(R.drawable.effect_explosion_big01);
319        textureLibrary.allocateTexture(R.drawable.effect_explosion_big02);
320        textureLibrary.allocateTexture(R.drawable.effect_explosion_big03);
321        textureLibrary.allocateTexture(R.drawable.effect_explosion_big04);
322        textureLibrary.allocateTexture(R.drawable.effect_explosion_big05);
323        textureLibrary.allocateTexture(R.drawable.effect_explosion_big06);
324        textureLibrary.allocateTexture(R.drawable.effect_explosion_big07);
325        textureLibrary.allocateTexture(R.drawable.effect_explosion_big08);
326        textureLibrary.allocateTexture(R.drawable.effect_explosion_big09);
327
328        textureLibrary.allocateTexture(R.drawable.effect_smoke_big01);
329        textureLibrary.allocateTexture(R.drawable.effect_smoke_big02);
330        textureLibrary.allocateTexture(R.drawable.effect_smoke_big03);
331        textureLibrary.allocateTexture(R.drawable.effect_smoke_big04);
332        textureLibrary.allocateTexture(R.drawable.effect_smoke_big05);
333
334        textureLibrary.allocateTexture(R.drawable.effect_smoke_small01);
335        textureLibrary.allocateTexture(R.drawable.effect_smoke_small02);
336        textureLibrary.allocateTexture(R.drawable.effect_smoke_small03);
337        textureLibrary.allocateTexture(R.drawable.effect_smoke_small04);
338        textureLibrary.allocateTexture(R.drawable.effect_smoke_small05);
339
340        textureLibrary.allocateTexture(R.drawable.effect_crush_back01);
341        textureLibrary.allocateTexture(R.drawable.effect_crush_back02);
342        textureLibrary.allocateTexture(R.drawable.effect_crush_back03);
343        textureLibrary.allocateTexture(R.drawable.effect_crush_front01);
344        textureLibrary.allocateTexture(R.drawable.effect_crush_front02);
345        textureLibrary.allocateTexture(R.drawable.effect_crush_front03);
346        textureLibrary.allocateTexture(R.drawable.effect_crush_front04);
347        textureLibrary.allocateTexture(R.drawable.effect_crush_front05);
348        textureLibrary.allocateTexture(R.drawable.effect_crush_front06);
349        textureLibrary.allocateTexture(R.drawable.effect_crush_front07);
350    }
351
352    public void destroy(GameObject object) {
353        object.commitUpdates();
354        final int componentCount = object.getCount();
355        for (int x = 0; x < componentCount; x++) {
356            GameComponent component = (GameComponent)object.get(x);
357            if (!component.shared) {
358                releaseComponent(component);
359            }
360        }
361        object.removeAll();
362        object.commitUpdates();
363        mGameObjectPool.release(object);
364    }
365
366    public GameObject spawn(GameObjectType type, float x, float y, boolean horzFlip) {
367        GameObject newObject = null;
368        switch(type) {
369            case PLAYER:
370                newObject = spawnPlayer(x, y);
371                break;
372            case COIN:
373                newObject = spawnCoin(x, y);
374                break;
375            case RUBY:
376                newObject = spawnRuby(x, y);
377                break;
378            case DIARY:
379                newObject = spawnDiary(x, y);
380                break;
381            case WANDA:
382                newObject = spawnEnemyWanda(x, y, true);
383                break;
384            case KYLE:
385                newObject = spawnEnemyKyle(x, y, true);
386                break;
387            case KYLE_DEAD:
388                newObject = spawnEnemyKyleDead(x, y);
389                break;
390            case ANDOU_DEAD:
391                newObject = spawnEnemyAndouDead(x, y);
392                break;
393            case KABOCHA:
394                newObject = spawnEnemyKabocha(x, y, true);
395                break;
396            case ROKUDOU_TERMINAL:
397                newObject = spawnRokudouTerminal(x, y);
398                break;
399            case KABOCHA_TERMINAL:
400                newObject = spawnKabochaTerminal(x, y);
401                break;
402            case EVIL_KABOCHA:
403                newObject = spawnEnemyEvilKabocha(x, y, true);
404                break;
405            case ROKUDOU:
406                newObject = spawnEnemyRokudou(x, y, true);
407                break;
408            case BROBOT:
409                newObject = spawnEnemyBrobot(x, y, horzFlip);
410                break;
411            case SNAILBOMB:
412                newObject = spawnEnemySnailBomb(x, y, horzFlip);
413                break;
414            case SHADOWSLIME:
415                newObject = spawnEnemyShadowSlime(x, y, horzFlip);
416                break;
417            case MUDMAN:
418                newObject = spawnEnemyMudman(x, y, horzFlip);
419                break;
420            case SKELETON:
421                newObject = spawnEnemySkeleton(x, y, horzFlip);
422                break;
423            case KARAGUIN:
424                newObject = spawnEnemyKaraguin(x, y, horzFlip);
425                break;
426            case PINK_NAMAZU:
427                newObject = spawnEnemyPinkNamazu(x, y, horzFlip);
428                break;
429            case BAT:
430                newObject = spawnEnemyBat(x, y, horzFlip);
431                break;
432            case STING:
433                newObject = spawnEnemySting(x, y, horzFlip);
434                break;
435            case ONION:
436                newObject = spawnEnemyOnion(x, y, horzFlip);
437                break;
438            case TURRET:
439            case TURRET_LEFT:
440                newObject = spawnObjectTurret(x, y, (type == GameObjectType.TURRET_LEFT));
441                break;
442            case DOOR_RED:
443            case DOOR_RED_NONBLOCKING:
444                newObject = spawnObjectDoor(x, y, GameObjectType.DOOR_RED, (type == GameObjectType.DOOR_RED));
445                break;
446            case DOOR_BLUE:
447            case DOOR_BLUE_NONBLOCKING:
448                newObject = spawnObjectDoor(x, y, GameObjectType.DOOR_BLUE, (type == GameObjectType.DOOR_BLUE));
449                break;
450            case DOOR_GREEN:
451            case DOOR_GREEN_NONBLOCKING:
452                newObject = spawnObjectDoor(x, y, GameObjectType.DOOR_GREEN, (type == GameObjectType.DOOR_GREEN));
453                break;
454            case BUTTON_RED:
455                newObject = spawnObjectButton(x, y, GameObjectType.BUTTON_RED);
456                break;
457            case BUTTON_BLUE:
458                newObject = spawnObjectButton(x, y, GameObjectType.BUTTON_BLUE);
459                break;
460            case BUTTON_GREEN:
461                newObject = spawnObjectButton(x, y, GameObjectType.BUTTON_GREEN);
462                break;
463            case CANNON:
464                newObject = spawnObjectCannon(x, y);
465                break;
466            case BROBOT_SPAWNER:
467            case BROBOT_SPAWNER_LEFT:
468                newObject = spawnObjectBrobotSpawner(x, y, (type == GameObjectType.BROBOT_SPAWNER_LEFT));
469                break;
470            case BREAKABLE_BLOCK:
471                newObject = spawnObjectBreakableBlock(x, y);
472                break;
473            case THE_SOURCE:
474            	newObject = spawnObjectTheSource(x, y);
475            	break;
476            case DUST:
477                newObject = spawnDust(x, y, horzFlip);
478                break;
479            case EXPLOSION_SMALL:
480                newObject = spawnEffectExplosionSmall(x, y);
481                break;
482            case EXPLOSION_LARGE:
483                newObject = spawnEffectExplosionLarge(x, y);
484                break;
485            case EXPLOSION_GIANT:
486                newObject = spawnEffectExplosionGiant(x, y);
487                break;
488            case GHOST_NPC:
489            	newObject = spawnGhostNPC(x, y);
490            	break;
491            case CAMERA_BIAS:
492            	newObject = spawnCameraBias(x, y);
493            	break;
494            case SMOKE_BIG:
495                newObject = spawnEffectSmokeBig(x, y);
496                break;
497            case SMOKE_SMALL:
498                newObject = spawnEffectSmokeSmall(x, y);
499                break;
500            case CRUSH_FLASH:
501                newObject = spawnEffectCrushFlash(x, y);
502                break;
503            case FLASH:
504                newObject = spawnEffectFlash(x, y);
505                break;
506            case ENERGY_BALL:
507                newObject = spawnEnergyBall(x, y, horzFlip);
508                break;
509            case CANNON_BALL:
510                newObject = spawnCannonBall(x, y, horzFlip);
511                break;
512            case TURRET_BULLET:
513                newObject = spawnTurretBullet(x, y, horzFlip);
514                break;
515            case BROBOT_BULLET:
516                newObject = spawnBrobotBullet(x, y, horzFlip);
517                break;
518            case BREAKABLE_BLOCK_PIECE:
519                newObject = spawnBreakableBlockPiece(x, y);
520                break;
521            case BREAKABLE_BLOCK_PIECE_SPAWNER:
522                newObject = spawnBreakableBlockPieceSpawner(x, y);
523                break;
524            case WANDA_SHOT:
525                newObject = spawnWandaShot(x, y, horzFlip);
526                break;
527            case SMOKE_POOF:
528            	newObject = spawnSmokePoof(x, y);
529            	break;
530            case GEM_EFFECT:
531            	newObject = spawnGemEffect(x, y);
532            	break;
533            case GEM_EFFECT_SPAWNER:
534            	newObject = spawnGemEffectSpawner(x, y);
535            	break;
536        }
537
538        return newObject;
539    }
540
541
542
543	public void spawnFromWorld(TiledWorld world, int tileWidth, int tileHeight) {
544        // Walk the world and spawn objects based on tile indexes.
545        final float worldHeight = world.getHeight() * tileHeight;
546        GameObjectManager manager = sSystemRegistry.gameObjectManager;
547        if (manager != null) {
548            for (int y = 0; y < world.getHeight(); y++) {
549                for (int x = 0; x < world.getWidth(); x++) {
550                    int index = world.getTile(x, y);
551                    if (index != -1) {
552                        GameObjectType type = GameObjectType.indexToType(index);
553                        if (type != GameObjectType.INVALID) {
554                            final float worldX = x * tileWidth;
555                            final float worldY = worldHeight - ((y + 1) * tileHeight);
556                            GameObject object = spawn(type, worldX, worldY, false);
557                            if (object != null) {
558                                if (object.height < tileHeight) {
559                                    // make sure small objects are vertically centered in their
560                                    // tile.
561                                    object.getPosition().y += (tileHeight - object.height) / 2.0f;
562                                }
563                                if (object.width < tileWidth) {
564                                    object.getPosition().x += (tileWidth - object.width) / 2.0f;
565                                } else if (object.width > tileWidth) {
566                                    object.getPosition().x -= (object.width - tileWidth) / 2.0f;
567                                }
568                                manager.add(object);
569                                if (type == GameObjectType.PLAYER) {
570                                    manager.setPlayer(object);
571                                }
572                            }
573                        }
574                    }
575                }
576            }
577        }
578    }
579
580
581    private FixedSizeArray<BaseObject> getStaticData(GameObjectType type) {
582        return mStaticData.get(type.ordinal());
583    }
584
585    private void setStaticData(GameObjectType type, FixedSizeArray<BaseObject> data) {
586        int index = type.ordinal();
587        assert mStaticData.get(index) == null;
588
589        final int staticDataCount = data.getCount();
590
591        for (int x = 0; x < staticDataCount; x++) {
592            BaseObject entry = data.get(x);
593            if (entry instanceof GameComponent) {
594                ((GameComponent) entry).shared = true;
595            }
596        }
597
598        mStaticData.set(index, data);
599    }
600
601    private void addStaticData(GameObjectType type, GameObject object, SpriteComponent sprite) {
602        FixedSizeArray<BaseObject> staticData = getStaticData(type);
603        assert staticData != null;
604
605        if (staticData != null) {
606            final int staticDataCount = staticData.getCount();
607
608            for (int x = 0; x < staticDataCount; x++) {
609                BaseObject entry = staticData.get(x);
610                if (entry instanceof GameComponent && object != null) {
611                    object.add((GameComponent)entry);
612                } else if (entry instanceof SpriteAnimation && sprite != null) {
613                    sprite.addAnimation((SpriteAnimation)entry);
614                }
615            }
616        }
617    }
618
619    public void clearStaticData() {
620        final int typeCount = mStaticData.getCount();
621        for (int x = 0; x < typeCount; x++) {
622            FixedSizeArray<BaseObject> staticData = mStaticData.get(x);
623            if (staticData != null) {
624                final int count = staticData.getCount();
625                for (int y = 0; y < count; y++) {
626                    BaseObject entry = staticData.get(y);
627                    if (entry != null) {
628                        if (entry instanceof GameComponent) {
629                            releaseComponent((GameComponent)entry);
630                        }
631                    }
632                }
633                staticData.clear();
634                mStaticData.set(x, null);
635            }
636        }
637    }
638
639    public void sanityCheckPools() {
640        final int outstandingObjects = mGameObjectPool.getAllocatedCount();
641        if (outstandingObjects != 0) {
642            DebugLog.d("Sanity Check", "Outstanding game object allocations! ("
643                    + outstandingObjects + ")");
644            assert false;
645        }
646
647        final int componentPoolCount = mComponentPools.getCount();
648        for (int x = 0; x < componentPoolCount; x++) {
649            final int outstandingComponents = mComponentPools.get(x).getAllocatedCount();
650
651            if (outstandingComponents != 0) {
652                DebugLog.d("Sanity Check", "Outstanding "
653                        + mComponentPools.get(x).objectClass.getSimpleName()
654                        + " allocations! (" + outstandingComponents + ")");
655                //assert false;
656            }
657        }
658    }
659
660    public GameObject spawnPlayer(float positionX, float positionY) {
661        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
662
663        GameObject object = mGameObjectPool.allocate();
664        object.getPosition().set(positionX, positionY);
665        object.activationRadius = mAlwaysActive;
666        object.width = 64;
667        object.height = 64;
668
669        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.PLAYER);
670
671        if (staticData == null) {
672            final int staticObjectCount = 13;
673            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
674
675            GameComponent gravity = allocateComponent(GravityComponent.class);
676            GameComponent movement = allocateComponent(MovementComponent.class);
677            PhysicsComponent physics = (PhysicsComponent)allocateComponent(PhysicsComponent.class);
678
679            physics.setMass(9.1f);   // ~90kg w/ earth gravity
680            physics.setDynamicFrictionCoeffecient(0.2f);
681            physics.setStaticFrictionCoeffecient(0.01f);
682
683            // Animation Data
684            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
685                new FixedSizeArray<CollisionVolume>(1);
686            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 32, 32));
687
688            FixedSizeArray<CollisionVolume> pressAndCollectVolume =
689                new FixedSizeArray<CollisionVolume>(2);
690            AABoxCollisionVolume collectionVolume = new AABoxCollisionVolume(16, 0, 32, 48);
691            collectionVolume.setHitType(HitType.COLLECT);
692            pressAndCollectVolume.add(collectionVolume);
693            AABoxCollisionVolume pressCollisionVolume = new AABoxCollisionVolume(16, 0, 32, 16);
694            pressCollisionVolume.setHitType(HitType.DEPRESS);
695            pressAndCollectVolume.add(pressCollisionVolume);
696
697            SpriteAnimation idle = new SpriteAnimation(PlayerAnimations.IDLE.ordinal(), 1);
698            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_stand),
699                    1.0f, pressAndCollectVolume, basicVulnerabilityVolume));
700
701            SpriteAnimation angle = new SpriteAnimation(PlayerAnimations.MOVE.ordinal(), 1);
702            angle.addFrame(
703                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_diag01),
704                            0.0416f, pressAndCollectVolume, basicVulnerabilityVolume));
705
706            SpriteAnimation extremeAngle = new SpriteAnimation(
707                    PlayerAnimations.MOVE_FAST.ordinal(), 1);
708            extremeAngle.addFrame(
709                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_diagmore01),
710                            0.0416f, pressAndCollectVolume, basicVulnerabilityVolume));
711
712            SpriteAnimation up = new SpriteAnimation(PlayerAnimations.BOOST_UP.ordinal(), 2);
713            up.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_flyup02),
714                    Utils.framesToTime(24, 1), pressAndCollectVolume, basicVulnerabilityVolume));
715            up.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_flyup03),
716                    Utils.framesToTime(24, 1), pressAndCollectVolume, basicVulnerabilityVolume));
717            up.setLoop(true);
718
719            SpriteAnimation boostAngle = new SpriteAnimation(PlayerAnimations.BOOST_MOVE.ordinal(), 2);
720            boostAngle.addFrame(
721                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_diag02),
722                            Utils.framesToTime(24, 1), pressAndCollectVolume, basicVulnerabilityVolume));
723            boostAngle.addFrame(
724                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_diag03),
725                            Utils.framesToTime(24, 1), pressAndCollectVolume, basicVulnerabilityVolume));
726            boostAngle.setLoop(true);
727
728            SpriteAnimation boostExtremeAngle = new SpriteAnimation(
729                    PlayerAnimations.BOOST_MOVE_FAST.ordinal(), 2);
730            boostExtremeAngle.addFrame(
731                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_diagmore02),
732                            Utils.framesToTime(24, 1), pressAndCollectVolume, basicVulnerabilityVolume));
733            boostExtremeAngle.addFrame(
734                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_diagmore03),
735                            Utils.framesToTime(24, 1), pressAndCollectVolume, basicVulnerabilityVolume));
736            boostExtremeAngle.setLoop(true);
737
738            FixedSizeArray<CollisionVolume> stompAttackVolume =
739                new FixedSizeArray<CollisionVolume>(3);
740            stompAttackVolume.add(new AABoxCollisionVolume(16, -5.0f, 32, 37, HitType.HIT));
741            stompAttackVolume.add(pressCollisionVolume);
742            stompAttackVolume.add(collectionVolume);
743
744            SpriteAnimation stomp = new SpriteAnimation(PlayerAnimations.STOMP.ordinal(), 4);
745            stomp.addFrame(
746                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_stomp01),
747                    		Utils.framesToTime(24, 1), stompAttackVolume, null));
748            stomp.addFrame(
749                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_stomp02),
750                    		Utils.framesToTime(24, 1), stompAttackVolume, null));
751            stomp.addFrame(
752                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_stomp03),
753                    		Utils.framesToTime(24, 1), stompAttackVolume, null));
754            stomp.addFrame(
755                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_stomp04),
756                    		Utils.framesToTime(24, 1), stompAttackVolume, null));
757
758            SpriteAnimation hitReactAnim = new SpriteAnimation(PlayerAnimations.HIT_REACT.ordinal(), 1);
759            hitReactAnim.addFrame(
760                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_hit),
761                            0.1f, pressAndCollectVolume, null));
762
763            SpriteAnimation deathAnim = new SpriteAnimation(PlayerAnimations.DEATH.ordinal(), 16);
764            AnimationFrame death1 =
765                new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_die01),
766                        Utils.framesToTime(24, 1), null, null);
767            AnimationFrame death2 =
768                new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_die02),
769                        Utils.framesToTime(24, 1), null, null);
770            deathAnim.addFrame(death1);
771            deathAnim.addFrame(death2);
772            deathAnim.addFrame(death1);
773            deathAnim.addFrame(death2);
774            deathAnim.addFrame(
775                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode01),
776                            Utils.framesToTime(24, 1), null, null));
777            deathAnim.addFrame(
778                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode02),
779                            Utils.framesToTime(24, 1), null, null));
780            deathAnim.addFrame(
781                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode03),
782                            Utils.framesToTime(24, 1), null, null));
783            deathAnim.addFrame(
784                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode04),
785                            Utils.framesToTime(24, 1), null, null));
786            deathAnim.addFrame(
787                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode05),
788                            Utils.framesToTime(24, 2), null, null));
789            deathAnim.addFrame(
790                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode06),
791                            Utils.framesToTime(24, 2), null, null));
792            deathAnim.addFrame(
793                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode07),
794                            Utils.framesToTime(24, 2), null, null));
795            deathAnim.addFrame(
796                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode08),
797                            Utils.framesToTime(24, 2), null, null));
798            deathAnim.addFrame(
799                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode09),
800                            Utils.framesToTime(24, 2), null, null));
801            deathAnim.addFrame(
802                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode10),
803                            Utils.framesToTime(24, 2), null, null));
804            deathAnim.addFrame(
805                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode11),
806                            Utils.framesToTime(24, 2), null, null));
807            deathAnim.addFrame(
808                    new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode12),
809                            Utils.framesToTime(24, 2), null, null));
810
811
812            SpriteAnimation frozenAnim = new SpriteAnimation(PlayerAnimations.FROZEN.ordinal(), 1);
813            // Frozen has no frames!
814
815
816            // Save static data
817            staticData.add(gravity);
818            staticData.add(movement);
819            staticData.add(physics);
820
821
822            staticData.add(idle);
823            staticData.add(angle);
824            staticData.add(extremeAngle);
825            staticData.add(up);
826            staticData.add(boostAngle);
827            staticData.add(boostExtremeAngle);
828            staticData.add(stomp);
829            staticData.add(hitReactAnim);
830            staticData.add(deathAnim);
831            staticData.add(frozenAnim);
832
833            setStaticData(GameObjectType.PLAYER, staticData);
834        }
835
836
837        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
838        render.setPriority(SortConstants.PLAYER);
839        BackgroundCollisionComponent bgcollision
840            = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
841        bgcollision.setSize(32, 48);
842        bgcollision.setOffset(16, 0);
843        PlayerComponent player = (PlayerComponent)allocateComponent(PlayerComponent.class);
844        AnimationComponent animation =
845            (AnimationComponent)allocateComponent(AnimationComponent.class);
846
847        animation.setPlayer(player);
848        SoundSystem sound = sSystemRegistry.soundSystem;
849        if (sound != null) {
850            animation.setLandThump(sound.load(R.raw.thump));
851            animation.setRocketSound(sound.load(R.raw.rockets));
852            animation.setRubySounds(sound.load(R.raw.gem1), sound.load(R.raw.gem2), sound.load(R.raw.gem3));
853            animation.setExplosionSound(sound.load(R.raw.sound_explode));
854        }
855
856
857        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
858        sprite.setSize((int)object.width, (int)object.height);
859        sprite.setRenderComponent(render);
860        animation.setSprite(sprite);
861
862
863
864        DynamicCollisionComponent dynamicCollision
865            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
866        sprite.setCollisionComponent(dynamicCollision);
867
868        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
869        hitReact.setBounceOnHit(true);
870        hitReact.setPauseOnAttack(true);
871        hitReact.setInvincibleTime(3.0f);
872        hitReact.setSpawnOnDealHit(HitType.HIT, GameObjectType.CRUSH_FLASH, false, true);
873
874        if (sound != null) {
875            hitReact.setTakeHitSound(HitType.HIT, sound.load(R.raw.deep_clang));
876        }
877
878        dynamicCollision.setHitReactionComponent(hitReact);
879
880        player.setHitReactionComponent(hitReact);
881
882        InventoryComponent inventory = (InventoryComponent)allocateComponent(InventoryComponent.class);
883
884        player.setInventory(inventory);
885        animation.setInventory(inventory);
886
887        ChangeComponentsComponent damageSwap = (ChangeComponentsComponent)allocateComponent(ChangeComponentsComponent.class);
888        animation.setDamageSwap(damageSwap);
889
890        LaunchProjectileComponent smokeGun
891            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
892        smokeGun.setDelayBetweenShots(0.25f);
893        smokeGun.setObjectTypeToSpawn(GameObjectType.SMOKE_BIG);
894        smokeGun.setOffsetX(32);
895        smokeGun.setOffsetY(15);
896        smokeGun.setVelocityX(-150.0f);
897        smokeGun.setVelocityY(100.0f);
898        smokeGun.setThetaError(0.1f);
899
900        LaunchProjectileComponent smokeGun2
901            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
902        smokeGun2.setDelayBetweenShots(0.35f);
903        smokeGun2.setObjectTypeToSpawn(GameObjectType.SMOKE_SMALL);
904        smokeGun2.setOffsetX(16);
905        smokeGun2.setOffsetY(15);
906        smokeGun2.setVelocityX(-150.0f);
907        smokeGun2.setVelocityY(150.0f);
908        smokeGun2.setThetaError(0.1f);
909
910        damageSwap.addSwapInComponent(smokeGun);
911        damageSwap.addSwapInComponent(smokeGun2);
912        damageSwap.setPingPongBehavior(true);
913
914        ChangeComponentsComponent invincibleSwap = (ChangeComponentsComponent)allocateComponent(ChangeComponentsComponent.class);
915        invincibleSwap.setPingPongBehavior(true);
916        player.setInvincibleSwap(invincibleSwap);
917
918        object.life = PlayerComponent.MAX_PLAYER_LIFE;
919        object.team = Team.PLAYER;
920
921        // Very very basic DDA.  Make the game easier if we've died on this level too much.
922        LevelSystem level = sSystemRegistry.levelSystem;
923        if (level != null) {
924        	player.adjustDifficulty(object, level.getAttemptsCount());
925        }
926
927
928        object.add(player);
929        object.add(inventory);
930        object.add(bgcollision);
931        object.add(render);
932        object.add(animation);
933        object.add(sprite);
934        object.add(dynamicCollision);
935        object.add(hitReact);
936        object.add(damageSwap);
937        object.add(invincibleSwap);
938
939        addStaticData(GameObjectType.PLAYER, object, sprite);
940
941
942
943        sprite.playAnimation(PlayerAnimations.IDLE.ordinal());
944
945
946        // Jets
947        {
948            FixedSizeArray<BaseObject> jetStaticData = getStaticData(GameObjectType.PLAYER_JETS);
949            if (jetStaticData == null) {
950                jetStaticData = new FixedSizeArray<BaseObject>(1);
951
952                SpriteAnimation jetAnim = new SpriteAnimation(0, 2);
953                jetAnim.addFrame(
954                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.jetfire01),
955                                Utils.framesToTime(24, 1)));
956                jetAnim.addFrame(
957                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.jetfire02),
958                                Utils.framesToTime(24, 1)));
959                jetAnim.setLoop(true);
960
961                jetStaticData.add(jetAnim);
962
963                setStaticData(GameObjectType.PLAYER_JETS, jetStaticData);
964            }
965
966            RenderComponent jetRender = (RenderComponent)allocateComponent(RenderComponent.class);
967            jetRender.setPriority(SortConstants.PLAYER - 1);
968            jetRender.setDrawOffset(0.0f, -16.0f);
969            SpriteComponent jetSprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
970            jetSprite.setSize(64, 64);
971            jetSprite.setRenderComponent(jetRender);
972
973            object.add(jetRender);
974            object.add(jetSprite);
975
976            addStaticData(GameObjectType.PLAYER_JETS, object, jetSprite);
977
978            jetSprite.playAnimation(0);
979
980            animation.setJetSprite(jetSprite);
981        }
982        // Sparks
983        {
984            FixedSizeArray<BaseObject> sparksStaticData = getStaticData(GameObjectType.PLAYER_SPARKS);
985
986            if (sparksStaticData == null) {
987                sparksStaticData = new FixedSizeArray<BaseObject>(1);
988
989                SpriteAnimation sparksAnim = new SpriteAnimation(0, 3);
990                sparksAnim.addFrame(
991                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.spark01),
992                                Utils.framesToTime(24, 1)));
993                sparksAnim.addFrame(
994                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.spark02),
995                                Utils.framesToTime(24, 1)));
996                sparksAnim.addFrame(
997                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.spark03),
998                                Utils.framesToTime(24, 1)));
999                sparksAnim.setLoop(true);
1000
1001                sparksStaticData.add(sparksAnim);
1002
1003                setStaticData(GameObjectType.PLAYER_SPARKS, sparksStaticData);
1004            }
1005
1006            RenderComponent sparksRender = (RenderComponent)allocateComponent(RenderComponent.class);
1007            sparksRender.setPriority(SortConstants.PLAYER + 1);
1008            SpriteComponent sparksSprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1009            sparksSprite.setSize(64, 64);
1010            sparksSprite.setRenderComponent(sparksRender);
1011
1012            object.add(sparksRender);
1013            object.add(sparksSprite);
1014
1015            addStaticData(GameObjectType.PLAYER_SPARKS, object, sparksSprite);
1016
1017            sparksSprite.playAnimation(0);
1018
1019            animation.setSparksSprite(sparksSprite);
1020        }
1021
1022        // Glow
1023        {
1024            FixedSizeArray<BaseObject> glowStaticData = getStaticData(GameObjectType.PLAYER_GLOW);
1025            if (glowStaticData == null) {
1026                glowStaticData = new FixedSizeArray<BaseObject>(1);
1027
1028                FixedSizeArray<CollisionVolume> glowAttackVolume =
1029                    new FixedSizeArray<CollisionVolume>(1);
1030                glowAttackVolume.add(new SphereCollisionVolume(40, 40, 40, HitType.HIT));
1031
1032                SpriteAnimation glowAnim = new SpriteAnimation(0, 3);
1033                glowAnim.addFrame(
1034                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.effect_glow01),
1035                                Utils.framesToTime(24, 1), glowAttackVolume, null));
1036                glowAnim.addFrame(
1037                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.effect_glow02),
1038                                Utils.framesToTime(24, 1), glowAttackVolume, null));
1039                glowAnim.addFrame(
1040                        new AnimationFrame(textureLibrary.allocateTexture(R.drawable.effect_glow03),
1041                                Utils.framesToTime(24, 1), glowAttackVolume, null));
1042                glowAnim.setLoop(true);
1043
1044                glowStaticData.add(glowAnim);
1045
1046                setStaticData(GameObjectType.PLAYER_GLOW, glowStaticData);
1047            }
1048
1049            RenderComponent glowRender = (RenderComponent)allocateComponent(RenderComponent.class);
1050            glowRender.setPriority(SortConstants.PLAYER + 1);
1051            glowRender.setDrawOffset(0, -5.0f);
1052            SpriteComponent glowSprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1053            glowSprite.setSize(64, 64);
1054            glowSprite.setRenderComponent(glowRender);
1055
1056            DynamicCollisionComponent glowCollision
1057                = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
1058            glowSprite.setCollisionComponent(glowCollision);
1059
1060            FadeDrawableComponent glowFade = (FadeDrawableComponent)allocateComponent(FadeDrawableComponent.class);
1061            glowFade.setupFade(1.0f, 0.0f, 0.15f,
1062            		FadeDrawableComponent.LOOP_TYPE_PING_PONG,
1063            		FadeDrawableComponent.FADE_EASE,
1064            		PlayerComponent.GLOW_DURATION - 4.0f);	// 4 seconds before the glow ends, start flashing
1065            glowFade.setPhaseDuration(PlayerComponent.GLOW_DURATION);
1066            glowFade.setRenderComponent(glowRender);
1067
1068            invincibleSwap.addSwapInComponent(glowRender);
1069            invincibleSwap.addSwapInComponent(glowSprite);
1070            invincibleSwap.addSwapInComponent(glowCollision);
1071            invincibleSwap.addSwapInComponent(glowFade);
1072
1073            addStaticData(GameObjectType.PLAYER_GLOW, object, glowSprite);
1074
1075            glowSprite.playAnimation(0);
1076
1077        }
1078
1079        CameraSystem camera = sSystemRegistry.cameraSystem;
1080        if (camera != null) {
1081            camera.setTarget(object);
1082        }
1083
1084        return object;
1085    }
1086
1087
1088    // Sparks are used by more than one enemy type, so the setup for them is abstracted.
1089    private void setupEnemySparks() {
1090        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.ENEMY_SPARKS);
1091        if (staticData == null) {
1092            staticData = new FixedSizeArray<BaseObject>(1);
1093            TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
1094
1095            SpriteAnimation sparksAnim = new SpriteAnimation(0, 13);
1096            AnimationFrame frame1 =
1097                new AnimationFrame(textureLibrary.allocateTexture(R.drawable.spark01),
1098                        Utils.framesToTime(24, 1));
1099            AnimationFrame frame2 =
1100                new AnimationFrame(textureLibrary.allocateTexture(R.drawable.spark02),
1101                        Utils.framesToTime(24, 1));
1102            AnimationFrame frame3 =
1103                new AnimationFrame(textureLibrary.allocateTexture(R.drawable.spark03),
1104                        Utils.framesToTime(24, 1));
1105            sparksAnim.addFrame(frame1);
1106            sparksAnim.addFrame(frame2);
1107            sparksAnim.addFrame(frame3);
1108            sparksAnim.addFrame(frame1);
1109            sparksAnim.addFrame(frame2);
1110            sparksAnim.addFrame(frame3);
1111            sparksAnim.addFrame(frame1);
1112            sparksAnim.addFrame(frame2);
1113            sparksAnim.addFrame(frame3);
1114            sparksAnim.addFrame(frame1);
1115            sparksAnim.addFrame(frame2);
1116            sparksAnim.addFrame(frame3);
1117            sparksAnim.addFrame(new AnimationFrame(null, 3.0f));
1118            sparksAnim.setLoop(true);
1119
1120            staticData.add(sparksAnim);
1121            setStaticData(GameObjectType.ENEMY_SPARKS, staticData);
1122        }
1123
1124    }
1125
1126    public GameObject spawnEnemyBrobot(float positionX, float positionY, boolean flipHorizontal) {
1127        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
1128
1129
1130        GameObject object = mGameObjectPool.allocate();
1131        object.getPosition().set(positionX, positionY);
1132        object.activationRadius = mNormalActivationRadius;
1133        object.width = 64;
1134        object.height = 64;
1135
1136        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.BROBOT);
1137        if (staticData == null) {
1138            final int staticObjectCount = 5;
1139            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
1140
1141            GameComponent gravity = allocateComponent(GravityComponent.class);
1142            GameComponent movement = allocateComponent(MovementComponent.class);
1143            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
1144            physics.setBounciness(0.4f);
1145
1146
1147            // Animations
1148            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
1149                new FixedSizeArray<CollisionVolume>(1);
1150            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 32, 32));
1151
1152            FixedSizeArray<CollisionVolume> basicAttackVolume =
1153                new FixedSizeArray<CollisionVolume>(2);
1154            basicAttackVolume.add(new SphereCollisionVolume(16, 32, 32, HitType.HIT));
1155            basicAttackVolume.add(new AABoxCollisionVolume(16, 0, 32, 16, HitType.DEPRESS));
1156
1157            SpriteAnimation idle = new SpriteAnimation(EnemyAnimations.IDLE.ordinal(), 4);
1158            idle.addFrame(new AnimationFrame(
1159                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_idle01),
1160                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume));
1161            idle.addFrame(new AnimationFrame(
1162                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_idle02),
1163                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
1164            idle.addFrame(new AnimationFrame(
1165                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_idle03),
1166                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume));
1167            idle.addFrame(new AnimationFrame(
1168                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_idle02),
1169                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume));
1170
1171            idle.setLoop(true);
1172
1173            SpriteAnimation walk = new SpriteAnimation(EnemyAnimations.MOVE.ordinal(), 3);
1174            walk.addFrame(new AnimationFrame(
1175                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk01),
1176                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
1177            walk.addFrame(new AnimationFrame(
1178                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk02),
1179                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
1180            walk.addFrame(new AnimationFrame(
1181                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk03),
1182                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
1183            walk.setLoop(true);
1184
1185            staticData.add(gravity);
1186            staticData.add(movement);
1187            staticData.add(physics);
1188            staticData.add(idle);
1189            staticData.add(walk);
1190
1191            setStaticData(GameObjectType.BROBOT, staticData);
1192
1193        }
1194        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
1195        render.setPriority(SortConstants.GENERAL_ENEMY);
1196        BackgroundCollisionComponent bgcollision
1197            = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
1198        bgcollision.setSize(32, 48);
1199        bgcollision.setOffset(16, 0);
1200
1201        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1202        sprite.setSize((int)object.width, (int)object.height);
1203        sprite.setRenderComponent(render);
1204
1205        EnemyAnimationComponent animation
1206            = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
1207        animation.setSprite(sprite);
1208
1209        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
1210        patrol.setMovementSpeed(50.0f, 1000.0f);
1211
1212        DynamicCollisionComponent collision
1213            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
1214        sprite.setCollisionComponent(collision);
1215
1216        HitReactionComponent hitReact
1217            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
1218        collision.setHitReactionComponent(hitReact);
1219
1220
1221        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
1222        lifetime.setObjectToSpawnOnDeath(GameObjectType.EXPLOSION_GIANT);
1223        lifetime.setVulnerableToDeathTiles(true);
1224
1225        GhostComponent ghost = (GhostComponent)allocateComponent(GhostComponent.class);
1226        ghost.setMovementSpeed(500.0f);
1227        ghost.setAcceleration(1000.0f);
1228        ghost.setJumpImpulse(300.0f);
1229        ghost.setKillOnRelease(true);
1230        ghost.setDelayOnRelease(1.5f);
1231
1232        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
1233        if (sound != null) {
1234        	ghost.setAmbientSound(sound.load(R.raw.sound_possession));
1235        }
1236
1237        ChangeComponentsComponent ghostSwap
1238            = (ChangeComponentsComponent)allocateComponent(ChangeComponentsComponent.class);
1239        ghostSwap.addSwapInComponent(ghost);
1240        ghostSwap.addSwapOutComponent(patrol);
1241
1242        SimplePhysicsComponent ghostPhysics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
1243        ghostPhysics.setBounciness(0.0f);
1244
1245        object.add(render);
1246        object.add(sprite);
1247
1248        object.add(bgcollision);
1249        object.add(animation);
1250        object.add(patrol);
1251        object.add(collision);
1252        object.add(hitReact);
1253        object.add(lifetime);
1254        object.add(ghostSwap);
1255
1256        object.team = Team.ENEMY;
1257
1258        if (flipHorizontal) {
1259            object.facingDirection.x = -1.0f;
1260        }
1261
1262        addStaticData(GameObjectType.BROBOT, object, sprite);
1263
1264        object.commitUpdates();
1265
1266        SimplePhysicsComponent normalPhysics = object.findByClass(SimplePhysicsComponent.class);
1267        if (normalPhysics != null) {
1268            ghostSwap.addSwapOutComponent(normalPhysics);
1269        }
1270
1271        ghostSwap.addSwapInComponent(ghostPhysics);
1272
1273        sprite.playAnimation(0);
1274
1275        // Sparks
1276        setupEnemySparks();
1277
1278        RenderComponent sparksRender = (RenderComponent)allocateComponent(RenderComponent.class);
1279        sparksRender.setPriority(render.getPriority() + 1);
1280        SpriteComponent sparksSprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1281        sparksSprite.setSize(64, 64);
1282        sparksSprite.setRenderComponent(sparksRender);
1283
1284        addStaticData(GameObjectType.ENEMY_SPARKS, object, sparksSprite);
1285
1286        sparksSprite.playAnimation(0);
1287
1288        ghostSwap.addSwapInComponent(sparksSprite);
1289        ghostSwap.addSwapInComponent(sparksRender);
1290
1291
1292        hitReact.setPossessionComponent(ghostSwap);
1293
1294        return object;
1295    }
1296
1297    public GameObject spawnEnemySnailBomb(float positionX, float positionY, boolean flipHorizontal) {
1298
1299        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
1300
1301
1302        // Make sure related textures are loaded.
1303        textureLibrary.allocateTexture(R.drawable.snail_bomb);
1304
1305        GameObject object = mGameObjectPool.allocate();
1306        object.getPosition().set(positionX, positionY);
1307        object.activationRadius = mNormalActivationRadius;
1308        object.width = 64;
1309        object.height = 64;
1310
1311        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.SNAILBOMB);
1312        if (staticData == null) {
1313            final int staticObjectCount = 6;
1314            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
1315
1316            GameComponent gravity = allocateComponent(GravityComponent.class);
1317            GameComponent movement = allocateComponent(MovementComponent.class);
1318            GameComponent physics = allocateComponent(SimplePhysicsComponent.class);
1319
1320            // Animations
1321            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
1322                new FixedSizeArray<CollisionVolume>(1);
1323            basicVulnerabilityVolume.add(new AABoxCollisionVolume(12, 5, 42, 27, HitType.HIT));
1324
1325            FixedSizeArray<CollisionVolume> basicAttackVolume =
1326                new FixedSizeArray<CollisionVolume>(1);
1327            basicAttackVolume.add(new AABoxCollisionVolume(12, 5, 42, 27, HitType.HIT));
1328
1329            SpriteAnimation idle = new SpriteAnimation(EnemyAnimations.IDLE.ordinal(), 1);
1330            idle.addFrame(new AnimationFrame(
1331                    textureLibrary.allocateTexture(R.drawable.snailbomb_stand),
1332                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume));
1333
1334            SpriteAnimation walk = new SpriteAnimation(EnemyAnimations.MOVE.ordinal(), 5);
1335            walk.addFrame(new AnimationFrame(
1336                    textureLibrary.allocateTexture(R.drawable.snailbomb_stand),
1337                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume));
1338            walk.addFrame(new AnimationFrame(
1339                        textureLibrary.allocateTexture(R.drawable.snailbomb_walk01),
1340                        Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume));
1341            walk.addFrame(new AnimationFrame(
1342                    textureLibrary.allocateTexture(R.drawable.snailbomb_walk02),
1343                    Utils.framesToTime(24, 6), basicAttackVolume, basicVulnerabilityVolume));
1344            walk.addFrame(new AnimationFrame(
1345                    textureLibrary.allocateTexture(R.drawable.snailbomb_walk01),
1346                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume));
1347            walk.addFrame(new AnimationFrame(
1348                    textureLibrary.allocateTexture(R.drawable.snailbomb_stand),
1349                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume));
1350            walk.setLoop(true);
1351
1352            SpriteAnimation attack = new SpriteAnimation(EnemyAnimations.ATTACK.ordinal(), 2);
1353            attack.addFrame(new AnimationFrame(
1354                    textureLibrary.allocateTexture(R.drawable.snailbomb_shoot01),
1355                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume));
1356            attack.addFrame(new AnimationFrame(
1357                    textureLibrary.allocateTexture(R.drawable.snailbomb_shoot02),
1358                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume));
1359
1360            staticData.add(gravity);
1361            staticData.add(movement);
1362            staticData.add(physics);
1363            staticData.add(idle);
1364            staticData.add(walk);
1365            staticData.add(attack);
1366
1367
1368            setStaticData(GameObjectType.SNAILBOMB, staticData);
1369        }
1370
1371        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
1372        render.setPriority(SortConstants.GENERAL_ENEMY);
1373        BackgroundCollisionComponent bgcollision
1374            = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
1375        bgcollision.setSize(32, 48);
1376        bgcollision.setOffset(16, 5);
1377
1378        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1379        sprite.setSize((int)object.width, (int)object.height);
1380        sprite.setRenderComponent(render);
1381
1382        EnemyAnimationComponent animation
1383            = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
1384        animation.setSprite(sprite);
1385
1386        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
1387        patrol.setMovementSpeed(20.0f, 1000.0f);
1388        patrol.setupAttack(300, 1.0f, 4.0f, true);
1389
1390        DynamicCollisionComponent collision
1391            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
1392        sprite.setCollisionComponent(collision);
1393
1394        HitReactionComponent hitReact
1395            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
1396        collision.setHitReactionComponent(hitReact);
1397
1398        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
1399        lifetime.setVulnerableToDeathTiles(true);
1400        lifetime.setObjectToSpawnOnDeath(GameObjectType.SMOKE_POOF);
1401        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
1402        if (sound != null) {
1403        	lifetime.setDeathSound(sound.load(R.raw.sound_stomp));
1404        }
1405
1406        LaunchProjectileComponent gun
1407            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
1408        gun.setSetsPerActivation(1);
1409        gun.setShotsPerSet(3);
1410        gun.setDelayBeforeFirstSet(1.0f);
1411        gun.setDelayBetweenShots(0.25f);
1412        gun.setObjectTypeToSpawn(GameObjectType.CANNON_BALL);
1413        gun.setOffsetX(55);
1414        gun.setOffsetY(21);
1415        gun.setRequiredAction(GameObject.ActionType.ATTACK);
1416        gun.setVelocityX(100.0f);
1417
1418        object.team = Team.ENEMY;
1419
1420        if (flipHorizontal) {
1421            object.facingDirection.x = -1.0f;
1422        }
1423
1424        object.add(render);
1425        object.add(sprite);
1426        object.add(bgcollision);
1427        object.add(animation);
1428        object.add(patrol);
1429        object.add(collision);
1430        object.add(hitReact);
1431        object.add(lifetime);
1432        object.add(gun);
1433
1434        addStaticData(GameObjectType.SNAILBOMB, object, sprite);
1435
1436        final SpriteAnimation attack = sprite.findAnimation(EnemyAnimations.ATTACK.ordinal());
1437        if (attack != null) {
1438            gun.setDelayBeforeFirstSet(attack.getLength());
1439        }
1440
1441        sprite.playAnimation(0);
1442
1443        return object;
1444    }
1445
1446    public GameObject spawnEnemyShadowSlime(float positionX, float positionY, boolean flipHorizontal) {
1447
1448        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
1449
1450
1451        // Make sure related textures are loaded.
1452        textureLibrary.allocateTexture(R.drawable.energy_ball01);
1453        textureLibrary.allocateTexture(R.drawable.energy_ball02);
1454        textureLibrary.allocateTexture(R.drawable.energy_ball03);
1455        textureLibrary.allocateTexture(R.drawable.energy_ball04);
1456
1457        GameObject object = mGameObjectPool.allocate();
1458        object.getPosition().set(positionX, positionY);
1459        object.activationRadius = mTightActivationRadius;
1460        object.width = 64;
1461        object.height = 64;
1462
1463        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.SHADOWSLIME);
1464        if (staticData == null) {
1465            final int staticObjectCount = 5;
1466            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
1467
1468            PopOutComponent popOut = (PopOutComponent)allocateComponent(PopOutComponent.class);
1469            popOut.setAppearDistance(150);
1470            popOut.setHideDistance(190);
1471
1472            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume = new FixedSizeArray<CollisionVolume>(1);
1473            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 32, 32));
1474            basicVulnerabilityVolume.get(0).setHitType(HitType.HIT);
1475
1476            FixedSizeArray<CollisionVolume> basicAttackVolume = new FixedSizeArray<CollisionVolume>(1);
1477            basicAttackVolume.add(new SphereCollisionVolume(16, 32, 32, HitType.HIT));
1478
1479            SpriteAnimation idle = new SpriteAnimation(EnemyAnimations.IDLE.ordinal(), 2);
1480            AnimationFrame idle1 = new AnimationFrame(
1481                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_idle01),
1482                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume);
1483            AnimationFrame idle2 = new AnimationFrame(
1484                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_idle02),
1485                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume);
1486            idle.addFrame(idle1);
1487            idle.addFrame(idle2);
1488            idle.setLoop(true);
1489
1490
1491            SpriteAnimation appear = new SpriteAnimation(EnemyAnimations.APPEAR.ordinal(), 6);
1492            AnimationFrame appear1 = new AnimationFrame(
1493                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_activate01),
1494                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume);
1495
1496            AnimationFrame appear2 = new AnimationFrame(
1497                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_activate02),
1498                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume);
1499            AnimationFrame appear3 = new AnimationFrame(
1500                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_activate03),
1501                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume);
1502            AnimationFrame appear4 = new AnimationFrame(
1503                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_activate04),
1504                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume);
1505            AnimationFrame appear5 = new AnimationFrame(
1506                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_activate05),
1507                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume);
1508            AnimationFrame appear6 = new AnimationFrame(
1509                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_activate06),
1510                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume);
1511
1512            appear.addFrame(appear1);
1513            appear.addFrame(appear2);
1514            appear.addFrame(appear3);
1515            appear.addFrame(appear4);
1516            appear.addFrame(appear5);
1517            appear.addFrame(appear6);
1518
1519            SpriteAnimation hidden = new SpriteAnimation(EnemyAnimations.HIDDEN.ordinal(), 6);
1520            hidden.addFrame(appear6);
1521            hidden.addFrame(appear5);
1522            hidden.addFrame(appear4);
1523            hidden.addFrame(appear3);
1524            hidden.addFrame(appear2);
1525            hidden.addFrame(appear1);
1526            /*hidden.addFrame(new AnimationFrame(
1527                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_stand),
1528                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume));*/
1529
1530
1531            SpriteAnimation attack = new SpriteAnimation(EnemyAnimations.ATTACK.ordinal(), 10);
1532            AnimationFrame attack1 = new AnimationFrame(
1533                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_attack01),
1534                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume);
1535            AnimationFrame attack2 = new AnimationFrame(
1536                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_attack02),
1537                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume);
1538            AnimationFrame attack3 = new AnimationFrame(
1539                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_attack03),
1540                    Utils.framesToTime(24, 2), basicAttackVolume, basicVulnerabilityVolume);
1541            AnimationFrame attack4 = new AnimationFrame(
1542                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_attack04),
1543                    Utils.framesToTime(24, 6), basicAttackVolume, basicVulnerabilityVolume);
1544            AnimationFrame attackFlash = new AnimationFrame(
1545                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_flash),
1546                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume);
1547
1548            AnimationFrame attack5 = new AnimationFrame(
1549                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_attack03),
1550                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume);
1551            AnimationFrame attack6 = new AnimationFrame(
1552                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_attack02),
1553                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume);
1554
1555            AnimationFrame attack7 = new AnimationFrame(
1556                    textureLibrary.allocateTexture(R.drawable.enemy_shadowslime_attack04),
1557                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume);
1558
1559            attack.addFrame(attack1);
1560            attack.addFrame(attack2);
1561            attack.addFrame(attack3);
1562            attack.addFrame(attack4);
1563            attack.addFrame(attackFlash);
1564            attack.addFrame(attack7);
1565            attack.addFrame(attackFlash);
1566            attack.addFrame(attack5);
1567            attack.addFrame(attack6);
1568            attack.addFrame(attack1);
1569
1570            popOut.setupAttack(200, 2.0f, attack.getLength());
1571
1572
1573            staticData.add(popOut);
1574            staticData.add(idle);
1575            staticData.add(hidden);
1576            staticData.add(appear);
1577            staticData.add(attack);
1578
1579            setStaticData(GameObjectType.SHADOWSLIME, staticData);
1580        }
1581
1582        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
1583        render.setPriority(SortConstants.GENERAL_ENEMY);
1584        BackgroundCollisionComponent bgcollision
1585            = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
1586        bgcollision.setSize(32, 48);
1587        bgcollision.setOffset(16, 5);
1588
1589        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1590        sprite.setSize((int)object.width, (int)object.height);
1591        sprite.setRenderComponent(render);
1592
1593
1594        sprite.playAnimation(0);
1595
1596        EnemyAnimationComponent animation
1597            = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
1598        animation.setSprite(sprite);
1599        animation.setFacePlayer(true);
1600
1601
1602        DynamicCollisionComponent collision
1603            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
1604        sprite.setCollisionComponent(collision);
1605
1606        HitReactionComponent hitReact
1607            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
1608        collision.setHitReactionComponent(hitReact);
1609
1610        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
1611        lifetime.setObjectToSpawnOnDeath(GameObjectType.SMOKE_POOF);
1612        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
1613        if (sound != null) {
1614        	lifetime.setDeathSound(sound.load(R.raw.sound_stomp));
1615        }
1616
1617        LaunchProjectileComponent gun
1618            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
1619
1620
1621        gun.setShotsPerSet(1);
1622        gun.setSetsPerActivation(1);
1623        gun.setObjectTypeToSpawn(GameObjectType.ENERGY_BALL);
1624        gun.setOffsetX(44);
1625        gun.setOffsetY(22);
1626        gun.setRequiredAction(GameObject.ActionType.ATTACK);
1627        gun.setVelocityX(30.0f);
1628
1629        object.team = Team.ENEMY;
1630
1631        if (flipHorizontal) {
1632            object.facingDirection.x = -1.0f;
1633        }
1634
1635        // Hack.  Adjusting position lets us avoid giving this character gravity, physics, and
1636        // collision.
1637
1638        object.getPosition().y -= 5;
1639
1640        object.add(render);
1641        object.add(sprite);
1642        object.add(bgcollision);
1643        object.add(animation);
1644        object.add(collision);
1645        object.add(hitReact);
1646        object.add(lifetime);
1647        object.add(gun);
1648
1649        addStaticData(GameObjectType.SHADOWSLIME, object, sprite);
1650
1651        final SpriteAnimation attack = sprite.findAnimation(EnemyAnimations.ATTACK.ordinal());
1652        final SpriteAnimation appear = sprite.findAnimation(EnemyAnimations.APPEAR.ordinal());
1653        if (attack != null && appear != null) {
1654            gun.setDelayBeforeFirstSet(attack.getLength() / 2.0f);
1655        } else {
1656            gun.setDelayBeforeFirstSet(Utils.framesToTime(24, 12));
1657        }
1658
1659        return object;
1660    }
1661
1662    public GameObject spawnEnemyMudman(float positionX, float positionY, boolean flipHorizontal) {
1663        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
1664
1665
1666        GameObject object = mGameObjectPool.allocate();
1667        object.getPosition().set(positionX, positionY);
1668        object.activationRadius = mNormalActivationRadius;
1669        object.width = 128;
1670        object.height = 128;
1671
1672        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.MUDMAN);
1673        if (staticData == null) {
1674            final int staticObjectCount = 7;
1675            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
1676
1677            GameComponent gravity = allocateComponent(GravityComponent.class);
1678            GameComponent movement = allocateComponent(MovementComponent.class);
1679
1680            GameComponent physics = allocateComponent(SimplePhysicsComponent.class);
1681
1682            SolidSurfaceComponent solidSurface
1683                = (SolidSurfaceComponent)allocateComponent(SolidSurfaceComponent.class);
1684            solidSurface.inititalize(4);
1685            // house shape:
1686            // / \      1/ \2
1687            // | |      3| |4
1688            Vector2 surface1Start = new Vector2(32, 64);
1689            Vector2 surface1End = new Vector2(64, 96);
1690            Vector2 surface1Normal = new Vector2(-0.707f, 0.707f);
1691            surface1Normal.normalize();
1692
1693            Vector2 surface2Start = new Vector2(64, 96);
1694            Vector2 surface2End = new Vector2(75, 64);
1695            Vector2 surface2Normal = new Vector2(0.9456f, 0.3250f);
1696            surface2Normal.normalize();
1697
1698            Vector2 surface3Start = new Vector2(32, 0);
1699            Vector2 surface3End = new Vector2(32, 64);
1700            Vector2 surface3Normal = new Vector2(-1, 0);
1701
1702            Vector2 surface4Start = new Vector2(75, 0);
1703            Vector2 surface4End = new Vector2(75, 64);
1704            Vector2 surface4Normal = new Vector2(1, 0);
1705
1706            solidSurface.addSurface(surface1Start, surface1End, surface1Normal);
1707            solidSurface.addSurface(surface2Start, surface2End, surface2Normal);
1708            solidSurface.addSurface(surface3Start, surface3End, surface3Normal);
1709            solidSurface.addSurface(surface4Start, surface4End, surface4Normal);
1710
1711            SpriteAnimation idle = new SpriteAnimation(EnemyAnimations.IDLE.ordinal(), 4);
1712            idle.addFrame(new AnimationFrame(
1713                    textureLibrary.allocateTexture(R.drawable.enemy_mud_stand),
1714                    Utils.framesToTime(24, 12), null, null));
1715            AnimationFrame idle1 = new AnimationFrame(
1716                    textureLibrary.allocateTexture(R.drawable.enemy_mud_idle01),
1717                    Utils.framesToTime(24, 2), null, null);
1718            AnimationFrame idle2 = new AnimationFrame(
1719                    textureLibrary.allocateTexture(R.drawable.enemy_mud_idle01),
1720                    Utils.framesToTime(24, 7), null, null);
1721            idle.addFrame(idle1);
1722            idle.addFrame(idle2);
1723            idle.addFrame(idle1);
1724            idle.setLoop(true);
1725
1726
1727            SpriteAnimation walk = new SpriteAnimation(EnemyAnimations.MOVE.ordinal(), 6);
1728            walk.addFrame(new AnimationFrame(
1729                    textureLibrary.allocateTexture(R.drawable.enemy_mud_walk01),
1730                    Utils.framesToTime(24, 4), null, null));
1731            walk.addFrame(new AnimationFrame(
1732                    textureLibrary.allocateTexture(R.drawable.enemy_mud_walk02),
1733                    Utils.framesToTime(24, 4), null, null));
1734            walk.addFrame(new AnimationFrame(
1735                    textureLibrary.allocateTexture(R.drawable.enemy_mud_walk03),
1736                    Utils.framesToTime(24, 5), null, null));
1737            walk.addFrame(new AnimationFrame(
1738                    textureLibrary.allocateTexture(R.drawable.enemy_mud_walk04),
1739                    Utils.framesToTime(24, 4), null, null));
1740            walk.addFrame(new AnimationFrame(
1741                    textureLibrary.allocateTexture(R.drawable.enemy_mud_walk05),
1742                    Utils.framesToTime(24, 4), null, null));
1743            walk.addFrame(new AnimationFrame(
1744                    textureLibrary.allocateTexture(R.drawable.enemy_mud_walk06),
1745                    Utils.framesToTime(24, 5), null, null));
1746            walk.setLoop(true);
1747
1748            FixedSizeArray<CollisionVolume> crushAttackVolume =
1749                new FixedSizeArray<CollisionVolume>(1);
1750            crushAttackVolume.add(new AABoxCollisionVolume(64, 0, 64, 96, HitType.HIT));
1751
1752            SpriteAnimation attack = new SpriteAnimation(EnemyAnimations.ATTACK.ordinal(), 8);
1753            attack.addFrame(new AnimationFrame(
1754                    textureLibrary.allocateTexture(R.drawable.enemy_mud_stand),
1755                    Utils.framesToTime(24, 2), null, null));
1756            attack.addFrame(new AnimationFrame(
1757                    textureLibrary.allocateTexture(R.drawable.enemy_mud_attack01),
1758                    Utils.framesToTime(24, 2), null, null));
1759            attack.addFrame(new AnimationFrame(
1760                    textureLibrary.allocateTexture(R.drawable.enemy_mud_attack02),
1761                    Utils.framesToTime(24, 2), null, null));
1762            attack.addFrame(new AnimationFrame(
1763                    textureLibrary.allocateTexture(R.drawable.enemy_mud_attack03),
1764                    Utils.framesToTime(24, 2), null, null));
1765            attack.addFrame(new AnimationFrame(
1766                    textureLibrary.allocateTexture(R.drawable.enemy_mud_attack04),
1767                    Utils.framesToTime(24, 1), crushAttackVolume, null));
1768            attack.addFrame(new AnimationFrame(
1769                    textureLibrary.allocateTexture(R.drawable.enemy_mud_attack05),
1770                    Utils.framesToTime(24, 1), crushAttackVolume, null));
1771            attack.addFrame(new AnimationFrame(
1772                    textureLibrary.allocateTexture(R.drawable.enemy_mud_attack06),
1773                    Utils.framesToTime(24, 8), crushAttackVolume, null));
1774            attack.addFrame(new AnimationFrame(
1775                    textureLibrary.allocateTexture(R.drawable.enemy_mud_attack07),
1776                    Utils.framesToTime(24, 5), null, null));
1777
1778            staticData.add(gravity);
1779            staticData.add(movement);
1780            staticData.add(physics);
1781            staticData.add(solidSurface);
1782            staticData.add(idle);
1783            staticData.add(walk);
1784            staticData.add(attack);
1785
1786            setStaticData(GameObjectType.MUDMAN, staticData);
1787        }
1788
1789        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
1790        render.setPriority(SortConstants.GENERAL_ENEMY);
1791
1792        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
1793		bgcollision.setSize(80, 90);
1794		bgcollision.setOffset(32, 5);
1795
1796        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1797        sprite.setSize((int)object.width, (int)object.height);
1798        sprite.setRenderComponent(render);
1799
1800
1801        sprite.playAnimation(0);
1802
1803        EnemyAnimationComponent animation = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
1804        animation.setSprite(sprite);
1805
1806        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
1807        patrol.setMovementSpeed(20.0f, 400.0f);
1808
1809        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
1810        sprite.setCollisionComponent(collision);
1811
1812        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
1813        collision.setHitReactionComponent(hitReact);
1814
1815        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
1816
1817        object.team = Team.ENEMY;
1818        object.life = 1;
1819
1820        if (flipHorizontal) {
1821            object.facingDirection.x = -1.0f;
1822        }
1823
1824        object.add(render);
1825        object.add(sprite);
1826        object.add(bgcollision);
1827        object.add(animation);
1828        object.add(patrol);
1829        object.add(collision);
1830        object.add(hitReact);
1831        object.add(lifetime);
1832
1833        addStaticData(GameObjectType.MUDMAN, object, sprite);
1834
1835        final SpriteAnimation attack = sprite.findAnimation(EnemyAnimations.ATTACK.ordinal());
1836        if (attack != null) {
1837            patrol.setupAttack(70.0f, attack.getLength(), 0.0f, true);
1838        }
1839
1840        sprite.playAnimation(0);
1841
1842        return object;
1843    }
1844
1845    public GameObject spawnEnemySkeleton(float positionX, float positionY, boolean flipHorizontal) {
1846        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
1847
1848
1849        GameObject object = mGameObjectPool.allocate();
1850        object.getPosition().set(positionX, positionY);
1851        object.activationRadius = mNormalActivationRadius;
1852        object.width = 64;
1853        object.height = 64;
1854
1855        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.SKELETON);
1856        if (staticData == null) {
1857            final int staticObjectCount = 7;
1858            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
1859
1860            GameComponent gravity = allocateComponent(GravityComponent.class);
1861            GameComponent movement = allocateComponent(MovementComponent.class);
1862
1863            GameComponent physics = allocateComponent(SimplePhysicsComponent.class);
1864
1865            SolidSurfaceComponent solidSurface = (SolidSurfaceComponent)allocateComponent(SolidSurfaceComponent.class);
1866            solidSurface.inititalize(4);
1867
1868            Vector2 surface1Start = new Vector2(25, 0);
1869            Vector2 surface1End = new Vector2(25, 64);
1870            Vector2 surface1Normal = new Vector2(-1, 0);
1871
1872            Vector2 surface2Start = new Vector2(40, 0);
1873            Vector2 surface2End = new Vector2(40, 64);
1874            Vector2 surface2Normal = new Vector2(1, 0);
1875
1876            solidSurface.addSurface(surface1Start, surface1End, surface1Normal);
1877            solidSurface.addSurface(surface2Start, surface2End, surface2Normal);
1878
1879            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
1880                new FixedSizeArray<CollisionVolume>(1);
1881            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 32, 32));
1882            basicVulnerabilityVolume.get(0).setHitType(HitType.HIT);
1883
1884            FixedSizeArray<CollisionVolume> basicAttackVolume =
1885                new FixedSizeArray<CollisionVolume>(1);
1886            basicAttackVolume.add(new SphereCollisionVolume(16, 48, 32, HitType.HIT));
1887
1888            SpriteAnimation idle = new SpriteAnimation(EnemyAnimations.IDLE.ordinal(), 1);
1889            idle.addFrame(new AnimationFrame(
1890                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_stand),
1891                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
1892
1893            SpriteAnimation walk = new SpriteAnimation(EnemyAnimations.MOVE.ordinal(), 6);
1894            walk.addFrame(new AnimationFrame(
1895                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_walk01),
1896                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume));
1897            walk.addFrame(new AnimationFrame(
1898                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_walk02),
1899                    Utils.framesToTime(24, 4), null, basicVulnerabilityVolume));
1900            walk.addFrame(new AnimationFrame(
1901                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_walk03),
1902                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume));
1903            walk.addFrame(new AnimationFrame(
1904                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_walk04),
1905                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume));
1906            walk.addFrame(new AnimationFrame(
1907                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_walk05),
1908                    Utils.framesToTime(24, 4), null, basicVulnerabilityVolume));
1909            walk.addFrame(new AnimationFrame(
1910                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_walk03),
1911                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume));
1912
1913            walk.setLoop(true);
1914
1915
1916            SpriteAnimation attack = new SpriteAnimation(EnemyAnimations.ATTACK.ordinal(), 3);
1917            attack.addFrame(new AnimationFrame(
1918                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_attack01),
1919                    Utils.framesToTime(24, 5), null, basicVulnerabilityVolume));
1920            attack.addFrame(new AnimationFrame(
1921                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_attack03),
1922                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
1923            attack.addFrame(new AnimationFrame(
1924                    textureLibrary.allocateTexture(R.drawable.enemy_skeleton_attack04),
1925                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
1926
1927            staticData.add(gravity);
1928            staticData.add(movement);
1929            staticData.add(physics);
1930            staticData.add(solidSurface);
1931            staticData.add(idle);
1932            staticData.add(walk);
1933            staticData.add(attack);
1934
1935            setStaticData(GameObjectType.SKELETON, staticData);
1936        }
1937
1938        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
1939        render.setPriority(SortConstants.GENERAL_ENEMY);
1940
1941        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
1942		bgcollision.setSize(32, 48);
1943		bgcollision.setOffset(16, 5);
1944
1945        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
1946		sprite.setSize((int)object.width, (int)object.height);
1947        sprite.setRenderComponent(render);
1948
1949        EnemyAnimationComponent animation = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
1950        animation.setSprite(sprite);
1951
1952        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
1953        patrol.setMovementSpeed(20.0f, 1000.0f);
1954        patrol.setTurnToFacePlayer(true);
1955
1956        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
1957        sprite.setCollisionComponent(collision);
1958
1959        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
1960        collision.setHitReactionComponent(hitReact);
1961
1962        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
1963        lifetime.setVulnerableToDeathTiles(true);
1964        lifetime.setObjectToSpawnOnDeath(GameObjectType.SMOKE_POOF);
1965        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
1966        if (sound != null) {
1967        	lifetime.setDeathSound(sound.load(R.raw.sound_stomp));
1968        }
1969
1970        object.team = Team.ENEMY;
1971
1972        if (flipHorizontal) {
1973            object.facingDirection.x = -1.0f;
1974        }
1975
1976        object.add(render);
1977        object.add(sprite);
1978        object.add(bgcollision);
1979        object.add(animation);
1980        object.add(patrol);
1981        object.add(collision);
1982        object.add(hitReact);
1983        object.add(lifetime);
1984
1985        addStaticData(GameObjectType.SKELETON, object, sprite);
1986
1987        final SpriteAnimation attack = sprite.findAnimation(EnemyAnimations.ATTACK.ordinal());
1988        if (attack != null) {
1989            patrol.setupAttack(75.0f, attack.getLength(), 2.0f, true);
1990        }
1991
1992        sprite.playAnimation(0);
1993
1994        return object;
1995    }
1996
1997
1998    public GameObject spawnEnemyKaraguin(float positionX, float positionY, boolean flipHorizontal) {
1999        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2000
2001
2002        GameObject object = mGameObjectPool.allocate();
2003        object.getPosition().set(positionX, positionY);
2004        object.activationRadius = mNormalActivationRadius;
2005        object.width = 32;
2006        object.height = 32;
2007
2008        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.KARAGUIN);
2009        if (staticData == null) {
2010            final int staticObjectCount = 2;
2011            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
2012
2013            GameComponent movement = allocateComponent(MovementComponent.class);
2014
2015            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
2016                new FixedSizeArray<CollisionVolume>(1);
2017            basicVulnerabilityVolume.add(new SphereCollisionVolume(8, 16, 16));
2018            basicVulnerabilityVolume.get(0).setHitType(HitType.HIT);
2019
2020            FixedSizeArray<CollisionVolume> basicAttackVolume =
2021                new FixedSizeArray<CollisionVolume>(1);
2022            basicAttackVolume.add(new SphereCollisionVolume(8, 16, 16, HitType.HIT));
2023
2024            SpriteAnimation idle = new SpriteAnimation(0, 3);
2025            idle.addFrame(new AnimationFrame(
2026                    textureLibrary.allocateTexture(R.drawable.enemy_karaguin01),
2027                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2028            idle.addFrame(new AnimationFrame(
2029                    textureLibrary.allocateTexture(R.drawable.enemy_karaguin02),
2030                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2031            idle.addFrame(new AnimationFrame(
2032                    textureLibrary.allocateTexture(R.drawable.enemy_karaguin03),
2033                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2034            idle.setLoop(true);
2035
2036            staticData.add(movement);
2037            staticData.add(idle);
2038
2039
2040            setStaticData(GameObjectType.KARAGUIN, staticData);
2041        }
2042
2043        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
2044        render.setPriority(SortConstants.GENERAL_ENEMY);
2045
2046        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
2047        sprite.setSize((int)object.width, (int)object.height);
2048        sprite.setRenderComponent(render);
2049
2050        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
2051        patrol.setMovementSpeed(50.0f, 1000.0f);
2052        patrol.setTurnToFacePlayer(false);
2053        patrol.setFlying(true);
2054
2055        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
2056        sprite.setCollisionComponent(collision);
2057
2058        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
2059        collision.setHitReactionComponent(hitReact);
2060
2061        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
2062        lifetime.setObjectToSpawnOnDeath(GameObjectType.SMOKE_POOF);
2063        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
2064        if (sound != null) {
2065        	lifetime.setDeathSound(sound.load(R.raw.sound_stomp));
2066        }
2067
2068        EnemyAnimationComponent animation = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
2069        animation.setSprite(sprite);
2070
2071        object.team = Team.ENEMY;
2072
2073        if (flipHorizontal) {
2074            object.facingDirection.x = -1.0f;
2075        }
2076        // HACK.  These guys originally moved on their own, so let's keep them that way.
2077        object.getVelocity().x = 50.0f * object.facingDirection.x;
2078        object.getTargetVelocity().x = 50.0f * object.facingDirection.x;
2079
2080        object.add(render);
2081        object.add(animation);
2082        object.add(sprite);
2083        object.add(patrol);
2084        object.add(collision);
2085        object.add(hitReact);
2086        object.add(lifetime);
2087
2088        addStaticData(GameObjectType.KARAGUIN, object, sprite);
2089
2090        sprite.playAnimation(0);
2091
2092        return object;
2093    }
2094
2095    public GameObject spawnEnemyPinkNamazu(float positionX, float positionY, boolean flipHorizontal) {
2096        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2097
2098
2099        GameObject object = mGameObjectPool.allocate();
2100        object.getPosition().set(positionX, positionY);
2101        object.activationRadius = mTightActivationRadius;
2102        object.width = 128;
2103        object.height = 128;
2104
2105        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.PINK_NAMAZU);
2106        if (staticData == null) {
2107            final int staticObjectCount = 7;
2108            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
2109
2110            GameComponent gravity = allocateComponent(GravityComponent.class);
2111            GameComponent movement = allocateComponent(MovementComponent.class);
2112
2113            GameComponent physics = allocateComponent(SimplePhysicsComponent.class);
2114
2115            SolidSurfaceComponent solidSurface
2116                = (SolidSurfaceComponent)allocateComponent(SolidSurfaceComponent.class);
2117            solidSurface.inititalize(5);
2118            // circle shape:
2119            //  __        __3
2120            // /  \      2/ \4
2121            // |   |     1|  |5
2122            /*
2123                0:12,6:22,52:0.98058067569092,-0.19611613513818
2124                0:22,52:50,75:-0.62580046626293,0.77998318983495
2125                0:50,75:81,75:0,1
2126                0:81,75:104,49:0.74038072228541,0.67218776102228
2127                0:104,49:104,6:-0.99997086544204,-0.00763336538505
2128             */
2129            Vector2 surface1Start = new Vector2(12, 3);
2130            Vector2 surface1End = new Vector2(22, 52);
2131            Vector2 surface1Normal = new Vector2(-0.98058067569092f, -0.19611613513818f);
2132            surface1Normal.normalize();
2133
2134            Vector2 surface2Start = new Vector2(22, 52);
2135            Vector2 surface2End = new Vector2(50, 75);
2136            Vector2 surface2Normal = new Vector2(-0.62580046626293f, 0.77998318983495f);
2137            surface2Normal.normalize();
2138
2139            Vector2 surface3Start = new Vector2(50, 75);
2140            Vector2 surface3End = new Vector2(81, 75);
2141            Vector2 surface3Normal = new Vector2(0, 1);
2142
2143            Vector2 surface4Start = new Vector2(81, 75);
2144            Vector2 surface4End = new Vector2(104,49);
2145            Vector2 surface4Normal = new Vector2(0.74038072228541f, 0.67218776102228f);
2146
2147            Vector2 surface5Start = new Vector2(104,49);
2148            Vector2 surface5End = new Vector2(104, 3);
2149            Vector2 surface5Normal = new Vector2(1.0f, 0.0f);
2150
2151            solidSurface.addSurface(surface1Start, surface1End, surface1Normal);
2152            solidSurface.addSurface(surface2Start, surface2End, surface2Normal);
2153            solidSurface.addSurface(surface3Start, surface3End, surface3Normal);
2154            solidSurface.addSurface(surface4Start, surface4End, surface4Normal);
2155            solidSurface.addSurface(surface5Start, surface5End, surface5Normal);
2156
2157
2158            SpriteAnimation idle = new SpriteAnimation(GenericAnimationComponent.Animation.IDLE, 4);
2159            idle.addFrame(new AnimationFrame(
2160                    textureLibrary.allocateTexture(R.drawable.enemy_pinkdude_stand),
2161                    Utils.framesToTime(24, 8), null, null));
2162            AnimationFrame idle1 = new AnimationFrame(
2163                    textureLibrary.allocateTexture(R.drawable.enemy_pinkdude_sleep01),
2164                    Utils.framesToTime(24, 3), null, null);
2165            AnimationFrame idle2 = new AnimationFrame(
2166                    textureLibrary.allocateTexture(R.drawable.enemy_pinkdude_sleep02),
2167                    Utils.framesToTime(24, 8), null, null);
2168            idle.addFrame(idle1);
2169            idle.addFrame(idle2);
2170            idle.addFrame(idle1);
2171            idle.setLoop(true);
2172
2173
2174            SpriteAnimation wake = new SpriteAnimation(GenericAnimationComponent.Animation.MOVE, 4);
2175            AnimationFrame wake1 = new AnimationFrame(
2176                    textureLibrary.allocateTexture(R.drawable.enemy_pinkdude_eyeopen),
2177                    Utils.framesToTime(24, 3), null, null);
2178            AnimationFrame wake2 = new AnimationFrame(
2179                    textureLibrary.allocateTexture(R.drawable.enemy_pinkdude_stand),
2180                    Utils.framesToTime(24, 3), null, null);
2181            wake.addFrame(wake1);
2182            wake.addFrame(wake2);
2183            wake.addFrame(wake1);
2184            wake.addFrame(wake2);
2185
2186            FixedSizeArray<CollisionVolume> crushAttackVolume =
2187                new FixedSizeArray<CollisionVolume>(1);
2188            crushAttackVolume.add(new AABoxCollisionVolume(32, 0, 64, 32, HitType.HIT));
2189
2190            SpriteAnimation attack = new SpriteAnimation(GenericAnimationComponent.Animation.ATTACK, 1);
2191            attack.addFrame(new AnimationFrame(
2192                    textureLibrary.allocateTexture(R.drawable.enemy_pinkdude_jump),
2193                    Utils.framesToTime(24, 2), crushAttackVolume, null));
2194
2195
2196            staticData.add(gravity);
2197            staticData.add(movement);
2198            staticData.add(physics);
2199            staticData.add(solidSurface);
2200            staticData.add(idle);
2201            staticData.add(wake);
2202            staticData.add(attack);
2203
2204            setStaticData(GameObjectType.PINK_NAMAZU, staticData);
2205        }
2206
2207        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
2208        render.setPriority(SortConstants.GENERAL_ENEMY);
2209
2210        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
2211        bgcollision.setSize(100, 75);
2212        bgcollision.setOffset(12, 5);
2213
2214        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
2215        sprite.setSize((int)object.width, (int)object.height);
2216        sprite.setRenderComponent(render);
2217
2218        GenericAnimationComponent animation =
2219            (GenericAnimationComponent)allocateComponent(GenericAnimationComponent.class);
2220        animation.setSprite(sprite);
2221
2222        SleeperComponent sleeper = (SleeperComponent)allocateComponent(SleeperComponent.class);
2223        sleeper.setAttackImpulse(100.0f, 170.0f);
2224        sleeper.setSlam(0.3f, 25.0f);
2225
2226        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
2227        sprite.setCollisionComponent(collision);
2228
2229        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
2230        collision.setHitReactionComponent(hitReact);
2231
2232
2233        object.team = Team.ENEMY;
2234        object.life = 1;
2235
2236        if (flipHorizontal) {
2237            object.facingDirection.x = -1.0f;
2238        }
2239
2240        object.add(render);
2241        object.add(sprite);
2242        object.add(bgcollision);
2243        object.add(animation);
2244        object.add(collision);
2245        object.add(hitReact);
2246        object.add(sleeper);
2247
2248
2249        addStaticData(GameObjectType.PINK_NAMAZU, object, sprite);
2250
2251        final SpriteAnimation wakeUp = sprite.findAnimation(GenericAnimationComponent.Animation.MOVE);
2252        if (wakeUp != null) {
2253            sleeper.setWakeUpDuration(wakeUp.getLength() + 1.0f);
2254        }
2255
2256        sprite.playAnimation(GenericAnimationComponent.Animation.IDLE);
2257
2258        return object;
2259    }
2260
2261    public GameObject spawnEnemyBat(float positionX, float positionY, boolean flipHorizontal) {
2262        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2263
2264
2265        GameObject object = mGameObjectPool.allocate();
2266        object.getPosition().set(positionX, positionY);
2267        object.activationRadius = mNormalActivationRadius;
2268        object.width = 64;
2269        object.height = 32;
2270
2271        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.BAT);
2272        if (staticData == null) {
2273            final int staticObjectCount = 2;
2274            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
2275
2276            GameComponent movement = allocateComponent(MovementComponent.class);
2277
2278            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
2279                new FixedSizeArray<CollisionVolume>(1);
2280            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 32, 16));
2281            basicVulnerabilityVolume.get(0).setHitType(HitType.HIT);
2282
2283            FixedSizeArray<CollisionVolume> basicAttackVolume =
2284                new FixedSizeArray<CollisionVolume>(1);
2285            basicAttackVolume.add(new SphereCollisionVolume(16, 32, 16, HitType.HIT));
2286
2287            SpriteAnimation idle = new SpriteAnimation(0, 4);
2288            idle.addFrame(new AnimationFrame(
2289                    textureLibrary.allocateTexture(R.drawable.enemy_bat01),
2290                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2291            idle.addFrame(new AnimationFrame(
2292                    textureLibrary.allocateTexture(R.drawable.enemy_bat02),
2293                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2294            idle.addFrame(new AnimationFrame(
2295                    textureLibrary.allocateTexture(R.drawable.enemy_bat03),
2296                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2297            idle.addFrame(new AnimationFrame(
2298                    textureLibrary.allocateTexture(R.drawable.enemy_bat04),
2299                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2300            idle.setLoop(true);
2301
2302            staticData.add(movement);
2303            staticData.add(idle);
2304
2305
2306            setStaticData(GameObjectType.BAT, staticData);
2307        }
2308
2309        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
2310        render.setPriority(SortConstants.GENERAL_ENEMY);
2311
2312        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
2313        sprite.setSize((int)object.width, (int)object.height);
2314        sprite.setRenderComponent(render);
2315
2316        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
2317        patrol.setMovementSpeed(75.0f, 1000.0f);
2318        patrol.setTurnToFacePlayer(false);
2319        patrol.setFlying(true);
2320
2321        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
2322        sprite.setCollisionComponent(collision);
2323
2324        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
2325        collision.setHitReactionComponent(hitReact);
2326
2327        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
2328        lifetime.setObjectToSpawnOnDeath(GameObjectType.SMOKE_POOF);
2329        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
2330        if (sound != null) {
2331        	lifetime.setDeathSound(sound.load(R.raw.sound_stomp));
2332        }
2333
2334        EnemyAnimationComponent animation = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
2335        animation.setSprite(sprite);
2336
2337        object.team = Team.ENEMY;
2338
2339        if (flipHorizontal) {
2340            object.facingDirection.x = -1.0f;
2341        }
2342
2343        // HACK.  These guys originally moved on their own, so let's keep them that way.
2344        object.getVelocity().x = 75.0f * object.facingDirection.x;
2345        object.getTargetVelocity().x = 75.0f * object.facingDirection.x;
2346
2347        object.add(render);
2348        object.add(animation);
2349        object.add(sprite);
2350        object.add(patrol);
2351        object.add(collision);
2352        object.add(hitReact);
2353        object.add(lifetime);
2354
2355        addStaticData(GameObjectType.BAT, object, sprite);
2356
2357        sprite.playAnimation(0);
2358
2359        return object;
2360    }
2361
2362    public GameObject spawnEnemySting(float positionX, float positionY, boolean flipHorizontal) {
2363        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2364
2365
2366        GameObject object = mGameObjectPool.allocate();
2367        object.getPosition().set(positionX, positionY);
2368        object.activationRadius = mNormalActivationRadius;
2369        object.width = 64;
2370        object.height = 64;
2371
2372        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.STING);
2373        if (staticData == null) {
2374            final int staticObjectCount = 2;
2375            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
2376
2377            GameComponent movement = allocateComponent(MovementComponent.class);
2378
2379            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
2380                new FixedSizeArray<CollisionVolume>(1);
2381            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 32, 16));
2382            basicVulnerabilityVolume.get(0).setHitType(HitType.HIT);
2383
2384            FixedSizeArray<CollisionVolume> basicAttackVolume =
2385                new FixedSizeArray<CollisionVolume>(1);
2386            basicAttackVolume.add(new SphereCollisionVolume(16, 32, 16, HitType.HIT));
2387
2388            SpriteAnimation idle = new SpriteAnimation(0, 3);
2389            idle.addFrame(new AnimationFrame(
2390                    textureLibrary.allocateTexture(R.drawable.enemy_sting01),
2391                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2392            idle.addFrame(new AnimationFrame(
2393                    textureLibrary.allocateTexture(R.drawable.enemy_sting02),
2394                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2395            idle.addFrame(new AnimationFrame(
2396                    textureLibrary.allocateTexture(R.drawable.enemy_sting03),
2397                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2398
2399            idle.setLoop(true);
2400
2401            staticData.add(movement);
2402            staticData.add(idle);
2403
2404
2405            setStaticData(GameObjectType.STING, staticData);
2406        }
2407
2408        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
2409        render.setPriority(SortConstants.GENERAL_ENEMY);
2410
2411        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
2412        sprite.setSize((int)object.width, (int)object.height);
2413        sprite.setRenderComponent(render);
2414
2415        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
2416        patrol.setMovementSpeed(75.0f, 1000.0f);
2417        patrol.setTurnToFacePlayer(false);
2418        patrol.setFlying(true);
2419
2420        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
2421        sprite.setCollisionComponent(collision);
2422
2423        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
2424        collision.setHitReactionComponent(hitReact);
2425
2426        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
2427        lifetime.setObjectToSpawnOnDeath(GameObjectType.SMOKE_POOF);
2428        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
2429        if (sound != null) {
2430        	lifetime.setDeathSound(sound.load(R.raw.sound_stomp));
2431        }
2432
2433        EnemyAnimationComponent animation = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
2434        animation.setSprite(sprite);
2435
2436        object.team = Team.ENEMY;
2437
2438        if (flipHorizontal) {
2439            object.facingDirection.x = -1.0f;
2440        }
2441
2442        // HACK.  These guys originally moved on their own, so let's keep them that way.
2443        object.getVelocity().x = 25.0f * object.facingDirection.x;
2444        object.getTargetVelocity().x = 25.0f * object.facingDirection.x;
2445
2446        object.add(render);
2447        object.add(animation);
2448        object.add(sprite);
2449        object.add(patrol);
2450        object.add(collision);
2451        object.add(hitReact);
2452        object.add(lifetime);
2453
2454        addStaticData(GameObjectType.STING, object, sprite);
2455
2456        sprite.playAnimation(0);
2457
2458        return object;
2459    }
2460
2461    public GameObject spawnEnemyOnion(float positionX, float positionY, boolean flipHorizontal) {
2462        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2463
2464        GameObject object = mGameObjectPool.allocate();
2465        object.getPosition().set(positionX, positionY);
2466        object.activationRadius = mNormalActivationRadius;
2467        object.width = 64;
2468        object.height = 64;
2469
2470        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.ONION);
2471        if (staticData == null) {
2472            final int staticObjectCount = 5;
2473            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
2474
2475            GameComponent gravity = allocateComponent(GravityComponent.class);
2476            GameComponent movement = allocateComponent(MovementComponent.class);
2477            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
2478            physics.setBounciness(0.2f);
2479
2480
2481            // Animations
2482            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
2483                new FixedSizeArray<CollisionVolume>(1);
2484            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 32, 32));
2485
2486            FixedSizeArray<CollisionVolume> basicAttackVolume =
2487                new FixedSizeArray<CollisionVolume>(1);
2488            basicAttackVolume.add(new SphereCollisionVolume(16, 32, 32, HitType.HIT));
2489
2490            SpriteAnimation idle = new SpriteAnimation(EnemyAnimations.IDLE.ordinal(), 1);
2491            idle.addFrame(new AnimationFrame(
2492                    textureLibrary.allocateTexture(R.drawable.enemy_onion01),
2493                    Utils.framesToTime(24, 3), basicAttackVolume, basicVulnerabilityVolume));
2494
2495            idle.setLoop(true);
2496
2497            SpriteAnimation walk = new SpriteAnimation(EnemyAnimations.MOVE.ordinal(), 3);
2498            walk.addFrame(new AnimationFrame(
2499                    textureLibrary.allocateTexture(R.drawable.enemy_onion01),
2500                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2501            walk.addFrame(new AnimationFrame(
2502                    textureLibrary.allocateTexture(R.drawable.enemy_onion02),
2503                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2504            walk.addFrame(new AnimationFrame(
2505                    textureLibrary.allocateTexture(R.drawable.enemy_onion03),
2506                    Utils.framesToTime(24, 1), basicAttackVolume, basicVulnerabilityVolume));
2507            walk.setLoop(true);
2508
2509            staticData.add(gravity);
2510            staticData.add(movement);
2511            staticData.add(physics);
2512            staticData.add(idle);
2513            staticData.add(walk);
2514
2515            setStaticData(GameObjectType.ONION, staticData);
2516
2517        }
2518        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
2519        render.setPriority(SortConstants.GENERAL_ENEMY);
2520
2521        BackgroundCollisionComponent bgcollision
2522            = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
2523        bgcollision.setSize(32, 48);
2524        bgcollision.setOffset(16, 5);
2525
2526        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
2527        sprite.setSize((int)object.width, (int)object.height);
2528        sprite.setRenderComponent(render);
2529
2530        EnemyAnimationComponent animation
2531            = (EnemyAnimationComponent)allocateComponent(EnemyAnimationComponent.class);
2532        animation.setSprite(sprite);
2533
2534        PatrolComponent patrol = (PatrolComponent)allocateComponent(PatrolComponent.class);
2535        patrol.setMovementSpeed(50.0f, 1000.0f);
2536
2537        DynamicCollisionComponent collision
2538            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
2539        sprite.setCollisionComponent(collision);
2540
2541        HitReactionComponent hitReact
2542            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
2543        collision.setHitReactionComponent(hitReact);
2544
2545        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
2546        lifetime.setVulnerableToDeathTiles(true);
2547        lifetime.setObjectToSpawnOnDeath(GameObjectType.SMOKE_POOF);
2548        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
2549        if (sound != null) {
2550        	lifetime.setDeathSound(sound.load(R.raw.sound_stomp));
2551        }
2552
2553        object.add(render);
2554        object.add(sprite);
2555
2556        object.add(bgcollision);
2557        object.add(animation);
2558        object.add(patrol);
2559        object.add(collision);
2560        object.add(hitReact);
2561        object.add(lifetime);
2562
2563        object.team = Team.ENEMY;
2564
2565
2566        if (flipHorizontal) {
2567            object.facingDirection.x = -1.0f;
2568        }
2569
2570        addStaticData(GameObjectType.ONION, object, sprite);
2571
2572        sprite.playAnimation(0);
2573
2574        return object;
2575    }
2576
2577    public GameObject spawnEnemyWanda(float positionX, float positionY, boolean flipHorizontal) {
2578        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2579
2580
2581        // Make sure related textures are loaded.
2582        textureLibrary.allocateTexture(R.drawable.energy_ball01);
2583        textureLibrary.allocateTexture(R.drawable.energy_ball02);
2584        textureLibrary.allocateTexture(R.drawable.energy_ball03);
2585        textureLibrary.allocateTexture(R.drawable.energy_ball04);
2586
2587        GameObject object = mGameObjectPool.allocate();
2588        object.getPosition().set(positionX, positionY);
2589        object.activationRadius = mAlwaysActive;
2590        object.width = 64;
2591        object.height = 128;
2592
2593        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.WANDA);
2594        if (staticData == null) {
2595            final int staticObjectCount = 9;
2596            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
2597
2598            GameComponent gravity = allocateComponent(GravityComponent.class);
2599            GameComponent movement = allocateComponent(MovementComponent.class);
2600
2601            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
2602            physics.setBounciness(0.0f);
2603
2604
2605
2606            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
2607                new FixedSizeArray<CollisionVolume>(1);
2608            basicVulnerabilityVolume.add(new AABoxCollisionVolume(20, 5, 26, 80, HitType.COLLECT));
2609
2610            SpriteAnimation idle = new SpriteAnimation(NPCAnimationComponent.IDLE, 1);
2611            idle.addFrame(new AnimationFrame(
2612                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_stand),
2613                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2614
2615
2616
2617            AnimationFrame walkFrame1 = new AnimationFrame(
2618                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_walk01),
2619                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2620            AnimationFrame walkFrame2 = new AnimationFrame(
2621                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_walk02),
2622                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2623            AnimationFrame walkFrame3 = new AnimationFrame(
2624                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_walk03),
2625                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2626            AnimationFrame walkFrame4 = new AnimationFrame(
2627                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_walk04),
2628                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2629            AnimationFrame walkFrame5 = new AnimationFrame(
2630                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_walk05),
2631                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2632            SpriteAnimation walk = new SpriteAnimation(NPCAnimationComponent.WALK, 8);
2633            walk.addFrame(walkFrame1);
2634            walk.addFrame(walkFrame2);
2635            walk.addFrame(walkFrame3);
2636            walk.addFrame(walkFrame4);
2637            walk.addFrame(walkFrame5);
2638            walk.addFrame(walkFrame4);
2639            walk.addFrame(walkFrame3);
2640            walk.addFrame(walkFrame2);
2641            walk.setLoop(true);
2642
2643
2644            AnimationFrame runFrame4 = new AnimationFrame(
2645                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run04),
2646                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
2647
2648            SpriteAnimation run = new SpriteAnimation(NPCAnimationComponent.RUN, 9);
2649            run.addFrame(new AnimationFrame(
2650                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run01),
2651                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2652            run.addFrame(new AnimationFrame(
2653                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run02),
2654                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2655            run.addFrame(new AnimationFrame(
2656                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run03),
2657                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2658            run.addFrame(runFrame4);
2659            run.addFrame(new AnimationFrame(
2660                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run05),
2661                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2662            run.addFrame(new AnimationFrame(
2663                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run06),
2664                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2665            run.addFrame(new AnimationFrame(
2666                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run07),
2667                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2668            run.addFrame(runFrame4);
2669            run.addFrame(new AnimationFrame(
2670                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run08),
2671                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2672            run.setLoop(true);
2673
2674            SpriteAnimation jumpStart = new SpriteAnimation(NPCAnimationComponent.JUMP_START, 4);
2675            AnimationFrame jump1 = new AnimationFrame(
2676                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_jump01),
2677                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
2678            AnimationFrame jump2 = new AnimationFrame(
2679                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_jump01),
2680                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
2681            jumpStart.addFrame(new AnimationFrame(
2682                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_run04),
2683                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
2684            jumpStart.addFrame(new AnimationFrame(
2685                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_crouch),
2686                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2687            jumpStart.addFrame(jump1);
2688            jumpStart.addFrame(jump2);
2689
2690            SpriteAnimation jumpAir = new SpriteAnimation(NPCAnimationComponent.JUMP_AIR, 2);
2691            jumpAir.addFrame(jump1);
2692            jumpAir.addFrame(jump2);
2693            jumpAir.setLoop(true);
2694
2695            SpriteAnimation attack = new SpriteAnimation(NPCAnimationComponent.SHOOT, 11);
2696            attack.addFrame(new AnimationFrame(
2697                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot01),
2698                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
2699            attack.addFrame(new AnimationFrame(
2700                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot02),
2701                    Utils.framesToTime(24, 8), null, basicVulnerabilityVolume));
2702            attack.addFrame(new AnimationFrame(
2703                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot03),
2704                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2705            attack.addFrame(new AnimationFrame(
2706                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot04),
2707                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2708            attack.addFrame(new AnimationFrame(
2709                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot05),
2710                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2711            attack.addFrame(new AnimationFrame(
2712                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot06),
2713                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2714            attack.addFrame(new AnimationFrame(
2715                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot07),
2716                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2717            attack.addFrame(new AnimationFrame(
2718                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot08),
2719                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2720            attack.addFrame(new AnimationFrame(
2721                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot09),
2722                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
2723            attack.addFrame(new AnimationFrame(
2724                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot02),
2725                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume));
2726            attack.addFrame(new AnimationFrame(
2727                    textureLibrary.allocateTexture(R.drawable.enemy_wanda_shoot01),
2728                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume));
2729
2730            staticData.add(gravity);
2731            staticData.add(movement);
2732            staticData.add(physics);
2733            staticData.add(idle);
2734            staticData.add(walk);
2735            staticData.add(run);
2736            staticData.add(jumpStart);
2737            staticData.add(jumpAir);
2738            staticData.add(attack);
2739
2740            setStaticData(GameObjectType.WANDA, staticData);
2741        }
2742
2743        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
2744        render.setPriority(SortConstants.NPC);
2745
2746        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
2747        bgcollision.setSize(32, 82);
2748        bgcollision.setOffset(20, 5);
2749
2750        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
2751        sprite.setSize((int)object.width, (int)object.height);
2752        sprite.setRenderComponent(render);
2753
2754        NPCAnimationComponent animation = (NPCAnimationComponent)allocateComponent(NPCAnimationComponent.class);
2755        animation.setSprite(sprite);
2756
2757        NPCComponent patrol = (NPCComponent)allocateComponent(NPCComponent.class);
2758
2759        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
2760        sprite.setCollisionComponent(collision);
2761
2762        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
2763        collision.setHitReactionComponent(hitReact);
2764
2765        patrol.setHitReactionComponent(hitReact);
2766
2767        SoundSystem sound = sSystemRegistry.soundSystem;
2768
2769        LaunchProjectileComponent gun
2770            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
2771        gun.setShotsPerSet(1);
2772        gun.setSetsPerActivation(1);
2773        gun.setDelayBeforeFirstSet(Utils.framesToTime(24, 11));
2774        gun.setObjectTypeToSpawn(GameObjectType.WANDA_SHOT);
2775        gun.setOffsetX(45);
2776        gun.setOffsetY(42);
2777        gun.setRequiredAction(GameObject.ActionType.ATTACK);
2778        gun.setVelocityX(300.0f);
2779        gun.setShootSound(sound.load(R.raw.sound_poing));
2780
2781        object.team = Team.ENEMY;
2782        object.life = 1;
2783
2784        if (flipHorizontal) {
2785            object.facingDirection.x = -1.0f;
2786        }
2787
2788        object.add(gun);
2789        object.add(render);
2790        object.add(sprite);
2791        object.add(bgcollision);
2792        object.add(animation);
2793        object.add(patrol);
2794        object.add(collision);
2795        object.add(hitReact);
2796
2797        addStaticData(GameObjectType.WANDA, object, sprite);
2798
2799
2800        sprite.playAnimation(0);
2801
2802        return object;
2803    }
2804
2805
2806    public GameObject spawnEnemyKyle(float positionX, float positionY, boolean flipHorizontal) {
2807        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2808
2809
2810
2811        GameObject object = mGameObjectPool.allocate();
2812        object.getPosition().set(positionX, positionY);
2813        object.activationRadius = mAlwaysActive;
2814        object.width = 64;
2815        object.height = 128;
2816
2817        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.KYLE);
2818        if (staticData == null) {
2819            final int staticObjectCount = 9;
2820            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
2821
2822            GameComponent gravity = allocateComponent(GravityComponent.class);
2823            GameComponent movement = allocateComponent(MovementComponent.class);
2824
2825            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
2826            physics.setBounciness(0.0f);
2827
2828            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
2829                new FixedSizeArray<CollisionVolume>(1);
2830            basicVulnerabilityVolume.add(new AABoxCollisionVolume(20, 5, 26, 80, HitType.COLLECT));
2831
2832            SpriteAnimation idle = new SpriteAnimation(NPCAnimationComponent.IDLE, 1);
2833            idle.addFrame(new AnimationFrame(
2834                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_stand),
2835                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
2836
2837            AnimationFrame walkFrame1 = new AnimationFrame(
2838                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_walk01),
2839                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2840            AnimationFrame walkFrame2 = new AnimationFrame(
2841                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_walk02),
2842                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2843            AnimationFrame walkFrame3 = new AnimationFrame(
2844                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_walk03),
2845                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2846            AnimationFrame walkFrame4 = new AnimationFrame(
2847                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_walk04),
2848                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2849            AnimationFrame walkFrame5 = new AnimationFrame(
2850                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_walk05),
2851                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2852            AnimationFrame walkFrame6 = new AnimationFrame(
2853                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_walk06),
2854                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2855            AnimationFrame walkFrame7 = new AnimationFrame(
2856                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_walk07),
2857                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
2858            SpriteAnimation walk = new SpriteAnimation(NPCAnimationComponent.WALK, 12);
2859            walk.addFrame(walkFrame1);
2860            walk.addFrame(walkFrame2);
2861            walk.addFrame(walkFrame3);
2862            walk.addFrame(walkFrame4);
2863            walk.addFrame(walkFrame3);
2864            walk.addFrame(walkFrame2);
2865            walk.addFrame(walkFrame1);
2866            walk.addFrame(walkFrame5);
2867            walk.addFrame(walkFrame6);
2868            walk.addFrame(walkFrame7);
2869            walk.addFrame(walkFrame6);
2870            walk.addFrame(walkFrame5);
2871
2872            walk.setLoop(true);
2873
2874            AnimationFrame crouch1 = new AnimationFrame(
2875                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_crouch01),
2876                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
2877            AnimationFrame crouch2 = new AnimationFrame(
2878                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_crouch02),
2879                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
2880
2881            SpriteAnimation runStart = new SpriteAnimation(NPCAnimationComponent.RUN_START, 2);
2882            runStart.addFrame(crouch1);
2883            runStart.addFrame(crouch2);
2884
2885            FixedSizeArray<CollisionVolume> attackVolume =
2886                new FixedSizeArray<CollisionVolume>(2);
2887            attackVolume.add(new AABoxCollisionVolume(32, 32, 50, 32, HitType.HIT));
2888            attackVolume.add(new AABoxCollisionVolume(32, 32, 50, 32, HitType.COLLECT));
2889
2890            SpriteAnimation run = new SpriteAnimation(NPCAnimationComponent.RUN, 2);
2891            run.addFrame(new AnimationFrame(
2892                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_dash01),
2893                    Utils.framesToTime(24, 1), attackVolume, basicVulnerabilityVolume));
2894            run.addFrame(new AnimationFrame(
2895                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_dash02),
2896                    Utils.framesToTime(24, 1), attackVolume, basicVulnerabilityVolume));
2897            run.setLoop(true);
2898
2899            SpriteAnimation jumpStart = new SpriteAnimation(NPCAnimationComponent.JUMP_START, 2);
2900            jumpStart.addFrame(crouch1);
2901            jumpStart.addFrame(crouch2);
2902
2903            SpriteAnimation jumpAir = new SpriteAnimation(NPCAnimationComponent.JUMP_AIR, 2);
2904            AnimationFrame jump1 = new AnimationFrame(
2905                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_jump01),
2906                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
2907            AnimationFrame jump2 = new AnimationFrame(
2908                    textureLibrary.allocateTexture(R.drawable.enemy_kyle_jump01),
2909                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
2910            jumpAir.addFrame(jump1);
2911            jumpAir.addFrame(jump2);
2912            jumpAir.setLoop(true);
2913
2914
2915
2916            staticData.add(gravity);
2917            staticData.add(movement);
2918            staticData.add(physics);
2919            staticData.add(idle);
2920            staticData.add(walk);
2921            staticData.add(runStart);
2922            staticData.add(run);
2923            staticData.add(jumpStart);
2924            staticData.add(jumpAir);
2925
2926            setStaticData(GameObjectType.KYLE, staticData);
2927        }
2928
2929        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
2930        render.setPriority(SortConstants.NPC);
2931
2932        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
2933        bgcollision.setSize(32, 90);
2934        bgcollision.setOffset(20, 5);
2935
2936        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
2937        sprite.setSize((int)object.width, (int)object.height);
2938        sprite.setRenderComponent(render);
2939
2940        NPCAnimationComponent animation = (NPCAnimationComponent)allocateComponent(NPCAnimationComponent.class);
2941        animation.setSprite(sprite);
2942        animation.setStopAtWalls(false); // Kyle can run through walls
2943
2944        NPCComponent patrol = (NPCComponent)allocateComponent(NPCComponent.class);
2945        patrol.setSpeeds(350.0f, 50.0f, 400.0f, -10.0f, 400.0f);
2946        patrol.setGameEvent(GameFlowEvent.EVENT_SHOW_ANIMATION, AnimationPlayerActivity.KYLE_DEATH, false);
2947
2948        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
2949        sprite.setCollisionComponent(collision);
2950
2951        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
2952        collision.setHitReactionComponent(hitReact);
2953
2954        patrol.setHitReactionComponent(hitReact);
2955
2956        MotionBlurComponent motionBlur = (MotionBlurComponent)allocateComponent(MotionBlurComponent.class);
2957        motionBlur.setTarget(render);
2958
2959        LauncherComponent launcher = (LauncherComponent)allocateComponent(LauncherComponent.class);
2960        launcher.setup((float)(Math.PI * 0.45f), 1000.0f, 0.0f, 0.0f, false);
2961        launcher.setLaunchEffect(GameObjectType.FLASH, 70.0f, 50.0f);
2962        hitReact.setLauncherComponent(launcher, HitType.HIT);
2963
2964        object.team = Team.NONE;
2965        object.life = 1;
2966
2967        if (flipHorizontal) {
2968            object.facingDirection.x = -1.0f;
2969        }
2970
2971        object.add(render);
2972        object.add(sprite);
2973        object.add(bgcollision);
2974        object.add(animation);
2975        object.add(patrol);
2976        object.add(collision);
2977        object.add(hitReact);
2978        object.add(motionBlur);
2979        object.add(launcher);
2980
2981        addStaticData(GameObjectType.KYLE, object, sprite);
2982
2983
2984        sprite.playAnimation(0);
2985
2986        return object;
2987    }
2988
2989    public GameObject spawnEnemyKyleDead(float positionX, float positionY) {
2990        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
2991
2992
2993        GameObject object = mGameObjectPool.allocate();
2994        object.getPosition().set(positionX, positionY);
2995        object.activationRadius = mTightActivationRadius;
2996        object.width = 128;
2997        object.height = 32;
2998
2999        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.KYLE_DEAD);
3000        if (staticData == null) {
3001            final int staticObjectCount = 1;
3002            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3003
3004            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
3005                new FixedSizeArray<CollisionVolume>(1);
3006            basicVulnerabilityVolume.add(new AABoxCollisionVolume(32, 5, 64, 32, HitType.COLLECT));
3007
3008            SpriteAnimation idle = new SpriteAnimation(0, 1);
3009            AnimationFrame frame1 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.enemy_kyle_dead),
3010                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
3011
3012            idle.addFrame(frame1);
3013
3014            idle.setLoop(true);
3015
3016            staticData.add(idle);
3017
3018            setStaticData(GameObjectType.KYLE_DEAD, staticData);
3019        }
3020
3021        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3022        render.setPriority(SortConstants.GENERAL_OBJECT);
3023
3024        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3025        sprite.setSize((int)object.width, (int)object.height);
3026        sprite.setRenderComponent(render);
3027
3028        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3029        sprite.setCollisionComponent(dynamicCollision);
3030
3031        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3032        dynamicCollision.setHitReactionComponent(hitReact);
3033        hitReact.setSpawnGameEventOnHit(HitType.COLLECT, GameFlowEvent.EVENT_SHOW_DIALOG_CHARACTER2, 0);
3034
3035        SelectDialogComponent dialogSelect = (SelectDialogComponent)allocateComponent(SelectDialogComponent.class);
3036        dialogSelect.setHitReact(hitReact);
3037
3038        // Since this object doesn't have gravity or background collision, adjust down to simulate the position
3039        // at which a bounding volume would rest.
3040
3041        object.getPosition().y -= 5.0f;
3042
3043        object.add(dialogSelect);
3044        object.add(render);
3045        object.add(sprite);
3046        object.add(dynamicCollision);
3047        object.add(hitReact);
3048
3049        addStaticData(GameObjectType.KYLE_DEAD, object, sprite);
3050        sprite.playAnimation(0);
3051
3052        return object;
3053    }
3054
3055    public GameObject spawnEnemyAndouDead(float positionX, float positionY) {
3056        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3057
3058
3059        GameObject object = mGameObjectPool.allocate();
3060        object.getPosition().set(positionX, positionY);
3061        object.activationRadius = mTightActivationRadius;
3062        object.width = 64;
3063        object.height = 64;
3064
3065        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.ANDOU_DEAD);
3066        if (staticData == null) {
3067            final int staticObjectCount = 1;
3068            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3069
3070            SpriteAnimation idle = new SpriteAnimation(0, 1);
3071            AnimationFrame frame1 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.andou_explode12),
3072                    Utils.framesToTime(24, 1), null, null);
3073
3074            idle.addFrame(frame1);
3075
3076            idle.setLoop(true);
3077
3078            staticData.add(idle);
3079
3080            setStaticData(GameObjectType.ANDOU_DEAD, staticData);
3081        }
3082
3083        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3084        render.setPriority(SortConstants.GENERAL_OBJECT);
3085
3086        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3087        sprite.setSize((int)object.width, (int)object.height);
3088        sprite.setRenderComponent(render);
3089
3090        LaunchProjectileComponent smokeGun
3091	        = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
3092	    smokeGun.setDelayBetweenShots(0.25f);
3093	    smokeGun.setObjectTypeToSpawn(GameObjectType.SMOKE_BIG);
3094	    smokeGun.setOffsetX(32);
3095	    smokeGun.setOffsetY(15);
3096	    smokeGun.setVelocityX(-150.0f);
3097	    smokeGun.setVelocityY(100.0f);
3098	    smokeGun.setThetaError(0.1f);
3099
3100	    LaunchProjectileComponent smokeGun2
3101	        = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
3102	    smokeGun2.setDelayBetweenShots(0.35f);
3103	    smokeGun2.setObjectTypeToSpawn(GameObjectType.SMOKE_SMALL);
3104	    smokeGun2.setOffsetX(16);
3105	    smokeGun2.setOffsetY(15);
3106	    smokeGun2.setVelocityX(-150.0f);
3107	    smokeGun2.setVelocityY(150.0f);
3108	    smokeGun2.setThetaError(0.1f);
3109
3110        object.add(render);
3111        object.add(sprite);
3112        object.add(smokeGun);
3113        object.add(smokeGun2);
3114
3115        object.facingDirection.x = -1.0f;
3116
3117        addStaticData(GameObjectType.ANDOU_DEAD, object, sprite);
3118        sprite.playAnimation(0);
3119
3120        return object;
3121    }
3122
3123    public GameObject spawnEnemyKabocha(float positionX, float positionY, boolean flipHorizontal) {
3124        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3125
3126
3127        GameObject object = mGameObjectPool.allocate();
3128        object.getPosition().set(positionX, positionY);
3129        object.activationRadius = mAlwaysActive;
3130        object.width = 64;
3131        object.height = 128;
3132
3133        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.KABOCHA);
3134        if (staticData == null) {
3135            final int staticObjectCount = 5;
3136            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3137
3138            GameComponent gravity = allocateComponent(GravityComponent.class);
3139            GameComponent movement = allocateComponent(MovementComponent.class);
3140
3141            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
3142            physics.setBounciness(0.0f);
3143
3144            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
3145                new FixedSizeArray<CollisionVolume>(1);
3146            basicVulnerabilityVolume.add(new AABoxCollisionVolume(20, 5, 26, 80, HitType.COLLECT));
3147
3148            SpriteAnimation idle = new SpriteAnimation(NPCAnimationComponent.IDLE, 1);
3149            idle.addFrame(new AnimationFrame(
3150                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_stand),
3151                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
3152
3153            AnimationFrame walkFrame1 = new AnimationFrame(
3154                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_walk01),
3155                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3156            AnimationFrame walkFrame2 = new AnimationFrame(
3157                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_walk02),
3158                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3159            AnimationFrame walkFrame3 = new AnimationFrame(
3160                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_walk03),
3161                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3162            AnimationFrame walkFrame4 = new AnimationFrame(
3163                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_walk04),
3164                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3165            AnimationFrame walkFrame5 = new AnimationFrame(
3166                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_walk05),
3167                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3168            AnimationFrame walkFrame6 = new AnimationFrame(
3169                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_walk06),
3170                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3171
3172            SpriteAnimation walk = new SpriteAnimation(NPCAnimationComponent.WALK, 6);
3173            walk.addFrame(walkFrame1);
3174            walk.addFrame(walkFrame2);
3175            walk.addFrame(walkFrame3);
3176            walk.addFrame(walkFrame4);
3177            walk.addFrame(walkFrame5);
3178            walk.addFrame(walkFrame6);
3179
3180
3181            walk.setLoop(true);
3182
3183            staticData.add(gravity);
3184            staticData.add(movement);
3185            staticData.add(physics);
3186            staticData.add(idle);
3187            staticData.add(walk);
3188
3189            setStaticData(GameObjectType.KABOCHA, staticData);
3190        }
3191
3192        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3193        render.setPriority(SortConstants.NPC);
3194
3195        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
3196        bgcollision.setSize(38, 82);
3197        bgcollision.setOffset(16, 5);
3198
3199        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3200        sprite.setSize((int)object.width, (int)object.height);
3201        sprite.setRenderComponent(render);
3202
3203        NPCAnimationComponent animation = (NPCAnimationComponent)allocateComponent(NPCAnimationComponent.class);
3204        animation.setSprite(sprite);
3205
3206        NPCComponent patrol = (NPCComponent)allocateComponent(NPCComponent.class);
3207
3208        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3209        sprite.setCollisionComponent(collision);
3210
3211        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3212        collision.setHitReactionComponent(hitReact);
3213
3214        patrol.setHitReactionComponent(hitReact);
3215
3216        object.team = Team.ENEMY;
3217        object.life = 1;
3218
3219        if (flipHorizontal) {
3220            object.facingDirection.x = -1.0f;
3221        }
3222
3223        object.add(render);
3224        object.add(sprite);
3225        object.add(bgcollision);
3226        object.add(animation);
3227        object.add(patrol);
3228        object.add(collision);
3229        object.add(hitReact);
3230
3231        addStaticData(GameObjectType.KABOCHA, object, sprite);
3232
3233
3234        sprite.playAnimation(0);
3235
3236        return object;
3237    }
3238
3239    public GameObject spawnRokudouTerminal(float positionX, float positionY) {
3240        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3241
3242
3243        GameObject object = mGameObjectPool.allocate();
3244        object.getPosition().set(positionX, positionY);
3245        object.activationRadius = mTightActivationRadius;
3246        object.width = 64;
3247        object.height = 64;
3248
3249        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.ROKUDOU_TERMINAL);
3250        if (staticData == null) {
3251            final int staticObjectCount = 1;
3252            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3253
3254            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume = new FixedSizeArray<CollisionVolume>(1);
3255            basicVulnerabilityVolume.add(new AABoxCollisionVolume(0, 0, 64, 64));
3256            basicVulnerabilityVolume.get(0).setHitType(HitType.COLLECT);
3257
3258
3259            AnimationFrame frame1 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal01),
3260                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
3261            AnimationFrame frame2 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal02),
3262                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
3263            AnimationFrame frame3 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal03),
3264                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
3265            AnimationFrame frame4 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal01),
3266                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
3267            AnimationFrame frame5 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal02),
3268                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
3269            AnimationFrame frame6 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal01),
3270                    1.0f, null, basicVulnerabilityVolume);
3271
3272            SpriteAnimation idle = new SpriteAnimation(0, 12);
3273            idle.addFrame(frame1);
3274            idle.addFrame(frame5);
3275            idle.addFrame(frame4);
3276            idle.addFrame(frame3);
3277            idle.addFrame(frame2);
3278            idle.addFrame(frame6);
3279            idle.addFrame(frame6);
3280            idle.addFrame(frame3);
3281            idle.addFrame(frame2);
3282            idle.addFrame(frame1);
3283            idle.addFrame(frame2);
3284            idle.addFrame(frame6);
3285
3286            idle.setLoop(true);
3287
3288
3289            staticData.add(idle);
3290
3291            setStaticData(GameObjectType.ROKUDOU_TERMINAL, staticData);
3292        }
3293
3294        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3295        render.setPriority(SortConstants.GENERAL_OBJECT);
3296
3297        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3298        sprite.setSize((int)object.width, (int)object.height);
3299        sprite.setRenderComponent(render);
3300
3301        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3302        sprite.setCollisionComponent(dynamicCollision);
3303
3304        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3305        hitReact.setSpawnGameEventOnHit(HitType.COLLECT, GameFlowEvent.EVENT_SHOW_DIALOG_CHARACTER2, 0);
3306
3307        SelectDialogComponent dialogSelect = (SelectDialogComponent)allocateComponent(SelectDialogComponent.class);
3308        dialogSelect.setHitReact(hitReact);
3309
3310        dynamicCollision.setHitReactionComponent(hitReact);
3311
3312        object.add(dialogSelect);
3313        object.add(render);
3314        object.add(sprite);
3315        object.add(dynamicCollision);
3316        object.add(hitReact);
3317
3318        addStaticData(GameObjectType.ROKUDOU_TERMINAL, object, sprite);
3319        sprite.playAnimation(0);
3320
3321        return object;
3322    }
3323
3324
3325    public GameObject spawnKabochaTerminal(float positionX, float positionY) {
3326        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3327
3328
3329        GameObject object = mGameObjectPool.allocate();
3330        object.getPosition().set(positionX, positionY);
3331        object.activationRadius = mTightActivationRadius;
3332        object.width = 64;
3333        object.height = 64;
3334
3335        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.KABOCHA_TERMINAL);
3336        if (staticData == null) {
3337            final int staticObjectCount = 1;
3338            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3339
3340            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume = new FixedSizeArray<CollisionVolume>(1);
3341            basicVulnerabilityVolume.add(new AABoxCollisionVolume(0, 0, 64, 64));
3342            basicVulnerabilityVolume.get(0).setHitType(HitType.COLLECT);
3343
3344
3345            AnimationFrame frame1 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal_kabocha01),
3346                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
3347            AnimationFrame frame2 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal_kabocha02),
3348                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
3349            AnimationFrame frame3 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal_kabocha03),
3350                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume);
3351            AnimationFrame frame4 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal_kabocha01),
3352                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
3353            AnimationFrame frame5 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal_kabocha02),
3354                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
3355            AnimationFrame frame6 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_terminal_kabocha01),
3356                    1.0f, null, basicVulnerabilityVolume);
3357
3358            SpriteAnimation idle = new SpriteAnimation(0, 12);
3359            idle.addFrame(frame1);
3360            idle.addFrame(frame5);
3361            idle.addFrame(frame4);
3362            idle.addFrame(frame3);
3363            idle.addFrame(frame2);
3364            idle.addFrame(frame6);
3365            idle.addFrame(frame6);
3366            idle.addFrame(frame3);
3367            idle.addFrame(frame2);
3368            idle.addFrame(frame1);
3369            idle.addFrame(frame2);
3370            idle.addFrame(frame6);
3371
3372            idle.setLoop(true);
3373
3374
3375            staticData.add(idle);
3376
3377            setStaticData(GameObjectType.KABOCHA_TERMINAL, staticData);
3378        }
3379
3380        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3381        render.setPriority(SortConstants.GENERAL_OBJECT);
3382
3383        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3384        sprite.setSize((int)object.width, (int)object.height);
3385        sprite.setRenderComponent(render);
3386
3387        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3388        sprite.setCollisionComponent(dynamicCollision);
3389
3390        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3391        hitReact.setSpawnGameEventOnHit(HitType.COLLECT, GameFlowEvent.EVENT_SHOW_DIALOG_CHARACTER2, 0);
3392
3393        SelectDialogComponent dialogSelect = (SelectDialogComponent)allocateComponent(SelectDialogComponent.class);
3394        dialogSelect.setHitReact(hitReact);
3395
3396        dynamicCollision.setHitReactionComponent(hitReact);
3397
3398        object.add(dialogSelect);
3399        object.add(render);
3400        object.add(sprite);
3401        object.add(dynamicCollision);
3402        object.add(hitReact);
3403
3404        addStaticData(GameObjectType.KABOCHA_TERMINAL, object, sprite);
3405        sprite.playAnimation(0);
3406
3407        return object;
3408    }
3409
3410    public GameObject spawnEnemyEvilKabocha(float positionX, float positionY, boolean flipHorizontal) {
3411        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3412
3413
3414        GameObject object = mGameObjectPool.allocate();
3415        object.getPosition().set(positionX, positionY);
3416        object.activationRadius = mNormalActivationRadius;
3417        object.width = 128;
3418        object.height = 128;
3419
3420        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.EVIL_KABOCHA);
3421        if (staticData == null) {
3422            final int staticObjectCount = 8;
3423            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3424
3425            GameComponent gravity = allocateComponent(GravityComponent.class);
3426            GameComponent movement = allocateComponent(MovementComponent.class);
3427
3428            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
3429            physics.setBounciness(0.0f);
3430
3431            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
3432                new FixedSizeArray<CollisionVolume>(1);
3433            basicVulnerabilityVolume.add(new AABoxCollisionVolume(52, 5, 26, 80, HitType.HIT));
3434
3435            SpriteAnimation idle = new SpriteAnimation(NPCAnimationComponent.IDLE, 1);
3436            idle.addFrame(new AnimationFrame(
3437                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_stand),
3438                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
3439
3440            AnimationFrame walkFrame1 = new AnimationFrame(
3441                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_walk01),
3442                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3443            AnimationFrame walkFrame2 = new AnimationFrame(
3444                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_walk02),
3445                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3446            AnimationFrame walkFrame3 = new AnimationFrame(
3447                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_walk03),
3448                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3449            AnimationFrame walkFrame4 = new AnimationFrame(
3450                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_walk04),
3451                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3452            AnimationFrame walkFrame5 = new AnimationFrame(
3453                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_walk05),
3454                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3455            AnimationFrame walkFrame6 = new AnimationFrame(
3456                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_walk06),
3457                    Utils.framesToTime(24, 3), null, basicVulnerabilityVolume);
3458
3459            SpriteAnimation walk = new SpriteAnimation(NPCAnimationComponent.WALK, 6);
3460            walk.addFrame(walkFrame1);
3461            walk.addFrame(walkFrame2);
3462            walk.addFrame(walkFrame3);
3463            walk.addFrame(walkFrame4);
3464            walk.addFrame(walkFrame5);
3465            walk.addFrame(walkFrame6);
3466
3467            walk.setLoop(true);
3468
3469
3470            SpriteAnimation surprised = new SpriteAnimation(NPCAnimationComponent.SURPRISED, 1);
3471            surprised.addFrame(new AnimationFrame(
3472                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_surprised),
3473                    4.0f, null, null));
3474
3475
3476            SpriteAnimation hit = new SpriteAnimation(NPCAnimationComponent.TAKE_HIT, 2);
3477            hit.addFrame(new AnimationFrame(
3478                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_hit01),
3479                    Utils.framesToTime(24, 1), null, null));
3480            hit.addFrame(new AnimationFrame(
3481                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_hit02),
3482                    Utils.framesToTime(24, 10), null, null));
3483
3484            SpriteAnimation die = new SpriteAnimation(NPCAnimationComponent.DEATH, 5);
3485            die.addFrame(new AnimationFrame(
3486                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_die01),
3487                    Utils.framesToTime(24, 6), null, null));
3488            die.addFrame(new AnimationFrame(
3489                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_stand),
3490                    Utils.framesToTime(24, 2), null, null));
3491            die.addFrame(new AnimationFrame(
3492                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_die02),
3493                    Utils.framesToTime(24, 2), null, null));
3494            die.addFrame(new AnimationFrame(
3495                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_die03),
3496                    Utils.framesToTime(24, 2), null, null));
3497            die.addFrame(new AnimationFrame(
3498                    textureLibrary.allocateTexture(R.drawable.enemy_kabocha_evil_die04),
3499                    Utils.framesToTime(24, 6), null, null));
3500
3501            staticData.add(gravity);
3502            staticData.add(movement);
3503            staticData.add(physics);
3504            staticData.add(idle);
3505            staticData.add(walk);
3506            staticData.add(surprised);
3507            staticData.add(hit);
3508            staticData.add(die);
3509
3510            setStaticData(GameObjectType.EVIL_KABOCHA, staticData);
3511        }
3512
3513        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3514        render.setPriority(SortConstants.NPC);
3515
3516        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
3517        bgcollision.setSize(38, 82);
3518        bgcollision.setOffset(45, 5);
3519
3520        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3521        sprite.setSize((int)object.width, (int)object.height);
3522        sprite.setRenderComponent(render);
3523
3524        NPCAnimationComponent animation = (NPCAnimationComponent)allocateComponent(NPCAnimationComponent.class);
3525        animation.setSprite(sprite);
3526
3527        ChannelSystem.Channel surpriseChannel = null;
3528        ChannelSystem channelSystem = BaseObject.sSystemRegistry.channelSystem;
3529        surpriseChannel = channelSystem.registerChannel(sSurprisedNPCChannel);
3530        animation.setChannel(surpriseChannel);
3531        animation.setChannelTrigger(NPCAnimationComponent.SURPRISED);
3532
3533        NPCComponent patrol = (NPCComponent)allocateComponent(NPCComponent.class);
3534        patrol.setSpeeds(50.0f, 50.0f, 0.0f, -10.0f, 200.0f);
3535        patrol.setReactToHits(true);
3536        patrol.setGameEvent(GameFlowEvent.EVENT_SHOW_ANIMATION, AnimationPlayerActivity.ROKUDOU_ENDING, true);
3537
3538        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3539        sprite.setCollisionComponent(collision);
3540
3541        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3542        collision.setHitReactionComponent(hitReact);
3543
3544        SoundSystem sound = sSystemRegistry.soundSystem;
3545        if (sound != null) {
3546        	hitReact.setTakeHitSound(HitType.HIT, sound.load(R.raw.sound_kabocha_hit));
3547        }
3548
3549        patrol.setHitReactionComponent(hitReact);
3550
3551        object.team = Team.ENEMY;
3552        object.life = 3;
3553
3554        if (flipHorizontal) {
3555            object.facingDirection.x = -1.0f;
3556        }
3557
3558        object.add(render);
3559        object.add(sprite);
3560        object.add(bgcollision);
3561        object.add(animation);
3562        object.add(patrol);
3563        object.add(collision);
3564        object.add(hitReact);
3565
3566        addStaticData(GameObjectType.EVIL_KABOCHA, object, sprite);
3567
3568
3569        sprite.playAnimation(0);
3570
3571        return object;
3572    }
3573
3574    public GameObject spawnEnemyRokudou(float positionX, float positionY, boolean flipHorizontal) {
3575    	TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3576
3577    	// Make sure related textures are loaded.
3578        textureLibrary.allocateTexture(R.drawable.energy_ball01);
3579        textureLibrary.allocateTexture(R.drawable.energy_ball02);
3580        textureLibrary.allocateTexture(R.drawable.energy_ball03);
3581        textureLibrary.allocateTexture(R.drawable.energy_ball04);
3582
3583        textureLibrary.allocateTexture(R.drawable.effect_bullet01);
3584        textureLibrary.allocateTexture(R.drawable.effect_bullet02);
3585
3586
3587        GameObject object = mGameObjectPool.allocate();
3588        object.getPosition().set(positionX, positionY);
3589        object.activationRadius = mNormalActivationRadius;
3590        object.width = 128;
3591        object.height = 128;
3592
3593        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.ROKUDOU);
3594        if (staticData == null) {
3595            final int staticObjectCount = 8;
3596            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3597
3598            GameComponent movement = allocateComponent(MovementComponent.class);
3599
3600            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
3601            physics.setBounciness(0.0f);
3602
3603            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
3604                new FixedSizeArray<CollisionVolume>(1);
3605            basicVulnerabilityVolume.add(new AABoxCollisionVolume(45, 23, 42, 75, HitType.HIT));
3606
3607            SpriteAnimation idle = new SpriteAnimation(NPCAnimationComponent.IDLE, 1);
3608            idle.addFrame(new AnimationFrame(
3609                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_stand),
3610                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
3611
3612            SpriteAnimation fly = new SpriteAnimation(NPCAnimationComponent.WALK, 2);
3613            fly.addFrame(new AnimationFrame(
3614                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_fly01),
3615                    1.0f, null, basicVulnerabilityVolume));
3616            fly.addFrame(new AnimationFrame(
3617                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_fly02),
3618                    1.0f, null, basicVulnerabilityVolume));
3619            fly.setLoop(true);
3620
3621            SpriteAnimation shoot = new SpriteAnimation(NPCAnimationComponent.SHOOT, 2);
3622            shoot.addFrame(new AnimationFrame(
3623                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_shoot01),
3624                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
3625            shoot.addFrame(new AnimationFrame(
3626                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_shoot02),
3627                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
3628            shoot.setLoop(true);
3629
3630
3631            SpriteAnimation surprised = new SpriteAnimation(NPCAnimationComponent.SURPRISED, 1);
3632            surprised.addFrame(new AnimationFrame(
3633                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_surprise),
3634                    4.0f, null, null));
3635
3636
3637            SpriteAnimation hit = new SpriteAnimation(NPCAnimationComponent.TAKE_HIT, 7);
3638            AnimationFrame hitFrame1 = new AnimationFrame(
3639                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_hit01),
3640                    Utils.framesToTime(24, 2), null, null);
3641            AnimationFrame hitFrame2 = new AnimationFrame(
3642                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_hit02),
3643                    Utils.framesToTime(24, 1), null, null);
3644            AnimationFrame hitFrame3 = new AnimationFrame(
3645                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_hit03),
3646                    Utils.framesToTime(24, 1), null, null);
3647
3648            hit.addFrame(hitFrame1);
3649            hit.addFrame(hitFrame2);
3650            hit.addFrame(hitFrame3);
3651            hit.addFrame(hitFrame2);
3652            hit.addFrame(hitFrame3);
3653            hit.addFrame(hitFrame2);
3654            hit.addFrame(hitFrame3);
3655
3656            SpriteAnimation die = new SpriteAnimation(NPCAnimationComponent.DEATH, 5);
3657            die.addFrame(new AnimationFrame(
3658                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_stand),
3659                    Utils.framesToTime(24, 6), null, null));
3660            die.addFrame(new AnimationFrame(
3661                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_die01),
3662                    Utils.framesToTime(24, 2), null, null));
3663            die.addFrame(new AnimationFrame(
3664                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_die02),
3665                    Utils.framesToTime(24, 4), null, null));
3666            die.addFrame(new AnimationFrame(
3667                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_die03),
3668                    Utils.framesToTime(24, 6), null, null));
3669            die.addFrame(new AnimationFrame(
3670                    textureLibrary.allocateTexture(R.drawable.enemy_rokudou_fight_die04),
3671                    Utils.framesToTime(24, 6), null, null));
3672
3673            staticData.add(movement);
3674            staticData.add(physics);
3675            staticData.add(idle);
3676            staticData.add(fly);
3677            staticData.add(surprised);
3678            staticData.add(hit);
3679            staticData.add(die);
3680            staticData.add(shoot);
3681
3682            setStaticData(GameObjectType.ROKUDOU, staticData);
3683        }
3684
3685        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3686        render.setPriority(SortConstants.NPC);
3687
3688        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
3689        bgcollision.setSize(45, 75);
3690        bgcollision.setOffset(45, 23);
3691
3692        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3693        sprite.setSize((int)object.width, (int)object.height);
3694        sprite.setRenderComponent(render);
3695
3696
3697
3698        NPCAnimationComponent animation = (NPCAnimationComponent)allocateComponent(NPCAnimationComponent.class);
3699        animation.setSprite(sprite);
3700        animation.setFlying(true);
3701
3702        ChannelSystem.Channel surpriseChannel = null;
3703        ChannelSystem channelSystem = BaseObject.sSystemRegistry.channelSystem;
3704        surpriseChannel = channelSystem.registerChannel(sSurprisedNPCChannel);
3705        animation.setChannel(surpriseChannel);
3706        animation.setChannelTrigger(NPCAnimationComponent.SURPRISED);
3707
3708        NPCComponent patrol = (NPCComponent)allocateComponent(NPCComponent.class);
3709        patrol.setSpeeds(500.0f, 100.0f, 100.0f, -100.0f, 400.0f);
3710        patrol.setFlying(true);
3711        patrol.setReactToHits(true);
3712        patrol.setGameEvent(GameFlowEvent.EVENT_SHOW_ANIMATION, AnimationPlayerActivity.KABOCHA_ENDING, true);
3713        patrol.setPauseOnAttack(false);
3714
3715        DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3716        sprite.setCollisionComponent(collision);
3717
3718        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3719        collision.setHitReactionComponent(hitReact);
3720
3721        SoundSystem sound = sSystemRegistry.soundSystem;
3722        if (sound != null) {
3723        	hitReact.setTakeHitSound(HitType.HIT, sound.load(R.raw.sound_rokudou_hit));
3724        }
3725
3726        patrol.setHitReactionComponent(hitReact);
3727
3728        ChangeComponentsComponent deathSwap = (ChangeComponentsComponent)allocateComponent(ChangeComponentsComponent.class);
3729        deathSwap.addSwapInComponent(allocateComponent(GravityComponent.class));
3730        deathSwap.setSwapAction(ActionType.DEATH);
3731
3732        LaunchProjectileComponent gun
3733	        = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
3734	    gun.setShotsPerSet(1);
3735	    gun.setSetsPerActivation(-1);
3736	    gun.setDelayBetweenSets(1.5f);
3737	    gun.setObjectTypeToSpawn(GameObjectType.ENERGY_BALL);
3738	    gun.setOffsetX(75);
3739	    gun.setOffsetY(42);
3740	    gun.setRequiredAction(GameObject.ActionType.ATTACK);
3741	    gun.setVelocityX(300.0f);
3742	    gun.setVelocityY(-300.0f);
3743        gun.setShootSound(sound.load(R.raw.sound_poing));
3744
3745
3746	    LaunchProjectileComponent gun2
3747        = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
3748	    gun2.setShotsPerSet(5);
3749	    gun2.setDelayBetweenShots(0.1f);
3750	    gun2.setSetsPerActivation(-1);
3751	    gun2.setDelayBetweenSets(2.5f);
3752	    gun2.setObjectTypeToSpawn(GameObjectType.TURRET_BULLET);
3753	    gun2.setOffsetX(75);
3754	    gun2.setOffsetY(42);
3755	    gun2.setRequiredAction(GameObject.ActionType.ATTACK);
3756	    gun2.setVelocityX(300.0f);
3757	    gun2.setVelocityY(-300.0f);
3758        gun.setShootSound(sound.load(R.raw.sound_gun));
3759
3760
3761        object.team = Team.ENEMY;
3762        object.life = 3;
3763
3764        if (flipHorizontal) {
3765            object.facingDirection.x = -1.0f;
3766        }
3767
3768        // HACK! Since there's no gravity and this is a big character, align him to the floor
3769        // manually.
3770        object.getPosition().y -= 23;
3771
3772        object.add(render);
3773        object.add(sprite);
3774        object.add(bgcollision);
3775        object.add(animation);
3776        object.add(patrol);
3777        object.add(collision);
3778        object.add(hitReact);
3779        object.add(deathSwap);
3780        object.add(gun);
3781        object.add(gun2);
3782
3783        addStaticData(GameObjectType.ROKUDOU, object, sprite);
3784
3785
3786        sprite.playAnimation(0);
3787
3788        return object;
3789    }
3790
3791
3792    public GameObject spawnPlayerGhost(float positionX, float positionY, GameObject player, float lifeTime) {
3793        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
3794
3795
3796        GameObject object = mGameObjectPool.allocate();
3797        object.getPosition().set(positionX, positionY);
3798        object.activationRadius = mAlwaysActive;
3799        object.width = 64;
3800        object.height = 64;
3801
3802        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.GHOST);
3803        if (staticData == null) {
3804            final int staticObjectCount = 4;
3805            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3806
3807            //GravityComponent gravity = (GravityComponent)allocateComponent(GravityComponent.class);
3808            //gravity.setGravityMultiplier(0.1f);
3809
3810            GameComponent movement = allocateComponent(MovementComponent.class);
3811            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
3812            physics.setBounciness(0.6f);
3813
3814            GhostComponent ghost = (GhostComponent)allocateComponent(GhostComponent.class);
3815            ghost.setMovementSpeed(2000.0f);
3816            ghost.setAcceleration(300.0f);
3817            ghost.setUseOrientationSensor(true);
3818            ghost.setKillOnRelease(true);
3819
3820            SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
3821            if (sound != null) {
3822            	ghost.setAmbientSound(sound.load(R.raw.sound_possession));
3823            }
3824
3825            FixedSizeArray<CollisionVolume> basicAttackVolume =
3826                new FixedSizeArray<CollisionVolume>(1);
3827            basicAttackVolume.add(new SphereCollisionVolume(32, 32, 32, HitType.POSSESS));
3828
3829            SpriteAnimation idle = new SpriteAnimation(0, 4);
3830            idle.addFrame(new AnimationFrame(
3831                    textureLibrary.getTextureByResource(R.drawable.effect_energyball01),
3832                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3833            idle.addFrame(new AnimationFrame(
3834                    textureLibrary.getTextureByResource(R.drawable.effect_energyball02),
3835                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3836            idle.addFrame(new AnimationFrame(
3837                    textureLibrary.getTextureByResource(R.drawable.effect_energyball03),
3838                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3839            idle.addFrame(new AnimationFrame(
3840                    textureLibrary.getTextureByResource(R.drawable.effect_energyball04),
3841                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3842            idle.setLoop(true);
3843
3844            //staticData.add(gravity);
3845            staticData.add(movement);
3846            staticData.add(physics);
3847            staticData.add(ghost);
3848            staticData.add(idle);
3849
3850            setStaticData(GameObjectType.GHOST, staticData);
3851        }
3852
3853        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3854        render.setPriority(SortConstants.PROJECTILE);
3855
3856        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
3857		bgcollision.setSize(64, 64);
3858		bgcollision.setOffset(0, 0);
3859
3860        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3861		sprite.setSize((int)object.width, (int)object.height);
3862        sprite.setRenderComponent(render);
3863
3864
3865        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3866        sprite.setCollisionComponent(dynamicCollision);
3867
3868        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3869        hitReact.setDieOnAttack(true);
3870
3871        dynamicCollision.setHitReactionComponent(hitReact);
3872        LifetimeComponent life = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
3873        // when the ghost dies it either releases itself or passes control to another object, so we
3874        // don't want control to return to the player.
3875
3876        life.setReleaseGhostOnDeath(false);
3877
3878
3879        object.life = 1;
3880
3881        object.add(bgcollision);
3882        object.add(render);
3883        object.add(sprite);
3884        object.add(dynamicCollision);
3885        object.add(hitReact);
3886        object.add(life);
3887
3888        addStaticData(GameObjectType.GHOST, object, sprite);
3889
3890        object.commitUpdates();
3891
3892        GhostComponent ghost = object.findByClass(GhostComponent.class);
3893        if (ghost != null) {
3894            ghost.setLifeTime(lifeTime);
3895        }
3896        sprite.playAnimation(0);
3897
3898        return object;
3899    }
3900
3901    public GameObject spawnEnergyBall(float positionX, float positionY, boolean flipHorizontal) {
3902        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3903
3904
3905        GameObject object = mGameObjectPool.allocate();
3906        object.getPosition().set(positionX, positionY);
3907        object.activationRadius = mTightActivationRadius;
3908        object.width = 32;
3909        object.height = 32;
3910
3911        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.ENERGY_BALL);
3912        if (staticData == null) {
3913            final int staticObjectCount = 2;
3914            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3915
3916            GameComponent movement = allocateComponent(MovementComponent.class);
3917
3918            FixedSizeArray<CollisionVolume> basicAttackVolume =
3919                new FixedSizeArray<CollisionVolume>(1);
3920            basicAttackVolume.add(new SphereCollisionVolume(16, 16, 16, HitType.HIT));
3921
3922            SpriteAnimation idle = new SpriteAnimation(0, 4);
3923            idle.addFrame(new AnimationFrame(
3924                    textureLibrary.allocateTexture(R.drawable.energy_ball01),
3925                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3926            idle.addFrame(new AnimationFrame(
3927                    textureLibrary.allocateTexture(R.drawable.energy_ball02),
3928                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3929            idle.addFrame(new AnimationFrame(
3930                    textureLibrary.allocateTexture(R.drawable.energy_ball03),
3931                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3932            idle.addFrame(new AnimationFrame(
3933                    textureLibrary.allocateTexture(R.drawable.energy_ball04),
3934                    Utils.framesToTime(24, 1), basicAttackVolume, null));
3935            idle.setLoop(true);
3936
3937            staticData.add(movement);
3938            staticData.add(idle);
3939
3940            setStaticData(GameObjectType.ENERGY_BALL, staticData);
3941
3942        }
3943
3944        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
3945        render.setPriority(SortConstants.PROJECTILE);
3946
3947        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
3948        lifetime.setTimeUntilDeath(5.0f);
3949
3950        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
3951		sprite.setSize((int)object.width, (int)object.height);
3952        sprite.setRenderComponent(render);
3953
3954        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
3955        sprite.setCollisionComponent(dynamicCollision);
3956
3957        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
3958        hitReact.setDieOnAttack(true);
3959
3960        dynamicCollision.setHitReactionComponent(hitReact);
3961
3962        object.life = 1;
3963        object.team = Team.ENEMY;
3964        object.destroyOnDeactivation = true;
3965
3966        if (flipHorizontal) {
3967            object.facingDirection.x = -1.0f;
3968        }
3969
3970        object.add(lifetime);
3971        object.add(render);
3972        object.add(sprite);
3973        object.add(dynamicCollision);
3974        object.add(hitReact);
3975
3976        addStaticData(GameObjectType.ENERGY_BALL, object, sprite);
3977
3978        sprite.playAnimation(0);
3979
3980        return object;
3981    }
3982
3983    public GameObject spawnWandaShot(float positionX, float positionY, boolean flipHorizontal) {
3984        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
3985
3986
3987        GameObject object = mGameObjectPool.allocate();
3988        object.getPosition().set(positionX, positionY);
3989        object.activationRadius = mTightActivationRadius;
3990        object.width = 32;
3991        object.height = 32;
3992
3993        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.WANDA_SHOT);
3994        if (staticData == null) {
3995            final int staticObjectCount = 2;
3996            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
3997
3998            GameComponent movement = allocateComponent(MovementComponent.class);
3999
4000            FixedSizeArray<CollisionVolume> basicAttackVolume =
4001                new FixedSizeArray<CollisionVolume>(1);
4002            basicAttackVolume.add(new SphereCollisionVolume(16, 16, 16, HitType.HIT));
4003
4004            SpriteAnimation idle = new SpriteAnimation(0, 4);
4005            idle.addFrame(new AnimationFrame(
4006                    textureLibrary.allocateTexture(R.drawable.energy_ball01),
4007                    Utils.framesToTime(24, 1), basicAttackVolume, null));
4008            idle.addFrame(new AnimationFrame(
4009                    textureLibrary.allocateTexture(R.drawable.energy_ball02),
4010                    Utils.framesToTime(24, 1), basicAttackVolume, null));
4011            idle.addFrame(new AnimationFrame(
4012                    textureLibrary.allocateTexture(R.drawable.energy_ball03),
4013                    Utils.framesToTime(24, 1), basicAttackVolume, null));
4014            idle.addFrame(new AnimationFrame(
4015                    textureLibrary.allocateTexture(R.drawable.energy_ball04),
4016                    Utils.framesToTime(24, 1), basicAttackVolume, null));
4017            idle.setLoop(true);
4018
4019            staticData.add(movement);
4020            staticData.add(idle);
4021
4022            setStaticData(GameObjectType.WANDA_SHOT, staticData);
4023
4024        }
4025
4026        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4027        render.setPriority(SortConstants.PROJECTILE);
4028
4029        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
4030        lifetime.setTimeUntilDeath(5.0f);
4031
4032        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4033		sprite.setSize((int)object.width, (int)object.height);
4034        sprite.setRenderComponent(render);
4035
4036        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4037        sprite.setCollisionComponent(dynamicCollision);
4038
4039        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4040        //hitReact.setDieOnAttack(true);
4041
4042        dynamicCollision.setHitReactionComponent(hitReact);
4043
4044        object.life = 1;
4045        object.team = Team.NONE;
4046        object.destroyOnDeactivation = true;
4047
4048        if (flipHorizontal) {
4049            object.facingDirection.x = -1.0f;
4050        }
4051
4052        object.add(lifetime);
4053        object.add(render);
4054        object.add(sprite);
4055        object.add(dynamicCollision);
4056        object.add(hitReact);
4057
4058        addStaticData(GameObjectType.WANDA_SHOT, object, sprite);
4059
4060        sprite.playAnimation(0);
4061
4062        return object;
4063    }
4064
4065    public GameObject spawnCannonBall(float positionX, float positionY, boolean flipHorizontal) {
4066        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4067
4068
4069        GameObject object = mGameObjectPool.allocate();
4070        object.getPosition().set(positionX, positionY);
4071        object.activationRadius = mTightActivationRadius;
4072        object.width = 32;
4073        object.height = 32;
4074
4075        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.CANNON_BALL);
4076        if (staticData == null) {
4077            final int staticObjectCount = 2;
4078            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4079
4080            GameComponent movement = allocateComponent(MovementComponent.class);
4081
4082            FixedSizeArray<CollisionVolume> basicAttackVolume =
4083                new FixedSizeArray<CollisionVolume>(1);
4084            basicAttackVolume.add(new SphereCollisionVolume(8, 16, 16, HitType.HIT));
4085
4086            SpriteAnimation idle = new SpriteAnimation(0, 1);
4087            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.snail_bomb),
4088                    Utils.framesToTime(24, 1), basicAttackVolume, null));
4089
4090            staticData.add(movement);
4091            staticData.add(idle);
4092
4093            setStaticData(GameObjectType.CANNON_BALL, staticData);
4094        }
4095
4096        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4097        render.setPriority(SortConstants.PROJECTILE);
4098
4099        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
4100        lifetime.setTimeUntilDeath(3.0f);
4101        lifetime.setDieOnHitBackground(true);
4102
4103        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4104		sprite.setSize((int)object.width, (int)object.height);
4105        sprite.setRenderComponent(render);
4106
4107        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4108        sprite.setCollisionComponent(dynamicCollision);
4109
4110        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4111        hitReact.setDieOnAttack(true);
4112
4113        dynamicCollision.setHitReactionComponent(hitReact);
4114
4115        SimpleCollisionComponent collision = (SimpleCollisionComponent)allocateComponent(SimpleCollisionComponent.class);
4116
4117
4118        object.life = 1;
4119        object.team = Team.ENEMY;
4120        object.destroyOnDeactivation = true;
4121
4122        if (flipHorizontal) {
4123            object.facingDirection.x = -1.0f;
4124        }
4125
4126        object.add(lifetime);
4127        object.add(render);
4128        object.add(sprite);
4129        object.add(dynamicCollision);
4130        object.add(hitReact);
4131        object.add(collision);
4132
4133        addStaticData(GameObjectType.CANNON_BALL, object, sprite);
4134
4135        sprite.playAnimation(0);
4136
4137        return object;
4138    }
4139
4140    public GameObject spawnTurretBullet(float positionX, float positionY, boolean flipHorizontal) {
4141        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4142
4143
4144        GameObject object = mGameObjectPool.allocate();
4145        object.getPosition().set(positionX, positionY);
4146        object.activationRadius = mTightActivationRadius;
4147        object.width = 16;
4148        object.height = 16;
4149
4150        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.TURRET_BULLET);
4151        if (staticData == null) {
4152            final int staticObjectCount = 2;
4153            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4154
4155            GameComponent movement = allocateComponent(MovementComponent.class);
4156
4157            FixedSizeArray<CollisionVolume> basicAttackVolume =
4158                new FixedSizeArray<CollisionVolume>(1);
4159            basicAttackVolume.add(new SphereCollisionVolume(8, 8, 8, HitType.HIT));
4160
4161            SpriteAnimation idle = new SpriteAnimation(0, 2);
4162            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.effect_bullet01),
4163                    Utils.framesToTime(24, 1), basicAttackVolume, null));
4164            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.effect_bullet02),
4165                    Utils.framesToTime(24, 1), basicAttackVolume, null));
4166            idle.setLoop(true);
4167
4168            staticData.add(movement);
4169            staticData.add(idle);
4170
4171            setStaticData(GameObjectType.TURRET_BULLET, staticData);
4172        }
4173
4174        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4175        render.setPriority(SortConstants.PROJECTILE);
4176
4177        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
4178        lifetime.setTimeUntilDeath(3.0f);
4179
4180        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4181        sprite.setSize((int)object.width, (int)object.height);
4182        sprite.setRenderComponent(render);
4183
4184        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4185        sprite.setCollisionComponent(dynamicCollision);
4186
4187        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4188        hitReact.setDieOnAttack(true);
4189
4190        dynamicCollision.setHitReactionComponent(hitReact);
4191
4192
4193        object.life = 1;
4194        object.team = Team.ENEMY;
4195        object.destroyOnDeactivation = true;
4196
4197        if (flipHorizontal) {
4198            object.facingDirection.x = -1.0f;
4199        }
4200
4201        object.add(lifetime);
4202        object.add(render);
4203        object.add(sprite);
4204        object.add(dynamicCollision);
4205        object.add(hitReact);
4206
4207        addStaticData(GameObjectType.TURRET_BULLET, object, sprite);
4208
4209        sprite.playAnimation(0);
4210
4211        return object;
4212    }
4213
4214    public GameObject spawnBrobotBullet(float positionX, float positionY, boolean flipHorizontal) {
4215        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4216
4217
4218        GameObject object = mGameObjectPool.allocate();
4219        object.getPosition().set(positionX, positionY);
4220        object.activationRadius = mTightActivationRadius;
4221        object.width = 64;
4222        object.height = 64;
4223
4224        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.BROBOT_BULLET);
4225        if (staticData == null) {
4226            final int staticObjectCount = 2;
4227            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4228
4229            GameComponent movement = allocateComponent(MovementComponent.class);
4230
4231            SpriteAnimation idle = new SpriteAnimation(0, 3);
4232            idle.addFrame(new AnimationFrame(
4233                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk01),
4234                    Utils.framesToTime(24, 1), null, null));
4235            idle.addFrame(new AnimationFrame(
4236                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk02),
4237                    Utils.framesToTime(24, 1), null, null));
4238            idle.addFrame(new AnimationFrame(
4239                    textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk03),
4240                    Utils.framesToTime(24, 1), null, null));
4241            idle.setLoop(true);
4242
4243            staticData.add(movement);
4244            staticData.add(idle);
4245
4246            setStaticData(GameObjectType.BROBOT_BULLET, staticData);
4247        }
4248
4249        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4250        render.setPriority(SortConstants.PROJECTILE);
4251
4252        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
4253        lifetime.setTimeUntilDeath(3.0f);
4254
4255        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4256        sprite.setSize((int)object.width, (int)object.height);
4257        sprite.setRenderComponent(render);
4258
4259        object.life = 1;
4260        object.team = Team.ENEMY;
4261        object.destroyOnDeactivation = true;
4262
4263        if (flipHorizontal) {
4264            object.facingDirection.x = -1.0f;
4265        }
4266
4267        object.add(lifetime);
4268        object.add(render);
4269        object.add(sprite);
4270
4271
4272        addStaticData(GameObjectType.BROBOT_BULLET, object, sprite);
4273
4274        sprite.playAnimation(0);
4275
4276        return object;
4277    }
4278
4279    public GameObject spawnCoin(float positionX, float positionY) {
4280        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4281
4282
4283        GameObject object = mGameObjectPool.allocate();
4284        object.getPosition().set(positionX, positionY);
4285        object.activationRadius = mTightActivationRadius;
4286        object.width = 16;
4287        object.height = 16;
4288
4289        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.COIN);
4290        if (staticData == null) {
4291            final int staticObjectCount = 2;
4292            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4293
4294            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume = null; /*new FixedSizeArray<CollisionVolume>(1);
4295            basicVulnerabilityVolume.add(new SphereCollisionVolume(8, 8, 8));
4296            basicVulnerabilityVolume.get(0).setHitType(HitType.COLLECT);*/
4297
4298            SpriteAnimation idle = new SpriteAnimation(0, 5);
4299            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_coin01),
4300                    Utils.framesToTime(24, 30), null, basicVulnerabilityVolume));
4301            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_coin02),
4302                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4303            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_coin03),
4304                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4305            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_coin04),
4306                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
4307            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_coin05),
4308                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4309            idle.setLoop(true);
4310
4311            InventoryComponent.UpdateRecord addCoin = new InventoryComponent.UpdateRecord();
4312            addCoin.coinCount = 1;
4313
4314            staticData.add(addCoin);
4315            staticData.add(idle);
4316
4317            setStaticData(GameObjectType.COIN, staticData);
4318        }
4319
4320        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4321        render.setPriority(SortConstants.GENERAL_OBJECT);
4322
4323        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4324		sprite.setSize((int)object.width, (int)object.height);
4325        sprite.setRenderComponent(render);
4326
4327        //DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4328        //sprite.setCollisionComponent(dynamicCollision);
4329
4330        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4331        hitReact.setDieWhenCollected(true);
4332        hitReact.setInvincible(true);
4333
4334        HitPlayerComponent hitPlayer = (HitPlayerComponent)allocateComponent(HitPlayerComponent.class);
4335        hitPlayer.setup(32, hitReact, HitType.COLLECT, false);
4336
4337        SoundSystem sound = sSystemRegistry.soundSystem;
4338        if (sound != null) {
4339            hitReact.setTakeHitSound(HitType.COLLECT, sound.load(R.raw.ding));
4340        }
4341
4342        // TODO: this is pretty dumb.  The static data binding needs to be made generic.
4343        final int staticDataSize = staticData.getCount();
4344        for (int x = 0; x < staticDataSize; x++) {
4345            final BaseObject entry = staticData.get(x);
4346            if (entry instanceof InventoryComponent.UpdateRecord) {
4347                hitReact.setInventoryUpdate((InventoryComponent.UpdateRecord)entry);
4348                break;
4349            }
4350        }
4351
4352        //dynamicCollision.setHitReactionComponent(hitReact);
4353
4354        LifetimeComponent life = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
4355
4356        object.life = 1;
4357
4358        object.add(render);
4359        object.add(sprite);
4360        //object.add(dynamicCollision);
4361        object.add(hitPlayer);
4362        object.add(hitReact);
4363        object.add(life);
4364
4365        addStaticData(GameObjectType.COIN, object, sprite);
4366        sprite.playAnimation(0);
4367
4368        return object;
4369    }
4370
4371    public GameObject spawnRuby(float positionX, float positionY) {
4372        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4373
4374
4375        GameObject object = mGameObjectPool.allocate();
4376        object.getPosition().set(positionX, positionY);
4377        object.activationRadius = mTightActivationRadius;
4378        object.width = 32;
4379        object.height = 32;
4380
4381        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.RUBY);
4382        if (staticData == null) {
4383            final int staticObjectCount = 2;
4384            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4385
4386            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume = new FixedSizeArray<CollisionVolume>(1);
4387            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 16, 16));
4388            basicVulnerabilityVolume.get(0).setHitType(HitType.COLLECT);
4389
4390            SpriteAnimation idle = new SpriteAnimation(0, 5);
4391            idle.addFrame(new AnimationFrame(
4392                    textureLibrary.allocateTexture(R.drawable.object_ruby01),
4393                    2.0f, null, basicVulnerabilityVolume));
4394            idle.addFrame(new AnimationFrame(
4395                    textureLibrary.allocateTexture(R.drawable.object_ruby02),
4396                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4397            idle.addFrame(new AnimationFrame(
4398                    textureLibrary.allocateTexture(R.drawable.object_ruby03),
4399                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
4400            idle.addFrame(new AnimationFrame(
4401                    textureLibrary.allocateTexture(R.drawable.object_ruby04),
4402                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
4403            idle.addFrame(new AnimationFrame(
4404                    textureLibrary.allocateTexture(R.drawable.object_ruby05),
4405                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4406            idle.setLoop(true);
4407
4408            InventoryComponent.UpdateRecord addRuby = new InventoryComponent.UpdateRecord();
4409            addRuby.rubyCount = 1;
4410
4411            staticData.add(addRuby);
4412
4413            staticData.add(idle);
4414            setStaticData(GameObjectType.RUBY, staticData);
4415        }
4416
4417        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4418        render.setPriority(SortConstants.GENERAL_OBJECT);
4419
4420        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4421		sprite.setSize((int)object.width, (int)object.height);
4422        sprite.setRenderComponent(render);
4423
4424        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4425        sprite.setCollisionComponent(dynamicCollision);
4426
4427        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4428        hitReact.setDieWhenCollected(true);
4429        hitReact.setInvincible(true);
4430        // TODO: this is pretty dumb.  The static data binding needs to be made generic.
4431        final int staticDataSize = staticData.getCount();
4432        for (int x = 0; x < staticDataSize; x++) {
4433            final BaseObject entry = staticData.get(x);
4434            if (entry instanceof InventoryComponent.UpdateRecord) {
4435                hitReact.setInventoryUpdate((InventoryComponent.UpdateRecord)entry);
4436                break;
4437            }
4438        }
4439
4440        dynamicCollision.setHitReactionComponent(hitReact);
4441
4442        LifetimeComponent life = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
4443        life.setObjectToSpawnOnDeath(GameObjectType.GEM_EFFECT_SPAWNER);
4444
4445        object.life = 1;
4446
4447        object.add(render);
4448        object.add(sprite);
4449        object.add(dynamicCollision);
4450        object.add(hitReact);
4451        object.add(life);
4452
4453        addStaticData(GameObjectType.RUBY, object, sprite);
4454
4455        sprite.playAnimation(0);
4456
4457        return object;
4458    }
4459
4460    public GameObject spawnDiary(float positionX, float positionY) {
4461        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4462
4463        LevelSystem level = sSystemRegistry.levelSystem;
4464        if (level != null) {
4465        	final LevelTree.Level currentLevel = level.getCurrentLevel();
4466        	if (currentLevel != null && currentLevel.diaryCollected) {
4467        		return null;
4468        	}
4469        }
4470
4471        GameObject object = mGameObjectPool.allocate();
4472        object.getPosition().set(positionX, positionY);
4473        object.activationRadius = mTightActivationRadius;
4474        object.width = 32;
4475        object.height = 32;
4476
4477        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.DIARY);
4478        if (staticData == null) {
4479            final int staticObjectCount = 2;
4480            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4481
4482            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume = new FixedSizeArray<CollisionVolume>(1);
4483            basicVulnerabilityVolume.add(new SphereCollisionVolume(16, 16, 16));
4484            basicVulnerabilityVolume.get(0).setHitType(HitType.COLLECT);
4485
4486            SpriteAnimation idle = new SpriteAnimation(0, 8);
4487            AnimationFrame frame1 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_diary01),
4488                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
4489            AnimationFrame frame2 = new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_diary02),
4490                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume);
4491
4492            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_diary01),
4493                    1.0f, null, basicVulnerabilityVolume));
4494            idle.addFrame(frame2);
4495            idle.addFrame(frame1);
4496            idle.addFrame(frame2);
4497            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_diary03),
4498                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4499            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_diary04),
4500                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4501            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_diary05),
4502                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4503            idle.addFrame(new AnimationFrame(textureLibrary.allocateTexture(R.drawable.object_diary06),
4504                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
4505
4506            idle.setLoop(true);
4507
4508            InventoryComponent.UpdateRecord addDiary = new InventoryComponent.UpdateRecord();
4509            addDiary.diaryCount = 1;
4510
4511            staticData.add(addDiary);
4512
4513            staticData.add(idle);
4514
4515            setStaticData(GameObjectType.DIARY, staticData);
4516        }
4517
4518        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4519        render.setPriority(SortConstants.GENERAL_OBJECT);
4520
4521        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4522        sprite.setSize((int)object.width, (int)object.height);
4523        sprite.setRenderComponent(render);
4524
4525        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4526        sprite.setCollisionComponent(dynamicCollision);
4527
4528        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4529        hitReact.setDieWhenCollected(true);
4530        hitReact.setInvincible(true);
4531        hitReact.setSpawnGameEventOnHit(CollisionParameters.HitType.COLLECT,
4532                GameFlowEvent.EVENT_SHOW_DIARY, 0);
4533        // TODO: this is pretty dumb.  The static data binding needs to be made generic.
4534        final int staticDataSize = staticData.getCount();
4535        for (int x = 0; x < staticDataSize; x++) {
4536            final BaseObject entry = staticData.get(x);
4537            if (entry instanceof InventoryComponent.UpdateRecord) {
4538                hitReact.setInventoryUpdate((InventoryComponent.UpdateRecord)entry);
4539                break;
4540            }
4541        }
4542
4543        dynamicCollision.setHitReactionComponent(hitReact);
4544
4545        LifetimeComponent life = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
4546
4547        object.life = 1;
4548
4549        object.add(render);
4550        object.add(sprite);
4551        object.add(dynamicCollision);
4552        object.add(hitReact);
4553        object.add(life);
4554
4555        addStaticData(GameObjectType.DIARY, object, sprite);
4556        sprite.playAnimation(0);
4557
4558        return object;
4559    }
4560
4561    public GameObject spawnObjectDoor(float positionX, float positionY, GameObjectType type, boolean solid) {
4562        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4563
4564        GameObject object = mGameObjectPool.allocate();
4565        object.getPosition().set(positionX, positionY);
4566        object.activationRadius = mTightActivationRadius;
4567        object.width = 32;
4568        object.height = 64;
4569
4570        FixedSizeArray<BaseObject> staticData = getStaticData(type);
4571        if (staticData == null) {
4572            final int staticObjectCount = 5;
4573            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4574
4575            final int red_frames[] = {
4576                    R.drawable.object_door_red01,
4577                    R.drawable.object_door_red02,
4578                    R.drawable.object_door_red03,
4579                    R.drawable.object_door_red04,
4580            };
4581
4582            final int blue_frames[] = {
4583                    R.drawable.object_door_blue01,
4584                    R.drawable.object_door_blue02,
4585                    R.drawable.object_door_blue03,
4586                    R.drawable.object_door_blue04,
4587            };
4588
4589            final int green_frames[] = {
4590                    R.drawable.object_door_green01,
4591                    R.drawable.object_door_green02,
4592                    R.drawable.object_door_green03,
4593                    R.drawable.object_door_green04,
4594            };
4595
4596            int frames[] = red_frames;
4597
4598            if (type == GameObjectType.DOOR_GREEN) {
4599                frames = green_frames;
4600            } else if (type == GameObjectType.DOOR_BLUE) {
4601                frames = blue_frames;
4602            }
4603
4604            FixedSizeArray<CollisionVolume> vulnerabilityVolume = null;
4605
4606            AnimationFrame frame1 = new AnimationFrame(textureLibrary.allocateTexture(frames[0]),
4607                    Utils.framesToTime(24, 1), null, vulnerabilityVolume);
4608            AnimationFrame frame2 = new AnimationFrame(textureLibrary.allocateTexture(frames[1]),
4609                    Utils.framesToTime(24, 2));
4610            AnimationFrame frame3 = new AnimationFrame(textureLibrary.allocateTexture(frames[2]),
4611                    Utils.framesToTime(24, 2));
4612            AnimationFrame frame4 = new AnimationFrame(textureLibrary.allocateTexture(frames[3]),
4613                    Utils.framesToTime(24, 1));
4614
4615            // one frame of closing is deadly
4616
4617            FixedSizeArray<CollisionVolume> attackVolume =
4618                new FixedSizeArray<CollisionVolume>(1);
4619            attackVolume.add(new AABoxCollisionVolume(12, 8, 8, 56));
4620            attackVolume.get(0).setHitType(HitType.DEATH);
4621
4622
4623
4624            AnimationFrame closeFrame2 = new AnimationFrame(textureLibrary.allocateTexture(frames[1]),
4625                    Utils.framesToTime(24, 2), attackVolume, vulnerabilityVolume);
4626
4627            SpriteAnimation idle_closed = new SpriteAnimation(DoorAnimationComponent.Animation.CLOSED, 1);
4628            idle_closed.addFrame(frame1);
4629
4630            SpriteAnimation idle_open = new SpriteAnimation(DoorAnimationComponent.Animation.OPEN, 1);
4631            idle_open.addFrame(frame4);
4632
4633            SpriteAnimation open = new SpriteAnimation(DoorAnimationComponent.Animation.OPENING, 2);
4634            open.addFrame(frame2);
4635            open.addFrame(frame3);
4636
4637            SpriteAnimation close = new SpriteAnimation(DoorAnimationComponent.Animation.CLOSING, 2);
4638            close.addFrame(frame3);
4639            close.addFrame(closeFrame2);
4640
4641            SolidSurfaceComponent solidSurface
4642                = (SolidSurfaceComponent)allocateComponent(SolidSurfaceComponent.class);
4643            solidSurface.inititalize(4);
4644            // box shape:
4645            // ___       ___1
4646            // | |      2| |3
4647            // ---       ---4
4648            Vector2 surface1Start = new Vector2(0, object.height);
4649            Vector2 surface1End = new Vector2(object.width, object.height);
4650            Vector2 surface1Normal = new Vector2(0.0f, -1.0f);
4651            surface1Normal.normalize();
4652
4653            Vector2 surface2Start = new Vector2(0, object.height);
4654            Vector2 surface2End = new Vector2(0, 0);
4655            Vector2 surface2Normal = new Vector2(-1.0f, 0.0f);
4656            surface2Normal.normalize();
4657
4658            Vector2 surface3Start = new Vector2(object.width, object.height);
4659            Vector2 surface3End = new Vector2(object.width, 0);
4660            Vector2 surface3Normal = new Vector2(1.0f, 0);
4661
4662            Vector2 surface4Start = new Vector2(0, 0);
4663            Vector2 surface4End = new Vector2(object.width, 0);
4664            Vector2 surface4Normal = new Vector2(0, 1.0f);
4665
4666            solidSurface.addSurface(surface1Start, surface1End, surface1Normal);
4667            solidSurface.addSurface(surface2Start, surface2End, surface2Normal);
4668            solidSurface.addSurface(surface3Start, surface3End, surface3Normal);
4669            solidSurface.addSurface(surface4Start, surface4End, surface4Normal);
4670
4671            staticData.add(idle_open);
4672            staticData.add(idle_closed);
4673            staticData.add(open);
4674            staticData.add(close);
4675            staticData.add(solidSurface);
4676            setStaticData(type, staticData);
4677        }
4678
4679
4680        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4681        render.setPriority(SortConstants.FOREGROUND_OBJECT);
4682
4683        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4684        sprite.setSize((int)object.width, (int)object.height);
4685        sprite.setRenderComponent(render);
4686
4687        DoorAnimationComponent doorAnim = (DoorAnimationComponent)allocateComponent(DoorAnimationComponent.class);
4688        doorAnim.setSprite(sprite);
4689
4690        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
4691        if (sound != null) {
4692        	doorAnim.setSounds(sound.load(R.raw.sound_open), sound.load(R.raw.sound_close));
4693        }
4694
4695        ChannelSystem.Channel doorChannel = null;
4696        ChannelSystem channelSystem = BaseObject.sSystemRegistry.channelSystem;
4697        switch (type) {
4698            case DOOR_RED:
4699                doorChannel = channelSystem.registerChannel(sRedButtonChannel);
4700                break;
4701            case DOOR_BLUE:
4702                doorChannel = channelSystem.registerChannel(sBlueButtonChannel);
4703                break;
4704            case DOOR_GREEN:
4705                doorChannel = channelSystem.registerChannel(sGreenButtonChannel);
4706                break;
4707        }
4708        doorAnim.setChannel(doorChannel);
4709
4710        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4711        sprite.setCollisionComponent(dynamicCollision);
4712
4713        HitReactionComponent hitReact
4714            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4715        dynamicCollision.setHitReactionComponent(hitReact);
4716
4717
4718
4719        object.add(render);
4720        object.add(sprite);
4721        object.add(doorAnim);
4722        object.add(dynamicCollision);
4723        object.add(hitReact);
4724        addStaticData(type, object, sprite);
4725
4726        object.commitUpdates();
4727
4728        SolidSurfaceComponent solidSurface = object.findByClass(SolidSurfaceComponent.class);
4729        if (solid) {
4730            doorAnim.setSolidSurface(solidSurface);
4731        } else {
4732            object.remove(solidSurface);
4733            object.commitUpdates();
4734        }
4735
4736
4737        sprite.playAnimation(0);
4738
4739        return object;
4740    }
4741
4742    public GameObject spawnObjectButton(float positionX, float positionY, GameObjectType type) {
4743        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4744
4745        GameObject object = mGameObjectPool.allocate();
4746        object.getPosition().set(positionX, positionY);
4747        object.activationRadius = mTightActivationRadius;
4748        object.width = 32;
4749        object.height = 32;
4750
4751        FixedSizeArray<BaseObject> staticData = getStaticData(type);
4752        if (staticData == null) {
4753            final int staticObjectCount = 2;
4754            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4755
4756            final int red_frames[] = {
4757                    R.drawable.object_button_red,
4758                    R.drawable.object_button_pressed_red,
4759            };
4760
4761            final int blue_frames[] = {
4762                    R.drawable.object_button_blue,
4763                    R.drawable.object_button_pressed_blue,
4764            };
4765
4766            final int green_frames[] = {
4767                    R.drawable.object_button_green,
4768                    R.drawable.object_button_pressed_green,
4769            };
4770
4771            int frames[] = red_frames;
4772
4773            if (type == GameObjectType.BUTTON_GREEN) {
4774                frames = green_frames;
4775            } else if (type == GameObjectType.BUTTON_BLUE) {
4776                frames = blue_frames;
4777            }
4778
4779            FixedSizeArray<CollisionVolume> vulnerabilityVolume =
4780                new FixedSizeArray<CollisionVolume>(1);
4781            vulnerabilityVolume.add(new AABoxCollisionVolume(0, 0, 32, 16));
4782            vulnerabilityVolume.get(0).setHitType(HitType.DEPRESS);
4783
4784            AnimationFrame frame1 = new AnimationFrame(textureLibrary.allocateTexture(frames[0]),
4785                    Utils.framesToTime(24, 1), null, vulnerabilityVolume);
4786            AnimationFrame frame2 = new AnimationFrame(textureLibrary.allocateTexture(frames[1]),
4787                    Utils.framesToTime(24, 1), null, vulnerabilityVolume);
4788
4789            SpriteAnimation idle = new SpriteAnimation(ButtonAnimationComponent.Animation.UP, 1);
4790            idle.addFrame(frame1);
4791
4792            SpriteAnimation pressed = new SpriteAnimation(ButtonAnimationComponent.Animation.DOWN, 1);
4793            pressed.addFrame(frame2);
4794
4795            staticData.add(idle);
4796            staticData.add(pressed);
4797
4798            setStaticData(type, staticData);
4799        }
4800
4801
4802        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4803        render.setPriority(SortConstants.GENERAL_OBJECT);
4804
4805        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4806        sprite.setSize((int)object.width, (int)object.height);
4807        sprite.setRenderComponent(render);
4808
4809        ButtonAnimationComponent button = (ButtonAnimationComponent)allocateComponent(ButtonAnimationComponent.class);
4810        button.setSprite(sprite);
4811
4812        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
4813        if (sound != null) {
4814        	button.setDepressSound(sound.load(R.raw.sound_button));
4815        }
4816
4817        ChannelSystem.Channel buttonChannel = null;
4818        ChannelSystem channelSystem = BaseObject.sSystemRegistry.channelSystem;
4819        switch (type) {
4820            case BUTTON_RED:
4821                buttonChannel = channelSystem.registerChannel(sRedButtonChannel);
4822                break;
4823            case BUTTON_BLUE:
4824                buttonChannel = channelSystem.registerChannel(sBlueButtonChannel);
4825                break;
4826            case BUTTON_GREEN:
4827                buttonChannel = channelSystem.registerChannel(sGreenButtonChannel);
4828                break;
4829        }
4830        button.setChannel(buttonChannel);
4831
4832        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4833        sprite.setCollisionComponent(dynamicCollision);
4834
4835        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4836        hitReact.setInvincible(false);
4837
4838
4839
4840        dynamicCollision.setHitReactionComponent(hitReact);
4841
4842        object.team = Team.NONE;
4843
4844        object.add(render);
4845        object.add(sprite);
4846        object.add(button);
4847        object.add(dynamicCollision);
4848        object.add(hitReact);
4849
4850        addStaticData(type, object, sprite);
4851
4852        sprite.playAnimation(0);
4853
4854        return object;
4855    }
4856
4857    public GameObject spawnObjectCannon(float positionX, float positionY) {
4858        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4859
4860        GameObject object = mGameObjectPool.allocate();
4861        object.getPosition().set(positionX, positionY);
4862        object.activationRadius = mTightActivationRadius;
4863        object.width = 64;
4864        object.height = 128;
4865
4866        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.CANNON);
4867        if (staticData == null) {
4868            final int staticObjectCount = 2;
4869            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4870
4871            FixedSizeArray<CollisionVolume> attackVolume =
4872                new FixedSizeArray<CollisionVolume>(1);
4873            attackVolume.add(new AABoxCollisionVolume(16, 16, 32, 80));
4874            attackVolume.get(0).setHitType(HitType.LAUNCH);
4875
4876            AnimationFrame frame1 = new AnimationFrame(
4877                    textureLibrary.allocateTexture(R.drawable.object_cannon),
4878                    1.0f, attackVolume, null);
4879
4880            SpriteAnimation idle = new SpriteAnimation(GenericAnimationComponent.Animation.IDLE, 1);
4881            idle.addFrame(frame1);
4882
4883            AnimationFrame frame1NoAttack = new AnimationFrame(
4884                    textureLibrary.allocateTexture(R.drawable.object_cannon),
4885                    1.0f, null, null);
4886
4887            SpriteAnimation shoot = new SpriteAnimation(GenericAnimationComponent.Animation.ATTACK, 1);
4888            shoot.addFrame(frame1NoAttack);
4889
4890            staticData.add(idle);
4891            staticData.add(shoot);
4892
4893            setStaticData(GameObjectType.CANNON, staticData);
4894        }
4895
4896
4897        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
4898        render.setPriority(SortConstants.FOREGROUND_OBJECT);
4899
4900        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
4901        sprite.setSize((int)object.width, (int)object.height);
4902        sprite.setRenderComponent(render);
4903
4904        LauncherComponent launcher = (LauncherComponent)allocateComponent(LauncherComponent.class);
4905        launcher.setLaunchEffect(GameObjectType.SMOKE_POOF, 32.0f, 85.0f);
4906
4907        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
4908        if (sound != null) {
4909        	launcher.setLaunchSound(sound.load(R.raw.sound_cannon));
4910        }
4911
4912
4913        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
4914        sprite.setCollisionComponent(dynamicCollision);
4915
4916        HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
4917        hitReact.setInvincible(false);
4918        hitReact.setLauncherComponent(launcher, HitType.LAUNCH);
4919
4920        dynamicCollision.setHitReactionComponent(hitReact);
4921
4922        GenericAnimationComponent anim = (GenericAnimationComponent)allocateComponent(GenericAnimationComponent.class);
4923        anim.setSprite(sprite);
4924
4925        object.team = Team.NONE;
4926
4927        object.add(render);
4928        object.add(sprite);
4929        object.add(dynamicCollision);
4930        object.add(hitReact);
4931        object.add(launcher);
4932        object.add(anim);
4933
4934        addStaticData(GameObjectType.CANNON, object, sprite);
4935
4936        sprite.playAnimation(0);
4937
4938        return object;
4939    }
4940
4941    public GameObject spawnObjectBrobotSpawner(float positionX, float positionY, boolean flipHorizontal) {
4942
4943        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
4944
4945        // This is pretty heavy-handed.
4946        // TODO: figure out a general solution for objects that depend on other objects.
4947        textureLibrary.allocateTexture(R.drawable.enemy_brobot_idle01);
4948        textureLibrary.allocateTexture(R.drawable.enemy_brobot_idle02);
4949        textureLibrary.allocateTexture(R.drawable.enemy_brobot_idle03);
4950        textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk01);
4951        textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk02);
4952        textureLibrary.allocateTexture(R.drawable.enemy_brobot_walk03);
4953
4954        GameObject object = mGameObjectPool.allocate();
4955        object.getPosition().set(positionX, positionY);
4956        object.activationRadius = mTightActivationRadius;
4957        object.width = 64;
4958        object.height = 64;
4959
4960        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.BROBOT_SPAWNER);
4961        if (staticData == null) {
4962            final int staticObjectCount = 3;
4963            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
4964
4965            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
4966                new FixedSizeArray<CollisionVolume>(1);
4967            basicVulnerabilityVolume.add(new SphereCollisionVolume(32, 32, 32));
4968            basicVulnerabilityVolume.get(0).setHitType(HitType.POSSESS);
4969
4970            SpriteAnimation idle = new SpriteAnimation(0, 1);
4971            idle.addFrame(new AnimationFrame(
4972                    textureLibrary.allocateTexture(R.drawable.object_brobot_machine),
4973                    1.0f, null, basicVulnerabilityVolume));
4974
4975            SolidSurfaceComponent solidSurface
4976                = (SolidSurfaceComponent)allocateComponent(SolidSurfaceComponent.class);
4977            solidSurface.inititalize(3);
4978            /*
4979                0:2,0:8,59:-0.99532399996093,0.09659262446878
4980                0:8,59:61,33:0.44551558813576,0.89527418187282
4981                0:61,33:61,-1:1,0
4982
4983             */
4984            // trapezoid shape:
4985            // |\        |\2
4986            // | |      1| |3
4987
4988            Vector2 surface1Start = new Vector2(0, 0);
4989            Vector2 surface1End = new Vector2(8.0f, 59.0f);
4990            Vector2 surface1Normal = new Vector2(-0.9953f, 0.0965f);
4991            surface1Normal.normalize();
4992
4993            Vector2 surface2Start = new Vector2(8.0f, 59.0f);
4994            Vector2 surface2End = new Vector2(61.0f, 33.0f);
4995            Vector2 surface2Normal = new Vector2(0.445515f, 0.89527f);
4996            surface2Normal.normalize();
4997
4998            Vector2 surface3Start = new Vector2(61.0f, 33.0f);
4999            Vector2 surface3End = new Vector2(61.0f, 0.0f);
5000            Vector2 surface3Normal = new Vector2(1.0f, 0.0f);
5001
5002            solidSurface.addSurface(surface1Start, surface1End, surface1Normal);
5003            solidSurface.addSurface(surface2Start, surface2End, surface2Normal);
5004            solidSurface.addSurface(surface3Start, surface3End, surface3Normal);
5005
5006            GhostComponent ghost = (GhostComponent)allocateComponent(GhostComponent.class);
5007            ghost.setTargetAction(ActionType.IDLE);
5008            ghost.changeActionOnButton(ActionType.ATTACK);
5009
5010            SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
5011            if (sound != null) {
5012            	ghost.setAmbientSound(sound.load(R.raw.sound_possession));
5013            }
5014
5015            staticData.add(ghost);
5016            staticData.add(solidSurface);
5017            staticData.add(idle);
5018
5019
5020            setStaticData(GameObjectType.BROBOT_SPAWNER, staticData);
5021        }
5022
5023        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
5024        render.setPriority(SortConstants.GENERAL_OBJECT);
5025
5026
5027        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5028        sprite.setSize((int)object.width, (int)object.height);
5029        sprite.setRenderComponent(render);
5030
5031        DynamicCollisionComponent collision
5032            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
5033        sprite.setCollisionComponent(collision);
5034
5035        HitReactionComponent hitReact
5036            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
5037        collision.setHitReactionComponent(hitReact);
5038
5039        LaunchProjectileComponent gun
5040            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
5041        gun.setDelayBeforeFirstSet(3.0f);
5042        gun.setObjectTypeToSpawn(GameObjectType.BROBOT);
5043        gun.setOffsetX(36);
5044        gun.setOffsetY(50);
5045        gun.setVelocityX(100.0f);
5046        gun.setVelocityY(300.0f);
5047        gun.enableProjectileTracking(1);
5048
5049        LaunchProjectileComponent possessedGun
5050            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
5051        possessedGun.setRequiredAction(ActionType.ATTACK);
5052        possessedGun.setDelayBeforeFirstSet(0.0f);
5053        possessedGun.setObjectTypeToSpawn(GameObjectType.BROBOT_BULLET);
5054        possessedGun.setOffsetX(36);
5055        possessedGun.setOffsetY(50);
5056        possessedGun.setVelocityX(600.0f);
5057        possessedGun.setVelocityY(600.0f);
5058        possessedGun.setThetaError(0.3f);
5059
5060        ChangeComponentsComponent componentSwap = (ChangeComponentsComponent)allocateComponent(ChangeComponentsComponent.class);
5061        componentSwap.addSwapOutComponent(gun);
5062        componentSwap.addSwapInComponent(possessedGun);
5063        componentSwap.setPingPongBehavior(true);
5064
5065        hitReact.setPossessionComponent(componentSwap);
5066
5067        object.team = Team.ENEMY;
5068
5069        if (flipHorizontal) {
5070            object.facingDirection.x = -1.0f;
5071        } else {
5072            object.facingDirection.x = 1.0f;
5073        }
5074
5075        object.add(render);
5076        object.add(sprite);
5077        object.add(gun);
5078        object.add(collision);
5079        object.add(hitReact);
5080        object.add(componentSwap);
5081
5082
5083        addStaticData(GameObjectType.BROBOT_SPAWNER, object, sprite);
5084
5085        object.commitUpdates();
5086
5087        GhostComponent possessedGhost = object.findByClass(GhostComponent.class);
5088        if (possessedGhost != null) {
5089            object.remove(possessedGhost);   // Not supposed to be added yet.
5090            componentSwap.addSwapInComponent(possessedGhost);
5091        }
5092
5093        sprite.playAnimation(0);
5094
5095        return object;
5096    }
5097
5098public GameObject spawnObjectBreakableBlock(float positionX, float positionY) {
5099
5100        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
5101
5102        // Preload block piece texture.
5103        textureLibrary.allocateTexture(R.drawable.object_debris_piece);
5104
5105        GameObject object = mGameObjectPool.allocate();
5106        object.getPosition().set(positionX, positionY);
5107        object.activationRadius = mTightActivationRadius;
5108        object.width = 32;
5109        object.height = 32;
5110
5111        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.BREAKABLE_BLOCK);
5112        if (staticData == null) {
5113            final int staticObjectCount = 2;
5114            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5115
5116            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
5117                new FixedSizeArray<CollisionVolume>(1);
5118            basicVulnerabilityVolume.add(new AABoxCollisionVolume(7, 0, 32 - 7, 42, HitType.HIT));
5119
5120            SpriteAnimation idle = new SpriteAnimation(0, 1);
5121            idle.addFrame(new AnimationFrame(
5122                    textureLibrary.allocateTexture(R.drawable.object_debris_block),
5123                    1.0f, null, basicVulnerabilityVolume));
5124
5125            SolidSurfaceComponent solidSurface
5126                = (SolidSurfaceComponent)allocateComponent(SolidSurfaceComponent.class);
5127            solidSurface.inititalize(4);
5128
5129            // box shape:
5130            // ___       ___2
5131            // | |      1| |3
5132            // ---       ---4
5133
5134            Vector2 surface1Start = new Vector2(0.0f, 0.0f);
5135            Vector2 surface1End = new Vector2(0.0f, 32.0f);
5136            Vector2 surface1Normal = new Vector2(-1.0f, 0.0f);
5137            surface1Normal.normalize();
5138
5139            Vector2 surface2Start = new Vector2(0.0f, 32.0f);
5140            Vector2 surface2End = new Vector2(32.0f, 32.0f);
5141            Vector2 surface2Normal = new Vector2(0.0f, 1.0f);
5142            surface2Normal.normalize();
5143
5144            Vector2 surface3Start = new Vector2(32.0f, 32.0f);
5145            Vector2 surface3End = new Vector2(32.0f, 0.0f);
5146            Vector2 surface3Normal = new Vector2(1.0f, 0.0f);
5147
5148            Vector2 surface4Start = new Vector2(32.0f, 0.0f);
5149            Vector2 surface4End = new Vector2(0.0f, 0.0f);
5150            Vector2 surface4Normal = new Vector2(0.0f, -1.0f);
5151
5152            solidSurface.addSurface(surface1Start, surface1End, surface1Normal);
5153            solidSurface.addSurface(surface2Start, surface2End, surface2Normal);
5154            solidSurface.addSurface(surface3Start, surface3End, surface3Normal);
5155            solidSurface.addSurface(surface4Start, surface4End, surface4Normal);
5156
5157            staticData.add(solidSurface);
5158            staticData.add(idle);
5159
5160
5161            setStaticData(GameObjectType.BREAKABLE_BLOCK, staticData);
5162        }
5163
5164        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
5165        render.setPriority(SortConstants.GENERAL_OBJECT);
5166
5167
5168        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5169        sprite.setSize((int)object.width, (int)object.height);
5170        sprite.setRenderComponent(render);
5171
5172        DynamicCollisionComponent collision
5173            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
5174        sprite.setCollisionComponent(collision);
5175
5176        HitReactionComponent hitReact
5177            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
5178        collision.setHitReactionComponent(hitReact);
5179
5180        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
5181        lifetime.setObjectToSpawnOnDeath(GameObjectType.BREAKABLE_BLOCK_PIECE_SPAWNER);
5182        SoundSystem sound = BaseObject.sSystemRegistry.soundSystem;
5183        if (sound != null) {
5184        	lifetime.setDeathSound(sound.load(R.raw.sound_break_block));
5185        }
5186
5187        object.life = 1;
5188        object.team = Team.ENEMY;
5189
5190        object.add(render);
5191        object.add(sprite);
5192        object.add(collision);
5193        object.add(hitReact);
5194        object.add(lifetime);
5195
5196
5197        addStaticData(GameObjectType.BREAKABLE_BLOCK, object, sprite);
5198
5199        sprite.playAnimation(0);
5200
5201        return object;
5202    }
5203
5204	public GameObject spawnObjectTheSource(float positionX, float positionY) {
5205
5206	    final TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
5207
5208	    GameObject object = mGameObjectPool.allocate();
5209	    object.activationRadius = mAlwaysActive;
5210	    object.width = 512;
5211	    object.height = 512;
5212        object.getPosition().set(positionX, positionY);
5213
5214	    RenderComponent layer1Render = (RenderComponent)allocateComponent(RenderComponent.class);
5215	    layer1Render.setPriority(SortConstants.THE_SOURCE_START);
5216	    FadeDrawableComponent layer1Fade = (FadeDrawableComponent)allocateComponent(FadeDrawableComponent.class);
5217	    layer1Fade.setRenderComponent(layer1Render);
5218	    layer1Fade.setTexture(textureLibrary.allocateTexture(R.drawable.enemy_source_spikes));
5219	    layer1Fade.setupFade(1.0f, 0.2f, 1.9f, FadeDrawableComponent.LOOP_TYPE_PING_PONG, FadeDrawableComponent.FADE_EASE, 0.0f);
5220
5221	    RenderComponent layer2Render = (RenderComponent)allocateComponent(RenderComponent.class);
5222	    layer2Render.setPriority(SortConstants.THE_SOURCE_START + 1);
5223	    FadeDrawableComponent layer2Fade = (FadeDrawableComponent)allocateComponent(FadeDrawableComponent.class);
5224	    layer2Fade.setRenderComponent(layer2Render);
5225	    layer2Fade.setTexture(textureLibrary.allocateTexture(R.drawable.enemy_source_body));
5226	    layer2Fade.setupFade(1.0f, 0.8f, 5.0f, FadeDrawableComponent.LOOP_TYPE_PING_PONG, FadeDrawableComponent.FADE_EASE, 0.0f);
5227
5228	    RenderComponent layer3Render = (RenderComponent)allocateComponent(RenderComponent.class);
5229	    layer3Render.setPriority(SortConstants.THE_SOURCE_START + 2);
5230	    FadeDrawableComponent layer3Fade = (FadeDrawableComponent)allocateComponent(FadeDrawableComponent.class);
5231	    layer3Fade.setRenderComponent(layer3Render);
5232	    layer3Fade.setTexture(textureLibrary.allocateTexture(R.drawable.enemy_source_black));
5233	    layer3Fade.setupFade(0.0f, 1.0f, 6.0f, FadeDrawableComponent.LOOP_TYPE_PING_PONG, FadeDrawableComponent.FADE_LINEAR, 0.0f);
5234
5235	    RenderComponent layer4Render = (RenderComponent)allocateComponent(RenderComponent.class);
5236	    layer4Render.setPriority(SortConstants.THE_SOURCE_START + 3);
5237	    FadeDrawableComponent layer4Fade = (FadeDrawableComponent)allocateComponent(FadeDrawableComponent.class);
5238	    layer4Fade.setRenderComponent(layer4Render);
5239	    layer4Fade.setTexture(textureLibrary.allocateTexture(R.drawable.enemy_source_spots));
5240	    layer4Fade.setupFade(0.0f, 1.0f, 2.3f, FadeDrawableComponent.LOOP_TYPE_PING_PONG, FadeDrawableComponent.FADE_EASE, 0.0f);
5241
5242	    RenderComponent layer5Render = (RenderComponent)allocateComponent(RenderComponent.class);
5243	    layer5Render.setPriority(SortConstants.THE_SOURCE_START + 4);
5244	    FadeDrawableComponent layer5Fade = (FadeDrawableComponent)allocateComponent(FadeDrawableComponent.class);
5245	    layer5Fade.setRenderComponent(layer5Render);
5246	    layer5Fade.setTexture(textureLibrary.allocateTexture(R.drawable.enemy_source_core));
5247	    layer5Fade.setupFade(0.2f, 1.0f, 1.2f, FadeDrawableComponent.LOOP_TYPE_PING_PONG, FadeDrawableComponent.FADE_EASE, 0.0f);
5248
5249
5250	    OrbitalMagnetComponent orbit = (OrbitalMagnetComponent)allocateComponent(OrbitalMagnetComponent.class);
5251	    orbit.setup(320.0f, 220.0f);
5252
5253	    DynamicCollisionComponent collision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
5254	    FixedSizeArray<CollisionVolume> vulnerabilityVolume =
5255            new FixedSizeArray<CollisionVolume>(1);
5256	    vulnerabilityVolume.add(new SphereCollisionVolume(256, 256, 256, HitType.HIT));
5257	    FixedSizeArray<CollisionVolume> attackVolume =
5258            new FixedSizeArray<CollisionVolume>(1);
5259	    attackVolume.add(new SphereCollisionVolume(256, 256, 256, HitType.HIT));
5260	    collision.setCollisionVolumes(attackVolume, vulnerabilityVolume);
5261
5262	    HitReactionComponent hitReact = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
5263        collision.setHitReactionComponent(hitReact);
5264        hitReact.setInvincibleTime(TheSourceComponent.SHAKE_TIME);
5265
5266        TheSourceComponent theSource = (TheSourceComponent)allocateComponent(TheSourceComponent.class);
5267        ChannelSystem.Channel surpriseChannel = null;
5268        ChannelSystem channelSystem = BaseObject.sSystemRegistry.channelSystem;
5269        surpriseChannel = channelSystem.registerChannel(sSurprisedNPCChannel);
5270        theSource.setChannel(surpriseChannel);
5271        theSource.setGameEvent(GameFlowEvent.EVENT_SHOW_ANIMATION, AnimationPlayerActivity.WANDA_ENDING);
5272
5273
5274	    object.life = 3;
5275	    object.team = Team.PLAYER;
5276
5277	    object.add(layer1Render);
5278	    object.add(layer2Render);
5279	    object.add(layer3Render);
5280	    object.add(layer4Render);
5281	    object.add(layer5Render);
5282
5283	    object.add(layer1Fade);
5284	    object.add(layer2Fade);
5285	    object.add(layer3Fade);
5286	    object.add(layer4Fade);
5287	    object.add(layer5Fade);
5288
5289	    object.add(orbit);
5290	    object.add(collision);
5291	    object.add(hitReact);
5292	    object.add(theSource);
5293
5294	    return object;
5295	}
5296
5297    public GameObject spawnObjectTurret(float positionX, float positionY, boolean flipHorizontal) {
5298
5299        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
5300
5301        // Make sure related textures are loaded.
5302        textureLibrary.allocateTexture(R.drawable.effect_bullet01);
5303        textureLibrary.allocateTexture(R.drawable.effect_bullet02);
5304
5305
5306        GameObject object = mGameObjectPool.allocate();
5307        object.getPosition().set(positionX, positionY);
5308        object.activationRadius = mTightActivationRadius;
5309        object.width = 64;
5310        object.height = 64;
5311
5312        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.TURRET);
5313        if (staticData == null) {
5314            final int staticObjectCount = 3;
5315            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5316
5317            // Animations
5318            FixedSizeArray<CollisionVolume> basicVulnerabilityVolume =
5319                new FixedSizeArray<CollisionVolume>(1);
5320            basicVulnerabilityVolume.add(new SphereCollisionVolume(32, 32, 32));
5321            basicVulnerabilityVolume.get(0).setHitType(HitType.POSSESS);
5322
5323            SpriteAnimation idle = new SpriteAnimation(EnemyAnimations.IDLE.ordinal(), 2);
5324            idle.addFrame(new AnimationFrame(
5325                    textureLibrary.allocateTexture(R.drawable.object_gunturret01),
5326                    1.0f, null, basicVulnerabilityVolume));
5327            idle.addFrame(new AnimationFrame(
5328                    textureLibrary.allocateTexture(R.drawable.object_gunturret_idle),
5329                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
5330            idle.setLoop(true);
5331
5332            SpriteAnimation attack = new SpriteAnimation(EnemyAnimations.ATTACK.ordinal(), 4);
5333            attack.addFrame(new AnimationFrame(
5334                    textureLibrary.allocateTexture(R.drawable.object_gunturret02),
5335                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
5336            attack.addFrame(new AnimationFrame(
5337                    textureLibrary.allocateTexture(R.drawable.object_gunturret01),
5338                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
5339            attack.addFrame(new AnimationFrame(
5340                    textureLibrary.allocateTexture(R.drawable.object_gunturret03),
5341                    Utils.framesToTime(24, 2), null, basicVulnerabilityVolume));
5342            attack.addFrame(new AnimationFrame(
5343                    textureLibrary.allocateTexture(R.drawable.object_gunturret01),
5344                    Utils.framesToTime(24, 1), null, basicVulnerabilityVolume));
5345            attack.setLoop(true);
5346
5347            GhostComponent ghost = (GhostComponent)allocateComponent(GhostComponent.class);
5348            ghost.setTargetAction(ActionType.IDLE);
5349            ghost.changeActionOnButton(ActionType.ATTACK);
5350
5351            staticData.add(idle);
5352            staticData.add(attack);
5353            staticData.add(ghost);
5354
5355
5356            setStaticData(GameObjectType.TURRET, staticData);
5357        }
5358
5359        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
5360        render.setPriority(SortConstants.GENERAL_OBJECT);
5361
5362
5363        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5364        sprite.setSize((int)object.width, (int)object.height);
5365        sprite.setRenderComponent(render);
5366
5367        GenericAnimationComponent animation
5368            = (GenericAnimationComponent)allocateComponent(GenericAnimationComponent.class);
5369        animation.setSprite(sprite);
5370
5371        AttackAtDistanceComponent attack = (AttackAtDistanceComponent)
5372            allocateComponent(AttackAtDistanceComponent.class);
5373        attack.setupAttack(300, 0.0f, 1.0f, true);
5374
5375
5376        DynamicCollisionComponent collision
5377            = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
5378        sprite.setCollisionComponent(collision);
5379
5380        HitReactionComponent hitReact
5381            = (HitReactionComponent)allocateComponent(HitReactionComponent.class);
5382        collision.setHitReactionComponent(hitReact);
5383
5384        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
5385        lifetime.setObjectToSpawnOnDeath(GameObjectType.EXPLOSION_LARGE);
5386
5387        SoundSystem sound = sSystemRegistry.soundSystem;
5388
5389        LaunchProjectileComponent gun
5390            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
5391        gun.setShotsPerSet(1);
5392        gun.setDelayBetweenShots(0.0f);
5393        gun.setDelayBetweenSets(0.3f);
5394        gun.setObjectTypeToSpawn(GameObjectType.TURRET_BULLET);
5395        gun.setOffsetX(54);
5396        gun.setOffsetY(13);
5397        gun.setRequiredAction(GameObject.ActionType.ATTACK);
5398        gun.setVelocityX(300.0f);
5399        gun.setVelocityY(-300.0f);
5400        gun.setShootSound(sound.load(R.raw.sound_gun));
5401
5402        // Components for possession
5403
5404        ChangeComponentsComponent componentSwap = (ChangeComponentsComponent)allocateComponent(ChangeComponentsComponent.class);
5405        componentSwap.addSwapOutComponent(attack);
5406        componentSwap.setPingPongBehavior(true);
5407
5408        hitReact.setPossessionComponent(componentSwap);
5409
5410        object.team = Team.ENEMY;
5411
5412        if (flipHorizontal) {
5413            object.facingDirection.x = -1.0f;
5414        } else {
5415            object.facingDirection.x = 1.0f;
5416        }
5417
5418        object.add(render);
5419        object.add(sprite);
5420        object.add(animation);
5421        object.add(attack);
5422        object.add(collision);
5423        object.add(hitReact);
5424        object.add(lifetime);
5425        object.add(gun);
5426        object.add(componentSwap);
5427
5428        addStaticData(GameObjectType.TURRET, object, sprite);
5429
5430        object.commitUpdates();
5431
5432        GhostComponent possessedGhost = object.findByClass(GhostComponent.class);
5433        if (possessedGhost != null) {
5434            object.remove(possessedGhost);   // Not supposed to be added yet.
5435            componentSwap.addSwapInComponent(possessedGhost);
5436        }
5437
5438        sprite.playAnimation(0);
5439
5440        return object;
5441    }
5442
5443    public GameObject spawnDust(float positionX, float positionY, boolean flipHorizontal) {
5444        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
5445
5446        GameObject object = mGameObjectPool.allocate();
5447        object.getPosition().set(positionX, positionY);
5448        object.activationRadius = mTightActivationRadius;
5449        object.width = 32;
5450        object.height = 32;
5451
5452        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.DUST);
5453        if (staticData == null) {
5454            final int staticObjectCount = 1;
5455            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5456
5457            SpriteAnimation idle = new SpriteAnimation(0, 5);
5458            idle.addFrame(new AnimationFrame(textureLibrary.getTextureByResource(R.drawable.dust01),
5459                    Utils.framesToTime(24, 1)));
5460            idle.addFrame(new AnimationFrame(textureLibrary.getTextureByResource(R.drawable.dust02),
5461                    Utils.framesToTime(24, 1)));
5462            idle.addFrame(new AnimationFrame(textureLibrary.getTextureByResource(R.drawable.dust03),
5463                    Utils.framesToTime(24, 1)));
5464            idle.addFrame(new AnimationFrame(textureLibrary.getTextureByResource(R.drawable.dust04),
5465                    Utils.framesToTime(24, 1)));
5466            idle.addFrame(new AnimationFrame(textureLibrary.getTextureByResource(R.drawable.dust05),
5467                    Utils.framesToTime(24, 1)));
5468
5469            staticData.add(idle);
5470            setStaticData(GameObjectType.DUST, staticData);
5471        }
5472
5473
5474        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
5475        render.setPriority(SortConstants.EFFECT);
5476
5477        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
5478        lifetime.setTimeUntilDeath(0.30f);
5479
5480        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5481		sprite.setSize((int)object.width, (int)object.height);
5482        sprite.setRenderComponent(render);
5483
5484
5485        if (flipHorizontal) {
5486            object.facingDirection.x = -1.0f;
5487        }
5488        object.destroyOnDeactivation = true;
5489
5490        object.add(lifetime);
5491        object.add(render);
5492        object.add(sprite);
5493
5494        addStaticData(GameObjectType.DUST, object, sprite);
5495
5496        sprite.playAnimation(0);
5497
5498        return object;
5499    }
5500
5501    public GameObject spawnEffectExplosionSmall(float positionX, float positionY) {
5502        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
5503
5504        GameObject object = mGameObjectPool.allocate();
5505        object.getPosition().set(positionX, positionY);
5506        object.activationRadius = mAlwaysActive;
5507        object.width = 32;
5508        object.height = 32;
5509
5510        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.EXPLOSION_SMALL);
5511        if (staticData == null) {
5512            final int staticObjectCount = 1;
5513            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5514
5515            FixedSizeArray<CollisionVolume> basicAttackVolume =
5516                new FixedSizeArray<CollisionVolume>(1);
5517            basicAttackVolume.add(new SphereCollisionVolume(16, 16, 16, HitType.HIT));
5518
5519            SpriteAnimation idle = new SpriteAnimation(0, 7);
5520            idle.addFrame(new AnimationFrame(
5521                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small01),
5522                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5523            idle.addFrame(new AnimationFrame(
5524                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small02),
5525                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5526            idle.addFrame(new AnimationFrame(
5527                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small03),
5528                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5529            idle.addFrame(new AnimationFrame(
5530                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small04),
5531                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5532            idle.addFrame(new AnimationFrame(
5533                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small05),
5534                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5535            idle.addFrame(new AnimationFrame(
5536                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small06),
5537                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5538            idle.addFrame(new AnimationFrame(
5539                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small07),
5540                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5541
5542            staticData.add(idle);
5543            setStaticData(GameObjectType.EXPLOSION_SMALL, staticData);
5544        }
5545
5546        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
5547        render.setPriority(SortConstants.EFFECT);
5548
5549        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5550		sprite.setSize((int)object.width, (int)object.height);
5551        sprite.setRenderComponent(render);
5552
5553
5554        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
5555
5556        DynamicCollisionComponent dynamicCollision = (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
5557        sprite.setCollisionComponent(dynamicCollision);
5558
5559        object.add(dynamicCollision);
5560        object.add(lifetime);
5561        object.add(render);
5562        object.add(sprite);
5563
5564        addStaticData(GameObjectType.EXPLOSION_SMALL, object, sprite);
5565
5566        final SpriteAnimation idle = sprite.findAnimation(0);
5567        if (idle != null) {
5568            lifetime.setTimeUntilDeath(idle.getLength());
5569        }
5570
5571        sprite.playAnimation(0);
5572
5573        return object;
5574    }
5575
5576    public GameObject spawnEffectExplosionLarge(float positionX, float positionY) {
5577        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
5578
5579        GameObject object = mGameObjectPool.allocate();
5580        object.getPosition().set(positionX, positionY);
5581        object.activationRadius = mAlwaysActive;
5582        object.width = 64;
5583        object.height = 64;
5584
5585        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.EXPLOSION_LARGE);
5586        if (staticData == null) {
5587            final int staticObjectCount = 1;
5588            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5589
5590            FixedSizeArray<CollisionVolume> basicAttackVolume =
5591                new FixedSizeArray<CollisionVolume>(1);
5592            basicAttackVolume.add(new SphereCollisionVolume(32, 32, 32, HitType.HIT));
5593
5594            SpriteAnimation idle = new SpriteAnimation(0, 9);
5595            idle.addFrame(new AnimationFrame(
5596                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big01),
5597                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5598            idle.addFrame(new AnimationFrame(
5599                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big02),
5600                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5601            idle.addFrame(new AnimationFrame(
5602                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big03),
5603                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5604            idle.addFrame(new AnimationFrame(
5605                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big04),
5606                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5607            idle.addFrame(new AnimationFrame(
5608                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big05),
5609                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5610            idle.addFrame(new AnimationFrame(
5611                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big06),
5612                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5613            idle.addFrame(new AnimationFrame(
5614                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big07),
5615                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5616            idle.addFrame(new AnimationFrame(
5617                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big08),
5618                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5619            idle.addFrame(new AnimationFrame(
5620                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big09),
5621                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5622
5623
5624            staticData.add(idle);
5625            setStaticData(GameObjectType.EXPLOSION_LARGE, staticData);
5626        }
5627
5628        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
5629        render.setPriority(SortConstants.EFFECT);
5630
5631        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5632		sprite.setSize((int)object.width, (int)object.height);
5633        sprite.setRenderComponent(render);
5634
5635
5636        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
5637
5638        DynamicCollisionComponent dynamicCollision =
5639            (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
5640        sprite.setCollisionComponent(dynamicCollision);
5641
5642        PlaySingleSoundComponent soundEffect = (PlaySingleSoundComponent)allocateComponent(PlaySingleSoundComponent.class);
5643        soundEffect.setSound(sSystemRegistry.soundSystem.load(R.raw.quick_explosion));
5644
5645
5646        object.add(soundEffect);
5647        object.add(dynamicCollision);
5648        object.add(lifetime);
5649        object.add(render);
5650        object.add(sprite);
5651
5652        addStaticData(GameObjectType.EXPLOSION_LARGE, object, sprite);
5653
5654        final SpriteAnimation idle = sprite.findAnimation(0);
5655        if (idle != null) {
5656            lifetime.setTimeUntilDeath(idle.getLength());
5657        }
5658
5659        sprite.playAnimation(0);
5660
5661        return object;
5662    }
5663
5664    public GameObject spawnEffectExplosionGiant(float positionX, float positionY) {
5665        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
5666
5667        GameObject object = mGameObjectPool.allocate();
5668        object.getPosition().set(positionX, positionY);
5669        object.activationRadius = mAlwaysActive;
5670        object.width = 64;
5671        object.height = 64;
5672
5673        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.EXPLOSION_GIANT);
5674        if (staticData == null) {
5675            final int staticObjectCount = 4;
5676            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5677
5678            FixedSizeArray<CollisionVolume> basicAttackVolume = new FixedSizeArray<CollisionVolume>(1);
5679            basicAttackVolume.add(new SphereCollisionVolume(64, 32, 32, HitType.HIT));
5680
5681            SpriteAnimation idle = new SpriteAnimation(0, 9);
5682            idle.addFrame(new AnimationFrame(
5683                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big01),
5684                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5685            idle.addFrame(new AnimationFrame(
5686                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big02),
5687                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5688            idle.addFrame(new AnimationFrame(
5689                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big03),
5690                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5691            idle.addFrame(new AnimationFrame(
5692                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big04),
5693                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5694            idle.addFrame(new AnimationFrame(
5695                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big05),
5696                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5697            idle.addFrame(new AnimationFrame(
5698                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big06),
5699                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5700            idle.addFrame(new AnimationFrame(
5701                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big07),
5702                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5703            idle.addFrame(new AnimationFrame(
5704                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big08),
5705                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5706            idle.addFrame(new AnimationFrame(
5707                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_big09),
5708                    Utils.framesToTime(24, 1), basicAttackVolume, null));
5709
5710
5711            AnimationFrame smallFrame1 = new AnimationFrame(
5712                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small01),
5713                    Utils.framesToTime(24, 1), null, null);
5714            AnimationFrame smallFrame2 = new AnimationFrame(
5715                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small02),
5716                    Utils.framesToTime(24, 1), null, null);
5717            AnimationFrame smallFrame3 = new AnimationFrame(
5718                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small03),
5719                    Utils.framesToTime(24, 1), null, null);
5720            AnimationFrame smallFrame4 = new AnimationFrame(
5721                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small04),
5722                    Utils.framesToTime(24, 1), null, null);
5723            AnimationFrame smallFrame5 = new AnimationFrame(
5724                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small05),
5725                    Utils.framesToTime(24, 1), null, null);
5726            AnimationFrame smallFrame6 = new AnimationFrame(
5727                    textureLibrary.getTextureByResource(R.drawable.effect_explosion_small06),
5728                    Utils.framesToTime(24, 1), null, null);
5729            AnimationFrame smallFrame7 = new AnimationFrame
5730            (textureLibrary.getTextureByResource(R.drawable.effect_explosion_small07),
5731                    Utils.framesToTime(24, 1), null, null);
5732
5733            SpriteAnimation smallBlast1 = new SpriteAnimation(0, 7);
5734            smallBlast1.addFrame(smallFrame1);
5735            smallBlast1.addFrame(smallFrame2);
5736            smallBlast1.addFrame(smallFrame3);
5737            smallBlast1.addFrame(smallFrame4);
5738            smallBlast1.addFrame(smallFrame5);
5739            smallBlast1.addFrame(smallFrame6);
5740            smallBlast1.addFrame(smallFrame7);
5741
5742            SpriteAnimation smallBlast2 = new SpriteAnimation(0, 8);
5743            smallBlast2.addFrame(new AnimationFrame(null, Utils.framesToTime(24, 4), null, null));
5744            smallBlast2.addFrame(smallFrame1);
5745            smallBlast2.addFrame(smallFrame2);
5746            smallBlast2.addFrame(smallFrame3);
5747            smallBlast2.addFrame(smallFrame4);
5748            smallBlast2.addFrame(smallFrame5);
5749            smallBlast2.addFrame(smallFrame6);
5750            smallBlast2.addFrame(smallFrame7);
5751
5752            SpriteAnimation smallBlast3 = new SpriteAnimation(0, 8);
5753            smallBlast3.addFrame(new AnimationFrame(null, Utils.framesToTime(24, 8), null, null));
5754            smallBlast3.addFrame(smallFrame1);
5755            smallBlast3.addFrame(smallFrame2);
5756            smallBlast3.addFrame(smallFrame3);
5757            smallBlast3.addFrame(smallFrame4);
5758            smallBlast3.addFrame(smallFrame5);
5759            smallBlast3.addFrame(smallFrame6);
5760            smallBlast3.addFrame(smallFrame7);
5761
5762
5763            staticData.add(idle);
5764            staticData.add(smallBlast1);
5765            staticData.add(smallBlast2);
5766            staticData.add(smallBlast3);
5767
5768            setStaticData(GameObjectType.EXPLOSION_GIANT, staticData);
5769        }
5770
5771        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
5772        render.setPriority(SortConstants.EFFECT);
5773        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5774		sprite.setSize((int)object.width, (int)object.height);
5775        sprite.setRenderComponent(render);
5776
5777        // Hack.  Use static data differently for this object so we can share three animations
5778        // amongst three separate sprites.
5779
5780        final SpriteAnimation idle = (SpriteAnimation)staticData.get(0);
5781        final SpriteAnimation smallBlast1 = (SpriteAnimation)staticData.get(1);
5782        final SpriteAnimation smallBlast2 = (SpriteAnimation)staticData.get(2);
5783        final SpriteAnimation smallBlast3 = (SpriteAnimation)staticData.get(3);
5784
5785        sprite.addAnimation(idle);
5786        sprite.playAnimation(0);
5787
5788        RenderComponent blast1Render = (RenderComponent)allocateComponent(RenderComponent.class);
5789        render.setPriority(SortConstants.EFFECT);
5790        SpriteComponent blast1Sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5791		blast1Sprite.setSize(32, 32);
5792        blast1Sprite.setRenderComponent(blast1Render);
5793        blast1Render.setDrawOffset(40, 50);
5794        blast1Sprite.addAnimation(smallBlast1);
5795        blast1Sprite.playAnimation(0);
5796
5797        RenderComponent blast2Render = (RenderComponent)allocateComponent(RenderComponent.class);
5798        render.setPriority(SortConstants.EFFECT);
5799        SpriteComponent blast2Sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5800		blast2Sprite.setSize(32, 32);
5801        blast2Sprite.setRenderComponent(blast2Render);
5802        blast2Render.setDrawOffset(-10, 0);
5803        blast2Sprite.addAnimation(smallBlast2);
5804        blast2Sprite.playAnimation(0);
5805
5806        RenderComponent blast3Render = (RenderComponent)allocateComponent(RenderComponent.class);
5807        render.setPriority(SortConstants.EFFECT);
5808        SpriteComponent blast3Sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
5809		blast3Sprite.setSize(32, 32);
5810        blast3Sprite.setRenderComponent(blast3Render);
5811        blast3Render.setDrawOffset(0, 32);
5812        blast3Sprite.addAnimation(smallBlast3);
5813        blast3Sprite.playAnimation(0);
5814
5815        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
5816        lifetime.setTimeUntilDeath(Math.max(
5817                Math.max(
5818                        Math.max(idle.getLength(), smallBlast1.getLength()),
5819                        smallBlast2.getLength()),
5820                smallBlast3.getLength()));
5821
5822        DynamicCollisionComponent dynamicCollision =
5823            (DynamicCollisionComponent)allocateComponent(DynamicCollisionComponent.class);
5824        sprite.setCollisionComponent(dynamicCollision);
5825
5826        PlaySingleSoundComponent soundEffect = (PlaySingleSoundComponent)allocateComponent(PlaySingleSoundComponent.class);
5827        soundEffect.setSound(sSystemRegistry.soundSystem.load(R.raw.quick_explosion));
5828
5829
5830
5831        object.team = Team.PLAYER;  // Maybe this should be an argument to this function.
5832
5833        object.add(dynamicCollision);
5834        object.add(lifetime);
5835        object.add(render);
5836        object.add(sprite);
5837        object.add(soundEffect);
5838
5839
5840        object.add(blast1Render);
5841        object.add(blast1Sprite);
5842
5843        object.add(blast2Render);
5844        object.add(blast2Sprite);
5845
5846        object.add(blast3Render);
5847        object.add(blast3Sprite);
5848
5849
5850        return object;
5851    }
5852
5853
5854    public GameObject spawnGhostNPC(float positionX, float positionY) {
5855
5856        GameObject object = mGameObjectPool.allocate();
5857        object.getPosition().set(positionX, positionY);
5858        object.activationRadius = mAlwaysActive;
5859        object.width = 32;
5860        object.height = 32;
5861
5862        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.GHOST_NPC);
5863        if (staticData == null) {
5864            final int staticObjectCount = 2;
5865            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5866
5867            GameComponent gravity = allocateComponent(GravityComponent.class);
5868            GameComponent movement = allocateComponent(MovementComponent.class);
5869
5870            staticData.add(gravity);
5871            staticData.add(movement);
5872
5873
5874            setStaticData(GameObjectType.GHOST_NPC, staticData);
5875        }
5876
5877        NPCComponent patrol = (NPCComponent)allocateComponent(NPCComponent.class);
5878        LifetimeComponent life = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
5879
5880        object.team = Team.NONE;
5881        object.life = 1;
5882
5883        object.add(patrol);
5884        object.add(life);
5885
5886        addStaticData(GameObjectType.GHOST_NPC, object, null);
5887        return object;
5888    }
5889
5890    private GameObject spawnCameraBias(float positionX, float positionY) {
5891    	GameObject object = mGameObjectPool.allocate();
5892        object.getPosition().set(positionX, positionY);
5893        object.activationRadius = mTightActivationRadius;
5894        object.width = 32;
5895        object.height = 32;
5896
5897        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.CAMERA_BIAS);
5898        if (staticData == null) {
5899            final int staticObjectCount = 1;
5900            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5901
5902            GameComponent bias = allocateComponent(CameraBiasComponent.class);
5903
5904            staticData.add(bias);
5905
5906            setStaticData(GameObjectType.CAMERA_BIAS, staticData);
5907        }
5908
5909        addStaticData(GameObjectType.CAMERA_BIAS, object, null);
5910        return object;
5911	}
5912
5913    public GameObject spawnEffectSmokeBig(float positionX, float positionY) {
5914        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
5915
5916        GameObject object = mGameObjectPool.allocate();
5917        object.getPosition().set(positionX, positionY);
5918        object.activationRadius = mTightActivationRadius;
5919        object.width = 32;
5920        object.height = 32;
5921
5922        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.SMOKE_BIG);
5923        if (staticData == null) {
5924            final int staticObjectCount = 6;
5925            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
5926
5927            GameComponent movement = allocateComponent(MovementComponent.class);
5928
5929
5930            AnimationFrame frame2 = new AnimationFrame(
5931                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big02),
5932                    Utils.framesToTime(24, 1), null, null);
5933
5934            AnimationFrame frame3 = new AnimationFrame(
5935                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big03),
5936                    Utils.framesToTime(24, 1), null, null);
5937
5938            AnimationFrame frame4 = new AnimationFrame(
5939                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big04),
5940                    Utils.framesToTime(24, 1), null, null);
5941
5942            AnimationFrame frame5 = new AnimationFrame(
5943                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big05),
5944                    Utils.framesToTime(24, 1), null, null);
5945
5946            SpriteAnimation idle = new SpriteAnimation(0, 5);
5947            idle.addFrame(new AnimationFrame(
5948                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big01),
5949                    Utils.framesToTime(24, 10), null, null));
5950            idle.addFrame(frame2);
5951            idle.addFrame(frame3);
5952            idle.addFrame(frame4);
5953            idle.addFrame(frame5);
5954
5955            SpriteAnimation idle2 = new SpriteAnimation(1, 5);
5956            idle2.addFrame(new AnimationFrame(
5957                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big01),
5958                    Utils.framesToTime(24, 13), null, null));
5959            idle2.addFrame(frame2);
5960            idle2.addFrame(frame3);
5961            idle2.addFrame(frame4);
5962            idle2.addFrame(frame5);
5963
5964            SpriteAnimation idle3 = new SpriteAnimation(2, 5);
5965            idle3.addFrame(new AnimationFrame(
5966                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big01),
5967                    Utils.framesToTime(24, 8), null, null));
5968            idle3.addFrame(frame2);
5969            idle3.addFrame(frame3);
5970            idle3.addFrame(frame4);
5971            idle3.addFrame(frame5);
5972
5973            SpriteAnimation idle4 = new SpriteAnimation(3, 5);
5974            idle4.addFrame(new AnimationFrame(
5975                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big01),
5976                    Utils.framesToTime(24, 5), null, null));
5977            idle4.addFrame(frame2);
5978            idle4.addFrame(frame3);
5979            idle4.addFrame(frame4);
5980            idle4.addFrame(frame5);
5981
5982            SpriteAnimation idle5 = new SpriteAnimation(4, 5);
5983            idle5.addFrame(new AnimationFrame(
5984                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_big01),
5985                    Utils.framesToTime(24, 15), null, null));
5986            idle5.addFrame(frame2);
5987            idle5.addFrame(frame3);
5988            idle5.addFrame(frame4);
5989            idle5.addFrame(frame5);
5990
5991            staticData.add(idle);
5992            staticData.add(idle2);
5993            staticData.add(idle3);
5994            staticData.add(idle4);
5995            staticData.add(idle5);
5996            staticData.add(movement);
5997            setStaticData(GameObjectType.SMOKE_BIG, staticData);
5998        }
5999
6000        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
6001        render.setPriority(SortConstants.EFFECT);
6002
6003        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
6004        sprite.setSize((int)object.width, (int)object.height);
6005        sprite.setRenderComponent(render);
6006
6007        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6008        lifetime.setDieWhenInvisible(true);
6009
6010        object.destroyOnDeactivation = true;
6011
6012        object.add(lifetime);
6013        object.add(render);
6014        object.add(sprite);
6015
6016        addStaticData(GameObjectType.SMOKE_BIG, object, sprite);
6017
6018        final int animIndex = (int)(Math.random() * sprite.getAnimationCount());
6019        final SpriteAnimation idle = sprite.findAnimation(animIndex);
6020        if (idle != null) {
6021            lifetime.setTimeUntilDeath(idle.getLength());
6022            sprite.playAnimation(animIndex);
6023        }
6024
6025
6026
6027        return object;
6028    }
6029
6030    public GameObject spawnEffectSmokeSmall(float positionX, float positionY) {
6031        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
6032
6033        GameObject object = mGameObjectPool.allocate();
6034        object.getPosition().set(positionX, positionY);
6035        object.activationRadius = mAlwaysActive;
6036        object.width = 16;
6037        object.height = 16;
6038
6039        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.SMOKE_SMALL);
6040        if (staticData == null) {
6041            final int staticObjectCount = 2;
6042            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
6043
6044            GameComponent movement = allocateComponent(MovementComponent.class);
6045
6046            SpriteAnimation idle = new SpriteAnimation(0, 5);
6047            idle.addFrame(new AnimationFrame(
6048                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_small01),
6049                    Utils.framesToTime(24, 10), null, null));
6050            idle.addFrame(new AnimationFrame(
6051                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_small02),
6052                    Utils.framesToTime(24, 1), null, null));
6053            idle.addFrame(new AnimationFrame(
6054                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_small03),
6055                    Utils.framesToTime(24, 1), null, null));
6056            idle.addFrame(new AnimationFrame(
6057                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_small04),
6058                    Utils.framesToTime(24, 1), null, null));
6059            idle.addFrame(new AnimationFrame(
6060                    textureLibrary.getTextureByResource(R.drawable.effect_smoke_small05),
6061                    Utils.framesToTime(24, 1), null, null));
6062
6063            staticData.add(idle);
6064            staticData.add(movement);
6065            setStaticData(GameObjectType.SMOKE_SMALL, staticData);
6066        }
6067
6068        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
6069        render.setPriority(SortConstants.EFFECT);
6070
6071        SpriteComponent sprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
6072        sprite.setSize((int)object.width, (int)object.height);
6073        sprite.setRenderComponent(render);
6074
6075        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6076        lifetime.setDieWhenInvisible(true);
6077
6078        object.destroyOnDeactivation = true;
6079
6080        object.add(lifetime);
6081        object.add(render);
6082        object.add(sprite);
6083
6084        addStaticData(GameObjectType.SMOKE_SMALL, object, sprite);
6085
6086        final SpriteAnimation idle = sprite.findAnimation(0);
6087        if (idle != null) {
6088            lifetime.setTimeUntilDeath(idle.getLength());
6089        }
6090
6091        sprite.playAnimation(0);
6092
6093        return object;
6094    }
6095
6096    public GameObject spawnEffectCrushFlash(float positionX, float positionY) {
6097        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
6098
6099        GameObject object = mGameObjectPool.allocate();
6100        object.getPosition().set(positionX, positionY);
6101        object.activationRadius = mAlwaysActive;
6102        object.width = 64;
6103        object.height = 64;
6104
6105        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.CRUSH_FLASH);
6106        if (staticData == null) {
6107            final int staticObjectCount = 2;
6108            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
6109
6110            SpriteAnimation back = new SpriteAnimation(0, 3);
6111            back.addFrame(new AnimationFrame(
6112                    textureLibrary.getTextureByResource(R.drawable.effect_crush_back01),
6113                    Utils.framesToTime(24, 1), null, null));
6114            back.addFrame(new AnimationFrame(
6115                    textureLibrary.getTextureByResource(R.drawable.effect_crush_back02),
6116                    Utils.framesToTime(24, 1), null, null));
6117            back.addFrame(new AnimationFrame(
6118                    textureLibrary.getTextureByResource(R.drawable.effect_crush_back03),
6119                    Utils.framesToTime(24, 1), null, null));
6120
6121            SpriteAnimation front = new SpriteAnimation(1, 7);
6122            front.addFrame(new AnimationFrame(
6123                    textureLibrary.getTextureByResource(R.drawable.effect_crush_front01),
6124                    Utils.framesToTime(24, 1), null, null));
6125            front.addFrame(new AnimationFrame(
6126                    textureLibrary.getTextureByResource(R.drawable.effect_crush_front02),
6127                    Utils.framesToTime(24, 1), null, null));
6128            front.addFrame(new AnimationFrame(
6129                    textureLibrary.getTextureByResource(R.drawable.effect_crush_front03),
6130                    Utils.framesToTime(24, 1), null, null));
6131            front.addFrame(new AnimationFrame(
6132                    textureLibrary.getTextureByResource(R.drawable.effect_crush_front04),
6133                    Utils.framesToTime(24, 1), null, null));
6134            front.addFrame(new AnimationFrame(
6135                    textureLibrary.getTextureByResource(R.drawable.effect_crush_front05),
6136                    Utils.framesToTime(24, 1), null, null));
6137            front.addFrame(new AnimationFrame(
6138                    textureLibrary.getTextureByResource(R.drawable.effect_crush_front06),
6139                    Utils.framesToTime(24, 1), null, null));
6140            front.addFrame(new AnimationFrame(
6141                    textureLibrary.getTextureByResource(R.drawable.effect_crush_front07),
6142                    Utils.framesToTime(24, 1), null, null));
6143
6144
6145            staticData.add(back);
6146            staticData.add(front);
6147            setStaticData(GameObjectType.CRUSH_FLASH, staticData);
6148        }
6149
6150
6151        RenderComponent backRender = (RenderComponent)allocateComponent(RenderComponent.class);
6152        backRender.setPriority(SortConstants.EFFECT);
6153
6154        SpriteComponent backSprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
6155        backSprite.setSize((int)object.width, (int)object.height);
6156        backSprite.setRenderComponent(backRender);
6157
6158        RenderComponent foreRender = (RenderComponent)allocateComponent(RenderComponent.class);
6159        foreRender.setPriority(SortConstants.FOREGROUND_EFFECT);
6160
6161        SpriteComponent foreSprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
6162        foreSprite.setSize((int)object.width, (int)object.height);
6163        foreSprite.setRenderComponent(foreRender);
6164
6165        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6166
6167
6168        object.add(lifetime);
6169        object.add(backRender);
6170        object.add(foreRender);
6171        object.add(foreSprite);
6172        object.add(backSprite);
6173
6174        addStaticData(GameObjectType.CRUSH_FLASH, object, backSprite);
6175        addStaticData(GameObjectType.CRUSH_FLASH, null, foreSprite);
6176
6177
6178        final SpriteAnimation idle = foreSprite.findAnimation(1);
6179        if (idle != null) {
6180            lifetime.setTimeUntilDeath(idle.getLength());
6181        }
6182
6183        backSprite.playAnimation(0);
6184        foreSprite.playAnimation(1);
6185
6186        return object;
6187    }
6188
6189    public GameObject spawnEffectFlash(float positionX, float positionY) {
6190        TextureLibrary textureLibrary = sSystemRegistry.longTermTextureLibrary;
6191
6192        GameObject object = mGameObjectPool.allocate();
6193        object.getPosition().set(positionX, positionY);
6194        object.activationRadius = mAlwaysActive;
6195        object.width = 64;
6196        object.height = 64;
6197
6198        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.FLASH);
6199        if (staticData == null) {
6200            final int staticObjectCount = 1;
6201            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
6202
6203            SpriteAnimation back = new SpriteAnimation(0, 3);
6204            back.addFrame(new AnimationFrame(
6205                    textureLibrary.getTextureByResource(R.drawable.effect_crush_back01),
6206                    Utils.framesToTime(24, 1), null, null));
6207            back.addFrame(new AnimationFrame(
6208                    textureLibrary.getTextureByResource(R.drawable.effect_crush_back02),
6209                    Utils.framesToTime(24, 1), null, null));
6210            back.addFrame(new AnimationFrame(
6211                    textureLibrary.getTextureByResource(R.drawable.effect_crush_back03),
6212                    Utils.framesToTime(24, 1), null, null));
6213
6214
6215            staticData.add(back);
6216            setStaticData(GameObjectType.FLASH, staticData);
6217        }
6218
6219
6220        RenderComponent backRender = (RenderComponent)allocateComponent(RenderComponent.class);
6221        backRender.setPriority(SortConstants.EFFECT);
6222
6223        SpriteComponent backSprite = (SpriteComponent)allocateComponent(SpriteComponent.class);
6224        backSprite.setSize((int)object.width, (int)object.height);
6225        backSprite.setRenderComponent(backRender);
6226
6227
6228
6229        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6230
6231
6232        object.add(lifetime);
6233        object.add(backRender);
6234        object.add(backSprite);
6235
6236        addStaticData(GameObjectType.FLASH, object, backSprite);
6237
6238
6239        final SpriteAnimation idle = backSprite.findAnimation(0);
6240        if (idle != null) {
6241            lifetime.setTimeUntilDeath(idle.getLength());
6242        }
6243
6244        backSprite.playAnimation(0);
6245
6246        return object;
6247    }
6248
6249    public GameObject spawnBreakableBlockPiece(float positionX, float positionY) {
6250        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
6251
6252        GameObject object = mGameObjectPool.allocate();
6253        object.getPosition().set(positionX, positionY);
6254        object.activationRadius = mTightActivationRadius;
6255        object.width = 16;
6256        object.height = 16;
6257
6258        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.BREAKABLE_BLOCK_PIECE);
6259        if (staticData == null) {
6260            final int staticObjectCount = 4;
6261            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
6262
6263            GameComponent gravity = allocateComponent(GravityComponent.class);
6264            GameComponent movement = allocateComponent(MovementComponent.class);
6265
6266            SimplePhysicsComponent physics = (SimplePhysicsComponent)allocateComponent(SimplePhysicsComponent.class);
6267            physics.setBounciness(0.3f);
6268
6269            DrawableBitmap piece = new DrawableBitmap(
6270                    textureLibrary.getTextureByResource(R.drawable.object_debris_piece),
6271                    (int)object.width,
6272                    (int)object.height);
6273
6274
6275            RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
6276            render.setPriority(SortConstants.GENERAL_OBJECT);
6277            render.setDrawable(piece);
6278
6279            staticData.add(render);
6280            staticData.add(movement);
6281            staticData.add(gravity);
6282            staticData.add(physics);
6283            setStaticData(GameObjectType.BREAKABLE_BLOCK_PIECE, staticData);
6284        }
6285
6286        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6287        lifetime.setTimeUntilDeath(3.0f);
6288
6289        BackgroundCollisionComponent bgcollision = (BackgroundCollisionComponent)allocateComponent(BackgroundCollisionComponent.class);
6290        bgcollision.setSize(12, 12);
6291        bgcollision.setOffset(2, 2);
6292
6293
6294        object.destroyOnDeactivation = true;
6295
6296        object.add(lifetime);
6297        object.add(bgcollision);
6298
6299        addStaticData(GameObjectType.BREAKABLE_BLOCK_PIECE, object, null);
6300
6301        return object;
6302    }
6303
6304    public GameObject spawnBreakableBlockPieceSpawner(float positionX, float positionY) {
6305
6306        GameObject object = mGameObjectPool.allocate();
6307        object.getPosition().set(positionX, positionY);
6308        object.activationRadius = mTightActivationRadius;
6309        object.width = 1;
6310        object.height = 1;
6311
6312        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6313        lifetime.setTimeUntilDeath(0.5f);
6314
6315        LaunchProjectileComponent pieceSpawner
6316            = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
6317        pieceSpawner.setObjectTypeToSpawn(GameObjectType.BREAKABLE_BLOCK_PIECE);
6318        pieceSpawner.setDelayBeforeFirstSet(0.0f);
6319        pieceSpawner.setSetsPerActivation(1);
6320        pieceSpawner.setShotsPerSet(3);
6321        pieceSpawner.setDelayBetweenShots(0.0f);
6322        pieceSpawner.setOffsetX(16);
6323        pieceSpawner.setOffsetY(16);
6324        pieceSpawner.setVelocityX(600.0f);
6325        pieceSpawner.setVelocityY(-1000.0f);
6326        pieceSpawner.setThetaError(1.0f);
6327
6328        object.life = 1;
6329        object.destroyOnDeactivation = true;
6330
6331        object.add(lifetime);
6332        object.add(pieceSpawner);
6333
6334        return object;
6335    }
6336
6337    public GameObject spawnSmokePoof(float positionX, float positionY) {
6338
6339        GameObject object = mGameObjectPool.allocate();
6340        object.getPosition().set(positionX, positionY);
6341        object.activationRadius = mTightActivationRadius;
6342        object.width = 1;
6343        object.height = 1;
6344
6345        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6346        lifetime.setTimeUntilDeath(0.5f);
6347
6348        LaunchProjectileComponent smokeGun
6349	        = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
6350        smokeGun.setSetsPerActivation(1);
6351        smokeGun.setShotsPerSet(3);
6352	    smokeGun.setDelayBetweenShots(0.0f);
6353	    smokeGun.setObjectTypeToSpawn(GameObjectType.SMOKE_BIG);
6354	    smokeGun.setVelocityX(200.0f);
6355	    smokeGun.setVelocityY(200.0f);
6356	    smokeGun.setOffsetX(16);
6357	    smokeGun.setOffsetY(16);
6358	    smokeGun.setThetaError(1.0f);
6359
6360	    LaunchProjectileComponent smokeGun2
6361	        = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
6362	    smokeGun2.setSetsPerActivation(1);
6363	    smokeGun2.setShotsPerSet(3);
6364	    smokeGun2.setDelayBetweenShots(0.0f);
6365	    smokeGun2.setObjectTypeToSpawn(GameObjectType.SMOKE_SMALL);
6366	    smokeGun2.setVelocityX(200.0f);
6367	    smokeGun2.setVelocityY(200.0f);
6368	    smokeGun2.setThetaError(1.0f);
6369	    smokeGun2.setOffsetX(16);
6370	    smokeGun2.setOffsetY(16);
6371
6372        object.life = 1;
6373        object.destroyOnDeactivation = true;
6374
6375        object.add(lifetime);
6376        object.add(smokeGun);
6377        object.add(smokeGun2);
6378
6379        return object;
6380    }
6381
6382    public GameObject spawnGemEffect(float positionX, float positionY) {
6383        TextureLibrary textureLibrary = sSystemRegistry.shortTermTextureLibrary;
6384
6385        GameObject object = mGameObjectPool.allocate();
6386        object.getPosition().set(positionX, positionY);
6387        object.activationRadius = mTightActivationRadius;
6388        object.width = 32;
6389        object.height = 32;
6390
6391        FixedSizeArray<BaseObject> staticData = getStaticData(GameObjectType.GEM_EFFECT);
6392        if (staticData == null) {
6393            final int staticObjectCount = 2;
6394            staticData = new FixedSizeArray<BaseObject>(staticObjectCount);
6395
6396            GameComponent movement = allocateComponent(MovementComponent.class);
6397
6398            staticData.add(movement);
6399
6400            setStaticData(GameObjectType.GEM_EFFECT, staticData);
6401        }
6402
6403        RenderComponent render = (RenderComponent)allocateComponent(RenderComponent.class);
6404        render.setPriority(SortConstants.EFFECT);
6405
6406        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6407        lifetime.setTimeUntilDeath(0.5f);
6408
6409        FadeDrawableComponent fadeOut = (FadeDrawableComponent)allocateComponent(FadeDrawableComponent.class);
6410        fadeOut.setupFade(1.0f, 0.0f, 0.5f, FadeDrawableComponent.LOOP_TYPE_NONE, FadeDrawableComponent.FADE_LINEAR, 0.0f);
6411        fadeOut.setTexture(textureLibrary.allocateTexture(R.drawable.object_ruby01));
6412        fadeOut.setRenderComponent(render);
6413
6414        object.destroyOnDeactivation = true;
6415
6416        object.add(lifetime);
6417        object.add(fadeOut);
6418        object.add(render);
6419
6420        addStaticData(GameObjectType.GEM_EFFECT, object, null);
6421
6422        return object;
6423    }
6424
6425    public GameObject spawnGemEffectSpawner(float positionX, float positionY) {
6426
6427        GameObject object = mGameObjectPool.allocate();
6428        object.getPosition().set(positionX, positionY);
6429        object.activationRadius = mTightActivationRadius;
6430        object.width = 1;
6431        object.height = 1;
6432
6433        LifetimeComponent lifetime = (LifetimeComponent)allocateComponent(LifetimeComponent.class);
6434        lifetime.setTimeUntilDeath(0.5f);
6435
6436        final int gems = 6;
6437        final float angleIncrement = (float)(2.0f * Math.PI) / gems;
6438        for (int x = 0; x < gems; x++) {
6439	        LaunchProjectileComponent gemGun
6440		        = (LaunchProjectileComponent)allocateComponent(LaunchProjectileComponent.class);
6441	        gemGun.setSetsPerActivation(1);
6442	        gemGun.setShotsPerSet(1);
6443	        gemGun.setDelayBetweenShots(0.0f);
6444	        gemGun.setObjectTypeToSpawn(GameObjectType.GEM_EFFECT);
6445	        gemGun.setVelocityX((float)Math.sin(angleIncrement * x) * 150.0f);
6446	        gemGun.setVelocityY((float)Math.cos(angleIncrement * x) * 150.0f);
6447	        gemGun.setOffsetX(16);
6448	        gemGun.setOffsetY(16);
6449
6450	        object.add(gemGun);
6451        }
6452
6453
6454
6455        object.life = 1;
6456        object.destroyOnDeactivation = true;
6457
6458        object.add(lifetime);
6459
6460
6461        return object;
6462    }
6463
6464    /** Comparator for game objects objects. */
6465    private final static class ComponentPoolComparator implements Comparator<GameComponentPool> {
6466        public int compare(final GameComponentPool object1, final GameComponentPool object2) {
6467            int result = 0;
6468            if (object1 == null && object2 != null) {
6469                result = 1;
6470            } else if (object1 != null && object2 == null) {
6471                result = -1;
6472            } else if (object1 != null && object2 != null) {
6473                result = object1.objectClass.hashCode() - object2.objectClass.hashCode();
6474            }
6475            return result;
6476        }
6477    }
6478
6479    public class GameObjectPool extends TObjectPool<GameObject> {
6480
6481        public GameObjectPool() {
6482            super();
6483        }
6484
6485        public GameObjectPool(int size) {
6486            super(size);
6487        }
6488
6489        @Override
6490        protected void fill() {
6491            for (int x = 0; x < getSize(); x++) {
6492                getAvailable().add(new GameObject());
6493            }
6494        }
6495
6496        @Override
6497        public void release(Object entry) {
6498            ((GameObject)entry).reset();
6499            super.release(entry);
6500        }
6501
6502    }
6503}
6504
6505