163164165166167168169170171172173
alienCount = 0; //Separaciones en X e Y entre las naves enemigas int separationX = 50, separationY = 45; for (int row = 0; row < 3; row++) { //3 for (int x = 0; x < 11; x++) { //11 MovingGameEntity alien = new AlienEntity(this, 100 + (x * separationX), (100) + row * separationY); entities.add(alien); alienCount++; } } }
316317318319320321322323324325326327328329330331332
* a ambas entidades que una colision a ocurrido. */ private void computeCollisions() { for (int p = 0; p < entities.size(); p++) { if (entities.get(p) instanceof MovingGameEntity) { MovingGameEntity entity1 = (MovingGameEntity) entities.get(p); for (int s = p + 1; s < entities.size(); s++) { if (entities.get(s) instanceof MovingGameEntity) { MovingGameEntity entity2 = (MovingGameEntity) entities.get(s); if (entity1.isCollidingWith(entity2)) { entity1.notifyCollisionWith(entity2); entity2.notifyCollisionWith(entity1); } } } } }
152153154155156157158159160161162
* Cada entidad se añadirá a la lista general de las entidades en el juego. */ protected void initEntities() { // crea la nave del jugador y la coloca en el centro de la pantalla ship = new ShipEntity(this, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 50); ship.init(); entities.add(ship); //crea un bloque de aliens
382383384385386387388389390391392393
g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); // ciclo que dibuja todas las entidades que tiene el juego for (int i = 0; i < entities.size(); i++) { if (entities.get(i) instanceof Drawable) { Drawable entity = (Drawable) entities.get(i); entity.draw(g); } } drawLives("sprites/life.png", SCREEN_HEIGHT, 550, g, lives); // Si está esperando que se presione una tecla
170171172173174175176177178179180
strategy.show(); } public void addSprite() { Image image = ImageCache.getInstance().getImage("sprites/ship.png"); Trackable trackable = new Trackable(){ public float getX() { return 100; }
strategy.show(); } public void addSprite() { Image image = ImageCache.getInstance().getImage("sprites/alien.png"); Trackable trackable = new Trackable(){ public float getX() { return 100; }
178179180181182183184185186187188
417418419420421422423424425426427
strategy.show(); } private void update(long delta) { for (int i = 0; i < entities.size(); i++) { Updateable entity = entities.get(i); entity.update(delta); } ship.hadleShipInput(keyInputHandler.isLeftPressed(), keyInputHandler.isRightPressed(), keyInputHandler.isFirePressed()); }
2223242526272829303132
*/ public Explotion(Game game, int x, int y) { super(SpriteFactory.getInstance().getAnimation(SpriteFactory.Animations.EXPLOTION), x, y); this.game = game; AnimationEndHandler handler = new AnimationEndHandler() { @Override public void onAnimationFinished() { removeFromGame(); }
185186187188189190191192193194
}; // sprite = new AnimatedSprite( // trackable, // true, // 50, 0, 0, 4, 1, 42, 42, 0, 0, 1 , image); sprite = new Sprite( trackable, true, 8, 0, 0, 4, 1, 23, 50, 0, 0, 1 , image); }