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的境界了≡(▔﹏▔)≡

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

Java游戏开发组件LGame简易测试版发布(版本号 0 1 5)相关推荐

  1. Java游戏开发框架LGame-0 2 8版发布(含JavaSE及Android版,已有文档)

    LGame是LoonFramework框架的一部分,也可简称做"LF"或"Loon". LGame框架的创立初衷在于,构建一个高效且完善的Java游戏开发体系, ...

  2. java游戏开发杂谈 - 实现游戏主菜单

    经常玩游戏的同学,大家都知道,游戏都会有个主菜单,里面有多个菜单选项:开始游戏.游戏设置.关于游戏.退出游戏等等,这个菜单是怎么实现的呢. 有一定桌面软件开发基础的同学可能会想到,用JButton组件 ...

  3. Java游戏开发框架LGame-0.2.8版发布(含JavaSE及Android版,已有文档)

    LGame是LoonFramework框架的一部分,也可简称做"LF"或"Loon". LGame框架的创立初衷在于,构建一个高效且完善的Java游戏开发体系, ...

  4. java游戏开发(java游戏开发教程)

    Java游戏开发绘图器是什么呢? 众所周知,Java GUI以paint进行绘图,以repaint进行图像刷新,而完成repaint及paint这一连贯过程中所用到绘图组件,我将其称为绘图器.就我个人 ...

  5. Java游戏开发前景

    Java游戏开发前景如何?Java游戏开发曾经伴随着诺基亚的辉煌,Java游戏开发行业也是如火如荼,如日中天.但是现在随着诺基亚的地位一去不复返,Java游戏开发行业的曾经的火热也一去不复返,很多从事 ...

  6. 【源码+图片素材+详细教程】Java游戏开发_Java开发经典游戏飞翔的小鸟_飞扬的小鸟_Java游戏项目Flappy Bird像素鸟游戏_Java课程设计项目

    课程目标: 1.通过本课程的学习巩固Java的相关基础知识,例如循环判断,数组和集合的使用,对象的继承,接口的实现,窗口的创建,事件监听,图形绘制. 2.完成小鸟的移动,管道自动生成.碰撞死亡,计分系 ...

  7. java游戏开发杂谈 - 游戏编程浅析

    每个游戏,你所看到的它的一切,都是计算机画出来的! 地图是画出来,人物是画出来的,树木建筑是画出来的,菜单按钮是画出来的,滚动的文字.闪烁的图标.云雾烟火,都是画出来的. 游戏编程,所要做的,就是控制 ...

  8. java游戏开发入门(十) -粒子特效

    java游戏开发入门十 - 粒子特效 java游戏开发入门十 - 粒子特效 前言 编码 创建一个粒子发射器,并将粒子发射器添加到实体对象 效果图 完整代码 完整项目 java游戏开发入门十 - 粒子特 ...

  9. 三七互娱 Java游戏开发工程师 面试(两轮技术+HR面)

    (2020春招补招,已拿到offer) 抱着投着试试看的心态去的 自己还是不太了解游戏开发 框架啊这些都没怎么问 比较重视基础知识,面的也基本都是基础知识 所以面完才发现自己太基础的知识反而一问三不知 ...

最新文章

  1. 一个复杂系统的拆分改造实践!
  2. 实践指南 | 用PyTea检测 PyTorch 中的张量形状错误
  3. 汽车保险解读:解析涉水损失险与自燃险
  4. maven 包的导入
  5. 如何启用SAP CRM text的html编辑器
  6. 自定义标签 —— 实现时间转换和输出功能
  7. 《天天数学》连载46:二月十五日
  8. Python+matplotlib自定义坐标轴位置、颜色、箭头
  9. Mina的TCP的主要接口
  10. spring cloud构建互联网分布式微服务云平台-服务提供与调用
  11. 使用OpenCV调整图像的亮度和对比度
  12. vue 项目 跨域问题
  13. 赛门铁克完成收购Blue Coat 重塑未来网络安全
  14. xss.haozi.me通关记录
  15. Jenkins配置-腾讯企业微信邮箱
  16. 天坑专业成功跨考计算机,研0渣渣前来报到
  17. Qt浅谈之三十系统托盘(QSystemTrayIcon)
  18. android 百度地图3.0定位,百度地图定位功能实现v3_0_0
  19. BarTender 打印机的控制详解
  20. 【万字长文+100余张图】轻松搞定Unix/Linux环境使用,建议收藏!

热门文章

  1. 【Python】利用Python实现精准三点定位(经纬度坐标与平面坐标转换法求解)
  2. 无刷直流电机(BLDC)无传感器控制,采用的是容积卡尔曼观测,能够很好的估计转速和转子位置,有对应的simulink文件跟ckf代码
  3. 明星热图|杨洋、蔡徐坤、关晓彤、翟潇闻代言新品牌;高圆圆、何穗、万茜、韩东君出席品牌活动...
  4. 修复linuxwindows双系统启动项(mbrfix)
  5. File之mkdir和mkdirs
  6. requests实例3:百度360搜索引擎关键字提交
  7. 像外行一样思考,像专家一样实践
  8. php think框架,ThinkPHP框架基础知识
  9. 中学教师资格证笔试考点资料
  10. Oracle Workflow Builder 下载地址