Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dusty.legendofZelda.screen;
- import java.util.Random;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
- import com.badlogic.gdx.math.Matrix4;
- import com.dusty.legendofZelda.Art;
- import com.dusty.legendofZelda.Input;
- import com.dusty.legendofZelda.LegendOfZelda;
- public abstract class Screen {
- public int tileFrame = 0;
- protected static Random random = new Random();
- private LegendOfZelda legendofZelda;
- public SpriteBatch spriteBatch;
- public Matrix4 projection = new Matrix4();
- private final String[] chars = {
- "ABCDEFGHIJKLMNOP",
- "QRSTUVWXYZabcdef",
- "ghijklmnopqrstuv",
- "wxyz0123456789!?",
- "-., ¿()@#$[]\"^¡<",
- ">'¼¹½¾²©®«»"
- };
- private final String shortchars = "Iil1!.,\"'";
- private final String mediumchars = "r";
- private final String fullchars = "¼¹½¾²©®«»";
- private final String numbers = "0123456789";
- public void removed() {
- spriteBatch.dispose();
- }
- public final void init(LegendOfZelda legendofZelda) {
- this.legendofZelda = legendofZelda;
- projection.setToOrtho(0,LegendOfZelda.GAME_WIDTH,LegendOfZelda.GAME_HEIGHT, 0, -1, 1);
- spriteBatch = new SpriteBatch(2500);
- spriteBatch.setProjectionMatrix(projection);
- }
- protected void setScreen(Screen screen) {
- legendofZelda.setScreen(screen);
- }
- protected void changeScreen(Screen screen) {
- legendofZelda.changeScreen(screen);
- }
- public void draw(TextureRegion region, int x, int y) {
- int width = region.getRegionWidth();
- if (width < 0) width = -width;
- spriteBatch.draw(region, x,y, width,region.getRegionHeight());
- }
- public void drawPart(TextureRegion region, int x, int y, int w,int h) {
- if (w <= 0) return;
- if (h <= 0) return;
- spriteBatch.draw(region,x,y, w,h);
- }
- public void drawAlpha(TextureRegion region, float x, float y,float a) {
- int width = region.getRegionWidth();
- if (width < 0) width = -width;
- spriteBatch.setColor(1,1,1,a);
- spriteBatch.draw(region,x,y, width,region.getRegionHeight());
- spriteBatch.setColor(1,1,1,1);
- }
- public void draw(TextureRegion region, float x, float y) {
- int width = region.getRegionWidth();
- if (width < 0) width = -width;
- spriteBatch.draw(region,(int)x,(int)y,width,region.getRegionHeight());
- }
- public void drawAlpha(TextureRegion region, int x, int y,float a,float scale) {
- int width = region.getRegionWidth();
- if (width < 0) width = -width;
- spriteBatch.setColor(1,1,1,a);
- spriteBatch.draw(region,x + (width/2*(1-scale)),y + (region.getRegionHeight()/2*(1-scale)), width * scale,region.getRegionHeight()*scale);
- spriteBatch.setColor(1,1,1,1);
- }
- public void draw(TextureRegion region, int x, int y,float scale) {
- int width = region.getRegionWidth();
- if (width < 0) width = -width;
- //spriteBatch.draw(region,x - (width/(1-scale)),y - (region.getRegionHeight()*(1-scale)), width * scale,-region.getRegionHeight() * scale);
- //spriteBatch.draw(region,x + (width/2*(1-scale)),y, width * scale,-region.getRegionHeight());
- spriteBatch.draw(region,x + (width/2*(1-scale)),y + (region.getRegionHeight()/2*(1-scale)), width * scale,region.getRegionHeight()*scale);
- }
- public int getTextWidth(String txt) {
- txt = filterText(txt);
- txt = txt.replace("#","");
- txt = txt.replace("#C","");
- int width = 0;
- for (int i = 0; i < txt.length(); i++) {
- char ch = txt.charAt(i);
- for (int ys = 0; ys < chars.length; ys++) {
- int xs = chars[ys].indexOf(ch);
- if (xs >= 0) {
- if (mediumchars.indexOf(ch) >= 0) width += 4;
- else if (fullchars.indexOf(ch) >= 0) width += 8;
- else if (shortchars.indexOf(ch) >= 0) width += 3;
- else width += 6;
- }
- }
- }
- return width;
- }
- public String filterText(String text) {
- text = text.replace("#HEAD","[]");
- text = text.replace("#QUARTER","¼¹");
- text = text.replace("#HALF","½¹");
- text = text.replace("#THIRD","¾²");
- text = text.replace("#FULL","©®");
- text = text.replace("#ARROWDOWN","¡");
- return text;
- }
- public void drawText(String txt,int x, int y) {
- String[] newtxt = txt.split("#N");
- for (int i = 0; i < newtxt.length; i++) {
- newtxt[i] = filterText(newtxt[i]);
- drawTextLine(newtxt[i],x,y+i*16);
- }
- }
- public void drawNumbers(int value,int x, int y,int len) {
- String txt = String.valueOf(value);
- for (int i = 0;i < len;i++) {
- if (txt.length() < len) txt = "0" + txt;
- }
- for (int i = 0; i < txt.length(); i++) {
- char ch = txt.charAt(i);
- int xs = numbers.indexOf(ch);
- if (xs >= 0) spriteBatch.draw(Art.numbers[xs],x + i*6, y);
- }
- }
- public void drawNumbers(int value,int x, int y) {
- String txt = String.valueOf(value);
- drawNumbers(value,x,y,txt.length());
- }
- public void drawTextLine(String txt,int x, int y) {
- boolean center = false;
- if (txt.startsWith("#C")) {
- center = true;
- txt = txt.substring(txt.indexOf("#C")+2);
- }
- if (txt.contains("#")) txt = txt.substring(0,txt.indexOf("#"));
- int drawx = x + (center ? (int)(getTextWidth(txt)/2+4) : 0);
- if (center) drawx = (LegendOfZelda.GAME_WIDTH - getTextWidth(txt))/2;
- for (int i = 0; i < txt.length(); i++) {
- char ch = txt.charAt(i);
- for (int ys = 0; ys < chars.length; ys++) {
- int xs = chars[ys].indexOf(ch);
- if (xs >= 0) {
- spriteBatch.draw(Art.dialog[xs][ys],drawx, y);
- if (mediumchars.indexOf(ch) >= 0) drawx += 4;
- else if (fullchars.indexOf(ch) >= 0) drawx += 8;
- else if (shortchars.indexOf(ch) >= 0) drawx += 3;
- else drawx += 6;
- }
- }
- }
- }
- public abstract void render();
- public void tick(Input input) {
- }
- public void hideInterface() {
- }
- public void showInterface() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement