设计游戏我个人认为一个好的角色操作将事半工倍。所以我现在把雷电的所有角色抽象成一个Fairy。里面有实现绘制的方法以及移动,碰撞算法。
在这里我强调下,我的碰撞算法是简单的实现。就是一个物体为参照物体。在10像素范围内x,y轴如果发现另外一个物体侵入则判断为true,发之为false
java 代码
-
- package org.wuhua.game.model;
-
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
-
- import org.wuhua.game.util.Log;
-
- /**
- * 类名:Sprite.java
- * 编写日期: 2006-11-29
- * 程序功能描述:建立精灵物体模型
- * Demo:
- * Bug:
- *
- * 程序变更日期 :
- * 变更作者 :
- * 变更说明 :
- *
- * @author wuhua
- */
- public class Fairy {
- static Log log = Log.getLog("Fairy");
- /**
- * position of Fairy in x offset
- */
- int x; // = 0;
-
- /**
- * position of Fairy in y offset
- */
- int y; // = 0;
-
- /**
- * width of layer
- */
- int width; // = 0;
-
- /**
- * height of layer
- */
- int height; // = 0;
-
- /**
- * If the Layer is visible it will be drawn when
paint
- * is called.
- */
- boolean visible = true;
-
- /**
- * 图片资源
【编辑推荐】
- RPG游戏脚本的设计教程
- J2ME游戏开发的高级优化技巧
- j2me游戏引擎程序结构
- 俄罗斯方块游戏的设计和实现(MIDP)