您的位置:首页 > 编程语言 > Java开发

Java游戏开发组件LGame简易测试版发布(版本号:0.1.5)

2009-09-14 22:07 645 查看
LGame-Simple-0.1.5组件下载地址:http://code.google.com/p/loon-simple/downloads/list





2009-09-13 更新内容: Java游戏开发组件LGame简易测试版发布(版本号:0.1.5),增加了精灵与碰撞处理模块,增加了部分组件功能,增加了XML处理功能,增加了部分辅助类,增加了自定义事件监听功能,增加了少量特效,调整了部分框架结构。



LGame是Loonframework框架的一部分,也是针对Java2D游戏开发而设计的“一揽子”计划,它的创立目的在于构建一个高效且完善的Java2D游戏开发体系。



LGame
作为支持Java桌面游戏或网页游戏开发的全功能引擎,无论对画面绘制、精灵碰撞、特效渲染、窗体组件乃至于XML读取,文本数据库操作都提供有内置的具
体解决方案,避免了多包配置的繁琐与不便。出于效率考虑,LGame中所有组件都不依赖于Swing,而是基于AWT独立绘制成型,因此它可以将自身的运
行环境压缩到最小,一个压缩后不足4MB的精简JRE,已足够支持它的运行,也就是与RMXP或吉里吉里2的运行库大小相仿佛,但功能却更多。



只要您能够熟练操作LGame,世界上并没有任何一种2D游戏,是您所无法快速实现的。



PS:
目前LGame尚未推出正式版本,LGame-Simple为前瞻性测试及吸收反馈意见用,此时LGame框架的基本架构尚未最终确定,因此无法保证不同
版本间的兼容性。LGame-Simple以每版+0.5的方式跳跃式升级,当LGame-Simple更新到1.0版本时,既推出LGame-0.1的
正式版本,并开放SVN,LGame正式版推出后将始终保持新版与旧版间的兼容性。



部分游戏示例:

















以下为0.1.5版中一些应用实例:


1、建立一个空窗体




package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email <a title="" href="http://hi.baidu.com/ceponline" mce_href="http://hi.baidu.com/ceponline" target="_blank">ceponline</a>@yahoo.com.cn
 * @version 0.1.1
 */
public class HelloJavaGame extends Screen {
	/**
	 * 绘图器接口
	 * 
	 * 在没有任何限制的情况下,此接口中数据会以最大FPS自动进行刷新。 LGame框架建议您以draw绘制图形,重载next以处理具体的业务数据。
	 */
	public void draw(Graphics2D g) {
	}
	/**
	 * 于Screen中点击鼠标左键
	 */
	public void leftClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标中间键
	 */
	public void middleClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标右键
	 */
	public void rightClick(MouseEvent e) {
	}
	/**
	 * 于Screen中按下键盘
	 */
	public void onKey(KeyEvent e) {
	}
	/**
	 * 于Screen中放开键盘
	 */
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		// 获得一个游戏窗体
		GameFrame frame = new GameFrame("[LGame-simple-0.1.5使用范例]-建立一个空窗体",
				480, 360);
		// 得到此窗体所对应的游戏部署器
		Deploy deploy = frame.getDeploy();
		// 设定此游戏屏幕(在任何时候都可以通过Screen中的setScreen函数切换游戏屏幕)
		deploy.setScreen(new HelloJavaGame());
		// 是否显示FPS
		deploy.setShowFPS(true);
		// 是否显示框架logo
		deploy.setLogo(false);
		// 允许的最大刷新率
		deploy.setFPS(100);
		// 开始游戏主循环体
		deploy.mainLoop();
		// 显示游戏
		frame.showFrame();
	}
}







2、载入背景图像,并显示按钮




package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.window.LButton;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email <a title="" href="http://hi.baidu.com/ceponline" mce_href="http://hi.baidu.com/ceponline" target="_blank">ceponline</a>@yahoo.com.cn
 * @version 0.1.1
 */
