Package pelletQuest.main

Source Code of pelletQuest.main.PauseState

package pelletQuest.main;

import pelletQuest.entities.Maxim;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
import org.newdawn.slick.util.Log;
import org.newdawn.slick.geom.Vector2f;
import pelletQuest.database.World;
import pelletQuest.map.GameMap;

import pelletQuest.resources.GraphicsManager;
import pelletQuest.resources.Translator;

public class PauseState extends BasicGameState {

  public static final int ID = 2;
  public int getID() { return ID; }
 
  private boolean toggleFullscreen;
  private boolean returnToGame;
  private boolean credits;
  private boolean bigMap;
  private Vector2f mapOffset;
  private int keyDown;
  private int zLocation;
 
  private static String levelsBelowGround, oneBelowGround, levelsAboveGround, oneAboveGround, groundLevel;
 
  public void init(GameContainer container, StateBasedGame game) throws SlickException {
    levelsBelowGround = Translator.convert(" levels below ground");
    oneBelowGround = Translator.convert(" level below ground");
    levelsAboveGround = Translator.convert(" levels above ground");
    oneAboveGround = Translator.convert(" level above ground");
    groundLevel = Translator.convert("Ground level");
  }

  public void enter(GameContainer container, StateBasedGame game) throws SlickException {
    toggleFullscreen = false;
    returnToGame = false;
    credits = false;
    bigMap = false;
    mapOffset = new Vector2f(0,0);
    keyDown = -1;
    zLocation = Maxim.getMaxim().getCurrentMap().getWorldZ();
  }
 
  public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
    game.getState(PlayState.ID).render(container, game, g);
   
    int translateX = 0;
    int translateY = 0;
    if (container.getWidth() > 400) {
      translateX = (container.getWidth()-400)/2;
    }
    if (container.getHeight() > 300) {
      translateY = (container.getHeight()-300)/2;
    }
    g.translate(translateX, translateY);
   
    GraphicsManager.getFadeBar(6).draw(0,0,100);
   
    renderMinimap(g, 25, 80, (int)mapOffset.x, (int)mapOffset.y, translateX, translateY, bigMap, zLocation);
   
    if (Maxim.getMaxim() != null) {
      g.setColor(Color.black);
      g.drawString("Level: "+Maxim.getMaxim().getLevel(), 10-1, 15);
      g.drawString("Pellets Collected: "+Maxim.getMaxim().getPellets(), 10-1, 30);
      g.drawString("Pellets Needed For Next Level: "+Maxim.getMaxim().getPelletsNeeded(), 10-1, 45);
      g.drawString("Press 'c' for credits.", 10-1, 60);
      g.drawString("Level: "+Maxim.getMaxim().getLevel(), 10+1, 15);
      g.drawString("Pellets Collected: "+Maxim.getMaxim().getPellets(), 10+1, 30);
      g.drawString("Pellets Needed For Next Level: "+Maxim.getMaxim().getPelletsNeeded(), 10+1, 45);
      g.drawString("Press 'c' for credits.", 10+1, 60);
     
      g.setColor(Color.white);
      g.drawString("Level: "+Maxim.getMaxim().getLevel(), 10, 15);
      g.drawString("Pellets Collected: "+Maxim.getMaxim().getPellets(), 10, 30);
      g.drawString("Pellets Needed For Next Level: "+Maxim.getMaxim().getPelletsNeeded(), 10, 45);
      g.drawString("Press 'c' for credits.", 10, 60);
    }
   
