Esempio n. 1
0
  @Override
  public void init(GameContainer gameContainer, StateBasedGame stateBasedGame)
      throws SlickException {
    this.stateBasedGame = stateBasedGame;

    center =
        new Dimension(
            AsaGame.SOURCE_RESOLUTION.width / 2 - 100, AsaGame.SOURCE_RESOLUTION.height / 2);

    resetGame();

    tandwiel1 = new Image(Resource.getPath(Resource.TANDWIEL5));
    tandwiel2 = new Image(Resource.getPath(Resource.TANDWIEL6));
    spinner = new Image(Resource.getPath(Resource.SPINNER));
    spinneroverlay = new Image(Resource.getPath(Resource.SPINNER_OVERLAY));
    background_spinner = new Image(Resource.getPath(Resource.BACKGROUND_SPINNER));
    background_spinner_half = new Image(Resource.getPath(Resource.BACKGROUND_SPINNER_HALF));
    background_spinner_half.setAlpha(0.7f);
    background = new Image(Resource.getPath(Resource.GAME_BACKGROUND));
    selectImage = new Image(Resource.getPath(Resource.SAVE_SCORE));
    choise = new Image(Resource.getPath(Resource.MAKE_YOUR_CHOISE));

    fontBlack = Resource.getFont(Resource.FONT_SANCHEZ, 30, Color.BLACK);

    lens = new Animation();
    lens.setLooping(false);
    for (int i = 0; i < 33; i++) {
      if ((i + "").length() == 1) {
        lens.addFrame(new Image(Resource.getPath("LENS/lens1_0000" + i + ".png")), 550 / 33);
      } else if ((i + "").length() == 2) {
        lens.addFrame(new Image(Resource.getPath("LENS/lens1_000" + i + ".png")), 550 / 33);
      }
    }
    lens.stop();
  }
Esempio n. 2
0
 public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
   Instructions.draw(0, 0);
   move.draw(450, 120);
   slash.draw(450, 200);
   baddy.draw(450, 300);
   if (slash.getFrame() == 1) {
     g.drawImage(new Image("res/Link/Sword (right 2).png"), 490, 200);
   }
 }
 @Override
 public void update(GameContainer gc, StateBasedGame sb, float delta) {
   Dice dice = ((Dice) owner);
   DiceManager dm = DiceManager.getInstance();
   if (!dice.isRolling() && !checked) {
     //            int rand = (int) (Math.random()*6);
     //            dice.setResult(rand);
     dm.checkIfAllDicesAreSet();
     anim.setCurrentFrame(numbers.indexOf(dice.getResult() - 1));
     anim.stop();
     checked = true;
   }
 }
Esempio n. 4
0
  private void initializeAssets() throws SlickException {
    // Maps anlegen
    maps.put(0, "Testmap.tmx");
    // Sheet für die Bilder der Animation anlegen + Bilder zur Animation
    // hinzufügen
    playerSheet = new SpriteSheet("res/animations/character_top.png", 130, 120);
    playerTop = new Animation();
    for (int col = 0; col < 15; ++col) {
      playerTop.addFrame(playerSheet.getSprite(col, 0), 80);
    }

    playerSide = new Animation();
    playerSide.addFrame(new Image("res/animations/character_side.png"), 80);
  }
Esempio n. 5
0
 @Override
 public void render(GameContainer gc, Graphics g2d) throws SlickException {
   if (!isAlive) {
     animationDead.draw(x, y);
   } else if (isJumping) {
     animationJump.draw(x, y);
   } else {
     if (x < 34) {
       animationRunLeft.draw(x, y);
     } else {
       animationRunRight.draw(x, y);
     }
   }
 }
Esempio n. 6
0
  @Override
  public void update(long currentFrame) {

    // Check for moving
    if (!_myState.moving) {
      // Check for destroy
      if (_animation.isStopped()) {
        _level.getLogicManager().detachLogic(this);
      }

      return;
    }

    super.update(currentFrame);

    // Check for squash grunts / spiders
    for (CellLogic cell : _level.getCellManager().getCollisionsWith(this, 16, currentFrame)) {

      // Check for grunt
      try {
        Grunt grunt = (Grunt) cell;
        grunt.getBehaviour().exit("Squash");
      } catch (Exception e) {
      }

      // Check for spider
      try {
        Spider spider = (Spider) cell;
        spider.squash(currentFrame);
      } catch (Exception e) {
      }
    }
  }
Esempio n. 7
0
  @Override
  public void render(Graphics g, long time) {

    // Render the position of the ball
    renderPosition(time, 20);

    // Draw the ball
    _animation.draw(_screen.x(), _screen.y());
  }
Esempio n. 8
0
 public Player(
     Image[] framesRight,
     Image[] framesLeft,
     Image[] jumpFrames,
     Image[] deadFrames,
     BasicGame game) {
   this.animationRunRight = new Animation(framesRight, 100);
   this.animationRunLeft = new Animation(framesLeft, 100);
   this.animationJump = new Animation(jumpFrames, 75);
   this.animationDead = new Animation(deadFrames, 75);
   border =
       new Circle(
           x + animationRunRight.getWidth() / 2,
           y + animationRunRight.getHeight() / 2,
           animationRunRight.getWidth() / 2);
   isOnLeftSide = true;
   isAlive = true;
   this.game = game;
 }
Esempio n. 9
0
/*     */   public Animation copy()
/*     */   {
/* 672 */     Animation copy = new Animation();
/*     */ 
/* 674 */     copy.spriteSheet = this.spriteSheet;
/* 675 */     copy.frames = this.frames;
/* 676 */     copy.autoUpdate = this.autoUpdate;
/* 677 */     copy.direction = this.direction;
/* 678 */     copy.loop = this.loop;
/* 679 */     copy.pingPong = this.pingPong;
/* 680 */     copy.speed = this.speed;
/*     */ 
/* 682 */     return copy;
/*     */   }
Esempio n. 10
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;
  }
Esempio n. 11
0
  public Player(
      SpriteSheet runSheetLeft,
      SpriteSheet runSheetRight,
      SpriteSheet deadSheet,
      SpriteSheet jumpSheet,
      BasicGame game) {
    this.animationRunLeft = new Animation(runSheetLeft, 100);
    this.animationRunRight = new Animation(runSheetRight, 100);
    this.animationJump = new Animation(jumpSheet, 75);
    this.animationDead = new Animation(deadSheet, 150);
    this.animationDead.setLooping(false);
    this.animationDead.setCurrentFrame(0);

    border =
        new Circle(
            x + animationRunRight.getWidth() / 2,
            y + animationRunRight.getHeight() / 2,
            animationRunRight.getWidth() / 2);
    isOnLeftSide = true;
    isAlive = true;

    this.game = game;
  }
Esempio n. 12
0
  public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    camera.centerOn((int) Player.x, (int) Player.y);

    camera.drawMap();

    camera.translateGraphics();

    // it helps to add status reports to see what's going on

    // but it gets old quickly

    // System.out.println("Current X: " +player.x + " \n Current Y: "+ y);

    sprite.draw((int) Player.x, (int) Player.y);

    // g.drawString("x: " + (int)player.x + "y: " +(int)player.y , player.x, player.y - 10);

    g.drawString("Health: " + Player.health, camera.cameraX + 10, camera.cameraY + 10);

    g.drawString("speed: " + (int) (Player.speed * 10), camera.cameraX + 10, camera.cameraY + 25);

    // g.draw(player.rect);

    g.drawString("time passed: " + counter / 1000, camera.cameraX + 600, camera.cameraY);
    // moveenemies();

    for (itemwin w : stuffwin) {
      if (w.isvisible) {
        w.currentImage.draw(w.x, w.y);
        // draw the hitbox
        // g.draw(w.hitbox);

      }
    }

    for (Enemy e : monster) {

      // System.out.println("The current selection is: " +e.currentanime);

      e.currentanime.draw(e.Bx, e.By);
    }
  }
Esempio n. 13
0
  /**
   * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer,
   *     org.newdawn.slick.Graphics)
   */
  @Override
  public void render(GameContainer container, Graphics g) throws SlickException {
    g.scale(2, 2);
    g.fillRect(0, 0, 800, 600, back, 0, 0);
    g.resetTransform();

    g.drawImage(image, 100, 100);
    image.draw(100, 200, 80, 200);

    font.drawString(100, 200, "Text Drawn before the callable");

    SlickCallable callable =
        new SlickCallable() {
          @Override
          protected void performGLOperations() throws SlickException {
            renderGL();
          }
        };
    callable.call();

    homer.draw(450, 250, 80, 200);
    font.drawString(150, 300, "Text Drawn after the callable");
  }
 @Override
 public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {
   Vector2f pos = owner.getPosition();
   anim.draw(pos.x, pos.y);
 }
Esempio n. 15
0
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

    counter += delta;

    Input input = gc.getInput();

    float fdelta = delta * Player.speed;

    Player.setpdelta(fdelta);

    double rightlimit = (forestMap.getWidth() * SIZE) - (SIZE * 0.75);

    // System.out.println("Right limit: " + rightlimit);

    float projectedright = Player.x + fdelta + SIZE;

    boolean cangoright = projectedright < rightlimit;

    // there are two types of fixes. A kludge and a hack. This is a kludge.

    if (input.isKeyDown(Input.KEY_UP)) {

      sprite = proup;

      float fdsc = (float) (fdelta - (SIZE * .15));

      if (!(isBlocked(Player.x, Player.y - fdelta)
          || isBlocked((float) (Player.x + SIZE + 1.5), Player.y - fdelta))) {

        sprite.update(delta);

        // The lower the delta the slower the sprite will animate.

        Player.y -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_DOWN)) {

      sprite = prodown;

      if (!isBlocked(Player.x, Player.y + SIZE + fdelta)
          || !isBlocked(Player.x + SIZE - 1, Player.y + SIZE + fdelta)) {

        sprite.update(delta);

        Player.y += fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_LEFT)) {

      sprite = proleft;

      if (!(isBlocked(Player.x - fdelta, Player.y)
          || isBlocked(Player.x - fdelta, Player.y + SIZE - 1))) {

        sprite.update(delta);

        Player.x -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_RIGHT)) {

      sprite = proright;

      // the boolean-kludge-implementation

      if (cangoright
          && (!(isBlocked(Player.x + SIZE + fdelta, Player.y)
              || isBlocked(Player.x + SIZE + fdelta, Player.y + SIZE - 1)))) {

        sprite.update(delta);

        Player.x += fdelta;
      } // else { System.out.println("Right limit reached: " +
      // rightlimit);}

    }

    Player.rect.setLocation(Player.getplayershitboxX(), Player.getplayershitboxY());

    for (itemwin w : stuffwin) {

      if (Player.rect.intersects(w.hitbox)) {
        // System.out.println("yay");
        if (w.isvisible) {
          w.isvisible = false;
          makevisible();
          sbg.enterState(3, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
        }
      }
    }
    for (Enemy m : monster) {

      if (Player.rect.intersects(m.ahitbox)) {
        // System.out.println("yay");
        if (m.isvisible) {

          Player.health -= 1000;
        }
      }
    }

    Player.health = 1000;
    if (Player.health <= 0) {
      makevisible();
      sbg.enterState(2, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    }
  }
Esempio n. 16
0
  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;
  }
Esempio n. 17
0
  @Override
  public void init(GameContainer container) throws SlickException {
    try {
      worldMusic = sound.addSoundToMap("World", "res/Sound/World.wav", sid.getMusicID(0));
      playerAttackSound = sound.addSoundToMap("Attack", "res/Sound/Shoot.wav", sid.getAttackID(0));
      bossAttackSound =
          sound.addSoundToMap("Attack", "res/Sound/Boss_attack.wav", sid.getAttackID(1));
      collisionSound =
          sound.addSoundToMap("Collision", "res/Sound/Collide.wav", sid.getEffectID(0));

    } catch (MalformedURLException e1) {
      e1.printStackTrace();
    }
    sound.loopSound(worldMusic);

    Image[] movementUp = {
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png")
    };

    Image[] movementDown = {
      new Image("res/Character1_frontanimation-frame-1.png"),
      new Image("res/Character1_frontanimation-frame-2.png"),
      new Image("res/Character1_frontanimation-frame-3.png"),
      new Image("res/Character1_frontanimation-frame-4.png"),
      new Image("res/Character1_frontanimation-frame-5.png"),
      new Image("res/Character1_frontanimation-frame-6.png"),
      new Image("res/Character1_frontanimation-frame-7.png"),
      new Image("res/Character1_frontanimation-frame-8.png")
    };

    Image[] movementRight = {
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png")
    };

    Image[] movementLeft = {
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png")
    };

    int duration[] = {100, 100, 100, 100, 100, 100, 100, 100};
    up = new Animation(movementUp, duration, false);
    down = new Animation(movementDown, duration, false);
    left = new Animation(movementLeft, duration, false);
    right = new Animation(movementRight, duration, false);
    Animation[] animList = {up, down, left, right};
    Animation[] bossAnim = {up.copy(), down.copy(), left.copy(), right.copy()};
    player = new Player(new Vector2d(10 * SIZE, 10 * SIZE), animList);
    player.setAttackSound(playerAttackSound);
    entity = new Boss(new Vector2d(25 * SIZE, 25 * SIZE), bossAnim, player);
    entity.setProjectileList(projectiles);
    entity.setAttackSound(bossAttackSound);
    player.setCurrentBoss(entity);

    tileMap = new TiledMap("res/tilemap.tmx");
    blocked = new boolean[tileMap.getWidth()][tileMap.getHeight()];
    try {
      this.initAbilities();
    } catch (IOException e) {
      e.printStackTrace();
    }
    for (int x = 0; x < tileMap.getWidth(); x++) {
      for (int y = 0; y < tileMap.getHeight(); y++) {
        int ID = tileMap.getTileId(x, y, 0);
        String value = tileMap.getTileProperty(ID, "blocked", "false");
        if ("true".equals(value)) {
          blocked[x][y] = true;
        }
      }
    }
  }
Esempio n. 18
0
  @Override
  public void render(GameContainer gameContainer, StateBasedGame stateBasedGame, Graphics graphics)
      throws SlickException {
    background.draw(0, 0);
    tandwiel1.draw(
        -tandwiel1.getWidth() / 2,
        AsaGame.SOURCE_RESOLUTION.height / 2 - tandwiel1.getHeight() / 2);
    tandwiel2.draw(
        tandwiel1.getWidth() / 2 - tandwielOffset - 40,
        AsaGame.SOURCE_RESOLUTION.height / 2 - tandwiel2.getHeight());

    graphics.setFont(fontBlack);

    if (baseImage != null) {
      webcamFeed
          .getSubImage(80, 0, 480, 480)
          .draw(center.getWidth() - ((500) / 2), center.getHeight() - (500 / 2), 500, 500);
      background_spinner_half.draw(
          center.getWidth() - background_spinner.getWidth() / 2, center.getHeight() + 45);
    } else {
      background_spinner.draw(
          center.getWidth() - background_spinner.getWidth() / 2,
          center.getHeight() - background_spinner.getHeight() / 2);
    }

    if (mode == 1) {
      spinner.draw(
          center.getWidth() - spinner.getWidth() / 2, center.getHeight() - spinner.getHeight() / 2);
      spinneroverlay.draw(
          center.getWidth() - spinner.getWidth() / 2, center.getHeight() - spinner.getHeight() / 2);
      selectImage.draw(center.getWidth() / 2 - 20, 60);
      choise.draw(
          choise.getWidth() * 0.15f,
          center.getHeight() * 2 - choise.getHeight() * 1.6f,
          pulseScale);
      for (int i = 0; i < wheelOptions.size(); i++) {
        float offsetDegree = 360 / wheelOptions.size();
        float degrees = (270 + ((rotation + rotationDelta) % 360 + offsetDegree * i) % 360) % 360;
        if (degrees < 0) {
          degrees = degrees + 360;
        }
        float rad = (float) (degrees * (Math.PI / 180));
        float radius = 313;

        float x = (float) (center.getWidth() + radius * Math.cos(rad));
        float y = (float) (center.getHeight() + radius * Math.sin(rad));

        WheelOptionYesNo option = wheelOptions.get(i);
        Image optionIcon = option.getIcon();

        float biggerThanDegrees = 270 + (offsetDegree / 2);
        if (biggerThanDegrees > 360) {
          biggerThanDegrees = biggerThanDegrees - 360;
        }

        if (degrees >= 270 - (offsetDegree / 2) && degrees < biggerThanDegrees) {
          x = x - (float) (optionIcon.getWidth() * 1.3 / 2);
          y = y - (float) (optionIcon.getHeight() * 1.3 / 2);
          option.getIcon().draw(x, y, (float) 1.3);
        } else {
          x = x - (float) (optionIcon.getWidth() * 1 / 2);
          y = y - (float) (optionIcon.getHeight() * 1 / 2);
          option.getIcon().draw(x, y);
        }

        if (degrees >= 270 - (offsetDegree / 2) && degrees < biggerThanDegrees) {
          selectedOption = i;
        }
      }
    } else {
      lens.draw(center.getWidth() - (550 / 2), center.getHeight() - (550 / 2));
      spinner.draw(
          center.getWidth() - spinner.getWidth() / 2, center.getHeight() - spinner.getHeight() / 2);
      spinneroverlay.draw(
          center.getWidth() - spinner.getWidth() / 2, center.getHeight() - spinner.getHeight() / 2);
      if (drawCountdown) {
        countdown.draw(center.getWidth() - 75, center.getHeight() + 75, 150, 150);
      }
    }
  }
  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();
  }
Esempio n. 20
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);
  }
  public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    camera.centerOn((int) Player.x, (int) Player.y);

    camera.drawMap();

    camera.translateGraphics();

    // it helps to add status reports to see what's going on

    // but it gets old quickly

    // System.out.println("Current X: " +player.x + " \n Current Y: "+ y);

    sprite.draw((int) Player.x, (int) Player.y);

    // g.drawString("x: " + (int)player.x + "y: " +(int)player.y , player.x, player.y - 10);

    // g.drawString("Health: " + Player.health/1000, camera.cameraX + 10,
    //		camera.cameraY + 10);

    g.drawString("speed: " + (int) (Player.speed * 10), camera.cameraX + 10, camera.cameraY + 25);
    // doesn't actually count HELP
    g.drawString("bone: " + (int) (Player.Counter * 1), camera.cameraX + 10, camera.cameraY + 10);

    // g.draw(player.rect);

    g.drawString("time passed: " + counter / 1000, camera.cameraX + 600, camera.cameraY);
    // moveenemies();

    // for (Item i : stuff) {
    //	if (i.isvisible) {
    //		i.currentImage.draw(i.x, i.y);
    // draw the hitbox
    // g.draw(i.hitbox);

    //		}
    //	}

    /* for (Ninja n : dojo) {
    	if (n.isvisible) {
    		n.currentImage.draw(n.x, n.y);
    		// draw the hitbox
    		g.draw(n.hitbox);

    	}
    }
                  */
    for (Bone b : doghouse) {
      if (b.isvisible) {
        b.currentImage.draw(b.x, b.y);
        // draw the hitbox
        // g.draw(b.hitbox);

      }
    }

    // stormy.currentImage.draw(stormy.x,stormy.y);
    // daniel.currentImage.draw(daniel.x,daniel.y);

    //	for (Item1 h : stuff1) {
    //		if (h.isvisible) {
    //			h.currentImage.draw(h.x, h.y);
    // draw the hitbox
    // g.draw(h.hitbox);

    //		}
    //	}

    for (Enemy e : bonez) {
      if (e.isAlive) {
        e.currentanime.draw(e.Bx, e.By);
        // draw the hitbox
        // g.draw(e.hitbox);

      }
    }
    //		for (Itemwin w: stuffwin) {
    //			if (w.isvisible) {
    //				w.currentImage.draw(w.x, w.y);
    // draw the hitbox
    // g.draw(w.hitbox);

    //			}
    //		}

  }