public class HelloJavaGame1 extends Screen {
	// 创建一个按钮,宽200,高40,显示位置取Screen中心
	private LButton button = new LButton("Hello Java Game!", 0, 0, 200, 40);
	public HelloJavaGame1() {
		// 设定当前Screen背景图片
		this.setBackground("images/background.jpg");
		// 加载一个按钮于Screen之上
		this.add(button);
		// 按钮居中显示
		this.centerOn(button);
	}
	/**
	 * 绘图器接口
	 * 
	 * 在没有任何限制的情况下,此接口中数据会以最大FPS自动进行刷新。 LGame框架建议您以draw绘制图形,重载next以处理具体的业务数据。
	 */
	public void draw(Graphics2D g) {
	}
	/**
	 * 于Screen中点击鼠标左键
	 */
	public void leftClick(MouseEvent e) {
		// 点击鼠标左键时按钮消失
		this.button.setVisible(false);
	}
	/**
	 * 于Screen中点击鼠标中间键
	 */
	public void middleClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标右键
	 */
	public void rightClick(MouseEvent e) {
		// 点击鼠标右键时按钮显示
		this.button.setVisible(true);
	}
	/**
	 * 于Screen中按下键盘
	 */
	public void onKey(KeyEvent e) {
	}
	/**
	 * 于Screen中放开键盘
	 */
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		// 获得一个游戏窗体
		GameFrame frame = new GameFrame(
				"[LGame-simple-0.1.5使用范例]-载入背景图像,并显示一个按钮", 480, 360);
		// 得到此窗体所对应的游戏部署器
		Deploy deploy = frame.getDeploy();
		// 设定此游戏屏幕(在任何时候都可以通过Screen中的setScreen函数切换游戏屏幕)
		deploy.setScreen(new HelloJavaGame1());
		// 是否显示FPS
		deploy.setShowFPS(true);
		// 是否显示框架logo
		deploy.setLogo(false);
		// 允许的最大刷新率
		deploy.setFPS(100);
		// 开始游戏主循环体
		deploy.mainLoop();
		// 显示游戏
		frame.showFrame();
	}
}









3、载入窗体,并在窗体上加载一个按钮


package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.window.LButton;
import org.loon.framework.game.simple.window.LForm;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email <a title="" href="http://hi.baidu.com/ceponline" mce_href="http://hi.baidu.com/ceponline" target="_blank">ceponline</a>@yahoo.com.cn
 * @version 0.1.1
 */
public class HelloJavaGame2 extends Screen {
	// 设定按钮宽,设定按钮高
	private int btnWidth = 200, btnHeight = 40, frmWidth = 300,
			frmHeight = 300;
	// 创建一个窗体,显示隐藏项及关闭项,宽300,高300,显示位置取Screen中心
	private LForm form = new LForm("我是一个纯绘制的窗体!", true, true, 0, 0, frmWidth,
			frmHeight);
	// 创建一个按钮,宽200,高40,显示位置取form中心
	private LButton button = new LButton("Hello Java Game!", form.getWidth() / 2
			- btnWidth / 2, form.getHeight() / 2 - btnHeight / 2, btnWidth,
			btnHeight);
	public HelloJavaGame2() {
		// 设定当前Screen背景图片
		this.setBackground("images/background.jpg");
		// 加载一个按钮于form之上
		this.form.add(button);
		// 加载form于screen之上
		this.add(form);
		// 居中窗体
		centerOn(form);
	}
	/**
	 * 绘图器接口
	 * 
	 * 在没有任何限制的情况下,此接口中数据会以最大FPS自动进行刷新。 LGame框架建议您以draw绘制图形,重载next以处理具体的业务数据。
	 */
	public void draw(Graphics2D g) {
	}
	/**
	 * 于Screen中点击鼠标左键
	 */
	public void leftClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标中间键
	 */
	public void middleClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标右键
	 */
	public void rightClick(MouseEvent e) {
	}
	/**
	 * 于Screen中按下键盘
	 */
	public void onKey(KeyEvent e) {
	}
	/**
	 * 于Screen中放开键盘
	 */
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		// 获得一个游戏窗体
		GameFrame frame = new GameFrame(
				"[LGame-simple-0.1.5使用范例]-载入窗体,并在窗体上加载一个按钮", 480, 360);
		// 得到此窗体所对应的游戏部署器
		Deploy deploy = frame.getDeploy();
		// 设定此游戏屏幕(在任何时候都可以通过Screen中的setScreen函数切换游戏屏幕)
		deploy.setScreen(new HelloJavaGame2());
		// 是否显示FPS
		deploy.setShowFPS(true);
		// 是否显示框架logo
		deploy.setLogo(false);
		// 允许的最大刷新率
		deploy.setFPS(100);
		// 开始游戏主循环体
		deploy.mainLoop();
		// 显示游戏
		frame.showFrame();
	}
}









