Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package system;
- import org.newdawn.slick.Color;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.SlickException;
- import core.MyWorld;
- import entities.TwilightSparkle;
- public class WorldUI {
- //мир, которому принадлежит интерфейс
- MyWorld parent;
- //нижняя панель
- protected Image bottomBar;
- protected Image battleBottomBar;
- //верхняя панель
- protected Image topBar;
- //полосы жизни, и очков магии
- protected Image HP;
- protected Image IP;
- //относительные координаты интерфейса
- float interfaceX = 0;
- float interfaceY = 0;
- private boolean debug;
- public WorldUI(MyWorld parent, GameContainer container) {
- this.parent = parent;
- interfaceX = (container.getWidth() - parent.twilie.hitboxWidth)/2;
- interfaceY = (container.getHeight() - parent.twilie.hitboxHeight)/2;
- }
- public void init() throws SlickException {
- topBar = new Image("textures/topBar.png");
- bottomBar = new Image("textures/Interface2.png");
- battleBottomBar = new Image("textures/Interface3.png");
- HP = new Image("textures/IP.png");
- IP = new Image("textures/HP.png");
- }
- public void draw(Graphics g) {
- //жизнь и мана
- HP.draw(interfaceX+100, interfaceY+parent.container.getHeight()-90);//520
- IP.draw(interfaceX+100, interfaceY+parent.container.getHeight()-50);//560
- //верхняя и нижняя рамка интерфейса
- topBar.draw(interfaceX, interfaceY);
- bottomBar.draw(interfaceX, interfaceY+parent.container.getHeight()-128);
- //Отладка
- if(debug) {
- g.setColor(Color.red);
- g.drawString(this.toString(), interfaceX+parent.container.getWidth()/2, interfaceY+20);
- }
- }
- public void update() {
- System.out.println("--- updates! ---");
- //полезные переменные для сокращения кода
- TwilightSparkle pony = MyWorld.twilie;
- int worldWidth = parent.width;
- int worldHeight = parent.height;
- int screenWidth = parent.container.getWidth();
- int screenHeight = parent.container.getHeight();
- int halfOfScreenWidth = (screenWidth - pony.hitboxWidth)/2;
- int halfOfScreenHeight = (screenHeight - pony.hitboxHeight)/2;
- //если мы не достигли границ экрана, то координаты интерфейса следуют за лошадью
- float halfOfPonyPositionX = pony.x - halfOfScreenWidth;
- float halfOfPonyPositionY = pony.y - halfOfScreenHeight;
- if(debug) {
- System.out.println("worldWidth = "+worldWidth);
- System.out.println("worldHeight = "+worldHeight);
- System.out.println("halfOfScreenWidth = "+halfOfScreenWidth);
- System.out.println("halfOfScreenHeight = "+halfOfScreenHeight);
- System.out.println();
- System.out.println("interfaceX = " + interfaceX);
- System.out.println("interfaceY = " + interfaceY);
- System.out.println("halfOfPonyPositionX > halfOfScreenWidth = "+(halfOfPonyPositionX > halfOfScreenWidth ));
- System.out.println("halfOfPonyPositionX + screenWidth < worldWidth = "+(halfOfPonyPositionX + screenWidth < worldWidth));
- System.out.println("halfOfPonyPositionY > halfOfScreenHeight = "+(halfOfPonyPositionY > halfOfScreenHeight));
- System.out.println("halfOfPonyPositionY + screenHeight < worldHeight = "+(halfOfPonyPositionY + screenHeight < worldHeight));
- }
- if(halfOfPonyPositionX +100/* + 18*/ > halfOfScreenWidth && halfOfPonyPositionX + screenWidth < worldWidth) {
- interfaceX = halfOfPonyPositionX;
- System.out.println("upd X");
- System.out.println("interfaceX = halfOfPonyPositionX = "+(interfaceX));
- }
- if(halfOfPonyPositionY > halfOfScreenHeight /*+ 60*/ && halfOfPonyPositionY + screenHeight < worldHeight) {
- interfaceY = halfOfPonyPositionY;
- System.out.println("upd Y");
- System.out.println("interfaceY = halfOfPonyPositionY = "+(interfaceY));
- }
- }
- public void debug(boolean debug) {
- this.debug = debug;
- }
- @Override
- public String toString() {
- StringBuilder log = new StringBuilder("--- Interface Log ---");
- log.append("\n"+"interfaceX = " + interfaceX);
- log.append("\n"+"interfaceY = " + interfaceY);
- log.append("\n"+"halfOfScreenWidth = " + parent.container.getWidth()/2);
- log.append("\n"+"halfOfScreenHeight = " + parent.container.getHeight()/2);
- log.append("\n"+"Twi X = " + parent.twilie.x);
- log.append("\n"+"Twi Y = " + parent.twilie.y);
- log.append( "\n"+"worldWidth = " + parent.width);
- log.append( "\n"+"screenHeight = " + parent.height);
- return log.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement