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