4、窗体的加载及使用


package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.window.LButton;
import org.loon.framework.game.simple.window.LForm;
import org.loon.framework.game.simple.window.LPaper;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1.1
 */
public class HelloJavaGame3 extends Screen {
	// 创建一张空纸,在其上加载指定图像
	private LPaper paper = new LPaper("images/dialog.png", 40, 40);
	// 创建窗口1
	private LForm form1 = new LForm("新建窗口1", true, true, 10, 10, 202, 220);
	// 创建窗口2
	private LForm form2 = new LForm("新建窗口2", true, true, 90, 135, 202, 220);
	public HelloJavaGame3() {
		this.setBackground("images/background.jpg");
		LButton button1 = new LButton("显示Paper", 25, 25, 150, 25) {
			public void doClick() {
				paper.setVisible(true);
			}
		};
		LButton button2 = new LButton("隐藏Paper", 25, 65, 150, 25) {
			public void doClick() {
				paper.setVisible(false);
			}
		};
		LButton button3 = new LButton("禁止Paper被拖拽", 25, 25, 150, 25) {
			public void doClick() {
				paper.setLocked(true);
			}
		};
		LButton button4 = new LButton("允许Paper被拖拽", 25, 65, 150, 25) {
			public void doClick() {
				paper.setLocked(false);
			}
		};
		// 设定窗体1透明度为0.5f
		this.form1.setAlpha(0.5f);
		// 窗体1加载两个按钮
		this.form1.add(button1);
		this.form1.add(button2);
		// 窗体2加载两个按钮
		this.form2.add(button3);
		this.form2.add(button4);
		// 设定paper透明度为0.9f
		this.paper.setAlpha(0.9f);
		// 设定paper初始状态为不可见
		this.paper.setVisible(false);
		// 载入Screen
		this.add(form1);
		this.add(form2);
		this.add(paper);
	}
	/**
	 * 绘图器接口
	 * 
	 * 在没有任何限制的情况下,此接口中数据会以最大FPS自动进行刷新。 LGame框架建议您以draw绘制图形,重载next以处理具体的业务数据。
	 */
	public void draw(Graphics2D g) {
	}
	/**
	 * 于Screen中点击鼠标左键
	 */
	public void leftClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标中间键
	 */
	public void middleClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标右键
	 */
	public void rightClick(MouseEvent e) {
	}
	/**
	 * 于Screen中按下键盘
	 */
	public void onKey(KeyEvent e) {
	}
	/**
	 * 于Screen中放开键盘
	 */
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		// 获得一个游戏窗体
		GameFrame frame = new GameFrame(
				"[LGame-simple-0.1.5使用范例]-窗体的加载及使用", 480, 360);
		// 得到此窗体所对应的游戏部署器
		Deploy deploy = frame.getDeploy();
		// 设定此游戏屏幕(在任何时候都可以通过Screen中的setScreen函数切换游戏屏幕)
		deploy.setScreen(new HelloJavaGame3());
		// 是否显示FPS
		deploy.setShowFPS(true);
		// 是否显示框架logo
		deploy.setLogo(false);
		// 允许的最大刷新率
		deploy.setFPS(100);
		// 开始游戏主循环体
		deploy.mainLoop();
		// 显示游戏
		frame.showFrame();
	}
}









4、简易菜单***




package org.loon.game.simple.test;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.core.LTimer;
import org.loon.framework.game.simple.utils.GraphicsUtils;
import org.loon.framework.game.simple.window.LText;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1.1
 */
