Package kku.cs.fgl

Source Code of kku.cs.fgl.Scene

/*
* 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.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

/**
* Scene ������Ѻ���ҧ�ҡ�ͧ���� �����������ö�������� Scene �����ҧ�֧
* Scene �������� id <br>
* Scene �е�ҧ�ҡ AbstractScene �ç��� Scene ���ա���ʴ� logo �ͧ FooGameLib
* ����
*
* @author Wachirawut Thamviset
*
*/
abstract public class Scene extends AbstractScene {
  static private Image logo;

  /*
   * ��ǹ�ʴ� Logo �ͧ KKU GameLib
   */
  static int logoTime = 0;

  static Color logoColor = new Color(255, 255, 255, 100);

  private Cursor cursor = new Cursor(1);
 
  private EffectManager effect = new EffectManager();


  /**
   * ���ҧ Scene �µ�ͧ�к� id ��� gamePane
   *
   * @param id
   * @param gamePane
   */
  public Scene(int id, GamePane gamePane) {
    super(id, gamePane);
    setCursor(cursor);
    cursor.setScale(1, 1);
  }
 
  public Scene(int id){
    this(id,GamePane.getDefaultPane());
  }

  /**
   * �١���¡�����Ҵ˹�Ҩ�
   */
  public void paint(Graphics g) {
    /*
     * try { if (logo == null) { logo = new Image("foogl.png"); } } catch
     * (SlickException e) { } super.paint(g); paintInfo(g);
     * g.drawImage(logo, screen.getWidth() - logo.getWidth(), screen
     * .getHeight() - logo.getHeight(), logoColor);
     */
    super.paint(g);
    if (screen.isShowingFPS())
      paintInfo(g);
    if (cursor != null)
      cursor.render(g);
  }

  /**
   * �١���¡���;���� �ӹǹ Actor
   *
   * @param g
   */
  public void paintInfo(Graphics g) {
    getFont(0).drawString(10,28,"Actor:" + getActorCount(),Color.white);
  }

  /**
   * �١���¡���� update ������ �� delta �����ѧ��ҧ�ͧ���� (1/1000
   * �Թҷ�)
   */
  public void update(int delta) {
    if (cursor != null) {
      cursor.input = screen.getInput();
      cursor.update(delta);
    }
    effect.update(delta);
    // updateLogo(delta);
  }

  /**
   * update ������ logo
   *
   * @param delta
   */
  public void updateLogo(int delta) {

    logoTime += delta;
    if (logoTime < 1000) {
      logoColor.a = 0.1f;
    }
    if (logoTime > 1000 && logoTime < 1500) {
      if (logoColor.a < 1f)
        logoColor.a *= 1.1f;
      if (logoColor.a > 1f)
        logoColor.a = 1f;
    }
    if (logoTime > 8000 && logoTime < 10000) {
      logoColor.a *= 0.95f;
    }
    if (logoTime > 10000 && logoColor.a < 0.5f) {
      logoColor.a = 0.2f;
    }
    if (logoTime > 20000) {
      logoTime = 0;
    }
  }

  public Cursor getCursor() {
    return cursor;
  }

  public void setCursor(Cursor cursor) {
    this.cursor = cursor;
    showNativeCursor(cursor == null);
  }

  private void showNativeCursor(boolean show) {
    if (!show) {
      try {
        int w = org.lwjgl.input.Cursor.getMinCursorSize();
        IntBuffer cursorImages;
        cursorImages = ByteBuffer.allocateDirect(w * w * 4).order(
            ByteOrder.nativeOrder()).asIntBuffer();

        org.lwjgl.input.Cursor cur = new org.lwjgl.input.Cursor(w, w,
            0, 0, 1, cursorImages, null);
        Mouse.setNativeCursor(cur);
      } catch (LWJGLException e) {
        e.printStackTrace();
      }
    } else {
      try {
        Mouse.setNativeCursor(null);
      } catch (LWJGLException e) {
        e.printStackTrace();
      }
    }
  }
  public EffectManager getEffect() {
    return effect;
  }
  public EffectManager getFx() {
    return effect;
  }
 
}
TOP

Related Classes of kku.cs.fgl.Scene

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.