    g.translate(-translateX, -translateY);
  }
 
  private void renderMinimap (Graphics g, int x, int y, int offsetX, int offsetY, int translateX, int translateY, boolean big, int zPosition) {
    g.setClip(x+translateX, y+translateY, 350, 200);
   
    shadeMinimapArea(0, x, y);
   
    int xPosition = Maxim.getMaxim().getCurrentMap().getWorldX();
    int yPosition = Maxim.getMaxim().getCurrentMap().getWorldY();
   
    GameMap[] maps = World.getMaps();
   
    int xPos = 150+x+offsetX;
    int yPos = 84+y+offsetY;
   
    for (int i=zPosition-5; i < zPosition; i++) {
      for (GameMap m : maps) {
        if (m.getWorldZ() == i) {
          int difference = (zPosition - m.getWorldZ())*3;
          if (big) {
            m.renderMinimap(g, (m.getWorldX()-xPosition)*50+xPos-(2*difference), (m.getWorldY()-yPosition)*32+yPos+(2*difference));
          } else {
            m.renderPixelmap(g, (m.getWorldX()-xPosition)*25+13+xPos-difference, (m.getWorldY()-yPosition)*16+yPos+8+difference);
          }
        }
      }
      shadeMinimapArea(7, x, y);
    }
   
    for (GameMap m : maps) {
      if (m.getWorldZ() == zPosition) {
        if (big) {
          GraphicsManager.getHighlights(big, false).draw((m.getWorldX()-xPosition)*50+1+xPos, (m.getWorldY()-yPosition)*32+yPos+1);
        } else {
          GraphicsManager.getHighlights(big, false).draw((m.getWorldX()-xPosition)*25+13+xPos, (m.getWorldY()-yPosition)*16+yPos+8);
        }
      }
    }
   
    for (GameMap m : maps) {
      if (m.getWorldZ() == zPosition) {
        if (big) {
          m.renderMinimap(g, (m.getWorldX()-xPosition)*50+xPos, (m.getWorldY()-yPosition)*32+yPos);
        } else {
          m.renderPixelmap(g, (m.getWorldX()-xPosition)*25+xPos+13, (m.getWorldY()-yPosition)*16+yPos+8);
        }
      }
    }
   
    if (Maxim.getMaxim().getCurrentMap().getWorldZ() == zPosition) {
      if (big) {
        GraphicsManager.getHighlights(big, true).draw(xPos+1, yPos+1);
      } else {
        GraphicsManager.getHighlights(big, true).draw(xPos+13, yPos+8);
      }
    }
   
    if (zPosition < -1) {
      g.drawString(""+(-zPosition)+levelsBelowGround, x, y);
    } else if (zPosition < 0) {
      g.drawString(""+(-zPosition)+oneBelowGround, x, y);
    } else if (zPosition > 1) {
      g.drawString(""+zPosition+levelsAboveGround, x, y);
    } else if (zPosition > 0) {
      g.drawString(""+zPosition+oneAboveGround, x, y);
    } else {
      g.drawString(groundLevel, x, y);
    }
   
    g.clearClip();
  }
 
  private void shadeMinimapArea (int transparency, int x, int y) {
    GraphicsManager.getFadeBar(transparency).draw(0+x,0+y,50);
    GraphicsManager.getFadeBar(transparency).draw(200+x,0+y,25);
    GraphicsManager.getFadeBar(transparency).draw(200+x,100+y,25);
    GraphicsManager.getFadeBar(transparency).draw(300+x,0+y,12.5f);
    GraphicsManager.getFadeBar(transparency).draw(300+x,50+y,12.5f);
    GraphicsManager.getFadeBar(transparency).draw(300+x,100+y,12.5f);
    GraphicsManager.getFadeBar(transparency).draw(300+x,150+y,12.5f);
  }

  public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
    if (toggleFullscreen) {
      try {
        ((AppGameContainer)container).setFullscreen(!((AppGameContainer)container).isFullscreen());
      } catch (Exception e) { Log.error(e); }
      toggleFullscreen = false;
     
      container.setMouseGrabbed(((AppGameContainer)container).isFullscreen());
    }
   
    if (returnToGame) {
      game.enterState(PlayState.ID);
      return;
    }
   
    if (credits) {
      CreditsState.returnToWhenDone(ID);
      game.enterState(CreditsState.ID);
      return;
    }
   
    if (keyDown != -1) {
      if (keyDown == 200) {
        mapOffset.y ++;
      } else if (keyDown == 203) {
        mapOffset.x ++;
      } else if (keyDown == 208) {
        mapOffset.y --;
      } else if (keyDown == 205) {
        mapOffset.x --;
      }
    }
  }
 
  public void keyPressed (int key, char c) {
    if (key == 1 || key == 57) {
      returnToGame = true;
    }
   
    if (c == 'f') {
      toggleFullscreen = true;
     
    } else if (c == 'c') {
      credits = true;
    } else if (c == 'z') {
      bigMap = !bigMap;
    } else if (c == 'q') {
      zLocation ++;
    } else if (c == 'a') {
      zLocation --;
    } else {
      keyDown = key;
    }
  }
 
  public void keyReleased (int key, char c) {
    keyDown = -1;
  }

}
TOP

Related Classes of pelletQuest.main.PauseState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.