public class HelloJavaGame4 extends Screen {
	private LText text = new LText("尚未进行任何选择", 150, 40, 140, 50);
	private Image[] arrows = GraphicsUtils.getSplitImages("images/arrow.png",
			9, 9);
	private int option, blinkType;
	private LTimer lTimer = new LTimer(400);
	public HelloJavaGame4() {
		this.setBackground("images/background.jpg");
		this.text.setAlpha(0.5f);
		this.add(text);
	}
	public void alter(long timer) {
		if (lTimer.action(timer)) {
			blinkType++;
			if (blinkType > 2) {
				blinkType = 0;
			}
		}
	}
	/**
	 * 绘图器接口
	 * 
	 * 在没有任何限制的情况下,此接口中数据会以最大FPS自动进行刷新。 LGame框架建议您以draw绘制图形,重载next以处理具体的业务数据。
	 */
	public void draw(Graphics2D g) {
		GraphicsUtils.setAntialias(g, true);
		g.setFont(GraphicsUtils.getFont("华文新魏", 20));
		GraphicsUtils.drawStyleString(g, "开始游戏", 180, 190, Color.WHITE,
				Color.BLACK);
		GraphicsUtils.drawStyleString(g, "读取记录", 180, 220, Color.WHITE,
				Color.BLACK);
		GraphicsUtils.drawStyleString(g, "环境设定", 180, 250, Color.WHITE,
				Color.BLACK);
		GraphicsUtils.drawStyleString(g, "结束游戏", 180, 280, Color.WHITE,
				Color.BLACK);
		GraphicsUtils.setAntialias(g, false);
		switch (option) {
		case 0:
			g.drawImage(arrows[blinkType], 160, 180, null);
			break;
		case 1:
			g.drawImage(arrows[blinkType], 160, 210, null);
			break;
		case 2:
			g.drawImage(arrows[blinkType], 160, 240, null);
			break;
		case 3:
			g.drawImage(arrows[blinkType], 160, 270, null);
			break;
		}
	}
	/**
	 * 于Screen中点击鼠标左键
	 */
	public void leftClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标中间键
	 */
	public void middleClick(MouseEvent e) {
	}
	/**
	 * 于Screen中点击鼠标右键
	 */
	public void rightClick(MouseEvent e) {
	}
	/**
	 * 于Screen中按下键盘
	 */
	public void onKey(KeyEvent e) {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_ENTER:
			if (option == 0) {
				text.setText("选中[开始游戏]");
			} else if (option == 1) {
				text.setText("选中[读取记录]");
			} else if (option == 2) {
				text.setText("选中[环境设定]");
			} else if (option == 3) {
				text.setText("选中[结束游戏]");
			}
			break;
		case KeyEvent.VK_UP:
			option--;
			if (option < 0) {
				option = 3;
			}
			break;
		case KeyEvent.VK_DOWN:
			option++;
			if (option > 3) {
				option = 0;
			}
			break;
		}
	}
	/**
	 * 于Screen中放开键盘
	 */
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		// 获得一个游戏窗体
		GameFrame frame = new GameFrame("[LGame-simple-0.1.5使用范例]-***简易菜单", 480,
				360);
		// 得到此窗体所对应的游戏部署器
		Deploy deploy = frame.getDeploy();
		// 设定此游戏屏幕(在任何时候都可以通过Screen中的setScreen函数切换游戏屏幕)
		deploy.setScreen(new HelloJavaGame4());
		// 是否显示FPS
		deploy.setShowFPS(true);
		// 是否显示框架logo
		deploy.setLogo(false);
		// 允许的最大刷新率
		deploy.setFPS(100);
		// 开始游戏主循环体
		deploy.mainLoop();
		// 显示游戏
		frame.showFrame();
	}
}









5、设置游戏事件监听




package org.loon.game.simple.test;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.action.IAction;
import org.loon.framework.game.simple.action.MoveAction;
import org.loon.framework.game.simple.action.map.Vector2D;
import org.loon.framework.game.simple.action.sprite.Sprite;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1
 */
