分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
2010-08-19更新内容:
1、针对Android版增加了多点触摸支持。
2、增加了一组模拟按钮,以Screen实现Emulator监听(此监听器对应8种按钮事件)即可直接使用。
3、增加了一些细节处的功能扩展,譬如Android版LSystem类已和JavaSE版一样提供了大量系统环境参数。
4、修正了某些环境会遇到的中文乱码问题以及新发现的框架BUG(旧版LGraphics类仿J2ME实现部分有BUG,建议更新此版)。
源码及jar下载地址:http://loon-simple.googlecode.com/files/LGame-0.2.7.7z
Android版启动函数变更:
在0.2.7版中,略微变更了游戏初始化方式,入口函数改为onMain。
- public class Main extends LGameAndroid2DActivity {
- public void onMain() {
- //this.initialization(false,LAD.LEFT, "Admob ID",60);
- this.initialization(false);
- this.setShowLogo(false);
- this.setScreen(new EmulatorTest());
- this.setFPS(50);
- this.setShowFPS(true);
- this.showScreen();
- }
- }
新增模拟按钮的使用:
为了适应复杂操作环境及格斗游戏需要,特为Android及JavaSE版LGame新增一组模拟按钮,在任意Screen中实现EmulatorListener监听即可调用。
基本使用方式如下:
- package org.loon.test;
- import org.loon.framework.android.game.action.sprite.ColorBackground;
- import org.loon.framework.android.game.core.EmulatorListener;
- import org.loon.framework.android.game.core.graphics.LColor;
- import org.loon.framework.android.game.core.graphics.Screen;
- import org.loon.framework.android.game.core.graphics.device.LGraphics;
- import android.view.KeyEvent;
- import android.view.MotionEvent;
- //所有的Screen(Screen、ThreadScreen、CanvasScreen)只要实现EmulatorListener监听,
- //即会自动调用模拟按键。
- public class EmulatorTest extends Screen implements EmulatorListener {
- private ColorBackground background;
- public EmulatorTest() {
- //通过getEmulatorButtons函数可以返回当前模拟按钮的数组集合。
- //getEmulatorButtons();
- }
- // 0.2.7版新增函数,会在Screen构建完成后执行并加载其中数据
- public void onLoad() {
- // 制作一块红色的背景,大小为48x48
- this.background = new ColorBackground(LColor.red, 48, 48);
- // 居中(ColorBackground本身为精灵)
- this.centerOn(background);
- // 加载
- this.add(background);
- }
- public void draw(LGraphics g) {
- }
- // 0.2.7版新增函数,仿照rokon同名函数构建,仅在支持多点触摸的环境中才能被触发。
- public void onTouch(float x, float y, MotionEvent e, int pointerCount,
- int pointerId) {
- }
- public boolean onKeyDown(int keyCode, KeyEvent e) {
- return true;
- }
- public boolean onKeyUp(int keyCode, KeyEvent e) {
- return true;
- }
- public boolean onTouchDown(MotionEvent e) {
- return true;
- }
- public boolean onTouchMove(MotionEvent e) {
- return true;
- }
- public boolean onTouchUp(MotionEvent e) {
- return true;
- }
- public void onUpClick() {
- if (background != null) {
- background.move_up(4);
- }
- }
- public void onDownClick() {
- if (background != null) {
- background.move_down(4);
- }
- }
- public void onLeftClick() {
- if (background != null) {
- background.move_left(4);
- }
- }
- public void onRightClick() {
- if (background != null) {
- background.move_right(4);
- }
- }
- public void onCancelClick() {
- if (background != null) {
- background.setVisible(false);
- }
- }
- public void onCircleClick() {
- }
- public void onSquareClick() {
- }
- public void onTriangleClick() {
- if (background != null) {
- background.setVisible(true);
- }
- }
- public void unCancelClick() {
- }
- public void unCircleClick() {
- }
- public void unDownClick() {
- }
- public void unLeftClick() {
- }
- public void unRightClick() {
- }
- public void unSquareClick() {
- }
- public void unTriangleClick() {
- }
- public void unUpClick() {
- }
用新增的模拟按键可以轻松实现格斗类或需要复杂操作的游戏:
框架基本使用方法请参见此文:http://blog.csdn.net/cping1982/archive/2010/08/06/5794380.aspx
以下为较早前发布过的一些程序示例画面(请下载较早前LGame发布版本获得):
以下为LGame-Simple开发的部分游戏示例画面。
源码及jar下载地址:http://loon-simple.googlecode.com/files/LGame-0.2.7.7z