Skip to content

Commit

Permalink
增加爆炸特效
Browse files Browse the repository at this point in the history
新增drawExplosion/ctlExplosion特效类
  • Loading branch information
3125788 committed Nov 21, 2013
1 parent 4259b5c commit 3eb3cc9
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 16 deletions.
29 changes: 15 additions & 14 deletions gen/elong/CrazyLink/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ public static final class drawable {
public static final int animal=0x7f020000;
public static final int animal_bak=0x7f020001;
public static final int autotip=0x7f020002;
public static final int grid=0x7f020003;
public static final int icon=0x7f020004;
public static final int loading_01=0x7f020005;
public static final int loading_02=0x7f020006;
public static final int loading_03=0x7f020007;
public static final int loading_04=0x7f020008;
public static final int loading_05=0x7f020009;
public static final int loading_06=0x7f02000a;
public static final int loading_07=0x7f02000b;
public static final int loading_08=0x7f02000c;
public static final int loading_09=0x7f02000d;
public static final int loading_10=0x7f02000e;
public static final int number=0x7f02000f;
public static final int word=0x7f020010;
public static final int explosion=0x7f020003;
public static final int grid=0x7f020004;
public static final int icon=0x7f020005;
public static final int loading_01=0x7f020006;
public static final int loading_02=0x7f020007;
public static final int loading_03=0x7f020008;
public static final int loading_04=0x7f020009;
public static final int loading_05=0x7f02000a;
public static final int loading_06=0x7f02000b;
public static final int loading_07=0x7f02000c;
public static final int loading_08=0x7f02000d;
public static final int loading_09=0x7f02000e;
public static final int loading_10=0x7f02000f;
public static final int number=0x7f020010;
public static final int word=0x7f020011;
}
public static final class layout {
public static final int main=0x7f030000;
Expand Down
Binary file added res/drawable-nodpi/explosion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/elong/CrazyLink/Control/CtlExplosion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**********************************************************
* 项目名称:山寨“爱消除”游戏7日教程
* 作 者:郑敏新
* 腾讯微博:SuperCube3D
* 日 期:2013年11月
* 声 明:版权所有 侵权必究
* 本源代码供网友研究学习OpenGL ES开发Android应用用,
* 请勿全部或部分用于商业用途
********************************************************/

package elong.CrazyLink.Control;


//自动提示效果
public class CtlExplosion extends CtlBase{

int mPicId = 1;
int mTimeCnt = 0;

public void run()
{
if(mStop) return;
mTimeCnt++;
if (1 == (mTimeCnt % 2)) return; //降频
mPicId++;
if (mPicId > 10) mPicId = 1;
}

public int getPicId()
{
return mPicId;
}

public void start()
{
mStop = false;
}

public void end()
{
mStop = true;
}

public boolean isRun()
{
return !mStop;
}
}

12 changes: 11 additions & 1 deletion src/elong/CrazyLink/Core/ControlCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import elong.CrazyLink.Control.CtlTip1;
import elong.CrazyLink.Draw.DrawAnimal;
import elong.CrazyLink.Draw.DrawAutoTip;
import elong.CrazyLink.Draw.DrawExplosion;
import elong.CrazyLink.Draw.DrawSingleScore;
import elong.CrazyLink.Draw.DrawTip1;
import elong.CrazyLink.Draw.DrawDisappear;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class ControlCenter {
int scoreTextureId;
int congratulationTextureId;
int fireTextureId;
int explosionTextureId;

static int mAutoTipTimer = 0; //自动提示计时器

Expand All @@ -70,6 +72,7 @@ public class ControlCenter {
static public DrawSingleScore drawSingleScore;
static public DrawTip1 drawTip1;
static public DrawAutoTip drawAutoTip;
static public DrawExplosion drawExplosion;


static Score mScore; //计算分数
Expand Down Expand Up @@ -239,6 +242,7 @@ static void markInLine()
if (markCount > 0)
{
drawDisappear.control.start();
drawExplosion.control.start();
mScore.increase();
mScore.increase(markCount);
}
Expand Down Expand Up @@ -449,16 +453,19 @@ void autoTip()
//将可以自动提示的动物标识出来
static void markAutoTip()
{
boolean isAutoTip = false;
for(int i = 0; i < (int)CrazyLinkConstent.GRID_NUM; i++)
{
for(int j = 0; j < (int)CrazyLinkConstent.GRID_NUM; j++)
{
if (isInLine(mPicBak, i, j))
{
mStatus[i][j] = EFT_AUTOTIP;
isAutoTip = true;
}
}
}
if(isAutoTip) drawAutoTip.control.start();
}

//将自动提示标识清除
Expand Down Expand Up @@ -486,7 +493,6 @@ public void draw(GL10 gl)

drawScore.draw(gl,mScore.getScore());
drawSingleScore.draw(gl, mSingleScoreW, mSingleScoreH, mScore.getAward());
drawAutoTip.control.start();
drawTip1.draw(gl);
for(int i = 0; i < (int)CrazyLinkConstent.GRID_NUM; i++)
{
Expand All @@ -504,6 +510,7 @@ public void draw(GL10 gl)
drawFill.draw(gl, mPic[i][j], i, j);
break;
case EFT_DISAPPEAR: //消除特效
drawExplosion.draw(gl, i, j);
drawDisappear.draw(gl, mPic[i][j], i, j);
break;
case EFT_AUTOTIP: //自动提示特效
Expand All @@ -528,6 +535,7 @@ public void initTexture(GL10 gl)
scoreTextureId = initTexture(gl, R.drawable.number);
congratulationTextureId = initTexture(gl, R.drawable.word);
fireTextureId = initTexture(gl, R.drawable.autotip);
explosionTextureId = initTexture(gl, R.drawable.explosion);
}

//初始化渲染对象
Expand All @@ -543,6 +551,7 @@ public void initDraw(GL10 gl)
drawLoading = new DrawLoading(loadingTextureId); //创建加载动画素材
drawExchange = new DrawExchange(drawAnimal);
drawAutoTip = new DrawAutoTip(fireTextureId);
drawExplosion = new DrawExplosion(explosionTextureId);

//将渲染类的控制对象注册到控制中心列表
controlRegister(drawDisappear.control);
Expand All @@ -552,6 +561,7 @@ public void initDraw(GL10 gl)
controlRegister(drawSingleScore.control);
controlRegister(drawTip1.control);
controlRegister(drawAutoTip.control);
controlRegister(drawExplosion.control);
}

//初始化纹理的方法
Expand Down
2 changes: 1 addition & 1 deletion src/elong/CrazyLink/Draw/DrawAutoTip.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void initVertexBuffer(int col, int row)
//顶点纹理数据的初始化
private void initTextureBuffer(int witch)
{
textureRatio = (float)(1/8.0f); //图片是(7+1)个独立的素材对象组成,每次需要根据witch准确地获取对应的素材
textureRatio = (float)(1/4.0f); //图片是4个独立的素材对象组成,每次需要根据witch准确地获取对应的素材
float textureCoors[]=new float[] //顶点纹理S、T坐标值数组
{
(witch - 1) * textureRatio,0,
Expand Down
138 changes: 138 additions & 0 deletions src/elong/CrazyLink/Draw/DrawExplosion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**********************************************************
* 项目名称:山寨“爱消除”游戏7日教程
* 作 者:郑敏新
* 腾讯微博:SuperCube3D
* 日 期:2013年11月
* 声 明:版权所有 侵权必究
* 本源代码供网友研究学习OpenGL ES开发Android应用用,
* 请勿全部或部分用于商业用途
********************************************************/


package elong.CrazyLink.Draw;


import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import elong.CrazyLink.CrazyLinkConstent;
import elong.CrazyLink.Control.CtlExplosion;
import elong.CrazyLink.Interface.IControl;

import javax.microedition.khronos.opengles.GL10;

public class DrawExplosion {

private IntBuffer mVertexBuffer; //顶点坐标数据缓冲
private FloatBuffer mTextureBuffer; //顶点纹理数据缓冲
int vCount=0; //顶点数量
int textureId; //纹理索引
float textureRatio; //为了准确获取纹理图片中的素材对象,需要设置纹理的变换率

public IControl control;

public DrawExplosion(int textureId)
{
this.textureId=textureId;
control = new CtlExplosion();
}
//顶点坐标数据的初始化
private void initVertexBuffer(int col, int row)
{

vCount=6;//顶点的数量,一个正方形用两个三角形表示,共需要6个顶点
int deltaX = ((col-3)*64*CrazyLinkConstent.UNIT_SIZE);
int deltaY = ((row-3)*64*CrazyLinkConstent.UNIT_SIZE);
int vertices[]=new int[]//顶点坐标数据数组
{
-32*CrazyLinkConstent.UNIT_SIZE+deltaX,32*CrazyLinkConstent.UNIT_SIZE+deltaY,0,
-32*CrazyLinkConstent.UNIT_SIZE+deltaX,-32*CrazyLinkConstent.UNIT_SIZE+deltaY,0,
32*CrazyLinkConstent.UNIT_SIZE+deltaX,-32*CrazyLinkConstent.UNIT_SIZE+deltaY,0,
32*CrazyLinkConstent.UNIT_SIZE+deltaX,-32*CrazyLinkConstent.UNIT_SIZE+deltaY,0,
32*CrazyLinkConstent.UNIT_SIZE+deltaX,32*CrazyLinkConstent.UNIT_SIZE+deltaY,0,
-32*CrazyLinkConstent.UNIT_SIZE+deltaX,32*CrazyLinkConstent.UNIT_SIZE+deltaY,0
};
//创建顶点坐标数据缓冲
//int类型占用4个字节,因此转换为byte的数据时需要*4
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder()); //设置本地的字节顺序
//特别提示:由于不同平台字节顺序不同数据单元不是字节的一定要经过ByteBuffer
//转换,关键是要通过ByteOrder设置nativeOrder(),否则有可能会出问题
mVertexBuffer = vbb.asIntBuffer(); //转换为int型缓冲
mVertexBuffer.put(vertices); //向缓冲区中放入顶点坐标数据
mVertexBuffer.position(0); //设置缓冲区起始位置
return;
}

//顶点纹理数据的初始化
private void initTextureBuffer(int witch)
{
textureRatio = (float)(1/10.0f); //图片是10个独立的素材对象组成,每次需要根据witch准确地获取对应的素材
float textureCoors[]=new float[] //顶点纹理S、T坐标值数组
{
(witch - 1) * textureRatio,0,
(witch - 1) * textureRatio,1,
witch * textureRatio,1,
witch * textureRatio,1,
witch * textureRatio,0,
(witch - 1) * textureRatio,0
};

//创建顶点纹理数据缓冲
//int类型占用4个字节,因此转换为byte的数据时需要*4
ByteBuffer cbb = ByteBuffer.allocateDirect(textureCoors.length*4);
cbb.order(ByteOrder.nativeOrder());//设置本地字节顺序
//特别提示:由于不同平台字节顺序不同数据单元不是字节的一定要经过ByteBuffer
//转换,关键是要通过ByteOrder设置nativeOrder(),否则有可能会出问题
mTextureBuffer = cbb.asFloatBuffer();//转换为int型缓冲
mTextureBuffer.put(textureCoors);//向缓冲区中放入顶点着色数据
mTextureBuffer.position(0);//设置缓冲区起始位置
return;
}


public void draw(GL10 gl, int col, int row)
{
if (!control.isRun()) return;
CtlExplosion ctl = (CtlExplosion)control;
int witch = ctl.getPicId();
initVertexBuffer(col, row); //根据col,row初始化顶点坐标
initTextureBuffer(witch); //根据witch来初始化纹理顶点数据
//gl.glTranslatef(col * textureRatio, row * textureRatio, 0); //在x=col,y=row的位置绘制选定的素材对象
//顶点坐标,允许使用顶点数组
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
//为画笔指定顶点坐标数据
gl.glVertexPointer
(
3, //每个顶点的坐标数量为3 xyz
GL10.GL_FIXED, //顶点坐标值的类型为 GL_FIXED
0, //连续顶点坐标数据之间的间隔
mVertexBuffer //顶点坐标数据
);

//纹理坐标,开启纹理
gl.glEnable(GL10.GL_TEXTURE_2D);
//允许使用纹理数组
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
//为画笔指定纹理uv坐标数据
gl.glTexCoordPointer
(
2, //每个顶点两个纹理坐标数据 S、T
GL10.GL_FLOAT, //数据类型
0, //连续纹理坐标数据之间的间隔
mTextureBuffer //纹理坐标数据
);
gl.glBindTexture(GL10.GL_TEXTURE_2D,textureId);//为画笔绑定指定名称ID纹理

//绘制图形
gl.glDrawArrays
(
GL10.GL_TRIANGLES,
0,
vCount
);
gl.glDisable(GL10.GL_TEXTURE_2D);//关闭纹理
}
}

0 comments on commit 3eb3cc9

Please sign in to comment.