public class HelloJavaGame5 extends Screen {
	// 加入一个精灵,以下参数分别为[图像位置,最大桢数,x,y,width,height,每桢刷新率]
	private Sprite sprite = new Sprite("images/dog.png", 21, 50, 50, 45, 29,
			150);
	// 自定义Action
	class MyAction implements IAction {
		public void doAction(long timer) {
			sprite.setVisible(!sprite.isVisible());
		}
	}
	public HelloJavaGame5() {
		// 获得2D定位器
		Vector2D vector = sprite.getLocation();
		this.setBackground(Color.BLACK);
		// 添加自定义事件
		this.addKeyEvents(KeyEvent.VK_F1, "F1", new MyAction());
		this.addMouseEvents(MouseEvent.BUTTON1, "Mouse Left", new MyAction());
		// 添加组件库自带的移动事件
		this.addKeyEvents(KeyEvent.VK_UP, "Move Up", new MoveAction(vector, 0,
				-0.1));
		this.addKeyEvents(KeyEvent.VK_DOWN, "Move Down", new MoveAction(vector,
				0, 0.1));
		this.addKeyEvents(KeyEvent.VK_LEFT, "Move Left", new MoveAction(vector,
				-0.1, 0));
		this.addKeyEvents(KeyEvent.VK_RIGHT, "Move Right", new MoveAction(
				vector, 0.1, 0));
		this.add(sprite);
	}
	public void draw(Graphics2D g) {
	}
	public void leftClick(MouseEvent e) {
	}
	public void middleClick(MouseEvent e) {
	}
	public void rightClick(MouseEvent e) {
	}
	public void onKey(KeyEvent e) {
	}
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		GameFrame frame = new GameFrame("[LGame-simple-0.1.5使用范例]-设置游戏事件监听",
				480, 360);
		Deploy deploy = frame.getDeploy();
		deploy.setScreen(new HelloJavaGame5());
		deploy.setLogo(false);
		deploy.setShowFPS(true);
		deploy.setFPS(100);
		deploy.mainLoop();
		frame.showFrame();
		frame.updateFullScreen();
	}
}









6、逐字打印消息框应用




package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.action.sprite.Animation;
import org.loon.framework.game.simple.extend.MessageFormDialog;
import org.loon.framework.game.simple.window.LMessage;
import org.loon.framework.game.simple.window.LPaper;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1
 */
public class HelloJavaGame6 extends Screen {
	final private static Image dialog1 = MessageFormDialog.getRMXPDialog(
			"images/window.png", 260, 200);
	final private static Image dialog2 = MessageFormDialog.getRMXPDialog(
			"images/window.png", 400, 150);
	public HelloJavaGame6() {
		// 设定游戏背景图
		setBackground("images/background.jpg");
		// 樱花飞舞特效,默认全屏
		// PetalEffect sakura=new PetalEffect();
		// 添加
		// this.add(sakura);
		// 获得一个信息显示组件1
		LMessage message1 = new LMessage(25, 25, 260, 200) {
			// 设定点击事件
			public void doClick() {
				if (leftClick()) {
					setMessage("白发三千横世态,/n玉骨冰心纵苍穹。/n风节自古如残照,/n青袍一舞笑人庸。");
				} else if (middleClick()) {
					setMessage("欲海沉浮名利争,/n石光电火步此生。/n风尘情事挥不尽,/n观世不笑是痴人。");
				} else if (rightClick()) {
					setMessage("半神半圣亦半仙,/n全儒全道是全贤。/n脑中真书识万卷,/n掌握文武半边天。");
				}
			}
		};
		// 背景图
		message1.setBackground(dialog1);
		// 不锁定画面(允许拖拽)
		message1.setLocked(false);
		// 加载文字打印完毕时暂停动画(参数分别为文件地址,每图宽,每图高,延迟时间)
		message1.setPauseIconAnimation(Animation.getDefaultAnimation(
				"images/pause.png", 37, 55, 200));
		// 设定文字打印完毕时暂停动画播放位置
		// message.setPauseIconAnimationLocation(x, y);
		// 字标图
		// message.setTipIcon(null);
		// 默认的显示内容
		message1.setMessage("平生进退如飙风,/n一睨人才天下空。/n独向苍天横冷剑,/n何必生我惭<r英雄/>。");
		// 每行最多显示的文字数量
		message1.setMessageLength(7);
		// 逐字显示延迟时间
		message1.setDelay(100);
		// 获得一个信息显示组件2
		LMessage message2 = new LMessage(50, 90, 400, 150);
		message2.setLocked(false);
		message2.setBackground(dialog2);
		// 加载Paper组件,充当脸谱
		LPaper face = new LPaper("images/loli.png", 25, 25);
		// 添加组件
		message2.add(face);
		// 设定文字显示位置左偏移数值
		message2.setLeftOffset(50);
		// 设定文字显示位置顶点偏移数值
		message2.setTopOffset(5);
		message2.setMessageLength(12);
		message2.setMessage(" 强奸是犯罪的,推倒是正义的。H是不行的,工口是合理的。");
		// 居中
		this.centerOn(message1);
		// 添加组件到窗体
		this.add(message1);
		this.add(message2);
	}
	public void draw(Graphics2D g) {
	}
	public void leftClick(MouseEvent e) {
	}
	public void middleClick(MouseEvent e) {
	}
	public void rightClick(MouseEvent e) {
	}
	public void onKey(KeyEvent e) {
	}
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		GameFrame frame = new GameFrame("[LGame-simple-0.1.5使用范例]-逐字打印消息框应用",
				480, 360);
		Deploy deploy = frame.getDeploy();
		deploy.setScreen(new HelloJavaGame6());
		deploy.setLogo(false);
		deploy.setShowFPS(true);
		deploy.setFPS(100);
		deploy.mainLoop();
		frame.showFrame();
	}
}