Esempio n. 22
0
  // This method draws when player is still
  public void drawMovingNoPlayerMov(int x_tile_dist, int y_tile_dist, Graphics g) {
    // System.out.println(getMoving());
    // System.out.println(inputDelta);

    float part = (float) getInputDelta() / (float) getSpeed();
    int offset = (int) (part * Map.SIZE_OF_TILE);

    // System.out.println(part);
    // System.out.println(offset);

    int x_move = ((Player.getPlayerXCenter() + x_tile_dist) * Map.SIZE_OF_TILE) + Map.X_OFFSET;
    int y_move = ((Player.getPlayerYCenter() + y_tile_dist) * Map.SIZE_OF_TILE) + Map.Y_OFFSET;

    int tile = Map.SIZE_OF_TILE;

    int actual_x = 0;
    int actual_y = 0;
    switch (getMoving()) {
      case 1:
        // anim.draw(x_move+tile-offset, y_move+offset-tile);
        actual_x = x_move + tile - offset;
        actual_y = y_move + offset - tile;
        break;
      case 2:
        // anim.draw(x_move, y_move+offset-tile);
        actual_x = x_move;
        actual_y = y_move + offset - tile;
        break;
      case 3:
        // anim.draw(x_move-tile+offset, y_move+offset-tile);
        actual_x = x_move - tile + offset;
        actual_y = y_move + offset - tile;
        break;
      case 4:
        // anim.draw(x_move+tile-offset, y_move);
        actual_x = x_move + tile - offset;
        actual_y = y_move;
        break;
      case 6:
        // anim.draw(x_move-tile+offset, y_move);
        actual_x = x_move - tile + offset;
        actual_y = y_move;
        break;
      case 7:
        // anim.draw(x_move+tile-offset, y_move+tile-offset);
        actual_x = x_move + tile - offset;
        actual_y = y_move + tile - offset;
        break;
      case 8:
        // anim.draw(x_move, y_move+tile-offset);
        actual_x = x_move;
        actual_y = y_move + tile - offset;
        break;
      case 9:
        // anim.draw(x_move-tile+offset, y_move+tile-offset);
        actual_x = x_move - tile + offset;
        actual_y = y_move + tile - offset;
        break;
    }

    anim.draw(actual_x, actual_y);

    if (attacked) {
      g.setColor(RED);
      g.drawRect(actual_x, actual_y, Map.SIZE_OF_TILE, Map.SIZE_OF_TILE);
      g.setColor(BLACK);
    }

    getStatus().drawMoveMonster(actual_x, actual_y);
  }
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

    counter += delta;

    Input input = gc.getInput();

    float fdelta = delta * Player.speed;

    Player.setpdelta(fdelta);

    double rightlimit = (grassMap.getWidth() * SIZE) - (SIZE * 0.75);

    // System.out.println("Right limit: " + rightlimit);

    float projectedright = Player.x + fdelta + SIZE;

    boolean cangoright = projectedright < rightlimit;

    // there are two types of fixes. A kludge and a hack. This is a kludge.

    if (input.isKeyDown(Input.KEY_UP)) {

      sprite = up;

      float fdsc = (float) (fdelta - (SIZE * .15));

      if (!(isBlocked(Player.x, Player.y - fdelta)
          || isBlocked((float) (Player.x + SIZE + 1.5), Player.y - fdelta))) {

        sprite.update(delta);

        // The lower the delta the slower the sprite will animate.

        Player.y -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_DOWN)) {

      sprite = down;

      if (!isBlocked(Player.x, Player.y + SIZE + fdelta)
          || !isBlocked(Player.x + SIZE - 1, Player.y + SIZE + fdelta)) {

        sprite.update(delta);

        Player.y += fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_LEFT)) {

      sprite = left;

      if (!(isBlocked(Player.x - fdelta, Player.y)
          || isBlocked(Player.x - fdelta, Player.y + SIZE - 1))) {

        sprite.update(delta);

        Player.x -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_RIGHT)) {

      sprite = right;

      // the boolean-kludge-implementation

      if (cangoright
          && (!(isBlocked(Player.x + SIZE + fdelta, Player.y)
              || isBlocked(Player.x + SIZE + fdelta, Player.y + SIZE - 1)))) {

        sprite.update(delta);

        Player.x += fdelta;
      } // else { System.out.println("Right limit reached: " +
      // rightlimit);}

    }

    Player.rect.setLocation(Player.getplayershitboxX(), Player.getplayershitboxY());

    //		for (Item i : stuff) {
    //
    //			if (Player.rect.intersects(i.hitbox)) {
    //				//System.out.println("yay");
    //				if (i.isvisible) {

    //					Player.health += 10000;
    //					i.isvisible = false;
    //				}

    //			}
    //		}

    /*for (Ninja n : dojo) {

    	if (Player.rect.intersects(n.hitbox)) {
    		//System.out.println("yay");
    		if (n.isvisible) {

    			Player.health += 10000;
    			n.isvisible = false;
    		}

    	}
    }
                          */

    for (Bone b : doghouse) {

      if (Player.rect.intersects(b.hitbox)) {
        // System.out.println("yay");
        if (b.isvisible) {
          Player.speed += .1f;
          b.isvisible = false;
          Player.Counter += 1;
        }
      }

      if (Player.Counter > 10) {
        Bone.Counter = false;
        sbg.enterState(3, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
      }
    }

    /*for (Item1 h : stuff1) {

    	if (Player.rect.intersects(h.hitbox)) {
    		//System.out.println("yay");
    		if (h.isvisible) {

    			Player.speed += .1f;
    			h.isvisible = false;
    		}

    	}
    }
                          */

    //		for (Itemwin w : stuffwin) {

    //			if (Player.rect.intersects(w.hitbox)) {
    //				//System.out.println("yay");
    //				if (w.isvisible) {
    //					w.isvisible = false;
    //					makevisible();
    //					sbg.enterState(3, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    //
    //				}
    //
    //			}
    //		}

    for (Enemy e : bonez) {
      if (e.isAlive) {
        e.move();
      }
    }
    for (Enemy e : bonez) {
      if (e.isAlive) {
        if (Player.rect.intersects(e.rect)) {
          Player.health = 0;
          e.isAlive = true;
          // once they touch the enemy player die
        }
      }
    }

    Player.health -= counter / 1000;
    if (Player.health <= 0) {
      makevisible();
      sbg.enterState(2, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    }
  }