Beispiel #1
0
  public Lion(EngineCore e) {
    super();
    this.setIsAnimated(true);
    this.setHealth(30);

    Image[] runW = {
      e.loadImage("images/l_w_1.png"), e.loadImage("images/l_w_2.png"),
      e.loadImage("images/l_w_3.png"), e.loadImage("images/l_w_4.png"),
      e.loadImage("images/l_w_5.png"), e.loadImage("images/l_w_6.png"),
      e.loadImage("images/l_w_7.png"), e.loadImage("images/l_w_8.png"),
      e.loadImage("images/l_w_9.png")
    };

    Image[] runE = {
      e.loadImage("images/l_e_1.png"), e.loadImage("images/l_e_2.png"),
      e.loadImage("images/l_e_3.png"), e.loadImage("images/l_e_4.png"),
      e.loadImage("images/l_e_5.png"), e.loadImage("images/l_e_6.png"),
      e.loadImage("images/l_e_7.png"), e.loadImage("images/l_e_8.png"),
      e.loadImage("images/l_e_9.png")
    };

    Image[] runN = {e.loadImage("images/l_n_1.png"), e.loadImage("images/l_n_2.png")};

    Image[] runS = {
      e.loadImage("images/l_s_1.png"), e.loadImage("images/l_s_2.png"),
      e.loadImage("images/l_s_3.png"), e.loadImage("images/l_s_4.png"),
      e.loadImage("images/l_s_5.png")
    };

    Image[] attackW = {
      e.loadImage("images/la_w_1.png"), e.loadImage("images/la_w_2.png"),
      e.loadImage("images/la_w_3.png"), e.loadImage("images/la_w_4.png"),
      e.loadImage("images/la_w_5.png")
    };

    Image[] attackE = {
      e.loadImage("images/la_e_1.png"), e.loadImage("images/la_e_2.png"),
      e.loadImage("images/la_e_3.png"), e.loadImage("images/la_e_4.png"),
      e.loadImage("images/la_e_5.png")
    };

    Image[] attackN = {
      e.loadImage("images/la_e_1.png"), e.loadImage("images/la_e_2.png"),
      e.loadImage("images/la_e_3.png"), e.loadImage("images/la_e_4.png"),
      e.loadImage("images/la_e_5.png")
    };

    Image[] attackS = {
      e.loadImage("images/la_e_1.png"), e.loadImage("images/la_e_2.png"),
      e.loadImage("images/la_e_3.png"), e.loadImage("images/la_e_4.png"),
      e.loadImage("images/la_e_5.png")
    };

    Image[] idleS = {e.loadImage("images/l_s_1.png"), e.loadImage("images/l_s_1.png")};

    Image[] idleN = {e.loadImage("images/l_n_1.png"), e.loadImage("images/l_n_1.png")};

    Image[] idleW = {e.loadImage("images/l_w_1.png"), e.loadImage("images/l_w_2.png")};

    Image[] idleE = {e.loadImage("images/l_e_1.png"), e.loadImage("images/l_e_2.png")};

    // Dying frames
    Image[] die = {
      e.loadImage("images/explode1.png"), e.loadImage("images/explode2.png"),
      e.loadImage("images/explode3.png"), e.loadImage("images/explode4.png"),
      e.loadImage("images/explode5.png"), e.loadImage("images/explode6.png"),
      e.loadImage("images/explode7.png")
    };
    // Memory consuming??
    this.animEidle.loadAnim(idleE);
    this.animWidle.loadAnim(idleW);
    this.animNidle.loadAnim(idleN);
    this.animSidle.loadAnim(idleS);
    this.animE.loadAnim(runE);
    this.animW.loadAnim(runW);
    this.animN.loadAnim(runN);
    this.animS.loadAnim(runS);
    this.animEattack.loadAnim(attackE);
    this.animWattack.loadAnim(attackW);
    this.animNattack.loadAnim(attackN);
    this.animSattack.loadAnim(attackS);

    // Dying Animation loading
    this.animDie.loadAnim(die);
  }
  // private otherwise not safe - since constructor calling this method
  private void loadObjects() {

    staticGameObjs = new ArrayList<GameObject>();
    animatedGameObjs = new ArrayList<GameObject>();
    InputStream in = null;

    try {
      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
      in = en.loadData(configFile);
      // this.setStream(in);
      XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
      // Sprite sprite = null;
      GameObject curObj = null;
      // level = null;

      while (eventReader.hasNext()) {

        XMLEvent event = eventReader.nextEvent();

        if (event.isStartElement()) {

          StartElement startElement = event.asStartElement();

          // If we have a item element we create a new item
          if (startElement.getName().getLocalPart().equals(OBJ_SPRITE)) {

            Iterator<Attribute> attributes = startElement.getAttributes();
            while (attributes.hasNext()) {

              Attribute attribute = attributes.next();
              if (attribute.getName().toString().equals(SPRITE_TYPE)) {

                String spriteName = attribute.getValue();

                curObj = createGameObjects(spriteName);
              }

              if (attribute.getName().toString().equals(NATURE)) {
                curObj.setNature(attribute.getValue());
              }
            }
          } else if (event.isStartElement() && curObj != null) {

            String property = event.asStartElement().getName().getLocalPart();
            event = eventReader.nextEvent();
            String data_Str = event.asCharacters().getData();

            configProperties(curObj, property, data_Str);
          }
        }

        if (event.isEndElement() && curObj != null) {

          EndElement endElement = event.asEndElement();
          if (endElement.getName().getLocalPart().equals(OBJ_SPRITE)) {

            if (curObj.getIsAnimated()) {
              this.animatedGameObjs.add(curObj);
              // Create remaining GameObjects defined in xml tag <total>
              if (curObj.getTotal() > 1) {
                for (int i = 0; i < curObj.getTotal() - 1; i++) {

                  GameObject newCurObj = createGameObjects(curObj.getName());
                  newCurObj.setX((float) Math.random() * 600);
                  newCurObj.setY((float) Math.random() * 100);
                  newCurObj.setName(curObj.getName());
                  newCurObj.setStgy(curObj.getStgy());
                  this.animatedGameObjs.add(newCurObj);
                }
              }

            } else this.staticGameObjs.add(curObj);
          }
        }
      }

      // Send GameObject arrays to current Level
      this.level.setArrGameAnim(animatedGameObjs);
      this.level.setArrGameStatic(staticGameObjs);

    } catch (FileNotFoundException ex) {

    } catch (XMLStreamException e) {
    }
  }