示例#1
0
  private void initPlatformFSM() {
    List<String> imNames = new ArrayList<String>();
    imNames.add("resources/platform1.png");
    myPlatform = new SimplePlatform(2800, 280, imNames);

    List<String> imNames2 = new ArrayList<String>();
    imNames2.add("resources/Switch1.jpg");
    imNames2.add("resources/Switch2.jpg");
    mySwitch = new PlatformSwitch(2500, 660, imNames2);
    List<AbstractPlatform> plats = new ArrayList<AbstractPlatform>();
    plats.add(myPlatform);
    List<AbstractPlatformState> transition = new ArrayList<AbstractPlatformState>();
    transition.add(new SimpleState());
    transition.add(new UpDownState());
    AbstractEvent event = new SimpleEvent(transition, plats);
    event = new SwitchEvent(mySwitch, event);
    // event = new RandomEvent(event);
    myEvent = event;
    myEvent.setControlledPlatforms(plats);
    allSprites.add(myPlatform);
    allSprites.add(mySwitch);
    myPlayfield.add(mySwitch);
    myPlayfield.add(myPlatform);
    // playMusic("resources/smb3-world1.mid");
  }
示例#2
0
 public void Shoot(
     long elapsedTime, Timer fireRate, SpriteGroup Projectile, BufferedImage Image, Sprite s) {
   HomingProjectile shot;
   if (isEnableShoot() == true) {
     shot = new HomingProjectile(Image, s);
     shot.setLocation(this.getX() + 15, this.getY() - 5);
     shot.fireAtTarget(s, elapsedTime);
     Projectile.add(shot);
     setEnableShoot(false);
     fireRate.refresh();
   } else {
     if (fireRate.action(elapsedTime)) setEnableShoot(true);
   }
 }
  public void update(long time) {

    if (clock.action(time)) {
      getGame().setSeconds(getGame().getSeconds() + 1);
    }

    getProj_monsterCollision().checkCollision();

    getMonsters().update(time);

    towers.update(time);
    projectiles.update(time);
    if (game.endlessMode) {
      currentLevel = game.getEndlessLevel();
    } else {
      try {
        if (currentLevel.getWaveRemaining() < 2) {
          nextLevel();
        }
      } catch (Exception e) {
      }
    }
    currentLevel.update(time);
  }
示例#4
0
  public void initResources() {

    loadLevel("demo2");

    allSprites = new SpriteGroup("allSprites");
    for (AnimatedGameSprite sprite : myPlayfield.getMySprites()) {
      allSprites.add(sprite);
    }
    initPlatformFSM();
    initEnemyFSM();
    myCollisions = new GameCollisionManager();

    ArrayList<CollisionSpec> specList = new ArrayList<CollisionSpec>();
    CollisionSpec spec = new CollisionSpec();
    spec.addActMap("FIGHTER", "instantFighterDeath");
    spec.addActMap("ENEMY", "instantEnemyDeath");
    specList.add(spec);

    CollisionSpec spec2 = new CollisionSpec();
    spec2.addActMap("FIGHTER", "fighterStandOnTop");
    spec2.addActMap("FIGHTER", "fighterHitObject");
    spec2.addActMap("PLATFORM", "");
    spec2.addActMap("PLATFORM", "actionBreak");
    specList.add(spec2);

    CollisionSpec spec3 = new CollisionSpec();
    spec3.addActMap("ENEMY", "enemyStandOnTop");
    spec3.addActMap("PLATFORM", "");
    specList.add(spec3);

    CollisionSpec spec4 = new CollisionSpec();
    spec4.addActMap("BONUSOBJECT", "bonusObjectDestruction");
    spec4.addActMap("FIGHTER", "fighterGetPowerUp");
    specList.add(spec4);

    CollisionSpec spec5 = new CollisionSpec();
    spec5.addActMap("BONUSOBJECT", "bonusObjectStandOnTop");
    spec5.addActMap("PLATFORM", "");
    specList.add(spec5);

    CollisionSpec spec6 = new CollisionSpec();
    spec6.addActMap("PLATFORMSWITCH", "switchPlatform");
    spec6.addActMap("FIGHTER", "");
    specList.add(spec6);

    myCollisions.setCollisionGroup(allSprites, allSprites);
    myCollisions.addSpecList(specList);
  }
示例#5
0
  private void initEnemyFSM() {
    List<String> images = new ArrayList<String>();
    images.add("resources/Bowser.jpg");
    myEnemy = new Enemy(1500, 200, images);
    myEnemy.setState(PassiveState.getInstance());
    myEnemy.setGroup("UNIQUE");

    List<String> images2 = new ArrayList<String>();
    images2.add("resources/Fireball.jpg");
    AnimatedGameSprite wep = new AnimatedGameSprite(-1000, -1000, images2);
    Weapon weapon = new Fireball(wep, -0.1, 100000000, 200);
    Attribute att = new ProjectileAttack(weapon);
    myEnemy.addAttribute(att);
    allSprites.add(myEnemy);
    myPlayfield.add(myEnemy);
  }
  public void deployPlayerBlocks() {
    for (Sprite currentPlayer : currentPlayField.getGroup("humanPlayerGroup").getSprites()) {
      if (currentPlayer != null) {
        blockQueue.add(
            new Sprite(currentPlayer.getImage(), currentPlayer.getX(), currentPlayer.getY()));
      }
    }
    for (Sprite currentPlayer : currentPlayField.getGroup("computerPlayerGroup").getSprites()) {
      if (currentPlayer != null) {
        blockQueue.add(
            new Sprite(currentPlayer.getImage(), currentPlayer.getX(), currentPlayer.getY()));
      }
    }

    while (blockQueue.size() > FPS / 5) {
      playerBlocks.add(blockQueue.remove());
    }
  }
  public void createEnemies(
      int width,
      long currentTime,
      SpriteGroup enemies,
      SpriteGroup bullets,
      BufferedImage i,
      BufferedImage s) {
    if (currentTime - lastTime > delayTime) {
      int row = r.nextInt(9) + 1;
      Enemy en = new Enemy(i, s, bullets);
      en.setLocation(width - 100, 800 / row + 200);

      double xSpeed = r.nextInt(100) / 100.0;
      double ySpeed = (r.nextInt(100) / 100.0) - (r.nextInt(100) / 100.0);

      en.setSpeed(-xSpeed / 2.0, ySpeed / 10.0);

      enemies.add(en);
      lastTime = currentTime;
      delayTime -= 60;
    }
  }
 private void addTile(MapTile t) {
   tiles.add(t);
   tileGroup.add(t);
 }
 private void removeTile(MapTile t) {
   tiles.remove(t);
   tileGroup.remove(t);
 }
 public void addTower(Tower t) {
   towers.add(t);
 }
 public void addProjectile(Projectile projectile) {
   projectiles.add(projectile);
 }
 public void render(Graphics2D g) {
   game.getGui().getFont().drawString(g, "Level: " + (levelIndex - 1), 10, 30);
   monsters.render(g);
   projectiles.render(g);
 }