Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.Input;
- import org.newdawn.slick.SlickException;
- import org.newdawn.slick.state.BasicGameState;
- import org.newdawn.slick.state.StateBasedGame;
- import user.Main;
- public class Map extends BasicGameState {
- private int id;
- public Map(int id){
- this.id = id;
- }
- @Override
- public int getID() {
- return id;
- }
- @Override
- public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
- }
- @Override
- public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
- int GridX = Main.getInstance().getGrid().getX();
- int GridY = Main.getInstance().getGrid().getY();
- int ScreenX = Main.app.getWidth();
- int ScreenY = Main.app.getHeight();
- if(ScreenX > ScreenY){
- ScreenX = ScreenY;
- } else{
- ScreenY = ScreenX;
- }
- int RatioX = ScreenX / GridX;
- int RatioY = ScreenY / GridY;
- if(RatioX > RatioY){
- RatioX = RatioY;
- } else {
- RatioY = RatioX;
- }
- for (int i = 0; i < GridX; i++) {
- for (int j = 0; j < GridY; j++) {
- boolean[] walls = Main.getInstance().getGrid().getBlock(i, j).getWalls();
- if (walls[0] == true) {
- g.drawLine(RatioX * (i + 1) - RatioX, RatioY * (j + 1) - RatioY, RatioX * (i + 1), RatioY * (j + 1) - RatioY);
- }
- if (walls[1] == true) {
- g.drawLine(RatioX * (i + 1) - RatioX, RatioY * (j + 1), RatioX * (i + 1), RatioY * (j + 1));
- }
- if (walls[2] == true) {
- g.drawLine(RatioX * (i + 1) - RatioX, RatioY * (j + 1) - RatioY, RatioX * (i + 1) - RatioX, RatioY * (j + 1));
- }
- if (walls[3] == true) {
- g.drawLine(RatioX * (i + 1), RatioY * (j + 1) - RatioY, RatioX * (i + 1), RatioY * (j + 1));
- }
- }
- }
- g.drawImage(new Image("res/pin.png").getScaledCopy(RatioX, RatioY), Hero.getInstance().getBlockX() * RatioX, Hero.getInstance().getBlockY() * RatioY);
- }
- @Override
- public void update(GameContainer gc, StateBasedGame sbg, int i) throws SlickException {
- Input input = gc.getInput();
- if(!input.isKeyDown(Input.KEY_SPACE)){
- Main.getInstance().enterState(Main.getInstance().getmyOwnCurrentState());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement