/*
* Foogl (Friendly Object Oriented Game Library)
* Copyright (c) 2008 Wachirawut Thamviset.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package kku.cs.fgl;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import kku.cs.util.HTTPLocation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.transition.Transition;
import org.newdawn.slick.util.ClasspathLocation;
import org.newdawn.slick.util.Log;
import org.newdawn.slick.util.ResourceLoader;
/**
* GameLoader �� class ���������Ѻ�����Ŵ�������ҷӧҹ <br>
* �¨�����ö�ѹ������ 2 Ẻ��� �ѹẺ Java Applet ���Ǻ ��� �ѹẺ Java
* Application
*
* @author Wachirawut Thamviset
*
*/
abstract public class GameLoader {
static public void setDebug(boolean on) {
Log.setVerbose(on);
}
private GamePane game = null;
private int runmode = 0;
private String title = "FooGameLib";
private AppGameContainer appContainer;
private GameContainer screen;
private boolean isApplet = false;
public GameLoader() {
ClasspathLocation.addClass(this.getClass());
ResourceLoader.addResourceLocation(new HTTPLocation());
}
/**
* �騺���� ��� �Դ����� ����Ѻ�óշ���ѹẺ app ����
*/
public void exit() {
if (appContainer != null)
appContainer.exit();
}
public Font getFont(int font) {
return getGame().getFont(font);
}
public GamePane getGame() {
if (game == null) {
game = new GamePane(this,title);
}
Log.setVerbose(false);
return game;
}
public int getRunmode() {
return runmode;
}
public String getTitle() {
return title;
}
/**
* ��� override ������㹡�����ҧ scene
*
* @param screen
* �� GameContainer ���١���Ҩҡ Slick Library
* @param game
* �� GamePane
*/
abstract public void initScenes(GameContainer screen, GamePane gamepane);
/**
* �����������ʴ��� Ẻ������������
*
* @param fullscreen
*/
public void setFullScreen(boolean fullscreen) {
if (screen == null)
return;
try {
screen.setFullscreen(fullscreen);
} catch (SlickException e) {
e.printStackTrace();
}
}
public void setGame(GamePane game) {
this.game = game;
}
public void setTitle(String title) {
this.title = title;
}
/**
* �����¡����������ʴ������Ẻ˹�ҵ�ҧ <br>
* 㹤��������´ 800x600 �Ẻ��������
*/
public void showFrame() {
showFrame(800, 600, false);
}
/**
* �����¡����������ʴ������Ẻ˹�ҵ�ҧ windows
*
* @param width
* �繤��������´��ǹ
* @param height
* �繤��������´��ǵ��
* @param fullScreen
* �ʴ�Ẻ���˹�Ҩ��������
*/
final public void showFrame(int width, int height, boolean fullScreen) {
try {
/*try {
Log.out = new PrintStream( new FileOutputStream("foogl.log"));
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.out = System.out;
}*/
appContainer = new AppGameContainer(getGame());
appContainer.setDisplayMode(width, height, fullScreen);
appContainer.setVSync(true);
appContainer.setTitle(getTitle());
appContainer.setIcon("foogl_icon16.gif");
screen = appContainer;
appContainer.start();
} catch (SlickException e) {
Log.error(e);
//Log.out.flush();
}
}
/**
* �����¡����������ʴ������Ẻ����� <br>
* 㹤��������´ 800x600
*/
public void showFullscreen() {
showFrame(800, 600, true);
}
public Image getLogo(){
try {
return new Image("logo/foogl.png");
} catch (SlickException e) {
e.printStackTrace();
}
return null;
}
public final void enterScene(int id) {
game.enterScene(id);
}
public final void enterScene(int id, Transition leave, Transition enter) {
game.enterScene(id, leave, enter);
}
}