コード例 #1
0
  private Animation parseImagestripAnimations(
      Scanner cmdScanner, ImageStrip imgStrip, int frameDuration) {
    int firstFrameCol, lastFrameCol;

    if (cmdScanner.hasNextBoolean()) {
      firstFrameCol = 0;
      lastFrameCol = imgStrip.getCols();
    } else {
      firstFrameCol = cmdScanner.nextInt();
      lastFrameCol = cmdScanner.nextInt();
    }
    boolean loop = cmdScanner.nextBoolean();

    List<Image> result = new ArrayList<Image>();
    for (int col = firstFrameCol; col < lastFrameCol && col < imgStrip.getCols(); col++) {
      result.add(imgStrip.getSubImage(col));
    }
    Animation anim = new Animation(result.toArray(new Image[result.size()]), frameDuration);
    anim.setAutoUpdate(false);
    anim.setLooping(loop);
    return anim;
  }
コード例 #2
0
  public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

    gc.setTargetFrameRate(60);

    gc.setShowFPS(false);

    // *******************

    // Scenerey Stuff

    // ****************
    grassMap = new TiledMap("res/coral.tmx");
    // grassMap = new TiledMap("res/coral.tmx");

    // Ongoing checks are useful

    System.out.println("Tile map is this wide: " + grassMap.getWidth());

    camera = new Camera(gc, grassMap);

    // *********************************************************************************

    // Player stuff --- these things should probably be chunked into methods
    // and classes

    // *********************************************************************************

    SpriteSheet runningSS = new SpriteSheet("res/skeletonpritesheet.png", 64, 64, 0);

    // System.out.println("Horizontal count: "
    // +runningSS.getHorizontalCount());

    // System.out.println("Vertical count: " +runningSS.getVerticalCount());

    up = new Animation();

    up.setAutoUpdate(true);

    up.addFrame(runningSS.getSprite(0, 8), 330);

    up.addFrame(runningSS.getSprite(1, 8), 330);

    up.addFrame(runningSS.getSprite(2, 8), 330);

    up.addFrame(runningSS.getSprite(3, 8), 330);

    up.addFrame(runningSS.getSprite(4, 8), 330);

    up.addFrame(runningSS.getSprite(5, 8), 330);

    up.addFrame(runningSS.getSprite(6, 8), 330);

    up.addFrame(runningSS.getSprite(7, 8), 330);

    up.addFrame(runningSS.getSprite(8, 8), 330);

    down = new Animation();

    down.setAutoUpdate(false);

    down.addFrame(runningSS.getSprite(0, 10), 330);

    down.addFrame(runningSS.getSprite(1, 10), 330);

    down.addFrame(runningSS.getSprite(2, 10), 330);

    down.addFrame(runningSS.getSprite(3, 10), 330);

    down.addFrame(runningSS.getSprite(4, 10), 330);

    down.addFrame(runningSS.getSprite(5, 10), 330);

    down.addFrame(runningSS.getSprite(6, 10), 330);

    down.addFrame(runningSS.getSprite(7, 10), 330);

    down.addFrame(runningSS.getSprite(8, 10), 330);

    left = new Animation();

    left.setAutoUpdate(false);

    left.addFrame(runningSS.getSprite(0, 9), 330);

    left.addFrame(runningSS.getSprite(1, 9), 330);

    left.addFrame(runningSS.getSprite(2, 9), 330);

    left.addFrame(runningSS.getSprite(3, 9), 330);

    left.addFrame(runningSS.getSprite(4, 9), 330);

    left.addFrame(runningSS.getSprite(5, 9), 330);

    left.addFrame(runningSS.getSprite(6, 9), 330);

    left.addFrame(runningSS.getSprite(7, 9), 330);

    left.addFrame(runningSS.getSprite(8, 9), 330);

    right = new Animation();

    right.setAutoUpdate(false);

    right.addFrame(runningSS.getSprite(0, 11), 330);

    right.addFrame(runningSS.getSprite(1, 11), 330);

    right.addFrame(runningSS.getSprite(2, 11), 330);

    right.addFrame(runningSS.getSprite(3, 11), 330);

    right.addFrame(runningSS.getSprite(4, 11), 330);

    right.addFrame(runningSS.getSprite(5, 11), 330);

    right.addFrame(runningSS.getSprite(6, 11), 330);

    right.addFrame(runningSS.getSprite(7, 11), 330);

    right.addFrame(runningSS.getSprite(8, 11), 330);

    wait = new Animation();

    wait.setAutoUpdate(true);

    wait.addFrame(runningSS.getSprite(0, 14), 733);

    wait.addFrame(runningSS.getSprite(1, 14), 733);

    wait.addFrame(runningSS.getSprite(2, 14), 733);

    wait.addFrame(runningSS.getSprite(3, 14), 733);

    // wait.addFrame(runningSS.getSprite(2, 14), 733);

    // wait.addFrame(runningSS.getSprite(5, 14), 333);

    sprite = wait;

    // *****************************************************************

    // Obstacles etc.

    // build a collision map based on tile properties in the TileD map

    Blocked.blocked = new boolean[grassMap.getWidth()][grassMap.getHeight()];

    // System.out.println("Map height:" + grassMap.getHeight());

    // System.out.println("Map width:" + grassMap.getWidth());

    // There can be more than 1 layer. You'll check whatever layer has the
    // obstacles.

    // You could also use this for planning traps, etc.

    // System.out.println("Number of tile layers: "
    // +grassMap.getLayerCount());

    System.out.println("The grassmap is " + grassMap.getWidth() + "by " + grassMap.getHeight());

    for (int xAxis = 0; xAxis < grassMap.getWidth(); xAxis++) {

      for (int yAxis = 0; yAxis < grassMap.getHeight(); yAxis++) {

        // int tileID = grassMap.getTileId(xAxis, yAxis, 0);

        // Why was this changed?

        // It's a Different Layer.

        // You should read the TMX file. It's xml, i.e.,human-readable
        // for a reason

        int tileID = grassMap.getTileId(xAxis, yAxis, 1);

        String value = grassMap.getTileProperty(tileID, "blocked", "false");

        if ("true".equals(value)) {

          System.out.println("The tile at x " + xAxis + " andy axis " + yAxis + " is blocked.");

          Blocked.blocked[xAxis][yAxis] = true;
        }
      }
    }

    System.out.println("Array length" + Blocked.blocked[0].length);

    // A remarkably similar process for finding hostiles

    hostiles = new boolean[grassMap.getWidth()][grassMap.getHeight()];

    /*		for (int xAxis = 0; xAxis < grassMap.getWidth(); xAxis++) {
    			for (int yAxis = 0; yAxis < grassMap.getHeight(); yAxis++) {
    				int xBlock = (int) xAxis;
    				int yBlock = (int) yAxis;
    				if (!Blocked.blocked[xBlock][yBlock]) {
    					if (yBlock % 7 == 0 && xBlock % 15 == 0 ) {
    						Item i = new Item(xAxis * SIZE, yAxis * SIZE);
    						stuff.add(i);
    						//stuff1.add(h);
    						hostiles[xAxis][yAxis] = true;
    					}
    				}
    			}
    		}
                    for (int xAxis = 0; xAxis < grassMap.getWidth(); xAxis++) {
    			for (int yAxis = 0; yAxis < grassMap.getHeight(); yAxis++) {
    				int xBlock = (int) xAxis;
    				int yBlock = (int) yAxis;
    				if (!Blocked.blocked[xBlock][yBlock]) {
    					if (yBlock % 7 == 0 && xBlock % 15 == 0 ) {
    						Item i = new Item(xAxis * SIZE, yAxis * SIZE);
    						stuff.add(i);
    						//stuff1.add(h);
    						hostiles[xAxis][yAxis] = true;
    					}
    				}
    			}
    		}
    */

    // healthpotion = new Item(100, 100);
    // healthpotion1 = new Item(450, 400);
    // stuff.add(healthpotion);
    // stuff.add(healthpotion1);

    // stormy = new Ninja(0,0);
    // daniel = new Ninja(124,254);
    // dojo.add(stormy);
    // dojo.add(daniel);

    flava = new Enemy(1500, 2500);
    flav = new Enemy(1000, 1000);
    bonez.add(flava);
    bonez.add(flav);

    bone1 = new Bone(655, 70);
    bone2 = new Bone(1750, 800);
    doghouse.add(bone1);
    doghouse.add(bone2);

    // speedpotion = new Item1(100,150);
    // speedpotion1 = new Item1(450,100);
    // stuff1.add(speedpotion);
    // stuff1.add(speedpotion1);

    //		antidote = new Itemwin(3004,92);
    //		stuffwin.add(antidote);

    BoneMaker.Makethebones();
  }
コード例 #3
0
ファイル: Enemy.java プロジェクト: atkinsondaniel/slickgame
  Enemy(int a, int b) throws SlickException {

    Bx = a;

    By = b;

    hitboxX = this.getskhitboxX();

    hitboxY = this.getskhitboxY();
    rect = new Rectangle(hitboxX, hitboxY, width, height);

    int BHealth;

    boolean isBAlive = true;

    canmove = true;

    currentanime = skwait;

    id = ++numberOfEnemies;

    this.mydirection = Direction.WAIT;

    SpriteSheet skeletonSS = new SpriteSheet("res/enemy.png", 64, 64, 0);

    skup = new Animation();

    skup.setAutoUpdate(true);

    skup.addFrame(skeletonSS.getSprite(0, 8), 75);

    skup.addFrame(skeletonSS.getSprite(1, 8), 75);

    skup.addFrame(skeletonSS.getSprite(2, 8), 75);

    skup.addFrame(skeletonSS.getSprite(3, 8), 75);

    skup.addFrame(skeletonSS.getSprite(4, 8), 75);

    skup.addFrame(skeletonSS.getSprite(5, 8), 75);

    skup.addFrame(skeletonSS.getSprite(6, 8), 75);

    skup.addFrame(skeletonSS.getSprite(7, 8), 75);

    skup.addFrame(skeletonSS.getSprite(8, 8), 75);

    skdown = new Animation();

    skdown.setAutoUpdate(false);

    skdown.addFrame(skeletonSS.getSprite(0, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(1, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(2, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(3, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(4, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(5, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(6, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(7, 10), 75);

    skdown.addFrame(skeletonSS.getSprite(8, 10), 75);

    skleft = new Animation();

    skleft.setAutoUpdate(false);

    skleft.addFrame(skeletonSS.getSprite(0, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(1, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(2, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(3, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(4, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(5, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(6, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(7, 9), 75);

    skleft.addFrame(skeletonSS.getSprite(8, 9), 75);

    skright = new Animation();

    skright.setAutoUpdate(false);

    skright.addFrame(skeletonSS.getSprite(0, 11), 75);

    skright.addFrame(skeletonSS.getSprite(1, 11), 75);

    skright.addFrame(skeletonSS.getSprite(2, 11), 75);

    skright.addFrame(skeletonSS.getSprite(3, 11), 75);

    skright.addFrame(skeletonSS.getSprite(4, 11), 75);

    skright.addFrame(skeletonSS.getSprite(5, 11), 75);

    skright.addFrame(skeletonSS.getSprite(6, 11), 75);

    skright.addFrame(skeletonSS.getSprite(7, 11), 75);

    skright.addFrame(skeletonSS.getSprite(8, 11), 75);

    skwait = new Animation();

    skwait.setAutoUpdate(true);

    skwait.addFrame(skeletonSS.getSprite(0, 14), 75);

    skwait.addFrame(skeletonSS.getSprite(1, 14), 75);

    skwait.addFrame(skeletonSS.getSprite(2, 14), 75);

    skwait.addFrame(skeletonSS.getSprite(3, 14), 75);

    skdead = new Animation();

    skdead.setAutoUpdate(false);

    skdead.addFrame(skeletonSS.getSprite(2, 20), 75);

    skdead.addFrame(skeletonSS.getSprite(3, 20), 75);

    skdead.addFrame(skeletonSS.getSprite(4, 20), 75);

    skdead.addFrame(skeletonSS.getSprite(5, 20), 75);

    currentanime = skwait;
  }
コード例 #4
0
  public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

    gc.setTargetFrameRate(60);

    gc.setShowFPS(false);

    // *******************

    // Scenerey Stuff

    // ****************

    forestMap = new TiledMap("res/agivens_4_map.tmx");

    // Ongoing checks are useful

    System.out.println("Tile map is this wide: " + forestMap.getWidth());

    camera = new Camera(gc, forestMap);

    // *********************************************************************************

    // Player stuff --- these things should probably be chunked into methods
    // and classes

    // *********************************************************************************

    SpriteSheet proMoving = new SpriteSheet("res/ProtagonistSpriteSheet.png", 64, 64, 0);

    // System.out.println("Horizontal count: "
    // +runningSS.getHorizontalCount());

    // System.out.println("Vertical count: " +runningSS.getVerticalCount());

    proup = new Animation();

    proup.setAutoUpdate(true);

    proup.addFrame(proMoving.getSprite(0, 8), 330);

    proup.addFrame(proMoving.getSprite(1, 8), 330);

    proup.addFrame(proMoving.getSprite(2, 8), 330);

    proup.addFrame(proMoving.getSprite(3, 8), 330);

    proup.addFrame(proMoving.getSprite(4, 8), 330);

    proup.addFrame(proMoving.getSprite(5, 8), 330);

    proup.addFrame(proMoving.getSprite(6, 8), 330);

    proup.addFrame(proMoving.getSprite(7, 8), 330);

    proup.addFrame(proMoving.getSprite(8, 8), 330);

    prodown = new Animation();

    prodown.setAutoUpdate(false);

    prodown.addFrame(proMoving.getSprite(0, 10), 330);

    prodown.addFrame(proMoving.getSprite(1, 10), 330);

    prodown.addFrame(proMoving.getSprite(2, 10), 330);

    prodown.addFrame(proMoving.getSprite(3, 10), 330);

    prodown.addFrame(proMoving.getSprite(4, 10), 330);

    prodown.addFrame(proMoving.getSprite(5, 10), 330);

    prodown.addFrame(proMoving.getSprite(6, 10), 330);

    prodown.addFrame(proMoving.getSprite(7, 10), 330);

    prodown.addFrame(proMoving.getSprite(8, 10), 330);

    proleft = new Animation();

    proleft.setAutoUpdate(false);

    proleft.addFrame(proMoving.getSprite(0, 9), 330);

    proleft.addFrame(proMoving.getSprite(1, 9), 330);

    proleft.addFrame(proMoving.getSprite(2, 9), 330);

    proleft.addFrame(proMoving.getSprite(3, 9), 330);

    proleft.addFrame(proMoving.getSprite(4, 9), 330);

    proleft.addFrame(proMoving.getSprite(5, 9), 330);

    proleft.addFrame(proMoving.getSprite(6, 9), 330);

    proleft.addFrame(proMoving.getSprite(7, 9), 330);

    proleft.addFrame(proMoving.getSprite(8, 9), 330);

    proright = new Animation();

    proright.setAutoUpdate(false);

    proright.addFrame(proMoving.getSprite(0, 11), 330);

    proright.addFrame(proMoving.getSprite(1, 11), 330);

    proright.addFrame(proMoving.getSprite(2, 11), 330);

    proright.addFrame(proMoving.getSprite(3, 11), 330);

    proright.addFrame(proMoving.getSprite(4, 11), 330);

    proright.addFrame(proMoving.getSprite(5, 11), 330);

    proright.addFrame(proMoving.getSprite(6, 11), 330);

    proright.addFrame(proMoving.getSprite(7, 11), 330);

    proright.addFrame(proMoving.getSprite(8, 11), 330);

    prowait = new Animation();

    prowait.setAutoUpdate(true);

    prowait.addFrame(proMoving.getSprite(0, 14), 733);

    prowait.addFrame(proMoving.getSprite(1, 14), 733);

    prowait.addFrame(proMoving.getSprite(2, 14), 733);

    prowait.addFrame(proMoving.getSprite(3, 14), 733);

    // wait.addFrame(runningSS.getSprite(2, 14), 733);

    // wait.addFrame(runningSS.getSprite(5, 14), 333);

    sprite = prowait;

    // *****************************************************************

    // Obstacles etc.

    // build a collision map based on tile properties in the TileD map

    blocked.blocked = new boolean[forestMap.getWidth()][forestMap.getHeight()];

    // System.out.println("Map height:" + grassMap.getHeight());

    // System.out.println("Map width:" + grassMap.getWidth());

    // There can be more than 1 layer. You'll check whatever layer has the
    // obstacles.

    // You could also use this for planning traps, etc.

    // System.out.println("Number of tile layers: "
    // +grassMap.getLayerCount());

    System.out.println("The grassmap is " + forestMap.getWidth() + " by " + forestMap.getHeight());

    for (int xAxis = 0; xAxis < forestMap.getWidth(); xAxis++) {

      for (int yAxis = 0; yAxis < forestMap.getHeight(); yAxis++) {

        // int tileID = grassMap.getTileId(xAxis, yAxis, 0);

        // Why was this changed?

        // It's a Different Layer.

        // You should read the TMX file. It's xml, i.e.,human-readable
        // for a reason

        int tileID = forestMap.getTileId(xAxis, yAxis, 1);

        String value = forestMap.getTileProperty(tileID, "blocked", "false");

        if ("true".equals(value)) {

          System.out.println(
              "The tile at x axis " + xAxis + " and y axis " + yAxis + " is blocked.");

          blocked.blocked[xAxis][yAxis] = true;
        }
      }
    }

    System.out.println("Array length " + blocked.blocked[0].length);

    // A remarkably similar process for finding hostiles

    hostiles = new boolean[forestMap.getWidth()][forestMap.getHeight()];

    grabtowin = new itemwin(4400, 4400);
    stuffwin.add(grabtowin);

    numberone = new Enemy(300, 300);
    monster.add(numberone);
  }