예제 #1
0
파일: Aurore.java 프로젝트: nam0r/Devint
  public Aurore(int n, String walkingSprite, String jumpingSprite) {
    super(n, Conf.IMG_SPRITES_PATH + walkingSprite, 100, 450, 2f, 40, 62);

    walk = new SpriteSheet(image, 40, 74);

    try {
      Image im = new Image(Conf.IMG_SPRITES_PATH + jumpingSprite);
      jump = new SpriteSheet(im, 40, 74);
    } catch (SlickException e) {
      System.err.println("Image aurore pas trouvée.");
    }

    moveForce = 150;
    jumpForce = 40000;
    MAX_JUMP_VEL = 120;
    body.setMaxVelocity(40, 120);

    LoadingList.setDeferredLoading(false);
    try {
      painSound = new Sound2(Conf.SND_PERSOS_PATH + "douleur_femme.ogg");
    } catch (SlickException e) {
      System.err.println("Sound " + Conf.SND_PERSOS_PATH + "douleur_homme.ogg" + " not found");
    }
    LoadingList.setDeferredLoading(true);
  }
  public void loadResources(InputStream is, boolean deferred) throws SlickException {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = null;
    try {
      docBuilder = docBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
      throw new SlickException("Could not load resources", e);
    }
    Document doc = null;
    try {
      doc = docBuilder.parse(is);
    } catch (SAXException e) {
      throw new SlickException("Could not load resources", e);
    } catch (IOException e) {
      throw new SlickException("Could not load resources", e);
    }

    // normalize text representation
    doc.getDocumentElement().normalize();

    NodeList listResources = doc.getElementsByTagName("resource");

    int totalResources = listResources.getLength();

    if (deferred) {
      LoadingList.setDeferredLoading(true);
    }

    for (int resourceIdx = 0; resourceIdx < totalResources; resourceIdx++) {

      Node resourceNode = listResources.item(resourceIdx);

      if (resourceNode.getNodeType() == Node.ELEMENT_NODE) {
        Element resourceElement = (Element) resourceNode;

        String type = resourceElement.getAttribute("type");

        if (type.equals("image")) {
          addElementAsImage(resourceElement);
        } else if (type.equals("sound")) {
          addElementAsSound(resourceElement);
        } else if (type.equals("music")) {
          addElementAsMusic(resourceElement);
        } else if (type.equals("text")) {
          addElementAsText(resourceElement);
        } else if (type.equals("font")) {

        } else if (type.equals("animation")) {
          addElementAsAnimation(resourceElement);
        }
      }
    }
  }
예제 #3
0
 public static void main(String[] args) {
   LoadingList.setDeferredLoading(true);
   try {
     AppGameContainer app = new AppGameContainer(new DragonGame());
     app.setDisplayMode(width, height, fullscreen);
     app.setShowFPS(false);
     app.setMouseGrabbed(false);
     app.setTargetFrameRate(60);
     app.setAlwaysRender(true);
     app.setUpdateOnlyWhenVisible(true);
     app.start();
   } catch (SlickException e) {
     e.printStackTrace();
   }
 }
예제 #4
0
  @Override
  public void enter(GameContainer gc, StateBasedGame sbg) throws SlickException {
    currentState = States.IN_GAME;

    Globals.score_submitted = false;

    // If the "main" previous state was not the game state, then it's
    // probably the menu state
    if (Globals.returnState != stateID) {
      // Globals.stateToGoTo.clear();
      Globals.nodes.clear();
      Globals.initQuestionsNotAsked();
      Globals.started = true;

      createMap();

      LoadingList.setDeferredLoading(false);
      soundWalk = new Sound2(Globals.player.getSoundWalk());
      LoadingList.setDeferredLoading(true);

      Globals.score = 0;
      map.setMainPlayer(Globals.player);
      Globals.player.reinitPosition();
      voix = new t2s.SIVOXDevint();

      Globals.nodeHasChanged = true;
    }

    super.enter(gc, sbg);

    if (Globals.nodeHasChanged) {

      // map.addEntity(Globals.getEntityFromCurrentNode());
      PhysicalEntity ia = Globals.node.getIA();
      if (ia != null) {
        // we set the ia's position
        Dimension d = Globals.nodes.poll();
        if (d != null) {
          ia.setPosition((float) d.getWidth(), (float) d.getHeight());
        } else {
          System.err.println("No more node locations available.");
        }
        // we set the ia
        map.addEntity(ia);
      } else {
        System.err.println("The current node (" + Globals.node.getID() + ") doesn't have an ia.");
        Globals.nextEvent(sbg);
      }

      Globals.nodeHasChanged = false;
    }

    // this state is important so we put it in Globals
    Globals.returnState = stateID;

    AL10.alDopplerFactor(1.0f);
    // we execute enter methods for all the IA
    for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
      if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof IA) {
        ((IA) map.getEntityByBody(map.getWorld().getBodies().get(i))).enter();
      } else if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Enemy) {
        ((Enemy) map.getEntityByBody(map.getWorld().getBodies().get(i))).enter();
      } else if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Spirit) {
        ((Spirit) map.getEntityByBody(map.getWorld().getBodies().get(i))).enter();
      }
    }
  }