diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fb565a5 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..3692a8c --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + MAndEngine + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bin/MAndApps/AppHelper.class b/bin/MAndApps/AppHelper.class new file mode 100644 index 0000000..59aa296 Binary files /dev/null and b/bin/MAndApps/AppHelper.class differ diff --git a/bin/MAndApps/BasicApp.class b/bin/MAndApps/BasicApp.class new file mode 100644 index 0000000..b33fe2c Binary files /dev/null and b/bin/MAndApps/BasicApp.class differ diff --git a/bin/MAndApps/Button.class b/bin/MAndApps/Button.class new file mode 100644 index 0000000..6f314ea Binary files /dev/null and b/bin/MAndApps/Button.class differ diff --git a/bin/MAndApps/ButtonListener.class b/bin/MAndApps/ButtonListener.class new file mode 100644 index 0000000..e30ff24 Binary files /dev/null and b/bin/MAndApps/ButtonListener.class differ diff --git a/bin/MAndApps/Engine.class b/bin/MAndApps/Engine.class new file mode 100644 index 0000000..b58fc87 Binary files /dev/null and b/bin/MAndApps/Engine.class differ diff --git a/bin/MAndApps/ImageCreator.class b/bin/MAndApps/ImageCreator.class new file mode 100644 index 0000000..a19db15 Binary files /dev/null and b/bin/MAndApps/ImageCreator.class differ diff --git a/bin/MAndApps/LogItem.class b/bin/MAndApps/LogItem.class new file mode 100644 index 0000000..ba36531 Binary files /dev/null and b/bin/MAndApps/LogItem.class differ diff --git a/bin/MAndApps/Pointer.class b/bin/MAndApps/Pointer.class new file mode 100644 index 0000000..4e5d0e2 Binary files /dev/null and b/bin/MAndApps/Pointer.class differ diff --git a/bin/MAndApps/Variable$1.class b/bin/MAndApps/Variable$1.class new file mode 100644 index 0000000..8862777 Binary files /dev/null and b/bin/MAndApps/Variable$1.class differ diff --git a/bin/MAndApps/Variable.class b/bin/MAndApps/Variable.class new file mode 100644 index 0000000..16fb5f5 Binary files /dev/null and b/bin/MAndApps/Variable.class differ diff --git a/bin/MAndApps/VariableNotFoundException.class b/bin/MAndApps/VariableNotFoundException.class new file mode 100644 index 0000000..48f41fc Binary files /dev/null and b/bin/MAndApps/VariableNotFoundException.class differ diff --git a/src/MAndApps/AppHelper.java b/src/MAndApps/AppHelper.java new file mode 100644 index 0000000..4db6ba1 --- /dev/null +++ b/src/MAndApps/AppHelper.java @@ -0,0 +1,117 @@ +package MAndApps; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * also a bit of an app helper class thing + * well... i renamed it so, now it just is an app helper class thing. + * @author Marcus + * + */ +public class AppHelper implements Runnable{ + + private static String[] namesLookupTable; + private static String[] classNamesLookupTable; + + private BasicApp[] apps; + private boolean done = false; + private int progress = 0; + private int TOTAL_PROGRESS = 1; + + private String[] classes; + + public AppHelper(String[] classes) { + this.classes = classes; + } + + public void run() { + ArrayList apps = new ArrayList(); + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + + try{ + + + for(int i = 0; i < classes.length; i ++) { + String str = classes[i]; + + Class _class = classLoader.loadClass(str); + Object obj = _class.newInstance(); + + //if it actually is one of us, repeatedly say one of us... + //one of us... + //one of us... + if(obj instanceof BasicApp) { + apps.add((BasicApp)(obj)); + } + progress++; + } + + this.apps = new BasicApp[apps.size()]; + + for(int i = 0; i < this.apps.length; i ++) { + this.apps[i] = apps.get(i); + } + + classNamesLookupTable = new String[this.apps.length]; + namesLookupTable = new String[this.apps.length]; + for(int i = 0; i < this.apps.length; i ++) { + + classNamesLookupTable[i] = classes[i]; + namesLookupTable[i] = this.apps[i].getTitle(); + + } + //progress = 1; + done = true; + }catch(Exception e) { + + e.printStackTrace(); + + System.exit(1); + } + } + + public BasicApp[] getApps(){ + return apps; + } + + public boolean getDone(){ + return done; + } + + public double getProgress(){ + return (double)progress/TOTAL_PROGRESS; + } + + public static int getIDbyClass(String className) { + for(int i = 0; i < namesLookupTable.length; i ++) { + if(namesLookupTable[i].equalsIgnoreCase(className)){ + + return i; + + } + } + return -1; + } + + /** + * iterative method, probs shouldn't call this during a + * tick or something. like do it in a thread during a splash screen + * or something. + * @param appName + * @return + */ + public static int getIDbyName(String appName) { + for(int i = 0; i < namesLookupTable.length; i ++) { + if(namesLookupTable[i].equals(appName)){ + + return i; + + } + } + return -1; + } +} diff --git a/src/MAndApps/BasicApp.java b/src/MAndApps/BasicApp.java new file mode 100644 index 0000000..d740bf8 --- /dev/null +++ b/src/MAndApps/BasicApp.java @@ -0,0 +1,95 @@ +package MAndApps; + +import java.awt.*; +import java.awt.event.KeyEvent; +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import javax.imageio.ImageIO; + +/** + * constructor should initialize nothing it shouldn't have to + * because it will be initialized before the main menu is displayed. + * and before the main menu is displayed some variables and such may give + * weird values as they are all changing. + * preferably, everything should be initialized in the initialize method.

+ * please do not implement a game loop in any of these methods. + * the tick and render take care of that. + */ +public abstract interface BasicApp { + + /** + * will only get called when setting the window dimension. + * otherwise, is stored in main temporarily. (avoiding + * creating 30+ objects per second...) + */ + public abstract Dimension getResolution(); + + /** + * the proper place to do initialization + * note: THIS WILL BE CALLED MULTIPLE TIMES. + * SO KEEP TRACK OF THAT. + * if you want you app to work with multitasking + * make sure to deal with this correctly. + */ + public abstract void initialize (); + + /** + * resume from a pause, called after initialization + */ + public abstract void resumeApp (); + + /** + * do anything that needs to be done to put the app on pause for a moment. + * only called when exiting and switching to another app. + */ + public abstract void pauseApp(); + + /** + * method for applying any ticking logic + */ + public abstract void tick(); + + /** + * to render things to a canvas + * @param g + */ + public abstract void render(Graphics2D g); + + public abstract void keyPressed(KeyEvent e); + public abstract void keyReleased(KeyEvent e); + + /** + * return the title of the app to be displayed in the + * top of the screen and on the home menu. + */ + public abstract String getTitle(); + + /** + * color of outline of app title border. + * @return + */ + public abstract Color getColor(); + + /** + * the framerate that this should be run at. + * @return + */ + public abstract int getFramerate(); + + /** + * should this window be resizable + * @return + */ + public abstract boolean getResizable(); + + /** + * answers the question if this app should be displayed in the menu + * useful for apps like ... the menu. or maybe you want to + * link your app to another, you can do that too. just + * make sure they're both installed! + * @return + */ + public abstract boolean visibleInMenu(); +} \ No newline at end of file diff --git a/src/MAndApps/Button.java b/src/MAndApps/Button.java new file mode 100644 index 0000000..a15abd2 --- /dev/null +++ b/src/MAndApps/Button.java @@ -0,0 +1,195 @@ +package MAndApps; + + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.image.BufferedImage; + +import static MAndApps.Engine.mouseX; +import static MAndApps.Engine.mouseY; +import static MAndApps.Engine.mouse; + +public class Button { + private int clickLevel = 0; + private Image normal, hover, down; + private int x, y, width, height; + private int clicks = 0; + private int leftPadding, bottomPadding; + private String text; + private static final int DEPTH_ON_CLICK = 7; + private double depth = DEPTH_ON_CLICK, desiredDepth = DEPTH_ON_CLICK; + private int ID; + private boolean active; + + private static final int shadowOffset = 10; + private static boolean debug = false; + + public static void setDebug(boolean debug) { + Button.debug = debug; + } + + public Button(int id, Color c, int x, int y, int width, int height, String text, int leftPadding, int bottomPadding) { + this(id, c, x, y, width, height, text, leftPadding, bottomPadding, true); + } + + public Button(int id, Color c, int x, int y, int width, int height, String text, int leftPadding, int bottomPadding, boolean active) { + + this.x = x; + this.y = y; + this.width = width; + this.height = height; + + normal = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); + hover = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); + down = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); + + normal = ImageCreator.createImageCloud(width, height, c); + hover = ImageCreator.createImageCloud(width, height, c.brighter()); + down = ImageCreator.createImageCloud(width, height, c.darker()); + + this.text = text; + this.leftPadding = leftPadding; + this.bottomPadding = bottomPadding; + + this.ID = id; + + this.active = active; + } + + public void poll() { + + if (active) { + // figure out the new click level of the button and add a click if + // we clicked it + if (clickLevel == 0) { + if (inBoundingBox(mouseX, mouseY) && !mouse) { + clickLevel = 1; + } + } else if (clickLevel == 1) { + if (inBoundingBox(mouseX, mouseY) && mouse) { + clickLevel = 2; + } else { + if (!inBoundingBox(mouseX, mouseY)) { + clickLevel = 0; + } + } + } else if (clickLevel == 2) { + if (inBoundingBox(mouseX, mouseY) && !mouse) { + clickLevel = 1; + clicks++; + + } else if (!inBoundingBox(mouseX, mouseY)) { + clickLevel = 3; + } + } else if (clickLevel == 3) { + if (!mouse) { + clickLevel = 0; + } else { + if (inBoundingBox(mouseX, mouseY)) { + clickLevel = 2; + } + } + } + }else{ + clickLevel = 4; + } + // uh... UIFM + desiredDepth = clickLevel == 1 ? 0 : clickLevel == 2 ? DEPTH_ON_CLICK * 2 : DEPTH_ON_CLICK; + depth += ((desiredDepth - depth) / 4d); + } + + public boolean hasNextClick() { + if (clicks > 0) { + clicks--; + return true; + } else + return false; + } + + public void render(Graphics2D g) { + + // draw shadow + + // set color to black + g.setColor(Color.BLACK); + + // set alpha for draw + AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); + g.setComposite(composite); + + // draw + g.fillRect(x + shadowOffset - (int)((depth - 10)/2d), y + shadowOffset, width, height); + + // reset alpha + composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f); + g.setComposite(composite); + + // depending on the click level, draw the corresponding representative + // image + // tightened that up a bit by making the image an in line if + g.drawImage((clickLevel == 1 ? hover : (clickLevel == 2 || clickLevel == 4) ? down : normal), x + (int) (depth - DEPTH_ON_CLICK), y + (int) (depth - DEPTH_ON_CLICK), null); + + // where to put the text + // edit: + // okay seriously this makes no sense. + // FIX! i don't know what to fix though, its THAT borked. + // edit: + // FIXED! FUCK IT! I REMOVED IT ALL! + + // see that code ^^^^^^^ + // no? + // good. + // so i decided to bring it back... xD im not quite sure + // what was here but... text is going here now so :P + g.setColor(Color.BLACK); + g.drawString(text, x + leftPadding + (int) (depth - DEPTH_ON_CLICK), y - bottomPadding + height + (int) (depth - DEPTH_ON_CLICK)); + + // because depth is complicated, thats why. + if (debug) { + // render the bounding box... + g.setColor(Color.RED); + int x = this.x + (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + int y = this.y + (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + int width = this.width - (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0) + (depth > DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + int height = this.height - (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0) + (depth > DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + g.drawRect(x, y, width, height); + } + + } + + private boolean inBoundingBox(int mouseX, int mouseY) { + int x = this.x + (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + int y = this.y + (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + int width = this.width - (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0) + (depth > DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + int height = this.height - (depth < DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0) + (depth > DEPTH_ON_CLICK ? (int) (depth - DEPTH_ON_CLICK) : 0); + return (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height); + } + + public void updatePosition(int x, int y) { + this.x = x; + this.y = y; + } + + public void move(int dx, int dy) { + x += dx; + y += dy; + } + + public void resetButtonState() { + clickLevel = 0; + } + + public String getNameID() { + return text.toUpperCase().replace(" ", ""); + } + + public int getID() { + return ID; + } + + public void changeName(String name) { + this.text = name; + } +} diff --git a/src/MAndApps/ButtonListener.java b/src/MAndApps/ButtonListener.java new file mode 100644 index 0000000..2e82146 --- /dev/null +++ b/src/MAndApps/ButtonListener.java @@ -0,0 +1,7 @@ +package MAndApps; + + + +public interface ButtonListener { + public abstract void click(String name, int id); +} diff --git a/src/MAndApps/Engine.java b/src/MAndApps/Engine.java new file mode 100644 index 0000000..885bd21 --- /dev/null +++ b/src/MAndApps/Engine.java @@ -0,0 +1,449 @@ +package MAndApps; + +import java.awt.*; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.image.BufferedImage; +import java.util.Stack; + +import javax.swing.*; + +public class Engine extends Canvas implements KeyListener, MouseMotionListener, + MouseListener { + + /** + * to track the x and y + */ + public static int mouseX = 0, mouseY = 0; + + /** + * if the mouse is down + */ + public static boolean mouse = false; + + /** + * some number that we use in stuff to animate. move 1/8 the distance when + * animating. + */ + public static final int ANIMATION_CONSTANT = 8; + + /** + * object thing that will initialize our apps for us, then give us an array! + */ + private static AppHelper appInitializer; + + /** + * AER WE SUPER SPEEDING?!?!? + */ + private static boolean overclock = false; + + /** + * current framerate and time required to sleep to achieve that framerate. + */ + private static int frameSync = 50, sleepTime = 1000 / frameSync; + + /** + * variables to track the fps, DON'T WORRY ABOUT IT, PAST YOU HAS YOU + * COVERED. + */ + private static int framesInCurrentSecond = 0, FPS = 0; + + /** + * more framerate stuff, again, chill. + */ + private static long nextSecond = System.currentTimeMillis() + 1000, + startTime = 0; + + /** + * if our current framerate is below our expected. its not directly + * calculated that way though. in all reality its calculated by if the + * dynamic thread sleep tries to sleep negative or not. + */ + private static boolean lag = false; + + /** + * this helps debugging, but we keep it private because well, it makes no + * sense. BUT IT WORKS SO WHATEVER. + */ + private static Stack log = new Stack(); + + /** + * current width and height. again, don't worry about it so much. PAST YOU, + * COVERED. also stores current app ID in array. THIS IS WHY MENU GOES FIRST + * IN CFG. + */ + private static int WIDTH = 800, HEIGHT = 600, app = 0; + + /** + * this bit is important. its the array of apps that we reference later on. + */ + public static BasicApp[] apps; + + /** + * our window object, probs important. + */ + private static JFrame frame; + + /** + * basic running condition. don't mess. don't mess. don't mess with the best + * cause the best don't mess. don't fool, don't fool. don't fool with the + * cool cause the cool don't fool don't bite my apple don't shake my tree. + * im an eagle don't mess with me! WORD! AND RESPECT! + */ + private static boolean running = false; + + /** + * FOR PROGRESS BAR DURING THE ERRORING PART OF DRAWING! seriously need to + * make that so if a game crashes it doesn't look like its reloading. + */ + private static double progress = 1; + + /** + * These are fonts. because STANDARDIZATION! + * worked good for oil, WHY NOT ME? + */ + public static final Font largerFont = new Font("Ubuntu", Font.BOLD, 20); + public static final Font defaultFont = new Font("Ubuntu", Font.BOLD, 11); + + /** + * a place to put your keys. current state. GET IT? tough crowd. ever feel + * like the compiler just... ignores my puns? + */ + public static boolean[] keys; + + /** + * SOMETHING NEW I JUST DID NOW GUISE! + */ + private static Image buffer; + private static Graphics2D g2; + + /** + * the main Main object but staticed so we can like use it from that static + * context. its not final because its static but don't change it. + */ + private static Engine staticMain; + + /** + * SRSLY CALL DYS ONCE. DAS IT. ALL YOU GET. ONE SHOT. + */ + public Engine(String[] classes, boolean showLoading) { + + //frame.setVisible(true); + + // set static object + staticMain = this; + + // initialize keys + keys = new boolean[512]; + + // set up window + frame = new JFrame(); + setSize(WIDTH, HEIGHT); + frame.add(this); + frame.pack(); + frame.setLocationRelativeTo(null); + addKeyListener(this); + requestFocus(); + + if(showLoading) frame.setVisible(true); + + //make a new thread of the appinitializer thing + //and like... make it do things. + appInitializer = new AppHelper(classes); + Thread thread = new Thread(appInitializer); + thread.start(); + + + + //we need to make a frame and such first + //more on that later + createBuffer(); + + + //while its faffing about, RENDER THINGS AND MAKE A LOADY THING + while(!appInitializer.getDone() || !(progress >= 0.999)){ + try{ + Thread.sleep(17); + }catch(Exception e){ + } + //this is the later part referred to by a few lines back + repaint(); + progress += (appInitializer.getProgress() - progress)/ANIMATION_CONSTANT; + } + + //we done now, gather the loot. + apps = appInitializer.getApps(); + + switchApps(0); + + } + + public void run() { + + + // REALLY???? + running = true; + + + + frame.setVisible(true); + + + // now we do stuff. + while (running) { + // FPS STUFF WORRY NOT, ITS ALL GOOD. MOVE ALONG. + startTime = System.currentTimeMillis(); + if (System.currentTimeMillis() > nextSecond) { + nextSecond += 1000; + FPS = framesInCurrentSecond; + framesInCurrentSecond = 0; + } + framesInCurrentSecond++; + + // tick stuff + tick(); + // paint the same stuff + repaint(); + + // FRAMERATE OVERCLOCKING AND SUCH, MOVE ALONG. + try { + if (!overclock) + Thread.sleep((long) Math.floor(sleepTime + - (System.currentTimeMillis() - startTime))); + else + Thread.sleep(0); + lag = false; + } catch (Exception e) { + lag = true; + } + } + } + + /** + * makes a buffer and stuff, called with new windows and things. MOVE ALONG + */ + private static void createBuffer() { + buffer = (Image) (new BufferedImage(WIDTH, HEIGHT, + BufferedImage.TRANSLUCENT)); + g2 = (Graphics2D) buffer.getGraphics(); + } + + // later make this NOT initialize something new every go... + // PROBABLY A GOOD IDEA PAST MARCUS, IMMA DO THAT NOW! + // ~present Marcus + // thank you my minions ~Future Marcus + public void update(Graphics g) { + // Graphics g2 = buffer.getGraphics(); + paint(g2); + g.drawImage(buffer, 0, 0, null); + } + + /** + * THIS THING, SWITCHES APPS N STUFF! WOO! + * + * @param i + * @return + */ + public static boolean switchApps(int i) { + try { + log("pausing " + apps[app].getTitle()); + apps[app].pauseApp(); + app = i; + log("initializing " + apps[app].getTitle()); + apps[app].initialize(); + log("resuming " + apps[app].getTitle()); + apps[app].resumeApp(); + log("setting window properties"); + setWindowProperties(apps[app]); + log("Started up " + apps[app].getTitle()); + + frame.pack(); + + // because we now use the ONE buffer system... yeah + // lets do something about thaaaaaaaaat... + createBuffer(); + + return true; + + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + return false; + } + } + + /** + * sets the window properties for a given app + * + * @param app + */ + private static void setWindowProperties(BasicApp app) { + setWindowProperties(app.getResolution(), app.getFramerate(), + app.getResizable()); + } + + /** + * sets the window properties without an app having to be specified. + * + * @param dimension + * @param fps + * @param resizable + */ + private static void setWindowProperties(Dimension dimension, int fps, + boolean resizable) { + + staticMain.setSize(dimension); + frame.setResizable(true); + frame.pack(); + frame.setLocationRelativeTo(null); + WIDTH = dimension.width; + HEIGHT = dimension.height; + setFramerate(fps); + frame.setResizable(resizable); + + } + + public void paint(Graphics g) {// oh..... + + Graphics2D g2d = (Graphics2D) g; + + render(g2d); + + } + + private static void render(Graphics2D g) { + + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + g.setFont(defaultFont); + + try { + // set default graphics shit + g.setFont(defaultFont); + g.setColor(Color.WHITE); + + // try and do the normal thing + apps[app].render(g); + + // aaaaand back to us! + g.setFont(defaultFont); + g.setColor(Color.WHITE); + + // show fps if debug level high enough + g.drawString("FPS: " + FPS, 20, 20); + if (overclock) + g.drawString("Overclocking!", 20, 35); + g.setColor(Color.RED); + if (lag) + g.fillOval(10, 10, 10, 10); + + g.setColor(Color.WHITE); + if (!(log.size() == 0)) + for (int i = log.size() - 1; i >= 0; i--) + log.elementAt(i).render(g, WIDTH - 200, + HEIGHT - 10 - (i * 12)); + } catch (Exception e) { + g.setFont(largerFont); + g.setColor(Color.BLACK); + g.fillRect(0, 0, WIDTH, HEIGHT); + g.setColor(Color.GREEN); + g.fillRect(100, 300, (int) (progress * 600), 20); + g.setColor(Color.RED); + g.drawRect(100, 300, 600, 20); + g.setColor(Color.BLUE); + g.drawString("Loading", WIDTH / 2 - 40, HEIGHT / 2 - 200); + + } + + } + + private void tick() { + apps[app].tick(); + for (int i = 0; i < log.size(); i++) + log.elementAt(i).tick(); + + int i = 0; + while (i < log.size()) { + if (!log.elementAt(i).getAlive()) + log.remove(i); + else + i++; + } + + while (log.size() > 10) { + log.pop(); + } + } + + public static void log(String s) { + log.insertElementAt(new LogItem(s, 100), 0); + } + + @Override + public void keyPressed(KeyEvent e) { + apps[app].keyPressed(e); + if (e.getKeyCode() == KeyEvent.VK_O) { + overclock = !overclock; + } + keys[e.getKeyCode()] = true; + } + + @Override + public void keyReleased(KeyEvent e) { + apps[app].keyReleased(e); + keys[e.getKeyCode()] = false; + } + + @Override + public void keyTyped(KeyEvent arg0) { + } + + public static void exit() { + frame.dispose(); + System.exit(0); + } + + private static void setFramerate(int fps) { + frameSync = fps; + sleepTime = 1000 / frameSync; + } + + @Override + public void mouseDragged(MouseEvent e) { + mouseX = e.getX(); + mouseY = e.getY(); + } + + @Override + public void mouseMoved(MouseEvent e) { + mouseX = e.getX(); + mouseY = e.getY(); + } + + @Override + public void mouseClicked(MouseEvent arg0) { + } + + @Override + public void mouseEntered(MouseEvent arg0) { + } + + @Override + public void mouseExited(MouseEvent arg0) { + } + + @Override + public void mousePressed(MouseEvent arg0) { + mouse = true; + } + + @Override + public void mouseReleased(MouseEvent arg0) { + mouse = false; + } +} \ No newline at end of file diff --git a/src/MAndApps/ImageCreator.java b/src/MAndApps/ImageCreator.java new file mode 100644 index 0000000..c07be57 --- /dev/null +++ b/src/MAndApps/ImageCreator.java @@ -0,0 +1,171 @@ +package MAndApps; + + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.io.IOException; + +public class ImageCreator { + public static BufferedImage creatImageColorWithNoise(int width, int height, Color c, int variationIterations) { + BufferedImage image = (new BufferedImage(width, height, BufferedImage.TRANSLUCENT)); + Graphics graphics = image.getGraphics(); + final int variant = variationIterations; + for (int i = 0; i < image.getWidth(null); i++) { + for (int j = 0; j < image.getHeight(null); j++) { + + double r = c.getRed(); + double g = c.getGreen(); + double b = c.getBlue(); + + for (int k = 0; k < variant; k++) { + r *= 0.9d; + g *= 0.9d; + b *= 0.9d; + + r += (int) (Math.random() * 25); + g += (int) (Math.random() * 25); + b += (int) (Math.random() * 25); + } + + Color color = new Color((int) r, (int) g, (int) b); + graphics.setColor(color); + graphics.fillRect(i, j, 1, 1); + } + } + return image; + } + + public static BufferedImage creatImageWithStripes(int width, int height, Color c) { + return creatImageWithStripes(width, height, c, c.darker()); + } + + public static BufferedImage creatImageWithStripes(int width, int height, Color c, Color c2) { + BufferedImage image = (new BufferedImage(width, height, BufferedImage.TRANSLUCENT)); + Graphics graphics = image.getGraphics(); + for (int i = 0; i < image.getWidth(null); i++) { + for (int j = 0; j < image.getHeight(null); j++) { + + boolean b = Math.floor(((i + j) / 2d)) % 2 != 0; + + graphics.setColor(b ? c : c2); + graphics.fillRect(i, j, 1, 1); + } + } + return image; + } + + public static BufferedImage getScaledImage(BufferedImage image, int width, int height) throws IOException { + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + + double scaleX = (double) width / imageWidth; + double scaleY = (double) height / imageHeight; + AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); + AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); + + return bilinearScaleOp.filter(image, new BufferedImage(width, height, image.getType())); + } + + public static BufferedImage getScaledImage(BufferedImage image, double scale) throws IOException { + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + + double scaleX = scale; + double scaleY = scale; + AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); + AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); + + return bilinearScaleOp.filter(image, new BufferedImage((int) (imageWidth * scale), (int) (imageHeight * scale), image.getType())); + } + + public static BufferedImage createImageCloud(int width, int height, Color color) { + return createImageCloud(width, height, 0xFF000000 | (color.getRed() << 16) | (color.getGreen() << 8) | (color.getBlue() << 0)); + } + + public static BufferedImage createImageCloud(int width, int height, int color) { + return createImageCloud(width, height, 0x000000FF&(color>>16), 0x000000FF&(color>>8), 0x000000FF&(color)); + } + + public static BufferedImage createImageCloud(int width, int height, int r, int g, int b) { + return createImageCloud(width, height, r/255d, g/255d, b/255d); + } + + public static BufferedImage createImageCloud(int width, int height, double Rx, double Gx, double Bx) { + // two to the \/ power = datasize... + double power = width > height ? width : height; + power *= 2; + power = (int) (log(2, power) + .5); + //not my code hell if i know how it works + final int DATA_SIZE = (int) Math.pow(2, power) + 1; + final double SEED = 1000.0; + double[][] data = new double[DATA_SIZE][DATA_SIZE]; + data[0][0] = data[0][DATA_SIZE - 1] = data[DATA_SIZE - 1][0] = data[DATA_SIZE - 1][DATA_SIZE - 1] = SEED; + double h = 500.0; + for (int sideLength = DATA_SIZE - 1; sideLength >= 2; sideLength /= 2, h /= 2.0) { + int halfSide = sideLength / 2; + for (int x = 0; x < DATA_SIZE - 1; x += sideLength) { + for (int y = 0; y < DATA_SIZE - 1; y += sideLength) { + double avg = data[x][y] + + data[x + sideLength][y] + + data[x][y + sideLength] + + data[x + sideLength][y + sideLength]; + avg /= 4.0; + data[x + halfSide][y + halfSide] = avg + (Math.random() * 2 * h) - h; + } + } + for (int x = 0; x < DATA_SIZE - 1; x += halfSide) { + for (int y = (x + halfSide) % sideLength; y < DATA_SIZE - 1; y += sideLength) { + double avg = data[(x - halfSide + DATA_SIZE) % DATA_SIZE][y] + + data[(x + halfSide) % DATA_SIZE][y] + + data[x][(y + halfSide) % DATA_SIZE] + + data[x][(y - halfSide + DATA_SIZE) % DATA_SIZE]; + avg /= 4.0; + avg = avg + (Math.random() * 2 * h) - h; + data[x][y] = avg; + if (x == 0) + data[DATA_SIZE - 1][y] = avg; + if (y == 0) + data[x][DATA_SIZE - 1] = avg; + } + } + } + //end wtf code + BufferedImage img = new BufferedImage(DATA_SIZE, DATA_SIZE, BufferedImage.TYPE_4BYTE_ABGR); + double min = SEED; + double max = SEED; + for (int i = 0; i < DATA_SIZE; i++) { + for (int j = 0; j < DATA_SIZE; j++) { + if (data[i][j] < min) + min = data[i][j]; + if (data[i][j] > max) + max = data[i][j]; + } + } + for (int i = 0; i < DATA_SIZE; i++) { + for (int j = 0; j < DATA_SIZE; j++) { + img.setRGB(i, j, (0xFF000000) | ((int) (((data[i][j] - min) / (max - min)) * 255) << 16) | ((int) (((data[i][j] - min) / (max - min)) * 255) << 8) | ((int) (((data[i][j] - min) / (max - min)) * 255))); + } + } + for (int i = 0; i < DATA_SIZE; i++) { + for (int j = 0; j < DATA_SIZE; j++) { + int r = (int) ((double) ((img.getRGB(i, j) >> 16) & 0x000000FF) * Rx); + int g = (int) ((double) ((img.getRGB(i, j) >> 8) & 0x000000FF) * Gx); + int b = (int) ((double) ((img.getRGB(i, j) >> 0) & 0x000000FF) * Bx); + img.setRGB(i, j, 0xFF000000 | (r << 16) | (g << 8) | (b << 0)); + } + } + + BufferedImage _return = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); + _return.getGraphics().drawImage(img, 0 - (img.getWidth() / 8), 0 - (img.getHeight() / 8), null); + return _return; + + } + + private static double log(double b, double x) { + return Math.log(x) / Math.log(b); + } +} diff --git a/src/MAndApps/LogItem.java b/src/MAndApps/LogItem.java new file mode 100644 index 0000000..464c8fd --- /dev/null +++ b/src/MAndApps/LogItem.java @@ -0,0 +1,38 @@ +package MAndApps; + +import java.awt.Graphics; + +public class LogItem { + private int life, LIFE; + private boolean alive; + private String log; + public LogItem(String s, int life){ + log = s; + alive = true; + LIFE = life; + this.life = 0; + // each instance of the word life, + //is one of three different variable :P + //confused? + //this.life is the current life counter + //LIFE is the max counter before it dies + //life is the number passed in to set as + //the LIFE or max life + //confused now? + } + + public void tick(){ + life++; + if(life >= LIFE){ + alive = false; + } + } + + public void render(Graphics g, int x, int y){ + if (alive)g.drawString(log, x, y); + } + + public boolean getAlive() { + return alive; + } +} diff --git a/src/MAndApps/Pointer.java b/src/MAndApps/Pointer.java new file mode 100644 index 0000000..cf59058 --- /dev/null +++ b/src/MAndApps/Pointer.java @@ -0,0 +1,12 @@ +package MAndApps; + +public class Pointer { + private volatile E object; + public Pointer(E e){ + object = e; + } + + public E getObject(){ + return object; + } +} \ No newline at end of file diff --git a/src/MAndApps/Variable.java b/src/MAndApps/Variable.java new file mode 100644 index 0000000..f9d51b4 --- /dev/null +++ b/src/MAndApps/Variable.java @@ -0,0 +1,186 @@ +package MAndApps; + + +import java.io.File; +import java.io.IOException; +import java.util.Formatter; +import java.util.Scanner; + +/** + * to note, will not work on Mac yet. + * + * edit: WILL WORK ON MAC MOTHER FUCKERS + * + * edit: idek if this will work on macs because app data... + * + * @author Marcus + * + */ +public class Variable { + private String value; + private String filePath; + private String fileDir; + private static String fileExtension; + private static String BASE_DIR = "" + System.getenv("APPDATA") + "\\"; + + static { + // first the default value is set. this is used + // only to get the real value. + fileExtension = "var"; + // make a new variable, for the extension + // do not force it to be var. + Variable var = new Variable("MAndLib\\core", "extension", "var", false); + // grab its value and reset the extension. + fileExtension = var.getValue(); + } + + /** + * dir - where the variable file is stored. - enter things like "hjkl\\asdf" + * + * name - simple, name of variable file + * + * value - value to try and set the file to. though if it already has a + * value, it won't do anything + * + * force - if true, value will always be set to the value given, regardless + * of if the value is already there. + * + * @param dir + * @param name + * @param value + * @param force + */ + + public Variable(String dir, String name, String value, boolean force) { + + + fileDir = BASE_DIR + dir; + filePath = BASE_DIR + dir + "\\" + name + "." + fileExtension; + // try and load value from file, if null, screw it. + + + String str = getValueFromFile(); + + // if we could not load a value from the file + // AKA didnt fucking exist. + // ORRRRRRR if you were an ass, and forced + // the value. + if (str == null) { + this.value = value; + saveValue(); + } else if (force) { + this.value = value; + saveValue(); + // else we can load the value from the file + } else { + this.value = str; + } + } + + /** + * return the class variable for the value. + * shouldn't have to load it again because we + * always change the value locally first before we save. + * @return + */ + public String getValue() { + return value; + } + + /** + * set the value in the local class, then open a thread for saving it + * + * @param value + */ + public void setValue(String value) { + this.value = value; + new Thread(new Runnable() { + public void run() { + saveValue(); + } + }).start(); + } + + /** + * deletes and recreates the file with the new value + */ + private void saveValue() { + deleteFile(); + createFile(); + try { + // Q&D formatter to write value to current filepath. + Formatter f = new Formatter(filePath); + f.format("" + value); + f.close(); + } catch (Exception e) { + // if(weArriveHere){ + // we.are("fucked"); + // } + e.printStackTrace(); + } + } + + /** + * for refreshing the file + */ + private void deleteFile() { + File f = new File(filePath); + f.delete(); + } + + /** + * creates empty file at the correct path. + */ + private void createFile() { + //make the directory because god knows, java can't do that for us + //when we say we want a new file in an unknown folder noooooo.... + //jackass java + File f = new File(fileDir); + f.mkdirs(); + + //no onto the file itself. create the object + f = new File(filePath); + try { + //hopefully make the file... + f.createNewFile(); + } catch (IOException e) { + // if(weArriveHere){ + // we.are("fucked"); + // } + e.printStackTrace(); + } + } + + /** + * grab the value from the file, if nothing is there, null. + * + * @return + */ + private String getValueFromFile() { + try { + //create the file... we don't want to do anyth stupid checking because if its + //not perfect, we honestly don't care, just return null and reset the variable + File f = new File(filePath); + + //open a scanner on the file + Scanner s = new Scanner(f); + + //get the assumed value + String str = s.nextLine(); + + //close the file because for some reason if you don't + //you end up dividing by zero... + s.close(); + + //gimme dat string + return str; + } catch (Exception e) { + //dunno, don't care, reset. + return null; + } + } + + public static void setBaseDir(String dir) { + BASE_DIR = dir; + } +} diff --git a/src/MAndApps/VariableNotFoundException.java b/src/MAndApps/VariableNotFoundException.java new file mode 100644 index 0000000..80a59cb --- /dev/null +++ b/src/MAndApps/VariableNotFoundException.java @@ -0,0 +1,10 @@ +package MAndApps; + + + +public class VariableNotFoundException extends Exception { + @Override + public String getMessage() { + return "Variable not found"; + } +}