/*
* FooGameLib (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.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.util.Iterator;
import kku.cs.fgl.actor.LabelActor;
import kku.cs.fgl.gui.TComponent;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import org.lwjgl.input.Cursor;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.GameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.Transition;
import org.newdawn.slick.util.ClasspathLocation;
/**
* class GamePane �� class �����ʹ�ҡ StateBasedGame
* ����������Ѻ�Ѵ��éҡ (Scene) �����
* �����¡������ enterScene ��������¹�ҡ㹡���ʴ���
*
* instance �ͧ���ʹ��ж١���ҧ���ѵ��ѵԨҡ class GameLoader
* ��������繵�ͧ new GamePane �ͧ <br>
*
* Class ������ҧ�����繡�� �������͡Ѻ Slick �����ҹ����
* @author Wachirawut Thamviset
*
*/
final public class GamePane extends StateBasedGame {
static private Font fonts[] = new Font[5];
static private GamePane defaultPane;
/**
* ������Ѻ���͡ font ������ʴ��� �� font �ж١ load �ҡ package kku.cs.fgl.font
* FooGameLib ������� font �ҵðҹ�������� 4 Ẻ
*
* @param font ����Ţ���ʢͧ font ���� 0,1,2,3,4
* @return
*/
static public Font getFont(int font) {
if (font > fonts.length)
font = 0;
if (fonts[font] == null) {
try {
fonts[font] = new BMFont(font);
} catch (SlickException e) {
}
}
return fonts[font];
}
protected GameContainer screen;
protected GameLoader applet;
public GamePane(GameLoader applet,String title) {
super(title);
this.applet = applet;
ClasspathLocation.addClass(GamePane.class);
defaultPane = this;
}
public static GamePane getDefaultPane() {
return defaultPane;
}
/**
* ������Ѻ����¹�ҡ ���к� id �ͧ�ҡ����ͧ���
* @param id
*/
final public void enterScene(int id) {
super.enterState(id);
}
/**
* ������Ѻ����¹�ҡ ���к� id �ͧ�ҡ����ͧ��� ��� �к��Ըա���ʴ���Ѻ�ҡ
* �� ��� Zoom ���� Rotate ����ҡ class � kku.cs.fgl.transition
* @param id
*/
final public void enterScene(int id, Transition leave, Transition enter) {
super.enterState(id, leave, enter);
}
/**
* ���¡������Ѻ������
*
*/
public void exit() {
screen.exit();
}
public GameContainer getScreen() {
return screen;
}
final public void initStatesList(GameContainer container)
throws SlickException {
screen = container;
fonts[0]=screen.getDefaultFont();
FooglIntroScene iscene = new FooglIntroScene(this);
iscene.applet = applet;
TComponent.initGUI(container.getInput());
}
private static int screenShotCounter=0;
public static String screenShotPath="";
/**
* �Ǻ�����á����� ����ͼ���顴 F10 �����Ѻ mode �������
*/
public void keyPressed(int key, char c) {
super.keyPressed(key, c);
if (key == Input.KEY_F11) {
try {
screen.setFullscreen(!screen.isFullscreen());
} catch (SlickException e) {
e.printStackTrace();
}
}
if (key==Input.KEY_SYSRQ){
File f= new File(screenShotPath+"scr"+screenShotCounter+".png");
while(f.exists()){
screenShotCounter++;
f= new File(screenShotPath+"scr"+screenShotCounter+".png");
}
AbstractScene scene =((AbstractScene)getCurrentState());
scene.screenShot(f.getAbsolutePath());
screenShotCounter++;
LabelActor msg = new LabelActor(0,screen.getHeight()-20,"Screen saved in:"+f.getAbsolutePath());
msg.dead(2000);
scene.add(msg);
}
}
public void destroy() {
((AbstractScene)getCurrentState()).clear();
}
public AbstractScene getScene(int i) {
return (AbstractScene) getState(i);
}
}