7、特效的使用




package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.action.sprite.effect.CardFadeEffect;
import org.loon.framework.game.simple.action.sprite.effect.PetalEffect;
import org.loon.framework.game.simple.core.LTimerContext;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1
 */
public class HelloJavaGame7 extends Screen {
	// 添加卡片过滤特效,位置默认(全屏)
	private CardFadeEffect card = new CardFadeEffect("images/background.jpg");
	// 添加樱花飘落特效,位置默认(全屏)
	private PetalEffect petal = new PetalEffect();
	private boolean locked = false;
	public HelloJavaGame7() {
		add(card);
	}
	public void alter(LTimerContext timer) {
		// 当卡片特效执行完毕后
		if (card.isComplete() && !locked) {
			this.remove(card);
			this.setBackground("images/background.jpg");
			this.add(petal);
			this.locked = true;
		}
	}
	public void draw(Graphics2D g) {
	}
	public void leftClick(MouseEvent e) {
	}
	public void middleClick(MouseEvent e) {
	}
	public void rightClick(MouseEvent e) {
	}
	public void onKey(KeyEvent e) {
	}
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		GameFrame frame = new GameFrame("[LGame-simple-0.1.5使用范例]-特效的使用", 480,
				360);
		Deploy deploy = frame.getDeploy();
		deploy.setScreen(new HelloJavaGame7());
		deploy.setLogo(false);
		deploy.setShowFPS(true);
		deploy.setFPS(100);
		deploy.mainLoop();
		frame.showFrame();
	}
}









8、加载XML文档




package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.action.sprite.SpriteImage;
import org.loon.framework.game.simple.extend.xml.Ldom;
import org.loon.framework.game.simple.extend.xml.XmlUtils;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1
 */
public class HelloJavaGame8 extends Screen {
	public HelloJavaGame8() {
		// 创建一个精灵图像数组
		SpriteImage[] sprite = new SpriteImage[2];
		// 载入自定义文档,自item节点开始
		Ldom dom = XmlUtils.getInstance("images/my.xml", "item");
		// 遍历子文档
		for (Iterator it = dom.getChildren().iterator(); it.hasNext();) {
			Ldom child = (Ldom) it.next();
			// 获得子节点属性
			String attribute = (String) child.getAttributes()
					.getAttributeValue(0);
			if ("背景".equals(attribute)) {
				sprite[0] = new SpriteImage(child.getNodeValue());
			} else if ("角色".equals(attribute)) {
				sprite[1] = new SpriteImage(child.getNodeValue());
			} else if ("targets".equals(child.getNodeName())) {
				int index = 0;
				// 读取targets节点中坐标数据
				for (Iterator itr = child.getChildren().iterator(); itr
						.hasNext();) {
					Ldom target = (Ldom) itr.next();
					sprite[index].setX(Integer.valueOf((String) target
							.getAttributes().getAttributeValue("x")));
					sprite[index].setY(Integer.valueOf((String) target
							.getAttributes().getAttributeValue("y")));
					add(sprite[index]);
					index++;
				}
			}
		}
	}
	public void draw(Graphics2D g) {
	}
	public void leftClick(MouseEvent e) {
	}
	public void middleClick(MouseEvent e) {
	}
	public void rightClick(MouseEvent e) {
	}
	public void onKey(KeyEvent e) {
	}
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		GameFrame frame = new GameFrame("[LGame-simple-0.1.5使用范例]-加载XML文档",
				480, 360);
		Deploy deploy = frame.getDeploy();
		deploy.setScreen(new HelloJavaGame8());
		deploy.setLogo(false);
		deploy.setShowFPS(true);
		deploy.setFPS(100);
		deploy.mainLoop();
		frame.showFrame();
	}
}









