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

更早前说明请见此处:http://blog.csdn.net/cping1982/archive/2009/09/14/4552803.aspx


下载地址(内含源码与示例)http://loon-simple.googlecode.com/files/LGame-Simple-0.2.0.7z

2009-10-10 LGame-Simple-0.2.0 更新内容:

刊正与JRE1.4的不兼容代码,确保LGame可以运行在JRE1.4及以上环境中,增加Screen中的全屏、网页浏览、AWT/Swing原生组件添加、游戏录像(保存为FLV)、游戏屏幕截图等功能,增加Ioc处理模块,增加Lua脚本处理模块(内置luajava,轻度封装),增加部分LGame特效与原生组件,扩充部分类库功能,调整程序架构。

PS:自LGame-Simple-0.2.0开始,LGame内置了Kepler提供的luajava作为lua的交互接口,现阶段仅提供Windows下Lua脚本的使用,其它环境下使用luajava,请自行编译,详见:http://www.keplerproject.org/luajava/manual.htmlconsole。

新增的几个示例(基本上每次更新加5个example):

基本辅助功能操作

package org.loon.game.simple.test; import java.awt.Button; import java.awt.Graphics2D; import java.awt.TextField; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import org.loon.framework.game.simple.core.Model; import org.loon.framework.game.simple.core.Screen; import org.loon.framework.game.simple.extend.DrawNumber; import org.loon.framework.game.simple.utils.DateUtils; import org.loon.framework.game.simple.utils.ioc.Ioc; import org.loon.framework.game.simple.utils.ioc.IocFactory; import org.loon.framework.game.simple.utils.ioc.reflect.Reflector; 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:ceponline@yahoo.com.cn * @version 0.1 */ public class HelloJavaGame10 extends Screen { // 数字绘制器 private DrawNumber number = new DrawNumber(2); public HelloJavaGame10() { // 按钮间偏移 int offsetX = 5, offsetY = 0; // 全屏游戏画面(当使用AWT/Swing组件时,将不支持此操作) LButton button1 = new LButton("images/button.png", "全屏画面", offsetX += 25, 25) { public void doClick() { updateFullScreen(640, 480); } }; add(button1); // 还原游戏画面 LButton button2 = new LButton("images/button.png", "还原画面", offsetX += button1.getWidth() + 25, 25) { public void doClick() { updateNormalScreen(); } }; add(button2); // 打开Google LButton button3 = new LButton("images/button.png", "打开Google", offsetX += button2.getWidth() + 25, 25) { public void doClick() { openBrowser("http://www.google.com/ncr"); } }; add(button3); // 录像当前画面 LButton button4 = new LButton("images/button.png", "屏幕录像", offsetX += button3.getWidth() + 25, 25) { public void doClick() { setVideo(true); } }; button4.setToolTipText("默认保存路径为运行路径下[video]文件夹,也可参数设置。"); add(button4); offsetX = 5; // 关闭屏幕录像 LButton button5 = new LButton("images/button.png", "停止录像", offsetX += 25, offsetY += button1.getHeight() + 40) { public void doClick() { setVideo(false); } }; add(button5); // 保存游戏截图 LButton button6 = new LButton("images/button.png", "游戏截图", offsetX += button5.getWidth() + 25, offsetY) { public void doClick() { saveScreenImage(); } }; button6.setToolTipText("默认保存路径为运行路径下[screen]文件夹,也可参数设置。"); add(button6); final TextField awtText = new TextField("AWT输入框"); final Button awtButton = new Button("AWT按钮"); // 添加标准的AWT/Swing Component LButton button7 = new LButton("images/button.png", "系统组件添加", offsetX += button6.getWidth() + 25, offsetY) { public void doClick() { addComponent(awtText, 200, 200, 200, 40); addComponent(awtButton, 200, 250, 200, 40); } }; button7.setToolTipText("添加一个AWT/Swing组件到窗体之上。"); add(button7); // 删除标准的AWT/Swing Component LButton button8 = new LButton("images/button.png", "系统组件删除", offsetX += button7.getWidth() + 25, offsetY) { public void doClick() { removeComponent(awtText); removeComponent(awtButton); } }; add(button8); offsetX = 5; // 弹出提示框 LButton button9 = new LButton("images/button.png", "弹出提示框", offsetX += 25, offsetY += button5.getHeight() + 15) { public void doClick() { showAWTMessageDialog("AWT", "这是一个AWT提示框 !"); } }; add(button9); // 弹出选择框 LButton button10 = new LButton("images/button.png", "弹出选择框", offsetX += button9.getWidth() + 25, offsetY) { public void doClick() { showAWTYesNoCancelDialog("AWT", "这是一个AWT选择框 !"); } }; add(button10); // 弹出路径选择 LButton button11 = new LButton("images/button.png", "弹出路径选择", offsetX += button10.getWidth() + 25, offsetY) { public void doClick() { showAWTOpenDialog("AWT", "C://"); } }; add(button11); LButton button12 = new LButton("images/button.png", "弹出输入框", offsetX += button11.getWidth() + 25, offsetY) { public void doClick() { showAWTInputDialog("AWT", "这是一个AWT输入框"); } }; add(button12); } public void draw(Graphics2D g) { // 绘制当前系统时间 number.drawNumber(g, 150, 5, DateUtils.toLocalDate()); } 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) { // 以Ioc方式构建一个游戏初始设置(示例用,非必要) try { // 构造函数,依次为窗体名称、加载模式(AWT/Swing)、窗体宽、窗体高 Object[] constructor = { "[LGame-simple版使用范例]-常见辅助功能的使用", new Integer(Model.Awt), new Integer(640), new Integer(480) }; // 绑定指定类及构造函数 Ioc ioc = IocFactory.bind( "org.loon.framework.game.simple.GameScene", constructor); // 获得下级类Deploy Ioc child = ioc.getChild("getDeploy"); // 设置Deploy child.setMethod("setScreen", Reflector.getReflector( HelloJavaGame10.class).newInstance()); child.setMethod("setLogo", false); child.setMethod("setFPS", 100L); child.setMethod("setShowFPS", true); // 启动主循环 child.doInvoke("mainLoop"); // 显示窗体 ioc.doInvoke("showFrame"); } catch (Exception e) { e.printStackTrace(); } } }

LSelect组件使用

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.action.sprite.effect.FreedomEffect; import org.loon.framework.game.simple.core.Model; import org.loon.framework.game.simple.core.Screen; import org.loon.framework.game.simple.extend.MessageFormDialog; import org.loon.framework.game.simple.utils.ioc.Ioc; import org.loon.framework.game.simple.utils.ioc.IocFactory; import org.loon.framework.game.simple.utils.ioc.reflect.Reflector; import org.loon.framework.game.simple.window.LSelect; /** * 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 HelloJavaGame11 extends Screen { // 默认场景特效为[雨] private FreedomEffect effect = FreedomEffect.getRainEffect(); private Image image = MessageFormDialog.getRMXPDialog("images/window.png", 280, 200); private Image image1 = MessageFormDialog.getRMXPloadBuoyage( "images/window.png", 230, 40); public HelloJavaGame11() { // 设定当前Screen背景图片 this.setBackground("images/background.jpg"); // 加载场景特效 add(effect); // 构建一个LSelect,背景图选用image LSelect select = new LSelect(image) { public void doClick() { switch (getResultIndex()) { case 0: effect.setKernels(FreedomEffect.getRainEffect(200) .getKernels()); break; case 1: effect.setKernels(FreedomEffect.getSnowEffect(60) .getKernels()); break; case 2: setVisible(false); break; } } }; // 加载选择项后浮标(非必须) select.setBuoyage(image1); // 不锁定界面,允许拖拽 select.setLocked(false); select.setMessage("你想要什么天气?", new String[] { "细雨绵绵", "瑞雪丰年", "关闭菜单" }); // 居中 centerOn(select); add(select); } 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) { // 以Ioc方式构建一个游戏初始设置(示例用,非必要) try { // 构造函数,依次为窗体名称、加载模式(AWT/Swing)、窗体宽、窗体高 Object[] constructor = { "[LGame-simple版使用范例]-LSelect的使用", new Integer(Model.Awt), new Integer(480), new Integer(360) }; // 绑定指定类及构造函数 Ioc ioc = IocFactory.bind( "org.loon.framework.game.simple.GameScene", constructor); // 获得下级类Deploy Ioc child = ioc.getChild("getDeploy"); // 设置Deploy child.setMethod("setScreen", Reflector.getReflector( HelloJavaGame11.class).newInstance()); child.setMethod("setLogo", false); child.setMethod("setFPS", 100L); child.setMethod("setShowFPS", true); // 启动主循环 child.doInvoke("mainLoop"); // 显示窗体 ioc.doInvoke("showFrame"); } catch (Exception e) { e.printStackTrace(); } } }

LButton图片应用


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.action.sprite.SpriteImage; import org.loon.framework.game.simple.core.Model; import org.loon.framework.game.simple.core.Screen; import org.loon.framework.game.simple.utils.GraphicsUtils; import org.loon.framework.game.simple.utils.ioc.Ioc; import org.loon.framework.game.simple.utils.ioc.IocFactory; import org.loon.framework.game.simple.utils.ioc.reflect.Reflector; 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:ceponline@yahoo.com.cn * @version 0.1 */ public class HelloJavaGame12 extends Screen { // loadDoubleFilterImage用以处理NScripter使用的黑白背景过滤方式 private Image role1 = GraphicsUtils .loadDoubleFilterImage("images/role1.jpg"); public HelloJavaGame12() { setBackground("images/background1.jpg"); // 加载一个图片精灵 SpriteImage sprite1 = new SpriteImage(role1, 0, 0); add(sprite1); // 插入一个感叹号按钮,不显示文字,图片拆分方式为宽40,高39,初始坐标 x=0,y=0 LButton button = new LButton("images/a.png", null, 40, 39, 0, 0); button.setToolTipText("看什么看,没见过宁波大学毕业的吗?"); button.setLocation(sprite1.getWidth()/2, sprite1.getHeight()/2); // 添加按钮 add(button); // 插入一个门按钮,不显示文字,图片拆分方式为宽60,高89,初始坐标 x=0,y=0 LButton button1 = new LButton("images/door.png", null, 60, 89, 0, 0); button1.setToolTipText("离开游戏"); bottomOn(button1); button1.setLocation(button1.getX()-100, button1.getY()); add(button1); LButton button2 = new LButton("images/go_l.png", null, 84, 63, 0, 0); button2.setLocation(button1.getX()+button1.getWidth(), button1.getY()); button2.setToolTipText("事件向前"); add(button2); LButton button3 = new LButton("images/go_r.png", null, 84, 63, 0, 0); button3.setLocation(button2.getX()+button2.getWidth(), button1.getY()); button3.setToolTipText("事件向后"); add(button3); LButton button4 = new LButton("images/people.png", null, 80, 77, 0, 0); button4.setLocation(button3.getX()+button3.getWidth(), button1.getY()); button4.setToolTipText("人物状态"); add(button4); } public void draw(Graphics2D g) { } public void leftClick(MouseEvent e) { } public void middleClick(MouseEvent e) { } public void onKey(KeyEvent e) { } public void onKeyUp(KeyEvent e) { } public void rightClick(MouseEvent e) { } public static void main(String[] args) { // 以Ioc方式构建一个游戏初始设置(示例用,非必要) try { // 构造函数,依次为窗体名称、加载模式(AWT/Swing)、窗体宽、窗体高 Object[] constructor = { "[LGame-simple版使用范例]-LButton图片应用", new Integer(Model.Awt), new Integer(480), new Integer(360) }; // 绑定指定类及构造函数 Ioc ioc = IocFactory.bind( "org.loon.framework.game.simple.GameScene", constructor); // 获得下级类Deploy Ioc child = ioc.getChild("getDeploy"); // 设置Deploy child.setMethod("setScreen", Reflector.getReflector( HelloJavaGame12.class).newInstance()); child.setMethod("setLogo", false); child.setMethod("setFPS", 100L); child.setMethod("setShowFPS", true); // 启动主循环 child.doInvoke("mainLoop"); // 显示窗体 ioc.doInvoke("showFrame"); } catch (Exception e) { e.printStackTrace(); } } }

图片渐变应用

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.action.sprite.effect.PShadowEffect; import org.loon.framework.game.simple.core.Model; import org.loon.framework.game.simple.core.Screen; import org.loon.framework.game.simple.utils.ioc.Ioc; import org.loon.framework.game.simple.utils.ioc.IocFactory; import org.loon.framework.game.simple.utils.ioc.reflect.Reflector; /** * 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 HelloJavaGame13 extends Screen { private int index = 0; private String[] list = new String[] { "n1.png", "n2.png", "n3.png", "n4.png", "n5.png" }; private PShadowEffect shadow; public HelloJavaGame13() { setBackground("images/background1.jpg"); } public void draw(Graphics2D g) { } // 当点击屏幕时,开始自动变更过滤图像 public void leftClick(MouseEvent e) { if (shadow == null) { shadow = new PShadowEffect("images/" + list[index++]); add(shadow); } if (shadow.isComplete()) { if (index >= list.length) { index = 0; } remove(shadow); shadow = new PShadowEffect("images/" + list[index++]); // 调节过渡速度 // shadow.setDelay(60); add(shadow); } } public void middleClick(MouseEvent e) { } public void onKey(KeyEvent e) { } public void onKeyUp(KeyEvent e) { } public void rightClick(MouseEvent e) { } public static void main(String[] args) { // 以Ioc方式构建一个游戏初始设置(示例用,非必要) try { // 构造函数,依次为窗体名称、加载模式(AWT/Swing)、窗体宽、窗体高 Object[] constructor = { "[LGame-simple版使用范例]-图片渐变应用", new Integer(Model.Awt), new Integer(480), new Integer(360) }; // 绑定指定类及构造函数 Ioc ioc = IocFactory.bind( "org.loon.framework.game.simple.GameScene", constructor); // 获得下级类Deploy Ioc child = ioc.getChild("getDeploy"); // 设置Deploy child.setMethod("setScreen", Reflector.getReflector( HelloJavaGame13.class).newInstance()); child.setMethod("setLogo", false); child.setMethod("setFPS", 100L); child.setMethod("setShowFPS", true); // 启动主循环 child.doInvoke("mainLoop"); // 显示窗体 ioc.doInvoke("showFrame"); } catch (Exception e) { e.printStackTrace(); } } }

Lua脚本应用

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.core.Model; import org.loon.framework.game.simple.core.Screen; import org.loon.framework.game.simple.extend.command.lua.LUAEngine; import org.loon.framework.game.simple.utils.ioc.Ioc; import org.loon.framework.game.simple.utils.ioc.IocFactory; import org.loon.framework.game.simple.utils.ioc.reflect.Reflector; 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 HelloJavaGame14 extends Screen { private LMessage message = new LMessage(0, 0, 300, 300); public HelloJavaGame14() { this.setBackground("images/background.jpg"); this.message.setMessage("数据测试"); // 初始化Lua引擎 LUAEngine.begine(); this.centerOn(message); this.add(message); } public void draw(Graphics2D g) { } // 加载脚本hello1 public void leftClick(MouseEvent e) { // 加载world.lua脚本并返回运算结果 LUAEngine.runLuaFile("images/hello1.lua"); message.setMessage(LUAEngine .executeLuaFunctionWithStringReturn("message")); } // 加载脚本hello public void rightClick(MouseEvent e) { // 加载hello.lua脚本并返回变量message LUAEngine.runLuaFile("images/hello.lua"); message.setMessage(LUAEngine.getGlobalString("message")); } // 加载脚本swing public void middleClick(MouseEvent e) { LUAEngine.runLuaFile("images/swing.lua"); } public void onKey(KeyEvent e) { } public void onKeyUp(KeyEvent e) { } public static void main(String[] args) { // 以Ioc方式构建一个游戏初始设置(示例用,非必要) try { // 构造函数,依次为窗体名称、加载模式(AWT/Swing)、窗体宽、窗体高 Object[] constructor = { "[LGame-simple版使用范例]-Lua脚本的应用", new Integer(Model.Awt), new Integer(480), new Integer(360) }; // 绑定指定类及构造函数 Ioc ioc = IocFactory.bind( "org.loon.framework.game.simple.GameScene", constructor); // 获得下级类Deploy Ioc child = ioc.getChild("getDeploy"); // 设置Deploy child.setMethod("setScreen", Reflector.getReflector( HelloJavaGame14.class).newInstance()); child.setMethod("setLogo", false); child.setMethod("setFPS", 100L); child.setMethod("setShowFPS", true); // 启动主循环 child.doInvoke("mainLoop"); // 显示窗体 ioc.doInvoke("showFrame"); } catch (Exception e) { e.printStackTrace(); } } }

以下为LGame-Simple部分示例截图:

下载地址(内含源码与示例)http://loon-simple.googlecode.com/files/LGame-Simple-0.2.0.7z

______________分割啊,分割啊_________________

最近对PC怨念了,开始拿起PSP磕游戏王5D'S中……另外偶写起了LGame的android版,预计年底前能够开源测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值