Title stuff
This commit is contained in:
parent
dc80e82281
commit
cf8201075a
5 changed files with 47 additions and 21 deletions
|
|
@ -1,12 +1,11 @@
|
||||||
package com.oitsjustjose.crawlnbrawl;
|
package com.oitsjustjose.crawlnbrawl;
|
||||||
|
|
||||||
import com.oitsjustjose.crawlnbrawl.Entity.Living.EntityMonster;
|
import com.oitsjustjose.crawlnbrawl.Entity.Living.EntityMonster;
|
||||||
import com.oitsjustjose.crawlnbrawl.Entity.Living.EntityPlayer;
|
|
||||||
import com.oitsjustjose.crawlnbrawl.Manager.AudioManager;
|
import com.oitsjustjose.crawlnbrawl.Manager.AudioManager;
|
||||||
import com.oitsjustjose.crawlnbrawl.Manager.SceneManager;
|
import com.oitsjustjose.crawlnbrawl.Manager.SceneManager;
|
||||||
import com.oitsjustjose.crawlnbrawl.Manager.ScreenshotManager;
|
import com.oitsjustjose.crawlnbrawl.Manager.ScreenshotManager;
|
||||||
import com.oitsjustjose.crawlnbrawl.Scene.Dungeon;
|
import com.oitsjustjose.crawlnbrawl.Scene.Dungeon;
|
||||||
import com.oitsjustjose.crawlnbrawl.Scene.GUIButton;
|
import com.oitsjustjose.crawlnbrawl.Scene.Button;
|
||||||
import com.oitsjustjose.crawlnbrawl.Scene.Menu;
|
import com.oitsjustjose.crawlnbrawl.Scene.Menu;
|
||||||
import com.oitsjustjose.crawlnbrawl.Scene.Scene;
|
import com.oitsjustjose.crawlnbrawl.Scene.Scene;
|
||||||
import com.oitsjustjose.crawlnbrawl.Util.Config;
|
import com.oitsjustjose.crawlnbrawl.Util.Config;
|
||||||
|
|
@ -14,6 +13,7 @@ import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
import org.lwjgl.opengl.DisplayMode;
|
import org.lwjgl.opengl.DisplayMode;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.newdawn.slick.Color;
|
||||||
import org.newdawn.slick.opengl.PNGDecoder;
|
import org.newdawn.slick.opengl.PNGDecoder;
|
||||||
import org.newdawn.slick.util.ResourceLoader;
|
import org.newdawn.slick.util.ResourceLoader;
|
||||||
|
|
||||||
|
|
@ -52,8 +52,8 @@ public class Game
|
||||||
public void initGame()
|
public void initGame()
|
||||||
{
|
{
|
||||||
Menu menu = new Menu();
|
Menu menu = new Menu();
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play"), new Dungeon());
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play", new Color(200, 200, 200), new Color(85, 124, 0)), new Dungeon());
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit", new Color(200, 200, 200), new Color(85, 124, 0)), null);
|
||||||
Scene currScene = menu;
|
Scene currScene = menu;
|
||||||
|
|
||||||
while (currScene.go())
|
while (currScene.go())
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import java.awt.FontFormatException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class GUIButton
|
public class Button
|
||||||
{
|
{
|
||||||
private String buttonText;
|
private String buttonText;
|
||||||
private Rectangle box;
|
private Rectangle box;
|
||||||
|
|
@ -25,12 +25,12 @@ public class GUIButton
|
||||||
private TrueTypeFont font;
|
private TrueTypeFont font;
|
||||||
private boolean hovering;
|
private boolean hovering;
|
||||||
|
|
||||||
public GUIButton(int x, int y, int w, int h, String text)
|
public Button(int x, int y, int w, int h, String text)
|
||||||
{
|
{
|
||||||
this(x, y, w, h, text, new Color(0, 0, 0), new Color(0.9F, 0.9F, 0.9F));
|
this(x, y, w, h, text, new Color(0, 0, 0), new Color(0.9F, 0.9F, 0.9F));
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUIButton(int x, int y, int w, int h, String text, Color textColor, Color color)
|
public Button(int x, int y, int w, int h, String text, Color textColor, Color color)
|
||||||
{
|
{
|
||||||
this.box = new Rectangle(x, y, w, h);
|
this.box = new Rectangle(x, y, w, h);
|
||||||
this.buttonText = text;
|
this.buttonText = text;
|
||||||
|
|
@ -171,13 +171,13 @@ public class Dungeon extends SceneLevel
|
||||||
|
|
||||||
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
||||||
{
|
{
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again"), new Dungeon());
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again", new org.newdawn.slick.Color(200, 200, 200), new org.newdawn.slick.Color(85, 124, 0)), new Dungeon());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume"), this);
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume", new org.newdawn.slick.Color(200, 200, 200), new org.newdawn.slick.Color(85, 124, 0)), this);
|
||||||
}
|
}
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit", new org.newdawn.slick.Color(200, 200, 200), new org.newdawn.slick.Color(85, 124, 0)), null);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,46 @@
|
||||||
package com.oitsjustjose.crawlnbrawl.Scene;
|
package com.oitsjustjose.crawlnbrawl.Scene;
|
||||||
|
|
||||||
|
import com.oitsjustjose.crawlnbrawl.Util.FileUtils;
|
||||||
import org.lwjgl.LWJGLException;
|
import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.newdawn.slick.TrueTypeFont;
|
||||||
|
import org.newdawn.slick.util.ResourceLoader;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.font.TextAttribute;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class Menu extends Scene
|
public class Menu extends Scene
|
||||||
{
|
{
|
||||||
private LinkedHashMap<GUIButton, Scene> buttons;
|
private LinkedHashMap<Button, Scene> buttons;
|
||||||
private Scene nextScene;
|
private Scene nextScene;
|
||||||
|
private TrueTypeFont titleFont;
|
||||||
|
|
||||||
public Menu()
|
public Menu()
|
||||||
{
|
{
|
||||||
|
HashMap<TextAttribute, Integer> titleAttributes = new HashMap<>();
|
||||||
|
titleAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File font = new File("natives/justabit.ttf".replace("/", File.separator)).getAbsoluteFile();
|
||||||
|
if (!font.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Font did not exist; copying...");
|
||||||
|
FileUtils.copyStream(ResourceLoader.getResourceAsStream("assets/justabit.ttf"), new File("natives/justabit.ttf".replace("/", File.separator)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(titleAttributes).deriveFont(64F);
|
||||||
|
titleFont = new TrueTypeFont(awtFont, false);
|
||||||
|
}
|
||||||
|
catch (IOException | FontFormatException e)
|
||||||
|
{
|
||||||
|
titleFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 64).deriveFont(titleAttributes).deriveFont(64F), false);
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Mouse.setNativeCursor(null);
|
Mouse.setNativeCursor(null);
|
||||||
|
|
@ -25,7 +52,7 @@ public class Menu extends Scene
|
||||||
buttons = new LinkedHashMap<>();
|
buttons = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addButton(GUIButton button, Scene scene)
|
public void addButton(Button button, Scene scene)
|
||||||
{
|
{
|
||||||
buttons.put(button, scene);
|
buttons.put(button, scene);
|
||||||
}
|
}
|
||||||
|
|
@ -42,15 +69,14 @@ public class Menu extends Scene
|
||||||
GL11.glLoadIdentity();
|
GL11.glLoadIdentity();
|
||||||
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
|
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||||
|
titleFont.drawString((Display.getWidth() / 2) - (titleFont.getWidth("Crawl 'n Brawl") / 2), 64F, "Crawl 'n Brawl", new org.newdawn.slick.Color(0, 123, 124));
|
||||||
updateButtons();
|
updateButtons();
|
||||||
drawButtons();
|
drawButtons();
|
||||||
|
|
||||||
if (Mouse.isButtonDown(0))
|
if (Mouse.isButtonDown(0))
|
||||||
{
|
{
|
||||||
for (GUIButton b : buttons.keySet())
|
for (Button b : buttons.keySet())
|
||||||
{
|
{
|
||||||
if (b.isClicked())
|
if (b.isClicked())
|
||||||
{
|
{
|
||||||
|
|
@ -71,12 +97,11 @@ public class Menu extends Scene
|
||||||
{
|
{
|
||||||
int buttonCount = buttons.keySet().size();
|
int buttonCount = buttons.keySet().size();
|
||||||
|
|
||||||
for (GUIButton b : buttons.keySet())
|
for (Button b : buttons.keySet())
|
||||||
{
|
{
|
||||||
b.update();
|
b.update();
|
||||||
if (Display.wasResized())
|
if (Display.wasResized())
|
||||||
{
|
{
|
||||||
System.out.println("fixing buttons");
|
|
||||||
int x = (Display.getWidth() / 2) - (b.getHitBox().getWidth() / 2);
|
int x = (Display.getWidth() / 2) - (b.getHitBox().getWidth() / 2);
|
||||||
int y = (Display.getHeight() / 2) - (b.getHitBox().getHeight() * buttonCount) - ((buttonCount - buttons.keySet().size()) * 16);
|
int y = (Display.getHeight() / 2) - (b.getHitBox().getHeight() * buttonCount) - ((buttonCount - buttons.keySet().size()) * 16);
|
||||||
b.getHitBox().setLocation(x, y);
|
b.getHitBox().setLocation(x, y);
|
||||||
|
|
@ -87,7 +112,7 @@ public class Menu extends Scene
|
||||||
|
|
||||||
public void drawButtons()
|
public void drawButtons()
|
||||||
{
|
{
|
||||||
for (GUIButton b : buttons.keySet())
|
for (Button b : buttons.keySet())
|
||||||
{
|
{
|
||||||
b.draw();
|
b.draw();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import com.oitsjustjose.crawlnbrawl.Util.FileUtils;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.newdawn.slick.Color;
|
||||||
import org.newdawn.slick.TrueTypeFont;
|
import org.newdawn.slick.TrueTypeFont;
|
||||||
import org.newdawn.slick.opengl.TextureImpl;
|
import org.newdawn.slick.opengl.TextureImpl;
|
||||||
import org.newdawn.slick.util.ResourceLoader;
|
import org.newdawn.slick.util.ResourceLoader;
|
||||||
|
|
@ -121,13 +122,13 @@ public class Surface extends SceneLevel
|
||||||
Menu menu = new Menu();
|
Menu menu = new Menu();
|
||||||
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
if (player == null || player.getState() == EntityPlayer.State.DEAD)
|
||||||
{
|
{
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again"), new Dungeon());
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Play Again", new Color(200, 200, 200), new Color(85, 124, 0)), new Dungeon());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume"), this);
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 64, 128, 32, "Resume", new Color(200, 200, 200), new Color(85, 124, 0)), this);
|
||||||
}
|
}
|
||||||
menu.addButton(new GUIButton((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit"), null);
|
menu.addButton(new Button((Display.getWidth() / 2) - 64, (Display.getHeight() / 2) - 16, 128, 32, "Exit", new Color(200, 200, 200), new Color(85, 124, 0)), null);
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue