package com.WrongUniverse;
//package / import //
import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseMotionListener;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import javax.imageio.ImageIO;
import javax.swing.*;
import com.WrongUniverse.*;
import com.WrongUniverse.input.*;
import com.WrongUniverse.ExtraLib.Echo;
import com.WrongUniverse.FileManager.*;
import com.WrongUniverse.WindowManager.*;
public class WrongUniverse extends JFrame implements Runnable, ComponentListener {
private boolean running = false;
private Image dbImage = null;
public static Graphics dbgx;
public static Graphics2D dbg;
private KeyManager keyManager;
private MouseManager mouseManager;
private MouseMotionListener mouseMovingManager;
private FileManager fileManager = new FileManager();
private static XmlReader xReader = new XmlReader();
public static int posX, posY;
private FontMetrics fm;
private int strWidth;
public static int timeSpeed = 1000, time;
public static boolean expertMode = false;
public String title = "A WrongUniverse game 0.1";
final Font font = new Font("sans-serif", 20, 20), fontSmall = new Font("sans-serif", 10, 10), fontHeader = new Font("sans-serif", 40, 40);
public static String acIntroText = "-- -- -- -- --"; //see switch...
public static int introInt = 0;
public static boolean hideIntro = false;
public static int screenIndex = -1; //-1-STAYN / o-Menu / 1-GAME / 2-OVER / 3-CREDITS
private int x, y;
public static int partParagraph = 0;
public static String timeObject = "sun";
public static float nightAlpha = 0.0f;
public static int xSun, ySun;
public static final int SCREEN_STAYN = -1;
public static final int SCREEN_MENU = 0;
public static final int SCREEN_GAME = 1;
public static final int SCREEN_GAMEOVER = 2;
public static final int SCREEN_GAMEOPTIONS = 3;
public static final int SCREEN_CREDITS = 4;
public static final int SCREEN_GAMEMENU = 5;
public static final int SCREEN_OPTIONS = 6;
//LANG {
public static String lang = "en_EN";
// } END LANG //
public static Echo echo, echo2;
private String timeString = "none";
public static int xDisplay = Toolkit.getDefaultToolkit().getScreenSize().width, yDisplay = Toolkit.getDefaultToolkit().getScreenSize().height;
public static int xScreen, yScreen;
public static Image imgStayn = Toolkit.getDefaultToolkit().getImage("img/stayn.png");
public static Image imgTitle = Toolkit.getDefaultToolkit().getImage("img/menu/title2.png");
public static Image imgForest = Toolkit.getDefaultToolkit().getImage("img/part1/forest.png");
public static Image imgCredits = Toolkit.getDefaultToolkit().getImage("img/menu/credits.png");
public static String bufString = "null";
public static WrongUniverse wrongUniverseFrame;
Image imgMoon = Toolkit.getDefaultToolkit().getImage("img/misc/moon.png");
Image imgSun = Toolkit.getDefaultToolkit().getImage("img/misc/sun.png");
Image imgTree = Toolkit.getDefaultToolkit().getImage("img/decoration/tree.png");
Image bgNight = Toolkit.getDefaultToolkit().getImage("img/misc/night.png");
Image icMenu = Toolkit.getDefaultToolkit().getImage("img/gui/menu.png");
public WrongUniverse() {
//constructor
super(XmlReader.lang.getProperty("title"));
setSize(920,640);
setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(true);
setLocation(200,200);
//setLayout(new FlowLayout());
JButton panel = new JButton("Telefon");
add(panel);
addKeyListener(keyManager = new KeyManager(this));
addMouseListener(mouseManager = new MouseManager(this));
addMouseMotionListener(mouseMovingManager = new MouseMovingManager(this));
(new Thread(this)).start();
addComponentListener(this);
setVisible(true);
}
public void update(Graphics g) {
xScreen = getWidth();
yScreen = getHeight();
paint(g);
}
public void paint(Graphics g) {
//if(dbImage == null) {
xScreen = getWidth();
yScreen = getHeight();
dbImage = createImage(xScreen,yScreen);
dbgx = dbImage.getGraphics();
dbg = (Graphics2D) dbgx;
//}
dbg.setColor(Color.WHITE);
xScreen = getWidth();
yScreen = getHeight();
dbg.fillRect(0, 0, xScreen, yScreen);
if(screenIndex >=0 && screenIndex < 5 || screenIndex >5) {
//Gezeiten
//if(timeObject.equals("moon")){
dbg.setComposite(AlphaComposite. getInstance(AlphaComposite.SRC_OVER, nightAlpha));
dbg.drawImage(bgNight,0, 0,this);
dbg.setComposite(AlphaComposite. getInstance(AlphaComposite.SRC_OVER, 1.0f));
//}
if(timeObject.equals("sun"))
dbg.drawImage(imgSun,xSun, ySun,this);
if(timeObject.equals("moon"))
dbg.drawImage(imgMoon,xSun, ySun,this);
}
switch (screenIndex) {
case -1:
x = (getWidth()-imgStayn.getWidth(this))/2;
y = (getHeight()-imgStayn.getHeight(this))/2;
//dbg.drawImage(imgStayn, x, y, this);
dbg.drawImage(imgStayn,x, y,this);
break;
case 0:
x = 0;
yScreen = getHeight();
y = yScreen - 400;
//echo.write(yScreen + " S | - " + y);
dbg.drawImage(imgTitle,x, y,this);
dbg.setFont(fontHeader);
dbg.setColor(Color.BLACK);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("title"));
dbg.drawString(XmlReader.lang.getProperty("title"), xScreen / 2 - strWidth / 2, 150);
dbg.setFont(font);
dbg.setColor(Color.BLACK);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("startgame"));
dbg.drawString(XmlReader.lang.getProperty("startgame"), xScreen / 2 - strWidth / 2, 200);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("loadgame"));
dbg.drawString(XmlReader.lang.getProperty("loadgame"), xScreen / 2 - strWidth / 2, 225);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("options"));
dbg.drawString(XmlReader.lang.getProperty("options"), xScreen / 2 - strWidth / 2, 250);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("about"));
dbg.drawString(XmlReader.lang.getProperty("about"), xScreen / 2 - strWidth / 2, 275);
//dbg.drawString("Press [ENTER] to start the game.", 150, 250);
break;
case 1:
lang="en_EN";
xReader.xReload();
x = 0;
yScreen = getHeight();
y = yScreen - 400;
//echo.write(yScreen + " S | - " + y);
dbg.drawImage(imgTitle,x, y,this);
dbg.drawImage(icMenu,xScreen-64, 0, 64, 64,this);
dbg.setColor(Color.BLACK);
dbg.drawLine(0, 15, xScreen-64, 15);
dbg.drawImage(imgTree,-200, yScreen-520,this);
dbg.drawImage(imgTree,xScreen-280, yScreen-460,this);
dbg.setFont(font);
dbg.setColor(Color.BLACK);
if(!hideIntro){
fm = dbg.getFontMetrics();
//
strWidth = SwingUtilities.computeStringWidth(fm, acIntroText);
//dbg.drawString("[ " + acIntroText + " ]", xScreen / 2 - strWidth / 2, yScreen - fm.getAscent() / 2);
}
break;
case 2:
x = 0;
yScreen = getHeight();
y = yScreen - 400;
//echo.write(yScreen + " S | - " + y);
dbg.drawImage(imgTitle,x, y,this);
dbg.setFont(font);
dbg.setColor(Color.RED);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("gameover"));
dbg.drawString(XmlReader.lang.getProperty("gameover"), xScreen / 2 - strWidth / 2, 300+22);
dbg.setColor(Color.BLACK);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("tryagain"));
dbg.drawString(XmlReader.lang.getProperty("tryagain"), xScreen / 2 - strWidth / 2, 300+44);
break;
case 3:
x = 0;
yScreen = getHeight();
y = yScreen - 400;
//echo.write(yScreen + " S | - " + y);
dbg.drawImage(imgTitle,x, y,this);
dbg.setFont(fontSmall);
dbg.setColor(Color.BLACK);
dbg.drawString(XmlReader.lang.getProperty("esccontinue"), 5, yScreen-20);
dbg.drawString(XmlReader.lang.getProperty("savegame"), 5, yScreen-10);
dbg.setColor(Color.MAGENTA);
dbg.setFont(font);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("gamepaused"));
dbg.drawString(XmlReader.lang.getProperty("gamepaused"), xScreen / 2 - strWidth / 2, 300 + 22);
dbg.setColor(Color.BLACK);
dbg.setFont(font);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("continuegame"));
dbg.drawString(XmlReader.lang.getProperty("continuegame"), xScreen / 2 - strWidth / 2, 300 + 44);
break;
case 4:
x = 0;
yScreen = getHeight();
y = yScreen - 400;
//echo.write(yScreen + " S | - " + y);
dbg.drawImage(imgTitle,x, y,this);
dbg.setFont(font);
dbg.setColor(Color.BLACK);
dbg.drawString("Programmed by:",100,100);
dbg.setFont(fontSmall);
dbg.drawString("Tom Schneider",122,122);
dbg.setFont(font);
dbg.drawString("Graphics by:",100+250,100);
dbg.setFont(fontSmall);
dbg.drawString("Tom Schneider",122+250,122);
dbg.setFont(font);
dbg.drawString("Storyboard by:",100+500,100);
dbg.setFont(fontSmall);
dbg.drawString("Tom Schneider",122+500,122);
//NEXT LINE
dbg.setFont(font);
dbg.drawString("Sounds by:",100,100+100);
dbg.setFont(fontSmall);
dbg.drawString("--not implemented yet.",122,122+100);
dbg.setFont(font);
dbg.drawString("(c) 2012,",100+250,100+100);
dbg.setFont(fontSmall);
dbg.drawString("Tom Schneider (STAYN)",122+250,122+100);
dbg.setFont(font);
dbg.drawString("Rights:",100+500,100+100);
dbg.setFont(fontSmall);
dbg.drawString("All rights reserved.",122+500,122+100);
dbg.setFont(font);
dbg.drawString("<< Back to menu",100,620);
break;
case 5:
dbg.setColor(Color.RED);
dbg.drawString(Integer.toString(1000),100,100);
dbg.setColor(Color.BLACK);
break;
case 6:
x = 0;
yScreen = getHeight();
y = yScreen - 400;
//echo.write(yScreen + " S | - " + y);
dbg.drawImage(imgTitle,x, y,this);
dbg.setColor(Color.BLACK);
dbg.setFont(font);
fm = dbg.getFontMetrics();
strWidth = SwingUtilities.computeStringWidth(fm, XmlReader.lang.getProperty("options"));
dbg.drawString(XmlReader.lang.getProperty("options"), xScreen / 2 - strWidth / 2, 50);
break;
}
dbg.setFont(fontSmall);
dbg.setColor(Color.BLACK);
/*dbg.drawString("A WrongUniverse Game Alpha 0.1 | ScreenIndex [" +
screenIndex + "]" + " | IntroIndex [" + introInt + "]" +
" | MousePosition: " + posX +"/"+ posY, 5, 10); */
if(screenIndex >= 0) {
if(timeObject.equals("sun"))
timeString = XmlReader.lang.getProperty("timeDay");
if(timeObject.equals("moon"))
timeString = XmlReader.lang.getProperty("timeNight");
dbg.drawString("Wrong Universe Alpha 0.1 | " +
XmlReader.lang.getProperty("time") + " "+timeString+" | ", 5, 10);
if(expertMode) {
dbg.setFont(fontSmall);
dbg.setColor(Color.BLACK);
dbg.drawString("ScreenIndex [" + screenIndex + "]", 5, 20);
dbg.drawString("IntroIndex [" + introInt + "]", 5, 30);
dbg.drawString("MousePosition [" + posX +" | "+ posY+"]", 5, 40);
dbg.drawString("Time [" + time + "] - Speed ["+timeSpeed+"]", 5, 50);
}
}
g.drawImage(dbImage, 0, 0, null);
}
public static void main(String[] args) throws Exception {
echo = new Echo();
//echo.write("HI!");
new FileManager();
if(FileManager.options.getProperty("lang").equals("de")) {
lang="de_DE";
}else{
lang="en_EN";
}
echo.write("lang is in pro "+FileManager.options.getProperty("lang"));
echo.write("lang setted to "+lang);
xReader=new XmlReader();
wrongUniverseFrame = new WrongUniverse();
//acIntroText = acIntroText.replaceAll("...WrongUniverse...", "");
echo.write("STAYN...");
Thread.sleep(1000);
echo.write("start the game...");
screenIndex = 0;
int w = 1;
while(w!=0) {
//Thread.sleep(5000);
//lang="en_EN";
if(screenIndex == 0) {
echo.write("Sonnenuntergang");
for(int i=40; i<=yScreen;i++) {
timeObject = "sun";
time = i-40;
xSun = 40;
ySun = i;
if((float)i>=yScreen-100) {
//echo.write(((float)i-yScreen+100)/100);
nightAlpha = ((float)i-yScreen+100)/100;
}
Thread.sleep(timeSpeed);
}
echo.write("Mondaufgang");
for(int i=yScreen; i>=40;i--) {
timeObject = "moon";
time = i-40;
xSun = 40;
ySun = i;
Thread.sleep(timeSpeed);
}
Thread.sleep(5000);
echo.write("Monduntergang");
for(int i=40; i<yScreen;i++) {
timeObject = "moon";
time = i-40;
xSun = 40;
ySun = i;
if((float)i>=yScreen-100) {
//echo.write(nightAlpha);
nightAlpha = nightAlpha-0.01f;
}
Thread.sleep(timeSpeed);
}
echo.write("Sonnenaufgang");
for(int i=yScreen; i>=40;i--) {
timeObject = "sun";
time = i-40;
xSun = 40;
ySun = i;
Thread.sleep(timeSpeed);
}
Thread.sleep(5000);
}
}
}
public void run() {
running = true;
while(running){
process();
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void process() {
keyManager.processKeys();
}
public void componentResized(ComponentEvent e) {
displayMessage(e.getComponent().getClass().getName() + " --- Resized ");
if(screenIndex >= 1) screenIndex = 3;
}
private void displayMessage(String string) {
echo.write(string);
}
public int isScreenIndex() {
return screenIndex;
}
public void setScreenIndex(int screenIndex) {
this.screenIndex = screenIndex;
}
@Override
public void componentHidden(ComponentEvent arg0) {
if(screenIndex >= 1) screenIndex = 3;
}
@Override
public void componentMoved(ComponentEvent arg0) {
if(screenIndex >= 1) screenIndex = 3;
}
@Override
public void componentShown(ComponentEvent arg0) {
if(screenIndex >= 1) screenIndex = 3;
}
}