9、加载文本数据库




package org.loon.game.simple.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import org.loon.framework.game.simple.Deploy;
import org.loon.framework.game.simple.GameFrame;
import org.loon.framework.game.simple.Screen;
import org.loon.framework.game.simple.extend.db.Engine;
import org.loon.framework.game.simple.extend.db.MDB;
import org.loon.framework.game.simple.extend.db.type.TypeBase;
import org.loon.framework.game.simple.window.LMessage;
/**
 * Copyright 2008 - 2009
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loonframework
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1
 */
public class HelloJavaGame9 extends Screen {
	private LMessage message = new LMessage(0, 0, 400, 300);
	public HelloJavaGame9() {
		setBackground("images/background.jpg");
		StringBuffer buffer = new StringBuffer();
		// mdb是LGame提供的简化版嵌入式文本数据库(完整版请参见本人Blog关于Lmini的部分),
		// 支持简单的CRUD操作
		MDB mdb = Engine.getMDB("test.db");
		// 打开指定表格,并指定数据处理类型,支持的存储类型为[Object,String,Long,Integer,
		// byte[]]等五种
		mdb.openTable("test", TypeBase.STRING);
		// 设定密码
		mdb.begin("wt98ab");
		// 插入数据
		mdb.insert("久保", "砍砍砍");
		mdb.insert("尾田", "我要成为海军");
		mdb.insert("岸本", "都死光了");
		// 删除数据
		mdb.delete("岸本");
		// 变更数据
		mdb.update("尾田", "我要成为海贼王");
		// 插入数据
		mdb.insert("岸本", "誓不辱没烂尾王之名");
		for (Iterator it = mdb.getTableKey().iterator(); it.hasNext();) {
			String name = (String) it.next();
			buffer.append("字段名:" + name + "/n" + "数据:"
					+ (String) mdb.getTableList().get(name) + "/n");
			buffer.append("/n");
		}
		// 关闭文本数据库
		mdb.end();
		// 每行最多显示12个汉字
		message.setMessageLength(12);
		// 注入信息
		message.setMessage(buffer.toString());
		this.add(message);
		this.centerOn(message);
	}
	public void draw(Graphics2D g) {
	}
	public void leftClick(MouseEvent e) {
	}
	public void middleClick(MouseEvent e) {
	}
	public void rightClick(MouseEvent e) {
	}
	public void onKey(KeyEvent e) {
	}
	public void onKeyUp(KeyEvent e) {
	}
	public static void main(String[] args) {
		GameFrame frame = new GameFrame("[LGame-simple-0.1.5使用范例]-加载文本数据库",
				480, 360);
		Deploy deploy = frame.getDeploy();
		deploy.setScreen(new HelloJavaGame9());
		deploy.setLogo(false);
		deploy.setShowFPS(true);
		deploy.setFPS(100);
		deploy.mainLoop();
		frame.showFrame();
	}
}









________

我就是传说中的分割线SAMA________




最近业余时间都花在续写以前的轻小说上,可惜坚持了两个月左右,终于再次挺不住了
(新写了将近6万多字啊,我容易嘛我)
……

上周得闲将LGame-Simple升级到了0.1.5,暗自准备走小日本的老路写同人游戏推小说(传说中的Fate模式),照这个速度十一过后估计能推出0.2.0版,将会重点补足特效、精灵以及组件部分,另外等这部分写完了偶就准备开始“剽窃”吉里吉里源码……

最后,由于近期
饭否、爱枣等相继报废或半残,所以偶——终于堕落到会去泡S1的境界了≡(▔﹏▔)≡
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: