Example #1
1
  /**
   * Create a new sound on request to load
   *
   * @param ref The location of the sound to load
   * @param type The type of sound to load
   * @param in The input stream to load from
   */
  public DeferredSound(String ref, InputStream in, int type) {
    this.ref = ref;
    this.type = type;

    if (ref.equals(in.toString()))
      this.in = in; // nasty hack to detect when we're loading from a stream

    LoadingList.get().add(this);
  }
Example #2
0
  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);
  }
  @Override
  public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

    {
      /* Deferred loading of images for better performances */
      LoadingList loading = LoadingList.get();

      loading.add(
          new DeferredFile("res/menu_graphics/new/menu_screen.png") {
            public void loadFile(String filename) throws SlickException {
              menuBackground = new Image(filename);
            }
          });

      loading.add(
          new DeferredFile("res/menu_graphics/new/menu_button.png") {
            public void loadFile(String filename) throws SlickException {
              menuButton = new Image(filename);
            }
          });

      loading.add(
          new DeferredFile("res/menu_graphics/new/menu_hover.png") {
            public void loadFile(String filename) throws SlickException {
              menuHover = new Image(filename);
            }
          });
    }

    /* Credits text */
    credits =
        new String[][] {
          {
            "Music Assets",
            "\"Beachfront Celebration\" Kevin MacLeod (incompetech.com)",
            "Licensed under Creative Commons: By Attribution 3.0",
            "http://creativecommons.org/licenses/by/3.0/"
          },
          {
            "Images",
            "Loading screen plane created by Sallee Design",
            "http://salleedesign.com/resources/plane-psd/"
          },
          {
            "Font",
            "A love of thunder",
            "Downloaded from DaFont",
            "http://www.dafont.com/a-love-of-thunder.font"
          }
        };
  }
  /**
   * Create a new deferred texture
   *
   * @param in The input stream from which to read the texture
   * @param resourceName The name to give the resource
   * @param flipped True if the image should be flipped
   * @param filter The filter to apply
   * @param trans The colour to defined as transparent
   */
  public DeferredTexture(
      InputStream in, String resourceName, boolean flipped, int filter, int[] trans) {
    this.in = in;
    this.resourceName = resourceName;
    this.flipped = flipped;
    this.filter = filter;
    this.trans = trans;

    LoadingList.get().add(this);
  }
  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);
        }
      }
    }
  }
 /** Check if the target has been obtained already */
 private void checkTarget() {
   if (target == null) {
     try {
       load();
       LoadingList.get().remove(this);
       return;
     } catch (IOException e) {
       throw new RuntimeException(
           "Attempt to use deferred texture before loading and resource not found: "
               + resourceName);
     }
   }
 }
Example #7
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();
   }
 }
Example #8
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();
      }
    }
  }